请教达人,关于末尾的CRC16校验问题。
这段代码只校验数据部分,不包含起始、校验、结束标志。但是不知道这样的算法行不行啊? 请教啦~~
CRC16校验算法如下:
/* ::---------------------------------------------------------------------
:: FN: CreateCRC; CRC in ANSI - C
:: Synopsis: static void CreateCRC(BYTE *CommData,WORD uLen)
:: Function: formation of the CRC16[code] checksum.
------------------------------------------------------------------------*/
static WORD CreateCRC(unsigned char *CommData, unsigned int uLen )
{
unsigned short uCrc16;
unsigned char abData[2];
uCrc16 = 0;
abData[0] = 0;
while (uLen-- )
{
abData[1] = abData[0];
abData[0] = *CommData++;
if(uCrc16 & 0x8000)
{
uCrc16 = (uCrc16 & 0x7fff) << 1;
uCrc16 ^= CRC16_GEN_POL;
}
else
{
uCrc16 <<= 1;
}
uCrc16 ^= MKSHORT (abData[0] , abData[1]);
}
return(uCrc16);
}
第