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 bitfield C macros #1099

Closed
wants to merge 5 commits into from
Closed

Fix bitfield C macros #1099

wants to merge 5 commits into from

Conversation

reimerix
Copy link
Contributor

@reimerix reimerix commented Mar 2, 2022

This PR fixes up the bitfield setting macros. The previous definition resulted in unexpected results because the bitfield was not reset before bitwise-or-ing the new value.

@@ -316,7 +316,7 @@ def create_bitfield_macros(field, msg):
bitrange = (item.get("range")).split(":")
start_bit = int(bitrange[0])
ret_list.append(
"#define {}_MASK ({})".format(base_string, hex((1 << nbits) - 1))
"#define {}_MASK ({}u)".format(base_string, hex((1 << nbits) - 1))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The changes in this file are the only ones that need to be reviewed - the rest was auto-generated.

Copy link
Contributor

@RReichert RReichert left a comment

Choose a reason for hiding this comment

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

LGTM. The only thing I would request, if possible, is adding a unit test to validate that you can set and clear the specified flags, would help avoid this issue resurfacing in the future.

@notoriaga
Copy link
Contributor

notoriaga commented Mar 3, 2022

LGTM. The only thing I would request, if possible, is adding a unit test to validate that you can set and clear the specified flags, would help avoid this issue resurfacing in the future.

It'd be nice if we could add this to the test generation framework. We recently added bitfield helpers to the rust client, so we already have two languages in which it'd be nice to have tests around this stuff. I also recently caught an error where the lsb/msb range was incorrect for a message in the spec. That'd be a bit more work than just adding a few unit tests here, @silverjam what do you think maybe track this on the dev infra board?

Copy link
Contributor

@silverjam silverjam left a comment

Choose a reason for hiding this comment

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

Please do not merge yet, since we've already published this behavior we need to think carefully about how this will affect existing users-- it looks like the existing macro was acting more like a |= -- which makes sense for "flag" style bitfields, but does not make sense for "value" style bitfields.

Some alternatives we should consider that are backwards compatible (or at least provide a clear migration path):

  1. creating a new macro SBP_<msg>_<bitfield>_RESET -- either clears the value, or takes a value to reset the bitfield to
  2. rev'ing the major version of the SBP library, and removing these macros, replacing with SBP_<msg>_<bitfield>_SET_FLAG and SBP_<msg>_<bitfield>_SET_VALUE.

@reimerix reimerix requested a review from jungleraptor March 3, 2022 22:36
@reimerix reimerix removed the request for review from jungleraptor March 3, 2022 22:36
@silverjam
Copy link
Contributor

silverjam commented Mar 4, 2022

Created https://swift-nav.atlassian.net/browse/DEVINFRA-655 to track (for next sprint)

@reimerix reimerix requested review from a team as code owners March 30, 2022 19:34
@silverjam
Copy link
Contributor

Closing since this will be covered in a different PR by @isaactorz for https://swift-nav.atlassian.net/browse/DEVINFRA-655

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.

5 participants