Projector Control

APPENDIX 1: CRC CALCULATION ALGORITHM

The following ‘C’ code can be used to calculate the 16-bit CRC required for all packets. The CRC is contained in the packet header and is calculated for the entire packet (header plus body). The CRC

calculation is performed with the CRC bytes of the packet header initialized to zero.

//Using two 256 byte lookup tables, quickly calculate a 16-bit CRC on // a block of data.

//Params:

//pcData : Pointer to data to calculate CRC on.

//nCount : Number of data bytes.

//Return: 16-bit CRC value.

WORD CalculateCRC16 (BYTE *pcData, int nCount)

{

BYTE cCRCHi = 0xFF; // high byte of CRC initialized BYTE cCRCLo = 0xFF; // low byte of CRC initialized BYTE cIndex; // will index into CRC lookup table while (nCount--) // step through each byte of data

{

cIndex = cCRCHi ^ *pcData++; // calculate the CRC

cCRCHi = cCRCLo ^ cCRCHiArray[cIndex]; cCRCLo = cCRCLoArray[cIndex];

}

return (cCRCHi << 8) + cCRCLo;

}

Page 10

Version 1.

Page 10
Image 10
InFocus C85, C95, C105 manual Appendix 1 CRC Calculation Algorithm