mirror of
https://github.com/davidgiven/fluxengine.git
synced 2025-10-31 11:17:01 -07:00
Add stateful decoders, which makes formats like the FB-100 much easier to work
with. Add a generic CRC tool allowing all the parameters to be set (currently unused).
This commit is contained in:
17
lib/crc.h
17
lib/crc.h
@@ -6,14 +6,29 @@
|
||||
#define MODBUS_POLY_REF 0xa001
|
||||
#define BROTHER_POLY 0x000201
|
||||
|
||||
struct crcspec
|
||||
{
|
||||
unsigned width;
|
||||
uint64_t poly;
|
||||
uint64_t init;
|
||||
uint64_t xorout;
|
||||
bool refin;
|
||||
bool refout;
|
||||
};
|
||||
|
||||
extern uint64_t generic_crc(const struct crcspec& spec, const Bytes& bytes);
|
||||
|
||||
extern uint16_t sumBytes(const Bytes& bytes);
|
||||
extern uint8_t xorBytes(const Bytes& bytes);
|
||||
extern uint16_t crc16(uint16_t poly, uint16_t init, const Bytes& bytes);
|
||||
extern uint16_t crc16ref(uint16_t poly, const Bytes& bytes);
|
||||
extern uint16_t crc16ref(uint16_t poly, uint16_t init, const Bytes& bytes);
|
||||
extern uint32_t crcbrother(const Bytes& bytes);
|
||||
|
||||
static inline uint16_t crc16(uint16_t poly, const Bytes& bytes)
|
||||
{ return crc16(poly, 0xffff, bytes); }
|
||||
|
||||
static inline uint16_t crc16ref(uint16_t poly, const Bytes& bytes)
|
||||
{ return crc16ref(poly, 0xffff, bytes); }
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
Reference in New Issue
Block a user