User's Manual

December 6, 2006 Proprietary Information 68
Revision 1.0
Appendix A CRC Calculation
This section shows how to calculate the CCITT CRC-16 over
the entire body of the message. The CCITT CRC-16 is
calculated starting with the LENGTH byte and continuing
through the length -2. The final two CRC bytes are not
included in the calculation but should be checked against the
CCITT CRC-16 for a match.
A typical command string, the Notify Command, with this
CRC Calculated follows:
01 05 00 00 27 6C
Where the 01 is the SOF byte, the 05 is the length and 00 00 is
the command for the Notify Command with the 276C as the
correctly calculated CRC.
Here is a ā€œCā€ language listing that shows the CCITT CRC-16
calculation.
// ***************************************************************************************************
//
// CRC_Calc
// Calculates CCITT-CRC for IDentity MaX Mobile RFID reader
//
// Version 1.0
//
// This routine calculates the two byte CCITT-CRC for command and data messages for the IDentity MaX Mobile reader UHF
RFID
// Reader.
//
// Inputs: Place the entire message to be transmitted including SOH and two empty bytes for CRC into an array.
// In this demo case CommandArray and the total length of the command in the length variable, CommandLength
// are passed. These are passed into "bytearray[]" and "arraylength" variables of the routine.
//
// Outputs: This routine will return the value of the two-byte CRC which is calculated in the variable "crc".
//
// The routine begins with array index [1], and goes to array length -2. You will have to move the two bytes returned
// into the last two bytes of the array before transmitting the command. You can also use it to verify received
// commands by checking the entire length, i.e. set your length to two more than the actual length of the command. If
// the returned, the CRC is "0000" then the command is valid
//
// ****************************************************************************************************
#include <stdio.h>
#include <stdlib.h>
unsigned short CRC_Calc(char bytearray[256],int arraylength)
{
unsigned short crc = 0xFFFF; // Preload to FFFF
unsigned short tempresults; // Just a temporary results holder
unsigned short bitindex; // 0 - 7
unsigned short byteindex; // The byte pointer into the byte
// array that holds