HEAD and TAIL missing in PXX2 frames

This commit is contained in:
Bertrand Songis
2018-11-28 16:53:18 +01:00
parent ab64360232
commit 3605109d25
2 changed files with 42 additions and 5 deletions
+1 -3
View File
@@ -24,7 +24,6 @@
void Pxx2Pulses::setupFrame(uint8_t port)
{
initFrame();
initCrc();
static uint8_t pass[NUM_MODULES] = { MODULES_INIT(0) };
uint8_t sendUpperChannels = 0;
@@ -55,6 +54,5 @@ void Pxx2Pulses::setupFrame(uint8_t port)
}
#endif
// CRC
addByte(crc); // TODO need to check the CRC chosen algorithm
endFrame();
}
+41 -2
View File
@@ -41,11 +41,16 @@ class SportCrcMixin {
};
class Pxx2Transport: public DataBuffer<uint8_t, 64>, public SportCrcMixin {
class Pxx2Transport: public DataBuffer<uint8_t, 64>, public PxxCrcMixin {
protected:
void addByte(uint8_t byte)
{
SportCrcMixin::addToCrc(byte);
PxxCrcMixin::addToCrc(byte);
addByteWithoutCrc(byte);
};
void addByteWithoutCrc(uint8_t byte)
{
*ptr++ = byte;
}
@@ -63,9 +68,43 @@ class Pxx2Pulses: public PxxPulses<Pxx2Transport> {
uint8_t data[64];
uint8_t * ptr;
void addHead()
{
// send 7E, do not CRC
Pxx2Transport::addByteWithoutCrc(0x7E);
// reserve 1 byte for LEN
Pxx2Transport::addByteWithoutCrc(0x00);
// TYPE_C + TYPE_ID
Pxx2Transport::addByte(0x26); // This one is CRC-ed on purpose
}
void addCrc()
{
Pxx2Transport::addByteWithoutCrc(PxxCrcMixin::crc >> 8);
Pxx2Transport::addByteWithoutCrc(PxxCrcMixin::crc);
}
void initFrame()
{
// init the CRC counter
initCrc();
// reset the frame pointer
Pxx2Transport::initBuffer();
// add the frame head
addHead();
}
void endFrame()
{
// update the frame LEN = frame length minus the 2 first bytes
data[1] = getSize() - 2;
// now add the CRC
addCrc();
}
};