1:本代码实现,有一个重要前提,就是转发帧和被转发帧,数据结构上是一模一样的。
如:CAN1: 0X110 [10 23 45 00 00 00 00 00]
转发到CAN2 0X210 [10 23 45 00 00 00 00 00]
1:实现模拟发送 我们要实现覆盖所有数据转发的完整性测试,以下规则
报文0x110 :Byte0=0开始 到Byte0=0xFF结束,然后Byte0置0。Byte1又按照Byte0的规则依次发送。
且报文需要按照固定周期发送
看代码
/*@!Encoding:936*/
includes
{
}
variables
{
message 0x601 Msg_0x601=
{
FDF=1,
BRS=1,
DLC=8,
Byte(0)=0,
Byte(1)=0,
Byte(2)=0,
Byte(3)=0,
Byte(4)=0,
Byte(5)=0,
Byte(6)=0,
Byte(7)=0
};
msTimer CycleTime_0x601Forward; //定义定时器用于发送固定周期的报文
const word CycleTime_0x601=10 ; //设置初始周期10ms
int LoopVar_1_0x601=0 //用于发送中循环计数
on sysvar ForwardVar::OnlyForForward_0x601_Flag
{
LoopVar_1_0x601=0;
// @FLRR_SYSVAR::FLRR_to_CAN_0x301=1;
if(@ForwardVar::OnlyForForward_0x601_Flag)
{
setTimer(CycleTime_0x601Forward,IniCycleTime_0x601); //初始化,计时器
}
else
cancelTimer(CycleTime_0x601Forward); //这里当系统变量=0时,取消计时器,
}
on timer CycleTime_0x601Forward
{
if(LoopVar_1_0x601<0xFF)
{
Msg_0x601.byte(7)=0;
Msg_0x601.byte(0)+=1;
output(Msg_0x601);
}
else if(0XFF<LoopVar_1_0x601&&LoopVar_1_0x601<=0xFF*2)
{
Msg_0x601.byte(0)=0;
Msg_0x601.byte(1)+=1;
output(Msg_0x601);
}
else if(0xFF*2<LoopVar_1_0x601&&LoopVar_1_0x601<=0xFF*3)
{
Msg_0x601.byte(1)=0;
Msg_0x601.byte(2)+=1;
output(Msg_0x601);
}
else if(0xFF*3<LoopVar_1_0x601&&LoopVar_1_0x601<=0xFF*4)
{
Msg_0x601.byte(2)=0;
Msg_0x601.byte(3)+=1;
output(Msg_0x601);
}
else if(0xFF*4<LoopVar_1_0x601&&LoopVar_1_0x601<=0xFF*5)
{
Msg_0x601.byte(3)=0;
Msg_0x601.byte(4)+=1;
output(Msg_0x601);
}
else if(0xFF*5<LoopVar_1_0x601&&LoopVar_1_0x601<=0xFF*6)
{
Msg_0x601.byte(4)=0;
Msg_0x601.byte(5)+=1;
output(Msg_0x601);
}
else if(0xFF*6<LoopVar_1_0x601&&LoopVar_1_0x601<=0xFF*7)
{
Msg_0x601.byte(5)=0;
Msg_0x601.byte(6)+=1;
output(Msg_0x601);
}
else if(0xFF*7<LoopVar_1_0x601&&LoopVar_1_0x601<=0xFF*8)
{
Msg_0x601.byte(6)=0;
Msg_0x601.byte(7)+=1;
output(Msg_0x601);
write("outputValueofLoopVar_1_0x601:%#X",LoopVar_1_0x601); //该步骤调试使用
}
LoopVar_1_0x601+=1;
setTimer(CycleTime_0x601Forward,10);
}