mavsigloss.py 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #!/usr/bin/env python
  2. '''
  3. show times when signal is lost
  4. '''
  5. from __future__ import print_function
  6. import time
  7. from argparse import ArgumentParser
  8. parser = ArgumentParser(description=__doc__)
  9. parser.add_argument("--no-timestamps", dest="notimestamps", action='store_true', help="Log doesn't have timestamps")
  10. parser.add_argument("--planner", action='store_true', help="use planner file format")
  11. parser.add_argument("--robust", action='store_true', help="Enable robust parsing (skip over bad data)")
  12. parser.add_argument("--deltat", type=float, default=1.0, help="loss threshold in seconds")
  13. parser.add_argument("--condition", default=None, help="select packets by condition")
  14. parser.add_argument("--types", default=None, help="types of messages (comma separated)")
  15. parser.add_argument("logs", metavar="LOG", nargs="+")
  16. args = parser.parse_args()
  17. from pymavlink import mavutil
  18. def sigloss(logfile):
  19. '''work out signal loss times for a log file'''
  20. print("Processing log %s" % filename)
  21. mlog = mavutil.mavlink_connection(filename,
  22. planner_format=args.planner,
  23. notimestamps=args.notimestamps,
  24. robust_parsing=args.robust)
  25. last_t = 0
  26. types = args.types
  27. if types is not None:
  28. types = types.split(',')
  29. while True:
  30. m = mlog.recv_match(condition=args.condition)
  31. if m is None:
  32. return
  33. if types is not None and m.get_type() not in types:
  34. continue
  35. if args.notimestamps:
  36. if not 'usec' in m._fieldnames:
  37. continue
  38. t = m.usec / 1.0e6
  39. else:
  40. t = m._timestamp
  41. if last_t != 0:
  42. if t - last_t > args.deltat:
  43. print("Sig lost for %.1fs at %s" % (t-last_t, time.asctime(time.localtime(t))))
  44. last_t = t
  45. total = 0.0
  46. for filename in args.logs:
  47. sigloss(filename)