Skip to content

Generate raw signal getters and setters - #193

Open
felixvanoost wants to merge 11 commits into
oxibus:mainfrom
felixvanoost:generate-raw-accessors
Open

Generate raw signal getters and setters#193
felixvanoost wants to merge 11 commits into
oxibus:mainfrom
felixvanoost:generate-raw-accessors

Conversation

@felixvanoost

@felixvanoost felixvanoost commented Aug 24, 2026

Copy link
Copy Markdown
Contributor
  • Generates new <signal>_raw_val getters and setters for every signal. These directly extract/pack the raw message payload bytes without any scaling or range checking.
  • Removes the existing <signal>_raw getters, which returned the physical (scaled) signal values. This value is derivable via Primitive::from(<signal>()) for enum-typed signals and is identical to <signal>_raw_val for multiplexor signals.
  • Renames the multiplexor routing selector function to <signal>_multiplexed to avoid confusion with ordinary getter functions.
  • Makes some minor improvements to the formatting of generated function documentation according to the Rust API guidelines.

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_val always operates on unprocessed message payload bits. This fixes the previously confusing function naming but is a breaking API change.

@felixvanoost
felixvanoost requested review from nyurik and trnila August 24, 2026 17:40
@felixvanoost felixvanoost self-assigned this Aug 24, 2026
@felixvanoost felixvanoost added the enhancement New feature or request label Aug 24, 2026
@nyurik

nyurik commented Aug 24, 2026

Copy link
Copy Markdown
Member

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?

@felixvanoost

felixvanoost commented Aug 24, 2026

Copy link
Copy Markdown
Contributor Author

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 _raw() can simply rename to _phys() to achieve the same behaviour as before. It should be a simple change as long as users are aware of it. Perhaps a good opportunity to bump the release version?

Though perhaps slightly painful, I think this resolves a big inconsistency in the function naming.

@nyurik

nyurik commented Aug 24, 2026

Copy link
Copy Markdown
Member

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

@felixvanoost

Copy link
Copy Markdown
Contributor Author

I'm happy to avoid the renaming if you prefer. We can keep the existing _raw() naming for the physical values, and I can call these new getter/setters _bits() instead. This is fully backwards compatible but IMO it now creates two naming changes that should be resolved at some point.

@nyurik

nyurik commented Aug 24, 2026

Copy link
Copy Markdown
Member

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.

@trnila

trnila commented Aug 24, 2026

Copy link
Copy Markdown
Member

This could be safe and not surprising anyone while moving towards correct naming?

  • rename {signal}_raw to {signal}_phys / {signal}_phys_val to get scaled physical values (now with correct name)
    • current users will have to trivially rename function in order to compile
  • new function {signal}_raw_bits() / {signal_raw_val()} to get received bits/value without any scaling

Suffix _val is little bit longer, but it could be consistent at least.

@felixvanoost

Copy link
Copy Markdown
Contributor Author

This could be safe and not surprising anyone while moving towards correct naming?

* rename `{signal}_raw` to `{signal}_phys` / `{signal}_phys_val` to get scaled physical values (now with correct name)
  
  * current users will have to trivially rename function in order to compile

* new function `{signal}_raw_bits()` / `{signal_raw_val()`} to get received bits/value without any scaling

Suffix _val is little bit longer, but it could be consistent at least.

I'm happy to rename to {signal}_phys_val and {signal}_raw_val for consistency everywhere. Any preference on phys_val/raw_val vs. val_raw/val_phys?

@felixvanoost
felixvanoost force-pushed the generate-raw-accessors branch from 4cff4d3 to 4a14b82 Compare August 25, 2026 19:42
@trnila

trnila commented Aug 26, 2026

Copy link
Copy Markdown
Member

phys_val / raw_val sounds more naturally - at least to me.

@felixvanoost
felixvanoost enabled auto-merge (squash) August 27, 2026 18:11
@codecov

codecov Bot commented Aug 28, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 95.29412% with 4 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/lib.rs 95.29% 4 Missing ⚠️

📢 Thoughts on this report? Let us know!

@felixvanoost

Copy link
Copy Markdown
Contributor Author

@trnila I've updated the function names, let me know what you think.

@nyurik any chance we could release v0.4.0 (#122) after this is merged since the API has changed?

@nyurik

nyurik commented Aug 28, 2026

Copy link
Copy Markdown
Member

sure, releasing is simple :)

@nyurik

nyurik commented Aug 28, 2026

Copy link
Copy Markdown
Member

note though that we can keep 0.3.x going if we also keep the old one as deprecated

@felixvanoost

Copy link
Copy Markdown
Contributor Author

Either version is OK with me, though there have been many feature additions and general updates since v0.3.0.

@nyurik

nyurik commented Aug 28, 2026

Copy link
Copy Markdown
Member

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

Comment thread src/lib.rs Outdated
msg: &Message,
) -> Result<()> {
writeln!(w, "/// Get raw value of '{}'", signal.name)?;
writeln!(w, "/// Get physical value of '{}'", signal.name)?;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

can we factor rendering comment into a function so its not duplicated with the code above?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

<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>();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

can we call the newly introduced function value1_raw_val?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done!

1 => CanMultiplexedValue1::One,
0 => CanMultiplexedValue1::Zero,
_ => CanMultiplexedValue1::_Other(self.value1_raw()),
_ => CanMultiplexedValue1::_Other(self.value1_phys_val()),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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)?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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>();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

can we call the newly introduced function value1_raw_val?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

See my comment above; most <signal>_phys_val functions have been removed entirely.

/// - Offset: 0
/// - Byte order: LittleEndian
/// - Value type: Signed
/// - Unit: ""

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

maybe we could omit empty units? and quotes?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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.

@felixvanoost
felixvanoost force-pushed the generate-raw-accessors branch from e9be606 to bfa1391 Compare August 31, 2026 14:37
@felixvanoost
felixvanoost force-pushed the generate-raw-accessors branch from f9b6591 to 5f80c98 Compare August 31, 2026 15:55
@felixvanoost
felixvanoost requested a review from trnila August 31, 2026 16:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants