Skip to content

Commit f421d8e

Browse files
authored
Merge pull request #175 from MDLZCOOL/refactor-crc8-dvb-s2-func
Refactor crc8_dvb_s2 Function for Improved Readability and Maintainability
2 parents fb2fc17 + 14865b4 commit f421d8e

File tree

1 file changed

+4
-11
lines changed

1 file changed

+4
-11
lines changed

lib/MSP/msp.cpp

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include "msp.h"
22

33
#include "logging.h"
4+
#include "crc.h"
45

56
/* ==========================================
67
MSP V2 Message Structure:
@@ -16,19 +17,11 @@ Offset: Usage: In CRC: Comment:
1617
n+8 checksum uint8, (n= payload size), crc8_dvb_s2 checksum
1718
========================================== */
1819

19-
// CRC helper function. External to MSP class
20-
// TODO: Move all our CRC functions to a CRC lib
20+
// CRC helper function.
2121
uint8_t crc8_dvb_s2(uint8_t crc, unsigned char a)
2222
{
23-
crc ^= a;
24-
for (int ii = 0; ii < 8; ++ii) {
25-
if (crc & 0x80) {
26-
crc = (crc << 1) ^ 0xD5;
27-
} else {
28-
crc = crc << 1;
29-
}
30-
}
31-
return crc;
23+
static GENERIC_CRC8 crc8_dvb_s2_instance(0xD5);
24+
return crc8_dvb_s2_instance.calc(crc ^ a);
3225
}
3326

3427
MSP::MSP() : m_inputState(MSP_IDLE)

0 commit comments

Comments
 (0)