4/14/2016
D014465 CR1400 CR1000 CR2300 CR2600 CR3600 CR44X5 CR8000 CR900FD CR6000 CR5000 T500 Client Version ICD
Page 101 of 106
© 2013-2016 The Code Corporation
12393 South Gateway Park Place Suite 600, Draper, UT 84020
(801) 495-2200
FAX (801) 495-0280
12 Appendix: Example CRC16 C Code
The CRC16 required by Reader to Host packets (see Section 6.2) can be calculated using the following
sample C code. This CRC16 consists of two consecutive bytes, each in range [0,255] most significant byte
first. A CRC16 is calculated on each packet byte, over the entire packet, excluding the prefix and the CRC16
itself.
crc_t crc = 0;
<send firstByte>
crc = crc(crc, firstByte, firstByteSize);
<send secondByte>
crc = crc(crc, secondByte, secondByteSize)
<…>
<send crcHighByte>
<send crcLowByte>
/* crc16.h */
#ifndef crc16_h
#define crc16_h
#include <stdint.h>
#include <stddef.h>
#ifdef __cplusplus
extern "C" {
#endif
typedef uint16_t crc_t;
crc_t crc
( crc_t initialCrc
, const unsigned char* bufPtr
, size_t length
);
#ifdef __cplusplus
} // extern "C"
#endif
#endif
/* crc16.c */