-
assigned issue to
Not able to write CanFdMessage to blf.
Hi Tobias,
I am writing CAN FD frames to blf but when i analyze the blf file in CANalyzer all seems to be wrong.
e.g.
Event type is CAN frame.
Data length is always 8.
Data is always 8 byte even if i copied 64 byte data. Below is a snippet of code. Please give your input.
auto* stdCAN = new Vector::BLF::CanFdMessage;
stdCAN->objectTimeStamp = time_ns;
stdCAN->channel = channel;
stdCAN->id = messageID;
stdCAN->objectType= Vector::BLF::ObjectType::CAN_FD_MESSAGE;
if (size > 64)
return false;
else if (size > 48)
stdCAN->dlc = 15;
else if (size > 32)
stdCAN->dlc = 14;
else if (size > 24)
stdCAN->dlc = 13;
else if (size > 20)
stdCAN->dlc = 12;
else if (size > 16)
stdCAN->dlc = 11;
else if (size > 12)
stdCAN->dlc = 10;
else if (size > 8)
stdCAN->dlc = 9;
else
stdCAN->dlc = 8;
stdCAN->dlc =size;
stdCAN->validDataBytes= size;
stdCAN->frameLength = size;
memcpy(&stdCAN->data, data, stdCAN->dlc);
hFile.write(stdCAN);
return true;
Comments (9)
-
repo owner -
repo owner - changed status to open
I'll check it.
-
repo owner Hello Deepen M,
In your code, there are some issues, we should fix first.
stdCAN->objectType= Vector::BLF::ObjectType::CAN_FD_MESSAGE;
This doesn’t need to be set, as it happens in the constructor of CanFdMessage already.
stdCAN->dlc =size;
This is likely wrong, as you already set it in the if/else statements. Or you would make the if/else statements useless, if you set another value afterwards.
stdCAN->frameLength = size;
frameLength is actually the message length in ns, not the byte size. You don’t need to set it.
memcpy(&stdCAN->data, data, stdCAN->dlc);
You should use stdCAN->size here instead.
Do you agree? Can you test again with these changes?
Bye
Tobias
-
reporter Hi Tobias,
I changed the code and give it a run but the result is same. Please find the updated code below.
auto* stdCAN = new Vector::BLF::CanFdMessage;
stdCAN->objectTimeStamp = time_ns;
stdCAN->channel = channel;
stdCAN->id = messageIDif (size > 64) return false; else if (size > 48) stdCAN->dlc = 15; else if (size > 32) stdCAN->dlc = 14; else if (size > 24) stdCAN->dlc = 13; else if (size > 20) stdCAN->dlc = 12; else if (size > 16) stdCAN->dlc = 11; else if (size > 12) stdCAN->dlc = 10; else if (size > 8) stdCAN->dlc = 9; else stdCAN->dlc = 8; stdCAN->validDataBytes= size; memcpy(&stdCAN->data, data, size); hFile.write(stdCAN); return true; Please let me know if you have any input.
-
reporter PFA for the CANalyzer screenshot.
-
repo owner I just checked the definition of the CanFdMessage class. The class is able to transport a CAN message and a CANFD message. Difference is that in a CANFD message, you have to set
canFdFlags = Vector::BLF::CanFdMessage::CanFdFlags::EDL
Let’s try this
-
reporter Thanks Tobias for the input. Now it is working.
-
reporter - changed status to resolved
Issue is fixed. Need to set CanFdflag in order to write CAN FD frames.
-
repo owner Great. Thanks for the feedback. :-)
- Log in to comment