Example Crc Calculation Routines For Serial Packets - Globalstar STINGR User Manual

Hide thumbs Also See for STINGR:
Table of Contents

Advertisement

5.4 Example CRC calculation routines for serial packets

The following example is written in the C programming language where:
int = 32 bits, short = 16 bits, char = 8 bits
unsigned short crc16_lsb(unsigned char *pData, int length)
{
unsigned char i;
unsigned short data, crc;
crc = 0xFFFF;
if (length == 0)
return 0;
do
{
data = (unsigned int)0x00FF & *pData++;
crc = crc ^ data;
for (i = 8; i > 0; i--)
{
if (crc & 0x0001)
crc = (crc >> 1) ^ 0x8408;
else
crc >>= 1;
}
}while (--length);
crc = ~crc;
return (crc);
}
USAGE:
calculate the CRC for a message and update the message CRC
Revision 0.2
06/24/15
Revision 0.2
unsigned short crc = crc16_lsb(msg, msg [1]-2);
msg [msg [1]-2] = (unsigned char) (crc&0xFF);
msg [msg [1]-1] = (unsigned char) (crc>>8);
Subject To Change without Notice
STINGR Users Manual
P a g e
| 29

Advertisement

Table of Contents
loading

Table of Contents