EasyManua.ls Logo

Globalstar STX3 - CRC Calculation Routines

Globalstar STX3
35 pages
Print Icon
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
8545-0198-01 Revision 1.9 STX3 Users Manual
9/24/2020 Globalstar, Inc. Confidential and Proprietary Page | 22
5.3 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
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);

Other manuals for Globalstar STX3

Related product manuals