CRC-16-CCITT-FALSE 在CAPL里面计算

算法: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;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值