embedded-hal icon indicating copy to clipboard operation
embedded-hal copied to clipboard

CAN: raw ID getter function

Open robamu opened this issue 6 months ago • 5 comments
trafficstars

robamu avatar May 13 '25 08:05 robamu

What is your use case for this? This has come up before (https://github.com/rust-embedded/embedded-hal/pull/428).

As described in the linked PR I’m not a big fan of the proposed API as it makes mixing Standard and Extended IDs easy, something that usually is not intended.

timokroeger avatar May 13 '25 16:05 timokroeger

I just wanted to retrieve the raw ID for quick debugging/printing purposes (after I could not simpy print it with defmt). I did not care about the Standard ID / Extended ID distinction in that case, and I found it weird/unintuitive that I had to unmatch the value. Basically, it is just an API that I expected to be there.

After going through the mentioned thread for a bit, I can see the point of intentionally making the mixup harder. The possible mixup of standard and extended ID is something that could be mentioned inside the documentation as well, but I guess this becomes a question about how to design the API and whether to expose methods like this which might increase convenience, but also introduce bugs when not used with care. I have not worked with more complex CAN buses yet with both standard and extended frames (just getting started) where this might become an issue.

robamu avatar May 13 '25 22:05 robamu

What about a raw_id_unchecked method with better documentation?

robamu avatar May 24 '25 10:05 robamu

after I could not simpy print it with defmt

Have you enabled defmt-0.3 feature?

burrbull avatar May 24 '25 11:05 burrbull

The latest main has defmt support, but not 0.4.1. A new release for embedded-can is required

robamu avatar May 24 '25 12:05 robamu

@timokroeger I updated the PR

robamu avatar Jul 22 '25 09:07 robamu

Looks reasonable to me but pinging @rust-embedded/hal for review

adamgreig avatar Aug 19 '25 18:08 adamgreig