REGISTER should be ready for tests

This commit is contained in:
Bertrand Songis
2019-02-05 17:08:09 +01:00
parent b4485ec730
commit 103eba6e63
9 changed files with 161 additions and 51 deletions
+3 -3
View File
@@ -80,7 +80,7 @@ PACK(struct ModuleSettings {
uint8_t protocol:5;
uint8_t paused:1;
uint8_t mode:2;
uint16_t failsafeCounter;
uint16_t counter;
});
extern ModuleSettings moduleSettings[NUM_MODULES];
@@ -195,12 +195,12 @@ inline bool pulsesStarted() { return moduleSettings[0].protocol != PROTOCOL_CHAN
inline void pausePulses() { s_pulses_paused = true; }
inline void resumePulses() { s_pulses_paused = false; }
#define SEND_FAILSAFE_NOW(idx) moduleSettings[idx].failsafeCounter = 1
#define SEND_FAILSAFE_NOW(idx) moduleSettings[idx].counter = 1
inline void SEND_FAILSAFE_1S()
{
for (int i=0; i<NUM_MODULES; i++) {
moduleSettings[i].failsafeCounter = 100;
moduleSettings[i].counter = 100;
}
}
+5 -5
View File
@@ -33,14 +33,14 @@ uint8_t Pxx1Pulses<PxxTransport>::addFlag1(uint8_t module)
}
else {
bool failsafeNeeded = g_model.moduleData[module].failsafeMode != FAILSAFE_NOT_SET && g_model.moduleData[module].failsafeMode != FAILSAFE_RECEIVER;
if (moduleSettings[module].failsafeCounter-- == 0) {
// failsafeCounter is also used for knowing if the frame is odd / even
moduleSettings[module].failsafeCounter = 1000;
if (moduleSettings[module].counter-- == 0) {
// counter is also used for knowing if the frame is odd / even
moduleSettings[module].counter = 1000;
if (failsafeNeeded) {
flag1 |= PXX_SEND_FAILSAFE;
}
}
if (failsafeNeeded && moduleSettings[module].failsafeCounter == 0 && g_model.moduleData[module].channelsCount > 0) {
if (failsafeNeeded && moduleSettings[module].counter == 0 && g_model.moduleData[module].channelsCount > 0) {
flag1 |= PXX_SEND_FAILSAFE;
}
}
@@ -120,7 +120,7 @@ void Pxx1Pulses<PxxTransport>::setupFrame(uint8_t module)
}
#else
uint8_t sendUpperChannels = 0;
if (moduleSettings[module].failsafeCounter & 0x01) {
if (moduleSettings[module].counter & 0x01) {
sendUpperChannels = g_model.moduleData[module].channelsCount;
}
add8ChannelsFrame(module, sendUpperChannels);
+15 -3
View File
@@ -25,8 +25,8 @@ uint8_t Pxx2Pulses::addFlag0(uint8_t module)
{
uint8_t flag0 = g_model.header.modelId[module] & 0x3F;
if (g_model.moduleData[module].failsafeMode != FAILSAFE_NOT_SET && g_model.moduleData[module].failsafeMode != FAILSAFE_RECEIVER) {
if (moduleSettings[module].failsafeCounter-- == 0) {
moduleSettings[module].failsafeCounter = 1000;
if (moduleSettings[module].counter-- == 0) {
moduleSettings[module].counter = 1000;
flag0 |= PXX2_FLAG0_FAILSAFE;
}
}
@@ -57,8 +57,20 @@ void Pxx2Pulses::setupChannelsFrame(uint8_t module)
void Pxx2Pulses::setupRegisterFrame(uint8_t module)
{
unsigned counter = moduleSettings[module].counter;
addFrameType(PXX2_TYPE_C_MODULE, PXX2_TYPE_ID_REGISTER);
Pxx2Transport::addByte(0);
if (counter == REGISTER_COUNTER_ID_RECEIVED) {
Pxx2Transport::addByte(1);
for (uint8_t i=0; i<4; i++) {
Pxx2Transport::addByte(g_model.modelRegistrationID[i]);
}
}
else {
addFrameType(PXX2_TYPE_C_MODULE, PXX2_TYPE_ID_REGISTER);
Pxx2Transport::addByte(0);
}
}
void Pxx2Pulses::setupBindFrame(uint8_t module)
+40
View File
@@ -21,10 +21,13 @@
#ifndef _PULSES_PXX2_H_
#define _PULSES_PXX2_H_
#include "fifo.h"
#include "./pxx.h"
#define PXX2_TYPE_C_MODULE 0x01
#define PXX2_TYPE_ID_REGISTER 0x01
#define REGISTER_COUNTER_ID_RECEIVED 1001
#define REGISTER_COUNTER_PASSWORD_RECEIVED 1002
#define PXX2_TYPE_ID_BIND 0x02
#define PXX2_TYPE_ID_CHANNELS 0x03
#define PXX2_TYPE_ID_SPORT 0xFE
@@ -35,6 +38,43 @@
#define PXX2_FLAG0_FAILSAFE (1 << 6)
class ModuleFifo : public Fifo<uint8_t, 32> {
public:
bool getFrame(uint8_t * frame)
{
while (1) {
if (isEmpty()) {
return false;
}
else if (fifo[ridx] != 0xFE) {
skip();
}
else {
break;
}
}
uint32_t next = nextIndex(ridx);
uint8_t len = fifo[next];
if (size() < unsigned(len + 4 /* 2 bytes header + 2 bytes CRC */)) {
return false;
}
for (uint32_t i=0; i<len; i++) {
next = nextIndex(next);
frame[i] = fifo[next];
}
// TODO CRC CHECK
next = nextIndex(next);
next = nextIndex(next);
ridx = nextIndex(next);
return true;
}
};
extern ModuleFifo intmoduleFifo;
// should not be used anymore
class SportCrcMixin {