diff --git a/src/utils/interface/lighthouse/ootx_decoder.h b/src/utils/interface/lighthouse/ootx_decoder.h index 9a775d49bf..6797fd348f 100644 --- a/src/utils/interface/lighthouse/ootx_decoder.h +++ b/src/utils/interface/lighthouse/ootx_decoder.h @@ -66,7 +66,6 @@ struct ootxDataFrame_s { typedef struct ootxDecoderState_s { int frameLength; - int bytesReceived; uint16_t currentWord; diff --git a/src/utils/src/lighthouse/ootx_decoder.c b/src/utils/src/lighthouse/ootx_decoder.c index 41c12bc98a..da7ae17a36 100644 --- a/src/utils/src/lighthouse/ootx_decoder.c +++ b/src/utils/src/lighthouse/ootx_decoder.c @@ -33,6 +33,7 @@ #include #include "ootx_decoder.h" +#include "crc32.h" // #include "debug.h" @@ -41,6 +42,12 @@ uint16_t betole(uint16_t value) return ((value&0xff00u)>>8) | ((value&0xffu)<<8); } +static bool checkCrc(const ootxDecoderState_t* state) { + const uint32_t crc32 = crc32CalculateBuffer(state->data, state->frameLength); + const bool isCrcCheckOk = (crc32 == state->crc32); + return isCrcCheckOk; +} + // Frame format described there: https://github.com/nairol/LighthouseRedox/blob/master/docs/Light%20Emissions.md#ootx-frame bool ootxDecoderProcessBit(ootxDecoderState_t * state, int data) { @@ -75,11 +82,11 @@ bool ootxDecoderProcessBit(ootxDecoderState_t * state, int data) state->bitInWord = 0; // At the stuffing bit after CRC1, we are done! - // TODO: Check CRC! if (state->rxState == rxDone) { + const bool isDataValid = checkCrc(state); + state->isFullyDecoded = isDataValid; state->synchronized = false; - state->isFullyDecoded = true; - return true; + return isDataValid; } else { state->isFullyDecoded = false; return false;