1 #ifndef CRC_H
2 #define CRC_H
3 
4 #define CCITT_POLY      0x1021
5 #define MODBUS_POLY     0x8005
6 #define MODBUS_POLY_REF 0xa001
7 #define BROTHER_POLY    0x000201
8 
9 struct crcspec
10 {
11     unsigned width;
12     uint64_t poly;
13     uint64_t init;
14     uint64_t xorout;
15     bool refin;
16     bool refout;
17 };
18 
19 extern uint64_t generic_crc(const struct crcspec& spec, const Bytes& bytes);
20 
21 extern uint16_t sumBytes(const Bytes& bytes);
22 extern uint8_t xorBytes(const Bytes& bytes);
23 extern uint16_t crc16(uint16_t poly, uint16_t init, const Bytes& bytes);
24 extern uint16_t crc16ref(uint16_t poly, uint16_t init, const Bytes& bytes);
25 extern uint32_t crcbrother(const Bytes& bytes);
26 
crc16(uint16_t poly,const Bytes & bytes)27 static inline uint16_t crc16(uint16_t poly, const Bytes& bytes)
28 { return crc16(poly, 0xffff, bytes); }
29 
crc16ref(uint16_t poly,const Bytes & bytes)30 static inline uint16_t crc16ref(uint16_t poly, const Bytes& bytes)
31 { return crc16ref(poly, 0xffff, bytes); }
32 
33 #endif
34 
35