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 bug with unsigned types and negative factors #78

Merged
merged 21 commits into from
Jun 26, 2024

Conversation

cpctaylo
Copy link
Contributor

@cpctaylo cpctaylo commented May 20, 2024

This PR fixes a bug in how the library chooses Rust types to represent signals.

We tried a DBC with a 16 bit unsigned signal with a factor of -1. This means the range of valid values is [-65535, 0]. But this confused the function scaled_signal_to_rust_int which chose i8 when it should have picked i32.

This PR will:

  • Change scaled_signal_to_rust_int to look at the whole range of values for a signal and pick the smallest Rust type.
  • Ignore min and max values when deciding Rust types for a signal because Config.check_ranges can disable range checking. To be on the safe side, this picks types assuming the worst-case values for a signal.
  • Drop the symlink in testing/can-messages/src/messages.rs because it doesn't work on Windows. Now testing/can-messages/build.rs copies the file from can-messages to can-embedded.
  • Fix build order so can-messages goes before can-embedded.
  • Add unit and integration tests. UnsignedNegativeFactorSignal in example.dbc will reproduce the bug.

Happy to address any comments or change requests.

@cpctaylo cpctaylo changed the title Fix negative factor (WIP) Fix bug with unsigned types and negative factors (WIP) May 21, 2024
@cpctaylo cpctaylo marked this pull request as ready for review May 21, 2024 20:57
@cpctaylo cpctaylo changed the title Fix bug with unsigned types and negative factors (WIP) Fix bug with unsigned types and negative factors May 21, 2024
Copy link

@cplnixon cplnixon left a comment

Choose a reason for hiding this comment

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

Implemented logic seems sound and test coverage looks thorough 👍

Copy link
Member

@killercup killercup left a comment

Choose a reason for hiding this comment

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

I trust you guys!

@killercup killercup merged commit a3fec55 into technocreatives:main Jun 26, 2024
2 checks passed
@cpctaylo cpctaylo deleted the fix-negative-factor branch June 26, 2024 15:28
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.

3 participants