diff --git a/libraries/AP_HAL/utility/srxl.cpp b/libraries/AP_HAL/utility/srxl.cpp index cbaf5af1e4..fe21d88a2a 100644 --- a/libraries/AP_HAL/utility/srxl.cpp +++ b/libraries/AP_HAL/utility/srxl.cpp @@ -23,6 +23,7 @@ #include #include #include +#include #include "srxl.h" @@ -69,31 +70,6 @@ static uint16_t crc_receiver = 0U; /* CRC extracted from srxl d static uint16_t max_channels; - - -/** - * This function calculates the 16bit crc as used throughout the srxl protocol variants - * - * This function is intended to be called whenever a new byte shall be added to the crc. - * Simply provide the old crc and the new data byte and the function return the new crc value. - * - * To start a new crc calculation for a new srxl frame, provide parameter crc=0 and the first byte of the frame. - * - * @param[in] crc - start value for crc - * @param[in] new_byte - byte that shall be included in crc calculation - * @return calculated crc - */ -static uint16_t srxl_crc16 (uint16_t crc, uint8_t new_byte) -{ - uint8_t loop; - crc = crc ^ (uint16_t)new_byte << 8; - for(loop = 0; loop < 8; loop++) { - crc = (crc & 0x8000) ? (crc << 1) ^ 0x1021 : (crc << 1); - } - return crc; -} - - /** * Get RC channel information as microsecond pulsewidth representation from srxl version 1 and 2 * @@ -297,7 +273,7 @@ int srxl_decode(uint64_t timestamp_us, uint8_t byte, uint8_t *num_values, uint16 switch (decode_state) { case STATE_NEW: /* buffer header byte and prepare for frame reception and decoding */ buffer[0U]=byte; - crc_fmu = srxl_crc16(0U,byte); + crc_fmu = crc_xmodem_update(0U,byte); buflen = 1U; decode_state_next = STATE_COLLECT; break; @@ -315,7 +291,7 @@ int srxl_decode(uint64_t timestamp_us, uint8_t byte, uint8_t *num_values, uint16 buflen++; /* CRC not over last 2 frame bytes as these bytes inhabitate the crc */ if (buflen <= (frame_len_full-2)) { - crc_fmu = srxl_crc16(crc_fmu,byte); + crc_fmu = crc_xmodem_update(crc_fmu,byte); } if( buflen == frame_len_full ) { /* CRC check here */ diff --git a/libraries/AP_HAL/utility/sumd.cpp b/libraries/AP_HAL/utility/sumd.cpp index 7b4b0af86e..816460f009 100644 --- a/libraries/AP_HAL/utility/sumd.cpp +++ b/libraries/AP_HAL/utility/sumd.cpp @@ -45,6 +45,7 @@ #include #include +#include #include "sumd.h" #define SUMD_MAX_CHANNELS 32 @@ -116,18 +117,6 @@ static uint8_t _rxlen; static ReceiverFcPacketHoTT _rxpacket; -static uint16_t sumd_crc16(uint16_t crc, uint8_t value) -{ - int i; - crc ^= (uint16_t)value << 8; - - for (i = 0; i < 8; i++) { - crc = (crc & 0x8000) ? (crc << 1) ^ 0x1021 : (crc << 1); - } - - return crc; -} - static uint8_t sumd_crc8(uint8_t crc, uint8_t value) { crc += value; @@ -153,7 +142,7 @@ int sumd_decode(uint8_t byte, uint8_t *rssi, uint8_t *rx_count, uint16_t *channe _crc16 = 0x0000; _crc8 = 0x00; _crcOK = false; - _crc16 = sumd_crc16(_crc16, byte); + _crc16 = crc_xmodem_update(_crc16, byte); _crc8 = sumd_crc8(_crc8, byte); _decode_state = SUMD_DECODE_STATE_GOT_HEADER; @@ -176,7 +165,7 @@ int sumd_decode(uint8_t byte, uint8_t *rssi, uint8_t *rx_count, uint16_t *channe } if (_sumd) { - _crc16 = sumd_crc16(_crc16, byte); + _crc16 = crc_xmodem_update(_crc16, byte); } else { _crc8 = sumd_crc8(_crc8, byte); @@ -199,7 +188,7 @@ int sumd_decode(uint8_t byte, uint8_t *rssi, uint8_t *rx_count, uint16_t *channe _rxpacket.length = byte; if (_sumd) { - _crc16 = sumd_crc16(_crc16, byte); + _crc16 = crc_xmodem_update(_crc16, byte); } else { _crc8 = sumd_crc8(_crc8, byte); @@ -222,7 +211,7 @@ int sumd_decode(uint8_t byte, uint8_t *rssi, uint8_t *rx_count, uint16_t *channe _rxpacket.sumd_data[_rxlen] = byte; if (_sumd) { - _crc16 = sumd_crc16(_crc16, byte); + _crc16 = crc_xmodem_update(_crc16, byte); } else { _crc8 = sumd_crc8(_crc8, byte);