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

MAVLink XML change to allow exponentiation operator in bitmask flag #33

Closed
hamishwillee opened this issue Feb 26, 2024 · 5 comments
Closed

Comments

@hamishwillee
Copy link

hamishwillee commented Feb 26, 2024

FYI We're modifying the MAVLink XSD validation file in ArduPilot/pymavlink#920 to allow a bitmask value to be declared using the Python exponentiation operator.

This makes it easier to immediately visualize which bit is set by a flag, because you can use the syntax

<entry value="2**15" name="BIT15" />

rather than

<entry value="32768" name=" BIT15" />

This is transparent to mavgen because the parser evaluates the number before creating the generated headers. However it may affect other parsers.
We're not updating the XML yet to allow other parsers time to update.

Any concerns, please raise on ArduPilot/pymavlink#920

@padcom
Copy link
Collaborator

padcom commented Feb 28, 2024

When is that going to be used in Mavlink definitions? Is it already there?

@padcom
Copy link
Collaborator

padcom commented Feb 28, 2024

More importantly, have you checked if it already works? The way mavlink-mappings works is it takes the content of the attribute and puts it straight in the generated code. Since Node.js already supports the ** operator since version 7 (that's 2017 so 7 years ago) it just works with no additional code changes to the generator.

For that reason, I am hesitant to make any additional parsing/interpreting of the values in XML definitions and just rely on the language to do the right thing.

@padcom padcom closed this as completed Feb 28, 2024
@padcom
Copy link
Collaborator

padcom commented Feb 28, 2024

/**
 * These flags encode the MAV mode.
 */
export enum MavModeFlag {
  /**
   * 0b10000000 MAV safety set to armed. Motors are enabled / running / can start. Ready to fly.
   * Additional note: this flag is to be ignore when sent in the command MAV_CMD_DO_SET_MODE and
   * MAV_CMD_COMPONENT_ARM_DISARM shall be used instead. The flag can still be used to report the armed
   * state.
   */
  'SAFETY_ARMED'                                 = 2**7,

...

@hamishwillee
Copy link
Author

Anything that uses mavgen will work because the python parser evaluates the Python evaluation operator before generating code. So yes, it works.

We haven't rolled it out yet, but it is tested for mavgen.

Generators that use some other language for the parsing will need to make sure the ** is evaluated as a exponentiation operator.

Probably we'll look at making some bitmap changes in a few week.s

@padcom
Copy link
Collaborator

padcom commented Feb 28, 2024

Ping me when you're through. I'll check it.

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

2 participants