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("-c", "--command", action="store_true", default=False, dest="command", help="indicates that source is a command") parser.add_argument("-u", "--hid", action="store_true", default=False, dest="hid", help="use usb hid to communicate with FC") parser.add_argument( "source", help="file, host:port, vid:pid, command, or serial port") # 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") 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: 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)