mavparms.py 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #!/usr/bin/env python
  2. '''
  3. extract mavlink parameter values
  4. '''
  5. from __future__ import print_function
  6. import time
  7. from argparse import ArgumentParser
  8. parser = ArgumentParser(description=__doc__)
  9. parser.add_argument("-c", "--changes", dest="changesOnly", default=False, action="store_true", help="Show only changes to parameters.")
  10. parser.add_argument("logs", metavar="LOG", nargs="+")
  11. args = parser.parse_args()
  12. from pymavlink import mavutil
  13. parms = {}
  14. def mavparms(logfile):
  15. '''extract mavlink parameters'''
  16. mlog = mavutil.mavlink_connection(filename)
  17. while True:
  18. try:
  19. m = mlog.recv_match(type=['PARAM_VALUE', 'PARM'])
  20. if m is None:
  21. return
  22. except Exception:
  23. return
  24. if m.get_type() == 'PARAM_VALUE':
  25. pname = str(m.param_id).strip()
  26. value = m.param_value
  27. else:
  28. pname = m.Name
  29. value = m.Value
  30. if len(pname) > 0:
  31. if args.changesOnly is True and pname in parms and parms[pname] != value:
  32. print("%s %-15s %.6f -> %.6f" % (time.asctime(time.localtime(m._timestamp)), pname, parms[pname], value))
  33. parms[pname] = value
  34. total = 0.0
  35. for filename in args.logs:
  36. mavparms(filename)
  37. if (args.changesOnly is False):
  38. keys = list(parms.keys())
  39. keys.sort()
  40. for p in keys:
  41. print("%-15s %.6f" % (p, parms[p]))