Generate enum-typed setters and constructors for signals with value descriptions#178
Generate enum-typed setters and constructors for signals with value descriptions#178felixvanoost wants to merge 4 commits into
Conversation
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
6fd246c to
fe3a365
Compare
| w, | ||
| "{visibility}fn set_{field}(&mut self, value: {typ}) -> Result<(), CanError> {{", | ||
| )?; | ||
| let param_ty = signal_pub_type(dbc, msg, signal); |
There was a problem hiding this comment.
(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> { |
There was a problem hiding this comment.
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.
fe3a365 to
43b5de7
Compare
new()constructors andset_<signal>()setters to accept enums for signals that have an associated enum type (value description in the DBC).set_<signal>_raw()setters for signals that have an associated enum type, which matches the existing behaviour ofset_<signal>before these changes. This now makes the API for the getters and setters symmetrical.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 usingset_<signal>_rawinstead.This PR should be stacked on top of #176.