mavlink_bitmask_decoder.py 938 B

1234567891011121314151617181920212223242526272829303132333435
  1. #!/usr/bin/env python
  2. from __future__ import print_function
  3. from pymavlink import mavutil
  4. import argparse
  5. def print_decode(messagetype, field, value):
  6. decoded = mavutil.decode_bitmask(messagetype, field, value)
  7. for bit_value in decoded:
  8. value = bit_value.value
  9. offset = bit_value.offset
  10. name = bit_value.name
  11. svalue = " "
  12. if not value:
  13. svalue = "!"
  14. if name is None:
  15. name = "[UNKNOWN]"
  16. print("%s %s" % (svalue, name))
  17. parser = argparse.ArgumentParser(description=__doc__)
  18. parser.add_argument("message")
  19. parser.add_argument("field")
  20. parser.add_argument("value")
  21. args = parser.parse_args()
  22. # print("Usage: decode-mavlink-bitmask.py MESSAGETYPE FIELDNAME VALUE")
  23. # print("e.g: decode-mavlink-bitmask.py SYS_STATUS onboard_control_sensors_health 12531")
  24. # sys.exit(1)
  25. print_decode(args.message, args.field, int(args.value))