Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

Merged
fpagliughi merged 5 commits intosocketcan-rs:masterfromdavidkirchner:master
Dec 23, 2024

Conversation

davidkirchner
Copy link
Contributor

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 thatDLC=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.

@davidkirchnerdavidkirchner changed the titleFix DLC for CANFDFix DLC and add padding for CANFD framesSep 25, 2024
@davidkirchner
Copy link
ContributorAuthor

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:

vcan1  123  [11]  11 22 33 44 55 66 77 88 99 AA BB

As you can see a invalid CANFD frame with a data length of 11 ist being transmittet.
In comparison, when sending the same frame using the following cansend command

cansend vcan0 123##F112233445566778899AABB

the data is being correctly padded with 0 to the next valid data length (in this case 12).

vcan1  123  [12]  11 22 33 44 55 66 77 88 99 AA BB 00

I therefore updated theCanFdFrame::init andCanFdFrame::set_data functions in the last commit to correctly add padding to the data when needed.

Copy link
Collaborator

@fpagliughifpagliughi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

LGTM

@fpagliughifpagliughi merged commit05851f6 intosocketcan-rs:masterDec 23, 2024
@fpagliughi
Copy link
Collaborator

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:

let mut frame = canfd_frame_default();

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.

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@fpagliughifpagliughifpagliughi approved these changes

Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

2 participants
@davidkirchner@fpagliughi

[8]ページ先頭

©2009-2025 Movatter.jp