-
Notifications
You must be signed in to change notification settings - Fork 260
Add traits for CAN FD #723
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
mickeprag
commented
Jan 23, 2026
- Implement CAN FD frame
- Implement a CAN FD interface
liamkinne
left a comment
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.
Just some thoughts on this implementation.
embedded-can/src/blocking.rs
Outdated
| fn transmit_fd(&mut self, frame: &Self::FDFrame) -> Result<(), Self::Error>; | ||
|
|
||
| /// Blocks until a fd frame was received or an error occurred. | ||
| fn receive_fd(&mut self) -> Result<Self::FDFrame, Self::Error>; |
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.
How does this work for receivers that want to receive both FD and non-FD frames? By your description this would only return FD frames.
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.
Do you have a suggestion for a signature?
Should we perhaps return an enum that can handle both frame types?
| fn dlc(&self) -> usize; | ||
|
|
||
| /// Returns the length of the frame data in bytes. | ||
| fn length(&self) -> usize { |
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.
Is this any different to .data().len()? I'm assuming it would be implemented that way anyway.
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.
The length will be derived from the dlc. So the .data() function must read the dlc anyway to be able to return the correct length for the slice. Doing .data().len() needs to call dlc() internally anyway. I see no reason for the extra roundtrip creating a slice. I am providing a default implementation anyway so consumers of the trait does not need to implement it.
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.
To be honest, I rather think the implementation will be the other way around. Implementations of data() will be calling the length() method, instead of length() calling data()...