applILTxPending函数 -- CAN报文发送前的字节预处理

目录

applILTxPending函数


applILTxPending函数

 

  1. applILTxPending函数定义:
    在IL(Interaction Layer,交互层)向总线发送消息之前,可以选择调用此回调。在此回调中,可以阻止消息的发送或更改消息的数据。
  2. applILTxPending函数作用:
    对指定CANID的报文进行字节的预处理
    可以对每一帧报文的特定字节做数据操作处理(applILTxPending函数通常用于计算滚动的Checksum和Counter上,对字节的处理非常方便)。
  3. applILTxPending与output(msg) 相比较的优势是什么?
    applILTxPending不用定义多条报文及其他报文参数,更适合周期发送数据库的报文,可以自由选择需要发送的报文,周期、发送类型;
  4. 语法:
  5. CAPL Example:         
dword applILTxPending (long aId, dword aDlc, byte data[])
{
  dword i;
  byte xor;
  /* Message 0x1A0 contains a XOR checksum in Byte 0. It will
  /* be calculated from the other data bytes of the message.
  */
  if(aId == 0x1A0)
  {
    // calculate
    xor = 0x00;
    for(i = 1; i < aDlc; ++i) {
      xor = xor ^ data[i]; //^异或, 按位不同为1,同为0
    }
    // set the new checksum
    data[0] = xor;
  }
  /* Message 0x1A1 contains a 4-Bit message counter in
  /* the first 4 Bits of Byte 0.
  */
  if(aId == 0x1A1)
  {
    // get the old value
    i = data[0] & 0x0F; // & 按位与
    // increment
    i++;
    i = i % 16; // % 取余数(也就是模运算mod)
    //set the new message counter
    data[0] = i & 0x0F;
  }
  return 1; // 执行之后就开始发出报文
}

  • 1
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值