35#ifndef _UTILS_CRC_HXX_
36#define _UTILS_CRC_HXX_
41#ifndef CRC8DALLAS_TABLE_SIZE
43#define CRC8DALLAS_TABLE_SIZE 16
45#ifndef CRC16CCITT_TABLE_SIZE
47#define CRC16CCITT_TABLE_SIZE 256
59uint16_t
crc_16_ibm(
const void* data,
size_t length_bytes);
74void crc3_crc16_ibm(
const void* data,
size_t length_bytes, uint16_t* checksum);
116 return (
state_ == checksum_byte);
124 uint8_t data =
state_ ^ message_byte;
166 uint8_t data =
state_ ^ message_byte;
182#if CRC8DALLAS_TABLE_SIZE == 0
184#elif CRC8DALLAS_TABLE_SIZE == 16
186#elif CRC8DALLAS_TABLE_SIZE == 256
189#error "Invalid value for CRC8DALLAS_TABLE_SIZE"
249 return (
state_ == checksum);
257 uint8_t data = (
state_ >> 8) ^ message_byte;
274#if CRC16CCITT_TABLE_SIZE == 16
276#elif CRC16CCITT_TABLE_SIZE == 256
279#error "Invalid value for CRC16CCITT_TABLE_SIZE"
286 void crc(
const void* data,
size_t length_bytes)
288 const uint8_t *payload =
static_cast<const uint8_t*
>(data);
290 for (
size_t i = 0; i < length_bytes; ++i)
301 static const uint16_t
table256[256];
326 const void* data,
size_t length_bytes, uint16_t checksum[3])
328 const uint8_t* payload =
static_cast<const uint8_t*
>(data);
334 for (
size_t i = 0; i < length_bytes; ++i)
336 crc_all.
update(payload[i]);
340 crc_odd.
update(payload[i]);
345 crc_even.
update(payload[i]);
349 checksum[0] = crc_all.
get();
350 checksum[1] = crc_even.
get();
351 checksum[2] = crc_odd.
get();
void crc3_crc16_ibm(const void *data, size_t length_bytes, uint16_t *checksum)
Computes the triple-CRC value over a chunk of data.
uint16_t crc_16_ibm(const void *data, size_t length_bytes)
Computes the 16-bit CRC value over data using the CRC16-ANSI (aka CRC16-IBM) settings.
static void crc3_crc16_ccitt(const void *data, size_t length_bytes, uint16_t checksum[3])
Computes the triple-CRC value over a chunk of data.
Helper class for computing CRC-16 according to the CCITT specification (polynomial = 0x1021,...
uint16_t state_
Current value of the state register for the CRC computation.
static const uint16_t tableHi16[16]
16-entry lookup table for the update16 function.
static const uint16_t table256[256]
256-entry lookup table for the update256 function.
void update16(uint8_t message_byte)
Processes one byte of the incoming message.
static const uint16_t tableLo16[16]
16-entry lookup table for the update16 function.
void crc(const void *data, size_t length_bytes)
Computes the 16-bit CRC value over data.
bool check_ok()
Checks that the message has a correct CRC.
void update(uint8_t message_byte)
Processes one byte of the incoming message.
void update256(uint8_t message_byte)
Processes one byte of the incoming message.
bool check_ok(uint16_t checksum)
Checks that the message has a correct CRC.
void init()
Re-sets the state machine for checksumming a new message.
Helper class for computing CRC-8 according to Dallas/Maxim specification for 1-wire protocol.
static const uint8_t tableLo16[16]
16-entry lookup table for the update16 function.
static const uint8_t tableHi16[16]
16-entry lookup table for the update16 function.
void update(uint8_t message_byte)
Processes one byte of the incoming message.
bool check_ok()
Checks that the message has a correct CRC.
void update0(uint8_t message_byte)
Processes one byte of the incoming message.
static const uint8_t table256[256]
256-entry lookup table for the update256 function.
void update16(uint8_t message_byte)
Processes one byte of the incoming message.
bool check_ok(uint8_t checksum_byte)
Checks that the message has a correct CRC.
void update256(uint8_t message_byte)
Processes one byte of the incoming message.
uint8_t state_
Current value of the state register for the CRC computation.
void init()
Re-sets the state machine for checksumming a new message.