def _finish_telemetry_args(parser, args, service_in_iter, iter_blocks): parse_header = False githash = None if args.githash is not None: # If we specify the log header no need to attempt to parse it githash = args.githash else: parse_header = args.parse_header # only for files from dronin import telemetry if args.serial: return telemetry.SerialTelemetry(args.source, speed=args.baud, service_in_iter=service_in_iter, iter_blocks=iter_blocks, githash=githash) if args.baud != "115200": parser.print_help() raise ValueError("Baud rates only apply to serial ports") if args.hid: return telemetry.HIDTelemetry(args.source, service_in_iter=service_in_iter, iter_blocks=iter_blocks, githash=githash) if args.command: return telemetry.SubprocessTelemetry(args.source, service_in_iter=service_in_iter, iter_blocks=iter_blocks, githash=githash) import os.path if os.path.isfile(args.source): file_obj = open(args.source, 'rb') if parse_header: return telemetry.FileTelemetry(file_obj, parse_header=True, gcs_timestamps=args.timestamped, name=args.source) else: return telemetry.FileTelemetry(file_obj, parse_header=False, gcs_timestamps=args.timestamped, name=args.source, githash=githash) # OK, running out of options, time to try the network! host,sep,port = args.source.partition(':') if sep != ':': parser.print_help() raise ValueError("Target doesn't exist and isn't a network address") return telemetry.NetworkTelemetry(host=host, port=int(port), name=args.source, service_in_iter=service_in_iter, iter_blocks=iter_blocks, githash=githash)
def get_telemetry_by_args(desc="Process telemetry", service_in_iter=True, iter_blocks=True): """ Parses command line to decide how to get a telemetry object. """ # Setup the command line arguments. import argparse parser = argparse.ArgumentParser(description=desc) # Log format indicates this log is using the old file format which # embeds the timestamping information between the UAVTalk packet # instead of as part of the packet parser.add_argument( "-t", "--timestamped", action='store_false', default=None, help="indicate that this is not timestamped in GCS format") parser.add_argument("-g", "--githash", action="store", dest="githash", help="override githash for UAVO XML definitions") parser.add_argument("-s", "--serial", action="store_true", default=False, dest="serial", help="indicates that source is a serial port") parser.add_argument("-b", "--baudrate", action="store", dest="baud", default="115200", help="baud rate for serial communications") parser.add_argument( "source", help="file, host:port, or serial port to get telemetry from") # Parse the command-line. args = parser.parse_args() parse_header = False githash = None if args.githash is not None: # If we specify the log header no need to attempt to parse it githash = args.githash else: parse_header = True # only for files from dronin import telemetry if args.serial: return telemetry.SerialTelemetry(args.source, speed=args.baud, service_in_iter=service_in_iter, iter_blocks=iter_blocks, githash=githash) if args.baud != "115200": parser.print_help() raise ValueError("Baud rates only apply to serial ports") import os.path if os.path.isfile(args.source): file_obj = open(args.source, 'rb') if parse_header: t = telemetry.FileTelemetry(file_obj, parse_header=True, gcs_timestamps=args.timestamped, name=args.source) else: t = telemetry.FileTelemetry(file_obj, parse_header=False, gcs_timestamps=args.timestamped, name=args.source, githash=githash) return t # OK, running out of options, time to try the network! host, sep, port = args.source.partition(':') if sep != ':': parser.print_help() raise ValueError("Target doesn't exist and isn't a network address") return telemetry.NetworkTelemetry(host=host, port=int(port), name=args.source, service_in_iter=service_in_iter, iter_blocks=iter_blocks, githash=githash)
def handle_open(ignored=False, fname=None): from dronin import telemetry, uavo if fname is None: fname = QtGui.QFileDialog.getOpenFileName( win, 'Open file', filter="Log files (*.drlog *.txt)") with pg.ProgressDialog("0 objects read...", wait=500, maximum=1000, cancelText=None) as dlg: global t if (len(fname[0]) > 1): fname = fname[0] f = open(fname, 'rb') num_bytes = 1000000000 try: import os stat_info = os.fstat(f.fileno()) num_bytes = stat_info.st_size except Exception: print("Couldn't stat file") pass def cb(n_objs, n_bytes): # Top out at 90%, so the dialog doesn't hang at 100% # during the non-reading operations... permille = (n_bytes * 900.0) / num_bytes # should not happen, but cover the case anyways if (permille > 900.0): permille = 900.0 dlg.setValue(permille) dlg.setLabelText("%d objects read..." % n_objs) t = telemetry.FileTelemetry(f, parse_header=True, service_in_iter=True, gcs_timestamps=None, name=fname, progress_callback=cb) global series, objtyps series = {} objtyps = {} for typ in t.uavo_defs.values(): short_name = typ._name[5:] objtyps[short_name] = typ event_series = scan_for_events(t) global last_plot last_plot = None thrust_plot = plot_vs_time('StabilizationDesired', 'Thrust') clear_plots(skip=[last_plot]) for tm, text in event_series: thrust_plot.addLine(x=tm) # label=text, labelOpts={'rotateAxis' : (1,0)} ) dlg.setValue(925) plot_vs_time('AttitudeActual', ['Yaw', 'Roll', 'Pitch']) dlg.setValue(975) plot_vs_time('Gyros', ['x', 'y', 'z']) plot_vs_time('ActuatorCommand', ['Channel:0', 'Channel:1', 'Channel:2', 'Channel:3']) objtyps = {k: v for k, v in objtyps.items() if v in t.last_values} #add all non-settings objects, and autotune, to the keys. objSel.clear() for typnam in sorted(objtyps.keys()): if typnam == "SystemIdent" or not objtyps[typnam]._is_settings: objSel.addItem(typnam) objSel.setEnabled(True)