-1

I am working on an API to read CAN signal. This part of the code outputs the received CAN in the form of a string.

xlCanGetEventString(&xlCanRxEvt)

The CAN signal is in the form of:

XL_CAN_EV_TAG_RX_OK ch:1 t=9026813952 id:98FF1880 dlc:8 862EC5350C138336 
XL_CAN_EV_TAG_RX_OK ch:1 t=9027108864 id:98FF1980 dlc:8 500111065C018C03 
XL_CAN_EV_TAG_RX_OK ch:1 t=9027411968 id:98FF1A80 dlc:8 0000FFFFFFFFFFFF
XL_CAN_EV_TAG_RX_OK ch:1 t=9027411968 id:98FF1A80 dlc:8 0000FFFFFFFFFFFF 
XL_CAN_EV_TAG_RX_OK ch:1 t=9027657728 id:98FF5180 dlc:5 C000000000

In that signal I need to read the IDs from each line and then display the data only for the IDs I need. I am currently doing this by using a bunch of if and for statements, and using char arrays to read different part of the line.

This feels very inefficient to me, is there another way to do it ? To maybe directly extract the Id part or compare the ID part without having to store the whole thread into an array ? Or any best or efficient way to do the same ? I don't find a variable storing the data or ID in the typedef struct xlCanRxEvt either. Any suggestion will be greatly appreciated.

Akash
  • 11
  • 1
  • 4

1 Answers1

2

You are talking about the Vector XL Driver Library.

You get your XlEvent first from XLCANReceive(). That XLEvent is a struct,

structs_xl_event{  
XLeventTag          tag;  
unsignedchar       chanIndex;  
unsignedshort      transId; 
unsignedshort      portHandle;  
unsignedchar       flags;  
unsignedchar       reserved;  
XLuint64            timeStamp;  
unions_xl_tag_datatagData;
};

And you can access their content like this:

xlEvent[i].tag                 =XL_TRANSMIT_MSG;
xlEvent[i].tagData.msg.id      =0x04;
xlEvent[i].tagData.msg.flags   =0;
xlEvent[i].tagData.msg.data[0]=1;
xlEvent[i].tagData.msg.data[1]=2;
xlEvent[i].tagData.msg.data[2]=3;  
xlEvent[i].tagData.msg.data[3]=4;  
xlEvent[i].tagData.msg.data[4]=5;
xlEvent[i].tagData.msg.data[5]=6;  
xlEvent[i].tagData.msg.data[6]=7;  
xlEvent[i].tagData.msg.data[7]=8;  
xlEvent[i].tagData.msg.dlc     =8;

I think this is enough for you to figure out the more "elegant" way to extract data.

VioletVynil
  • 502
  • 5
  • 11