1
0
Fork 0
mirror of https://github.com/iNavFlight/inav.git synced 2025-07-25 09:16:01 +03:00

Revert "Improve FrSky's CRC lib"

This commit is contained in:
Konstantin Sharlaimov 2020-05-09 09:13:51 +02:00 committed by GitHub
parent 4da9245588
commit c0a87cdcc2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 15 deletions

View file

@ -255,7 +255,7 @@ static uint8_t fportFrameStatus(rxRuntimeConfig_t *rxRuntimeConfig)
if (frameLength != bufferLength - 2) {
reportFrameError(DEBUG_FPORT_ERROR_SIZE);
} else {
if (!frskyCheckSumIsGood(&rxBuffer[rxBufferReadIndex].data[0], bufferLength)) {
if (!frskyChecksumIsGood(&rxBuffer[rxBufferReadIndex].data[0], bufferLength)) {
reportFrameError(DEBUG_FPORT_ERROR_CHECKSUM);
} else {
fportFrame_t *frame = (fportFrame_t *)&rxBuffer[rxBufferReadIndex].data[1];

View file

@ -26,29 +26,22 @@ FILE_COMPILE_FOR_SPEED
void frskyCheckSumStep(uint16_t *checksum, uint8_t byte)
{
*checksum += byte;
*checksum += (*checksum >> 8);
*checksum &= 0xFF;
}
void frskyCheckSumFini(uint16_t *checksum)
{
while (*checksum > 0xFF) {
*checksum = (*checksum & 0xFF) + (*checksum >> 8);
}
*checksum = 0xFF - *checksum;
}
uint8_t frskyCheckSum(uint8_t *data, uint8_t length)
bool frskyChecksumIsGood(uint8_t *data, uint8_t length)
{
uint16_t checksum = 0;
for (unsigned i = 0; i < length; i++) {
frskyCheckSumStep(&checksum, *data++);
}
frskyCheckSumFini(&checksum);
return checksum;
return checksum == FRSKY_CHECKSUM_GOOD_VALUE;
}
bool frskyCheckSumIsGood(uint8_t *data, uint8_t length)
{
uint16_t checksum = frskyCheckSum(data, length);
return checksum == 0xFF;
}

View file

@ -18,7 +18,8 @@
#include <stdbool.h>
#include <stdint.h>
uint8_t frskyCheckSum(uint8_t *data, uint8_t length);
bool frskyCheckSumIsGood(uint8_t *data, uint8_t length);
#define FRSKY_CHECKSUM_GOOD_VALUE 0xFF
bool frskyChecksumIsGood(uint8_t *data, uint8_t length);
void frskyCheckSumStep(uint16_t *checksum, uint8_t byte); // Add byte to checksum
void frskyCheckSumFini(uint16_t *checksum); // Finalize checksum