mavgen.py 1.7 KB

12345678910111213141516171819202122232425262728293031
  1. #!/usr/bin/env python
  2. '''
  3. parse a MAVLink protocol XML file and generate a python implementation
  4. Copyright Andrew Tridgell 2011
  5. Released under GNU GPL version 3 or later
  6. '''
  7. # allow running mavgen from within the tree without installing
  8. if __name__ == "__main__" and __package__ is None:
  9. from os import sys, path
  10. sys.path.insert(0, path.dirname(path.dirname(path.dirname(path.abspath(__file__)))))
  11. from pymavlink.generator import mavgen
  12. from pymavlink.generator import mavparse
  13. from argparse import ArgumentParser
  14. parser = ArgumentParser(description="This tool generate implementations from MAVLink message definitions")
  15. parser.add_argument("-o", "--output", default="mavlink", help="output directory.")
  16. parser.add_argument("--lang", dest="language", choices=mavgen.supportedLanguages, default=mavgen.DEFAULT_LANGUAGE, help="language of generated code [default: %(default)s]")
  17. parser.add_argument("--wire-protocol", choices=[mavparse.PROTOCOL_0_9, mavparse.PROTOCOL_1_0, mavparse.PROTOCOL_2_0], default=mavgen.DEFAULT_WIRE_PROTOCOL, help="MAVLink protocol version. [default: %(default)s]")
  18. parser.add_argument("--no-validate", action="store_false", dest="validate", default=mavgen.DEFAULT_VALIDATE, help="Do not perform XML validation. Can speed up code generation if XML files are known to be correct.")
  19. parser.add_argument("--error-limit", default=mavgen.DEFAULT_ERROR_LIMIT, help="maximum number of validation errors to display")
  20. parser.add_argument("--strict-units", action="store_true", dest="strict_units", default=mavgen.DEFAULT_STRICT_UNITS, help="Perform validation of units attributes.")
  21. parser.add_argument("definitions", metavar="XML", nargs="+", help="MAVLink definitions")
  22. args = parser.parse_args()
  23. mavgen.mavgen(args, args.definitions)