Generate raw signal getters and setters - #193
Conversation
|
wouldn't this be really hard to update for the users? E.g. if they are using _raw now, would the meaning of that change? |
Users currently calling Though perhaps slightly painful, I think this resolves a big inconsistency in the function naming. |
|
right, but my point is that if we can make it backwards compat, perhas we should try to? A modification A->B + new A with the same signature is usually a path for foot-gun |
|
I'm happy to avoid the renaming if you prefer. We can keep the existing |
|
TBH I don't know what's better - I am not as much of a domain expert as others here, rather I focus on Rust itself. I am totally OK to rename things, as long as the old code fails to compile - thus helping users update it. If the meaning changes, but fn signature stays the same, we get a lot of non-obvious errors. |
|
This could be safe and not surprising anyone while moving towards correct naming?
Suffix |
I'm happy to rename to |
4cff4d3 to
4a14b82
Compare
|
|
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
|
sure, releasing is simple :) |
|
note though that we can keep 0.3.x going if we also keep the old one as deprecated |
|
Either version is OK with me, though there have been many feature additions and general updates since |
|
0.3.* is simpler to update to - i.e. it has no breaking changes (deprecations are ok as they are warnings) - so likely more ppl will update to it faster. If we can, we should stick to it |
| msg: &Message, | ||
| ) -> Result<()> { | ||
| writeln!(w, "/// Get raw value of '{}'", signal.name)?; | ||
| writeln!(w, "/// Get physical value of '{}'", signal.name)?; |
There was a problem hiding this comment.
can we factor rendering comment into a function so its not duplicated with the code above?
There was a problem hiding this comment.
<signal>_phys_val() is identical to the <signal> getter (except for multiplexed signals), so I ended up removing it from the public API and keeping it as an internal helper when required instead. This code is no longer duplicated.
| /// - Receivers: Node1 | ||
| #[inline(always)] | ||
| pub fn value1(&self) -> CanMultiplexedValue1 { | ||
| let signal = self.raw.view_bits::<Lsb0>()[8..16].load_le::<u8>(); |
There was a problem hiding this comment.
can we call the newly introduced function value1_raw_val?
| 1 => CanMultiplexedValue1::One, | ||
| 0 => CanMultiplexedValue1::Zero, | ||
| _ => CanMultiplexedValue1::_Other(self.value1_raw()), | ||
| _ => CanMultiplexedValue1::_Other(self.value1_phys_val()), |
There was a problem hiding this comment.
The signal is raw value, but then we are passing physical value into _Other.
Not sure if physical values exists for multiplexor - isnt it just raw value (enumerator value)?
There was a problem hiding this comment.
Apparently physical values can exist for multiplexor signals as they can still having scaling applied.
| #[inline(always)] | ||
| pub fn value1_raw(&self) -> u8 { | ||
| pub fn value1_phys_val(&self) -> u8 { | ||
| let signal = self.raw.view_bits::<Lsb0>()[8..16].load_le::<u8>(); |
There was a problem hiding this comment.
can we call the newly introduced function value1_raw_val?
There was a problem hiding this comment.
See my comment above; most <signal>_phys_val functions have been removed entirely.
| /// - Offset: 0 | ||
| /// - Byte order: LittleEndian | ||
| /// - Value type: Signed | ||
| /// - Unit: "" |
There was a problem hiding this comment.
maybe we could omit empty units? and quotes?
There was a problem hiding this comment.
Undefined units now shows up as Unit: Not specified instead of Unit: "". We could remove it entirely when the unit is not provided in the DBC, but I think it's better to be explicit and consistent whenever possible.
e9be606 to
bfa1391
Compare
f9b6591 to
5f80c98
Compare
<signal>_raw_valgetters and setters for every signal. These directly extract/pack the raw message payload bytes without any scaling or range checking.<signal>_rawgetters, which returned the physical (scaled) signal values. This value is derivable viaPrimitive::from(<signal>())for enum-typed signals and is identical to<signal>_raw_valfor multiplexor signals.<signal>_multiplexedto avoid confusion with ordinary getter functions.As a result,
<signal>/set_<signal>consistently operates on the fully-processed (scaled, typed) signal regardless of type (simple, enum, or multiplexor), and<signal>_raw_val/set_<signal>_raw_valalways operates on unprocessed message payload bits. This fixes the previously confusing function naming but is a breaking API change.