Skip to content

Commit

Permalink
Merge pull request #1266 from bitcraze/krichardsson/lh-calib-crc
Browse files Browse the repository at this point in the history
Check CRC on LH calibration data
  • Loading branch information
ataffanel authored Apr 13, 2023
2 parents 43a45c7 + b1da931 commit d183a2c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
1 change: 0 additions & 1 deletion src/utils/interface/lighthouse/ootx_decoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ struct ootxDataFrame_s {

typedef struct ootxDecoderState_s {
int frameLength;
int bytesReceived;

uint16_t currentWord;

Expand Down
13 changes: 10 additions & 3 deletions src/utils/src/lighthouse/ootx_decoder.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include <stdint.h>

#include "ootx_decoder.h"
#include "crc32.h"

// #include "debug.h"

Expand All @@ -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)
{
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit d183a2c

Please sign in to comment.