Skip to content

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
@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