Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check CRC on LH calibration data #1266

Merged
merged 1 commit into from
Apr 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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