mavsearch.py 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #!/usr/bin/env python
  2. '''
  3. search a set of log files for a condition
  4. '''
  5. from __future__ import print_function
  6. from pymavlink import mavutil
  7. from argparse import ArgumentParser
  8. parser = ArgumentParser(description=__doc__)
  9. parser.add_argument("--condition", default=None, help="conditional check on log")
  10. parser.add_argument("--types", default=None, help="message types to look for (comma separated)")
  11. parser.add_argument("--stop", action='store_true', help="stop when message type found")
  12. parser.add_argument("--stopcondition", action='store_true', help="stop when condition met")
  13. parser.add_argument("logs", metavar="LOG", nargs="+")
  14. args = parser.parse_args()
  15. def mavsearch(filename):
  16. print("Loading %s ..." % filename)
  17. mlog = mavutil.mavlink_connection(filename)
  18. if args.types is not None:
  19. types = args.types.split(',')
  20. else:
  21. types = None
  22. while True:
  23. m = mlog.recv_match(type=types)
  24. if m is None:
  25. break
  26. if mlog.check_condition(args.condition):
  27. print(m)
  28. if args.stopcondition:
  29. break
  30. if args.stop:
  31. break
  32. for f in args.logs:
  33. mavsearch(f)