Generating Source Files
Language-specific files can be generated using a Python script from the command line or via a GUI. The available languages for each version of the MAVLink protocol are listed in Introduction > Supported Languages (these include C, C#, Java, Python etc).
The tools must already have been set up as described in Getting Started > Installation section (in particular Tkinter must be installed to use the GUI tool).
Dialect XML files that have dependencies on other XML files must be located in the same directory. Since most MAVLink dialects depend on the common.xml message set, you should place your dialect with the others in
MAVLink Generator Tool (GUI)
MAVLink Generator (mavgenerate.py) is a header generation tool GUI written in Python. It can be run from anywhere using Python's -m argument:
python -m mavgenerate
- Choose the target XML file (typically in mavlink/message_definitions).
- Choose an output directory (e.g. mavlink/include).
- Select the target output programming language.
- Select the target MAVLink protocol version (ideally 2.0)
Generation will fail if the protocol is not supported by the selected programming language.
- Optionally check Validate and/or Validate Units (if checked validates XML specifications).
- Click Generate to create the source files.
Mavgen (Command Line)
mavgen.py is a command-line interface for generating a language-specific MAVLink library.
mavlink directory has been added to the
PYTHONPATH, it can be run by executing from the command line.
This is the backend used by mavgenerate.py. The documentation below explains all the options for both tools.
For example, to generate MAVLink 2 C libraries for the common.xml dialect:
python -m pymavlink.tools.mavgen --lang=C --wire-protocol=2.0 --output=generated/include/mavlink/v2.0 message_definitions/v1.0/common.xml
The full syntax can be output by running mavgen with the
-h flag (reproduced below):