InFocus C85, C95, C105 manual Appendix 1 CRC Calculation Algorithm

Page 10

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.

Image 10
Contents C85/C95/C105 Projector Control VersionRS232 Settings Setting UPRs232 Control Cables Protocol Messages GeneralFunction Type Message FormatsField description Message BodyOpTypeLo Transaction Examples Command Return Codes0xBE 0xEF 0x80 0x06 0x00 0x2E 0x04 0x01 0x00 0x11 0x00 0xB2 Example 5 Hex sequence for get Brightness Table of Functions Function FuncNum Type States Minimum MaximumVIDEO1 CVBS1 Appendix 1 CRC Calculation Algorithm Projector Control Projector Control