Skip to content
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

Added an id method to all message structs #71

Closed
wants to merge 4 commits into from

Conversation

JoNil
Copy link
Contributor

@JoNil JoNil commented May 8, 2024

No description provided.

Copy link
Contributor

@projectgus projectgus left a comment

Choose a reason for hiding this comment

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

Nice, I was going to submit a PR to add this too. :)

@@ -351,6 +351,15 @@ fn render_message(mut w: impl Write, config: &Config<'_>, msg: &Message, dbc: &D
writeln!(&mut w, "}}")?;
writeln!(w)?;

writeln!(&mut w, "/// Access message id")?;
writeln!(&mut w, "pub fn id(&self) -> u32 {{",)?;
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
writeln!(&mut w, "pub fn id(&self) -> u32 {{",)?;
writeln!(&mut w, "pub fn message_id(&self) -> u32 {{",)?;

For consistency with the constant name?

writeln!(&mut w, "pub fn id(&self) -> u32 {{",)?;
{
let mut w = PadAdapter::wrap(&mut w);
writeln!(&mut w, "Self::MESSAGE_ID & 0x1FFF_FFFF")?;
Copy link
Contributor

Choose a reason for hiding this comment

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

Just curious, why does it need the bitwise AND? If MESSAGE_ID is bigger than 29-bits then shouldn't it fail somewhere else?

Copy link
Member

@killercup killercup left a comment

Choose a reason for hiding this comment

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

What's the value of this over accessing the public constant?

If we decide to add this, please add a check that we don't conflict if there is a field called "id".

@projectgus
Copy link
Contributor

projectgus commented May 13, 2024

What's the value of this over accessing the public constant?

I can't speak for @JoNil, but what I was hoping to work towards is defining a trait over all messages that lets you access message_id and raw. With a goal to writing code in my project like a send<impl that_trait>(&msg) function that sends an arbitrary message struct to a CAN controller, for example.

@killercup
Copy link
Member

killercup commented May 14, 2024 via email

@killercup
Copy link
Member

#82 adds impls for embedded_can::Frame which has an id method. I'll go with that one :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants