Skip to content

Generate enum-typed setters and constructors for signals with value descriptions#178

Open
felixvanoost wants to merge 4 commits into
oxibus:mainfrom
felixvanoost:allow-enum-values-in-setters
Open

Generate enum-typed setters and constructors for signals with value descriptions#178
felixvanoost wants to merge 4 commits into
oxibus:mainfrom
felixvanoost:allow-enum-values-in-setters

Conversation

@felixvanoost

Copy link
Copy Markdown
Contributor
  • Updates the generated new() constructors and set_<signal>() setters to accept enums for signals that have an associated enum type (value description in the DBC).
  • Generates additional set_<signal>_raw() setters for signals that have an associated enum type, which matches the existing behaviour of set_<signal> before these changes. This now makes the API for the getters and setters symmetrical.
  • Cleans up the formatting of some generated getter/setter function comments for readability and consistency.

This is a breaking change for DBCs that have signals with value descriptions, but should make these signals much cleaner to handle. The best approach is to directly pass the enum-typed signals into set_<signal>, but you can retain the existing behaviour by simply using set_<signal>_raw instead.

This PR should be stacked on top of #176.

@felixvanoost
felixvanoost requested a review from nyurik July 14, 2026 21:05
@felixvanoost felixvanoost self-assigned this Jul 14, 2026
@felixvanoost felixvanoost added the enhancement New feature or request label Jul 14, 2026
@codecov

codecov Bot commented Jul 15, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 84.26966% with 14 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/lib.rs 84.26% 14 Missing ⚠️

📢 Thoughts on this report? Let us know!

@felixvanoost
felixvanoost requested a review from trnila July 17, 2026 14:08
@felixvanoost
felixvanoost force-pushed the allow-enum-values-in-setters branch from 6fd246c to fe3a365 Compare July 18, 2026 02:53
Comment thread src/lib.rs Outdated
w,
"{visibility}fn set_{field}(&mut self, value: {typ}) -> Result<(), CanError> {{",
)?;
let param_ty = signal_pub_type(dbc, msg, signal);

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.

(would prefer full name param_type or signal_type?)

/// Set raw value of 'Value1'
#[inline(always)]
pub fn set_value1(&mut self, value: u8) -> Result<(), CanError> {
pub fn set_value1_raw(&mut self, value: u8) -> Result<(), CanError> {

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.

I think signal bits extracted from received/sent bytes are called raw. This raw value is then converted into physical value (e.g. bits into floating voltage 5.02V) by scaling and adding offset.

This function is actually converting physical value into its raw value and we dont have any function to set the real raw bits. Not sure if there are usecases, but it might be little confusing? Not sure if set_value1_logical wouldn't be better?

The non-suffix type-safe set_value1 would pass logical value into set_value1_logical, that applies linear transformation and then stores the raw bits into the buffer.

@felixvanoost
felixvanoost force-pushed the allow-enum-values-in-setters branch from fe3a365 to 43b5de7 Compare July 18, 2026 14:04
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.

2 participants