我需要从CAN消息中解析和解码数据字段。
我发送了已发送的请求,然后又返回了数据字段:
02 01 20 00 00 00 00 00
现在我必须在SWITCH中对其进行解码,第一个字节是length(02),但是我如何将整个数据字段拆分为单独的字节,然后将它们一一对应地进行解码?
答案 0 :(得分:0)
我不知道SWITCH协议,但是我可以帮助您逐字节访问感兴趣的消息的有效负载。 假设您的消息ID为0x100(或者您通过数据库dbc拥有其名称,即定义消息的调用)。
如果您在测试环境中工作(例如CAPL / XML测试节点之类的测试节点),则可以定义一个测试用例/函数,并按以下顺序进行定义:
message 0x100 MessageContainer;
然后在您希望有效载荷符合您的意愿的位置等待消息:
.. 。 。 。
testwaitformessage(0x100,cycletimeofMessage); /*Cycletime the message has, or maximum time you expect your message to arrive*/
testGetWaitEventMsgData(MessageContainer); /*the message object MessageContainer will be filled with the content of the message catched early in testwaitformessage()*/
write("%X",MessageContainer.byte(0)); /*you access the bytes through the .byte selector field of the message object and do whatever you wish with it.*/
如果要在模拟节点中进行解码,则只能通过on事件来完成解码,而且要简单得多:
on message 0x100
{
write("The first byte of the captured message 0x100 is 0x%X",this.byte(0));
}
当然,此事件过程也适用于测试环境。