- Notifications
You must be signed in to change notification settings - Fork81
Fix DLC and add padding for CANFD frames#75
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
I recently came across a case where I initialized and sent a CANFD frame with a payload whose length is not a valid CANFD data length. I therefore digged a little deeper and discovered that CANFD frames are also being sent with an invalid data length. Here is the example code for creating and sending a CANFD frame with an invalid DataLength (DL=11): let sock =CanFdSocket::open("vcan0").expect("open canfd socket0");let id =StandardId::new(0x123).expect("create CAN id");// invalid data length (DL=11)let data:&[u8] =&[0x11,0x22,0x33,0x44,0x55,0x66,0x77,0x88,0x99,0xAA,0xBB];let flags:FdFlags =FdFlags::all();let frame =CanFdFrame::with_flags(id, data, flags).expect("create CANFD frame");sock.write_frame(&frame).expect("send frame"); The candump output of the (via cangw connected) vcan1 interface looks like this:
As you can see a invalid CANFD frame with a data length of 11 ist being transmittet.
the data is being correctly padded with 0 to the next valid data length (in this case 12).
I therefore updated the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
LGTM
Oh, BTW, on a closer 2nd look, I realized you don't need to manually add zero padding to the FD frame (along with the added allocation/deallocation). The creation of the underlying C variable zeros out the whole struct already, including the data field:
So all you need to do is copy in the user data, even if it's not a valid length, andthen set the length to a valid value. |
This PR fixes the calculation of the data length code (DLC) for CANFD frames with extended data length.
The current code only returns the data length which is incorrect for frames with data length > 8 (also see:https://elearning.vector.com/mod/page/view.php?id=368)
I have currently implemented the fix so that
DLC=0
is returned if the data length is invalid. I am not completely satisfied with this solution, as a check when creating a CANFD frame would probably make more sense but requires changing theCanFdFrame::init
function.Please let me know what you think about this.