mavsigloss.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 
00003 '''
00004 show times when signal is lost
00005 '''
00006 
00007 import sys, time, os
00008 
00009 from argparse import ArgumentParser
00010 parser = ArgumentParser(description=__doc__)
00011 parser.add_argument("--no-timestamps", dest="notimestamps", action='store_true', help="Log doesn't have timestamps")
00012 parser.add_argument("--planner", action='store_true', help="use planner file format")
00013 parser.add_argument("--robust", action='store_true', help="Enable robust parsing (skip over bad data)")
00014 parser.add_argument("--deltat", type=float, default=1.0, help="loss threshold in seconds")
00015 parser.add_argument("--condition", default=None, help="select packets by condition")
00016 parser.add_argument("--types", default=None, help="types of messages (comma separated)")
00017 parser.add_argument("logs", metavar="LOG", nargs="+")
00018 
00019 args = parser.parse_args()
00020 
00021 from pymavlink import mavutil
00022 
00023 
00024 def sigloss(logfile):
00025     '''work out signal loss times for a log file'''
00026     print("Processing log %s" % filename)
00027     mlog = mavutil.mavlink_connection(filename,
00028                                       planner_format=args.planner,
00029                                       notimestamps=args.notimestamps,
00030                                       robust_parsing=args.robust)
00031 
00032     last_t = 0
00033 
00034     types = args.types
00035     if types is not None:
00036         types = types.split(',')
00037 
00038     while True:
00039         m = mlog.recv_match(condition=args.condition)
00040         if m is None:
00041             return
00042         if types is not None and m.get_type() not in types:
00043             continue
00044         if args.notimestamps:
00045             if not 'usec' in m._fieldnames:
00046                 continue
00047             t = m.usec / 1.0e6
00048         else:
00049             t = m._timestamp
00050         if last_t != 0:
00051             if t - last_t > args.deltat:
00052                 print("Sig lost for %.1fs at %s" % (t-last_t, time.asctime(time.localtime(t))))
00053         last_t = t
00054 
00055 total = 0.0
00056 for filename in args.logs:
00057     sigloss(filename)


mavlink
Author(s): Lorenz Meier
autogenerated on Sun May 22 2016 04:05:43