Figure 9 CRC Byte Sequence
Example
An example of a C language function performing CRC generation is shown on the following pages. All of the possible CRC
values are preloaded into two arrays, which are simply indexed as the function increments through the message buffer. One
array contains all of the 256 possible CRC values for the high byte of the 16-bit
CRC field, and the other array contains all of
the values for the low byte.
Indexing the CRC in this way provides faster execution than would be achieved by calculating a new CRC value with each
new character from the message buffer.
Note: This function performs the swapping of the high/low CRC bytes internally. The bytes are already swapped in the CRC
value that is returned from the function. Therefore the CRC value returned from the function can
be directly placed into the
message for transmission.
The function takes two arguments:
unsigned char *puchMsg ; A pointer to the message buffer
containing
binary data to be used
for
generating the CRC
unsigned
short usDataLen ; The quantity of bytes in the
message
buffer.
The function returns the CRC as a type unsigned short.
Chia sẻ với bạn bè của bạn: