USER'S GUIDE ____________________________________________________________________
170 __________________________________________________________________ M211187EN-C
CRC16 Checksum
The CRC16 checksum can be calculated using the following algorithm
written in the C programming language:
/* 16 bit type */
typedef unsigned short Word16;
/* Calculate CRC-16 value as used in FS11 protocol */
Word16 crc16(const unsigned char *buf, int len) {
Word16 crc;
int i,j;
crc=0xffff;
for (i=0;i<len;++i) {
crc^=buf[i]<<8;
for (j=0;j<8;++j) {
Word16 xmask=(crc&0x8000)?0x1021:0;
crc<<=1;
crc^=xmask;
}
}
return crc^0xffff;
}
The calculation of the checksum starts after the
!
(start of heading)
character and ends after the
#
(end of transmission) character.