From 4c835a0df94529f93efcc9a7558547f29bd8248d Mon Sep 17 00:00:00 2001 From: murata Date: Tue, 14 Apr 2020 19:29:33 +0900 Subject: [PATCH] AP_GPS: Move the CRC24 to the AP_Math class --- libraries/AP_GPS/RTCM3_Parser.cpp | 28 ++-------------------------- libraries/AP_GPS/RTCM3_Parser.h | 2 -- 2 files changed, 2 insertions(+), 28 deletions(-) diff --git a/libraries/AP_GPS/RTCM3_Parser.cpp b/libraries/AP_GPS/RTCM3_Parser.cpp index 64587fb063..b76e0e8ed9 100644 --- a/libraries/AP_GPS/RTCM3_Parser.cpp +++ b/libraries/AP_GPS/RTCM3_Parser.cpp @@ -18,6 +18,7 @@ */ #include +#include #include "RTCM3_Parser.h" // reset state @@ -86,7 +87,7 @@ bool RTCM3_Parser::parse(void) { const uint8_t *parity = &pkt[pkt_len+3]; uint32_t crc1 = (parity[0] << 16) | (parity[1] << 8) | parity[2]; - uint32_t crc2 = crc24(pkt, pkt_len+3); + uint32_t crc2 = crc_crc24(pkt, pkt_len+3); if (crc1 != crc2) { resync(); return false; @@ -134,31 +135,6 @@ bool RTCM3_Parser::read(uint8_t byte) return false; } -/* - calculate 24 bit RTCMv3 crc. We take an approach that saves memory - and flash at the cost of higher CPU load. This makes it appropriate - for use in the f103 AP_Periph nodes - On a F765 this costs us approx 2ms of CPU per second of 5Hz all - constellation RTCM data -*/ -uint32_t RTCM3_Parser::crc24(const uint8_t *bytes, uint16_t len) -{ - uint32_t crc = 0; - while (len--) { - uint8_t b = *bytes++; - const uint8_t idx = (crc>>16) ^ b; - uint32_t crct = idx<<16; - for (uint8_t j=0; j<8; j++) { - crct <<= 1; - if (crct & 0x1000000) { - crct ^= POLYCRC24; - } - } - crc = ((crc<<8)&0xFFFFFF) ^ crct; - } - return crc; -} - #ifdef RTCM_MAIN_TEST /* parsing test, taking a raw file captured from UART to u-blox F9 diff --git a/libraries/AP_GPS/RTCM3_Parser.h b/libraries/AP_GPS/RTCM3_Parser.h index f1e606870a..462e4777fa 100644 --- a/libraries/AP_GPS/RTCM3_Parser.h +++ b/libraries/AP_GPS/RTCM3_Parser.h @@ -38,7 +38,6 @@ public: private: const uint8_t RTCMv3_PREAMBLE = 0xD3; - const uint32_t POLYCRC24 = 0x1864CFB; // raw packet, we shouldn't need over 300 bytes for the MB configs we use uint8_t pkt[300]; @@ -54,6 +53,5 @@ private: bool parse(void); void resync(void); - uint32_t crc24(const uint8_t *bytes, uint16_t len); };