Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix decode choices #624

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

fix decode choices #624

wants to merge 1 commit into from

Conversation

xlb8
Copy link

@xlb8 xlb8 commented Nov 17, 2023

hi :
I noticed that the values used for decoding choices are not scaled. Is this a bug or is there some other consideration? For example, here is my choice list [-1: good, 0: ok, 1: good], with a scale and shift of 1, -1. When the value is 2, after decoding, it becomes 2 * 1 - 1 = 1, which means "good." However, when I select the decode choice, it is interpreted as the numerical value 1 instead of "good." This is because 2 is not in the choice list, so it returns the decoded value of 2 * 1 - 1 = 1, rather than "good." If the value is 1, it actually equals 1 * 1 - 1 = 0. However, in this case, it returns "good." Is there a bug or is there a specific reason for this behavior?

@andlaus
Copy link
Member

andlaus commented Nov 17, 2023

Is this a bug or is there some other consideration?

your understanding of how the DBC file format works is probably slightly wrong, as things are supposed to be like this: the choices are based on internal values (i.e., the values send over the wire). If scaling was taken into account before resolving names, it would be pretty difficult to specify any named values considering that scaling factors and offsets are often floating point values and thus subject to rounding errors...

@xlb8
Copy link
Author

xlb8 commented Nov 18, 2023 via email

@andlaus
Copy link
Member

andlaus commented Nov 18, 2023

maybe the dbc designer was wrong...?

as I see it, that is almost certainly the case. If you really are not able to fix that particular DBC, you can decode your messages using msg.decode(data, scaling=False, decode_choices=False) and manually do the scaling/decoding as a post processing step...

@xlb8
Copy link
Author

xlb8 commented Nov 18, 2023 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants