on ethernetPacket可以用来接收指定报文,并根据一些判断条件,比如目标MAC地址和IP地址判断报文是否是发给"我"的。
比如想通过on ethernetPacket *来接收发送给02:00:00:00:00:17和192.168.0.17的SYN报文。CAPL代码可以这样写:
variables
{
ethernetPacket ppkt;
}
on ethernetPacket *
{
if (this.dir == 0)//packet that switch received and ecu sent
{
if (this.destination == ethGetMacAddressAsNumber("02:00:00:00:00:17") ||
this.destination == ethGetMacAddressAsNumber("FF:FF:FF:FF:FF:FF"))//destination mac
{
if (this.ipv4.destination == ipGetAddressAsNumber("192.168.0.17"))//destination ip
{
//...
}
}
}
}
但Client在发送SYN前很有可能先发送ARP Request报文。而上面的代码显然对ARP报文没有相应的处理机制。于是CANoe软件停止运行且Write窗口报错:
报错的真正原因是接收到的ARP Request报文里并没有ipv4.destination字段。
那么on ethe