CAN Busmaster DataField Decoding message

499 views Asked by At

I need to parse and decode the data field from a CAN Message.

I sent the transmitted the request and i got back the data field :

02 01 20 00 00 00 00 00

Now I have to decode it in a SWITCH, the first byte is the length(02) but how I split the whole data field in separate bytes and then take them 1 by 1 to decode?

1

There are 1 answers

0
VioletVynil On

I do not know the SWITCH protocol, but I can help you with accessing byte by byte the payload of the message you are interested in. Lets say your message ID is 0x100 (or you have its name by database dbc, your call to define the message).

If you are working in a test environment (test node like CAPL/XML test node), you can define a testcase/function, and in it the following sequence:

message 0x100 MessageContainer;

then you wait for your message in the point where you expect the payload to be to your liking:

.. . . . .

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.*/

If you want to do the decoding in a Simulation Node, you can do it only through on events, and it is much simpler:

on message 0x100
{
write("The first byte of the captured message 0x100 is 0x%X",this.byte(0));
}

Of course, this on event procedure is working in test environments also.