ODIN-W2 series - System integration manual
UBX-14040040 - R20 Appendix Page 40 of 43
C1-Public
CRC calculation
/* Calculate the 16bit CRC for XMODEM */
/* byte = data buffer in the xmodem block */
/* count = number of data bytes */
/* offset = where to start the calculation */
private ushort xmodemCalcrc(byte[] buffer, int offset, int count)
{
ushort crc, i;
int j;
crc = 0;
for (j = offset; j < count + offset; j++) {
crc = (ushort)(crc ^ (buffer[j] << 8));
for (i = 0; i < 8; i++) {
if ((crc & 0x8000) > 0) {
crc = (ushort)((crc << 1) ^ 0x1021);
} else {
crc = (ushort)(crc << 1);
}
}
}
return (ushort)(crc & 0xFFFF);
}