CANoe CAPL 之 Checksum and Counter


 

参考文献:

1、CANoe帮助文档:

CAPL Functions » CANoe IL » applILTxPending

Example

Calculation of a checksum and a message counter:

dword applILTxPending (long aId, dword aDlc, byte data[])
{
  dword i;
  byte xor;
  
  /* Message 0x1A0 contains a XOR checksum in Byte 0. 
  /* Message 0x1A1 contains a 4-Bit message counter in the first 4 Bits of Byte 7.
  /* It will be calculated from the other data bytes of the message.
  */
  
  if(aId == 0x1A0)
  {
    // calculate checksum
    xor = 0x00;
    for(i = 1; i < aDlc; ++i) {
      xor = xor ^ data[i];
    }
    // set the new checksum
    data[0] = xor;

    // get the old counter value
    i = (data[7] & 0xF0) >> 4;
    data[7] &= 0x0F;
    // increment
    i++;
    i = i % 16;
    //set the new message counter
    data[7] |= (i << 4) & 0xF0;
  }
  return 1; // don't prevent sending of the message
}

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM