From 3605109d256ef6dfd8f495ec51e2f24486483696 Mon Sep 17 00:00:00 2001 From: Bertrand Songis Date: Mon, 19 Nov 2018 03:41:51 +0100 Subject: [PATCH] HEAD and TAIL missing in PXX2 frames --- radio/src/pulses/pxx2.cpp | 4 +--- radio/src/pulses/pxx2.h | 43 +++++++++++++++++++++++++++++++++++++-- 2 files changed, 42 insertions(+), 5 deletions(-) diff --git a/radio/src/pulses/pxx2.cpp b/radio/src/pulses/pxx2.cpp index b57f052f3..2ae1adfd8 100644 --- a/radio/src/pulses/pxx2.cpp +++ b/radio/src/pulses/pxx2.cpp @@ -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(); } diff --git a/radio/src/pulses/pxx2.h b/radio/src/pulses/pxx2.h index 939d0204d..1ba2bc045 100644 --- a/radio/src/pulses/pxx2.h +++ b/radio/src/pulses/pxx2.h @@ -41,11 +41,16 @@ class SportCrcMixin { }; -class Pxx2Transport: public DataBuffer, public SportCrcMixin { +class Pxx2Transport: public DataBuffer, 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 { 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(); } };