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

Allow for split integers #60

Open
wucke13 opened this issue Dec 3, 2020 · 3 comments
Open

Allow for split integers #60

wucke13 opened this issue Dec 3, 2020 · 3 comments

Comments

@wucke13
Copy link

wucke13 commented Dec 3, 2020

I want to use packed_struct to implement this protocol. Unfortunately it uses split integers. By that I mean an integer which is derived by concatenating multiple bit sequences together. For example, the subprotocol is the number one gets by the following expression: (buf[0] & 1)<<5 | (buf[1] & 0b11111) | (buf[26] & 0b11000000). Is it possible to make this work in packed_struct with reasonable effort?

Edit: Actually flipping bits would be useful as well, but there is ways to work around it.

@rudib
Copy link
Member

rudib commented Dec 3, 2020

This seems like a very niche problem, if there are more protocols like this in the wild (I've never encountered one) then I might be interested in this. Internally, all of the fields are represented by bits ranges (from bit 0 to bit 7, for instance), so that would need to be rewritten into a list-of-ranges-or-bits structure.

For your use case, I'd define three fields with smaller bit widths, then simply implement a method on the structure to either set or get the final value from these three small integers.

@wucke13
Copy link
Author

wucke13 commented Dec 3, 2020

Ok then. I also was kind of stunned when I first saw that protocol, but I guess that's what happens if evolution hits a project.

@cujomalainey
Copy link

cujomalainey commented Jan 22, 2022

Garmin's ANT+ Environment Profile also suffers from this problem, I think it was more of a design error though because I have yet to see it any other profile and I have read probably half of them

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

No branches or pull requests

3 participants