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 formating of Arg::Ixx based integer hex values #646

Merged
merged 3 commits into from
Dec 14, 2021

Conversation

justahero
Copy link
Contributor

@justahero justahero commented Dec 1, 2021

This PR solves #632, it formats signed integers as hex values based on their given type, instead of formating it using a i128 based value.

Before this change the following log code:

defmt::info!("x: {=i16:#x}", -1_i16);

produced the output:

0 INFO  x: 0xffffffffffffffffffffffffffffffff
└─ hello::__cortex_m_rt_main @ src/bin/hello.rs:8

After the change the decoder takes the initial integer type into account when formating integer based hex values, the output is now:

0 INFO  x: 0xffff
└─ hello::__cortex_m_rt_main @ src/bin/hello.rs:8

The reason is that the decoder parsed all integer values as either Arg::Ixx or Arg::Uxx variants with the biggest data type to store the value in (i128 & u128), while keeping the original type information in a separate Parameter as part of the Frame.

The change now passes the integer type information to function Frame::format_i128. The new helper struct Hex128 implements both the LowerHex and UpperHex traits by delegating the call to the appropriate underlying type implementation.

Note this requires an update of probe-run that uses the defmt-decoder with the fix, a release will follow soon.

  • fix formating of integer based hex values
  • expand snapshot program log to output a number of different hex values

* add struct to implement `LowerHex` & `UpperHex` traits for different
  integer values
* expand `log` snapshot tests
* pass type parameter to `format_i128` function
@justahero justahero force-pushed the fix-negative-values-i16-formatted-output branch from 3f498eb to 0c32f36 Compare December 1, 2021 17:40
* add test output to check unsigned integer hex display
@jonas-schievink
Copy link
Contributor

Nice!

bors r+

@bors
Copy link
Contributor

bors bot commented Dec 14, 2021

Build succeeded:

@bors bors bot merged commit 45a56ac into main Dec 14, 2021
@bors bors bot deleted the fix-negative-values-i16-formatted-output branch December 14, 2021 15:37
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