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