Calculates values commonly used in checksum computations.
uint8_t CRC8_u8Calc(uint8_t *pu8Data, uint8_t size, uint8_t init=0)
uint8_t CRC8_u8CalcU32(uint32_t u32c, uint8_t init=0)
uint8_t CRC8_u8CalcU16(uint16_t u16c, uint8_t init=0)
uint8_t XOR_u8Calc(uint8_t *pu8Data, uint8_t size)
uint8_t LRC_u8Calc(uint8_t* pu8Data, uint8_t size)
Performs calculations for CRC8, XOR, and LRC (used in ASCII format).
CRC8_u8CalcU16()
and CRC8_u8CalcU32()
compute the CRC8 for u16c
and u32c
assuming big-endian order.
CRC8 has several variants depending on the polynomial and initial value used. This library uses the polynomial
X^8+X^5+X^4+1
(polynomial value 0x31), which is sometimes referred to as CRC8-CCITT or CRC8-Maxim.XOR computes the bitwise exclusive OR of all elements.
LRC computes the sum of all elements and then takes the two’s complement of the lower 8 bits. As a result, the total sum of all elements including the checksum becomes zero.
Background
These functions were added as library procedures because they are used for validating wireless packet data sequences, ASCII format checksums (LRC), and various sensor data checks.