-
Notifications
You must be signed in to change notification settings - Fork 600
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
Mavschema: Allow enum values to be powers of 2 #920
Mavschema: Allow enum values to be powers of 2 #920
Conversation
On Sat, 10 Feb 2024, Simon Hancock wrote:
I tried out the full variety of enum value syntax with Mavgen, and it works without any modifications, as it already does an 'eval' on the value. e.g.:
We should be careful making assumptions about what's parsing this.
mavgen.py (and the XML validator ;-) isn't the only thing used to go
through this XML, and implementation might not be as simple on other
devices.
Not to say that we can't make the change, just that we should at least
know who we are going to annoy before we do it...
@hamishwillee might know of other things that walk this XML?
|
Firstly, thanks @shancock884 ! My general preference would have been to use the ^ symbol, as that is by far the most common operator used for indicating exponent. I guess you used the That makes sense for the mavgen parser because I assume it evaluates this value in the parsing stage and stores it as the full number. So when code is generated, the output is already converted - right? I am not sure we can make that assumption for other parsers, but in any case, as we discussed last night in the dev call they need to be updated anyway. I have emailed the GCS group for discussion and pinged a few of the other generators https://mavlink.io/en/#external-generatorslanguages - you can see the ones I added comments for as linked issues |
FYI, from OllieW:
|
I also would have preferred '^' visually, but as '^' is bitwise-not in Python (and Javascript), parsers that simply do 'eval' on the string would end up with the wrong number (e.g. 2^3 => 1) and it may not be obvious that something has gone wrong, whereas using '**' may well work without (or with easy) modifications in parsers written in Python and JS.
Correct. |
@shancock884 Thanks for the clarifications. While XML is supposed to be language agnostic I think using |
@peterbarker What do you think of this? Can we get it merged? |
On Tue, 20 Feb 2024, Hamish Willee wrote:
@peterbarker What do you think of this? Can we get it merged?
Probably - I've marked it for DevCallEU tonight.
|
Thanks very much. Good to see. |
Implemented in libmav here: Auterion/libmav#42 |
This is a follow-up from comments in #915.
It allows use of powers of 2 to specify enum values - which would be most useful for big bitmasks.
Example syntax is:
<entry value="2**7" name="BIT7" />
@hamishwillee in #915 (comment) wrote:
I couldn't see how this was possible, as this is part of the rule for the 'value' field of enum 'entry' tag. Although I suspect xsd syntax can do many things that I don't know about!
The syntax allows the user to use any of: decimal, hex, binary, power of 2.
No XML has been changed.
Note that the comment next to the binary rule has also been corrected from 'base 1' to 'base 2'.
Testing
I tried out the full variety of enum value syntax with Mavgen, and it works without any modifications, as it already does an 'eval' on the value. e.g.:
I was planning to include this in the Wireshark generator test I am building for the fix to issue: #895 (of which the above is an extract). This would mean it will be tested as part of pymavlink CI.