AceCRC  1.1.1
Cyclic Redundancy Check (CRC) algorithms (e.g. crc16ccitt, crc32) programmatically converted from C99 code generated by pycrc (https://pycrc.org) to Arduino C++ using namespaces and PROGMEM flash memory.
crc16modbus_bit.hpp
Go to the documentation of this file.
1 
44 #ifndef ACE_CRC_CRC16MODBUS_BIT_HPP
45 #define ACE_CRC_CRC16MODBUS_BIT_HPP
46 
47 #include <stdlib.h>
48 #include <stdint.h>
49 
50 namespace ace_crc {
51 namespace crc16modbus_bit {
52 
53 
60 const uint8_t CRC_ALGO_BIT_BY_BIT_FAST = 1;
61 
62 
68 typedef uint16_t crc_t;
69 
70 
78 crc_t crc_reflect(crc_t data, size_t data_len);
79 
80 
86 inline crc_t crc_init(void)
87 {
88  return 0xffff;
89 }
90 
91 
100 crc_t crc_update(crc_t crc, const void *data, size_t data_len);
101 
102 
109 inline crc_t crc_finalize(crc_t crc)
110 {
111  return crc_reflect(crc, 16);
112 }
113 
114 
122 inline crc_t crc_calculate(const void *data, size_t data_len) {
123  crc_t crc = crc_init();
124  crc = crc_update(crc, data, data_len);
125  return crc_finalize(crc);
126 }
127 
128 } // crc16modbus_bit
129 } // ace_crc
130 
131 #endif /* ACE_CRC_CRC16MODBUS_BIT_HPP */
crc_t crc_reflect(crc_t data, size_t data_len)
Reflect all bits of a data word of data_len bytes.
uint16_t crc_t
The type of the CRC values.