算法:CRC-16-CCITT-FALSE
配置:AutoSar profile 5
通讯:CAN FD
使用CAPL Test Mode网络节点测试,CAN FD的CRC16结果检查。.
includes
{
}
variables
{
message * msgDynamically; //声明CAN ID
}
testcase MainTest()
{
int crcCapacity[32]; //存储报文数据
word i,redundancy;
msgDynamically.id = 0x100; //指向要计算的报文
testWaitForMessage(msgDynamically.id,500);
testGetWaitEventMsgData(msgDynamically);
// 拿到报文数据并进行存储
for(i=0;i<elcount(crcCapacity);i++)
{
crcCapacity[i] = msgDynamically.byte(i);
}
redundancy = Crc_CalculateCRC16_CCITT_FALSE(crcCapacity,elcount(crcCapacity)); //将数据进行计算
write("Message Timestamp: %f ; Cyclic redundancy check : 0x%X",(msgDynamically.time_ns)/1000000000.0,redundancy); //将计算的CRC结果输出到Write窗口且带有时间戳
}
/*****************************CRC info*************************************
* Formula: CRC-16-CCITT-FALSE
* Width: 16
* Poly: 0x1021
* Init: 0xFFFF
* Refin: False
* Refout: False
* Xorout: 0x0000
**************************************************************************/
word Crc_CalculateCRC16_CCITT_FALSE(int crcCapacity[], int crcLength)
{
int i;
word crcInit = 0xFFFF;
word cecPoly = 0x1021;
for(crcLength=0;crcLength<elcount(crcCapacity);crcLength++)
{
crcInit ^= (crcCapacity[crcLength]<<8);
for(i = 0;i<8;i++)
{
if(crcInit & 0x8000)
{
crcInit = (crcInit << 1) ^ cecPoly;
}
else
{
crcInit <<= 1;
}
}
}
return crcInit;
}