Exemplo n.º 1
0
def main():
    """
    Get configuration, get driver, and build handler and start it.
    """
    args = get_args()
    driver = serial_link.get_base_args_driver(args)
    # Driver with context
    # Handler with context
    with Handler(Framer(driver.read, driver.write,
                        verbose=args.verbose)) as link:
        data = bytearray(open(args.firmware, 'rb').read())

        def progress_cb(size, _):
            sys.stdout.write("\rProgress: %d%%    \r" %
                             (100 * size / len(data)))
            sys.stdout.flush()

        print('Transferring image file...')
        FileIO(link).write(b"upgrade.image_set.bin",
                           data,
                           progress_cb=progress_cb)
        print('Committing file to flash...')
        link.add_callback(serial_link.log_printer, SBP_MSG_LOG)
        link.add_callback(serial_link.printer, SBP_MSG_PRINT_DEP)

        code = shell_command(link, b"upgrade_tool upgrade.image_set.bin", 300)
        if code != 0:
            print('Failed to perform upgrade (code = %d)' % code)
            return
        print('Resetting Piksi...')
        link(MsgReset(flags=0))
Exemplo n.º 2
0
def main(args=None):
    """
    Get configuration, get driver, and build handler and start it.
    """
    args = get_args(args)
    command = args.command
    driver = serial_link.get_base_args_driver(args)
    with Handler(Framer(driver.read, driver.write,
                        verbose=args.verbose)) as link:
        settings = Settings(link, timeout=args.timeout)
        with settings:
            if command == 'write':
                settings.write(args.section,
                               args.setting,
                               args.value,
                               verbose=args.verbose)
            elif command == 'read':
                print(
                    settings.read(args.section,
                                  args.setting,
                                  verbose=args.verbose))
            elif command == 'all':
                settings.read_all(verbose=True)
            elif command == 'save':
                settings.save()
            elif command == 'reset':
                settings.reset()
            elif command == 'read_to_file':
                settings.read_to_file(args.output, verbose=args.verbose)
            elif command == 'write_from_file':
                settings.write_from_file(args.filename, verbose=args.verbose)
            # If saving was requested, we have done a write command, and the write was requested, we save
            if command.startswith("write") and args.save_after_write:
                print("Saving Settings to Flash.")
                settings.save()
Exemplo n.º 3
0
def main():
    args = get_args()
    selected_driver = serial_link.get_base_args_driver(args)

    # Driver with context
    with selected_driver as driver:
        # Handler with context
        with Handler(Framer(driver.read, driver.write, args.verbose)) as link:
            f = FileIO(link)
            try:
                if args.write:
                    f.write(raw_filename(args.write[1]), bytearray(open(args.write[0], 'rb').read()))
                elif args.read:
                    if len(args.read) not in [1, 2]:
                        sys.stderr.write("Error: fileio read requires either 1 or 2 arguments, SOURCE and optionally DEST.")
                        sys.exit(1)
                    data = f.read(raw_filename(args.read[0]))
                    if len(args.read) == 2:
                        with open(args.read[1], ('w' if args.hex else 'wb')) as fd:
                            fd.write(hexdump(data) if args.hex else data)
                    elif args.hex:
                        print(hexdump(data))
                    else:
                        print(printable_text_from_device(data))
                elif args.delete:
                    f.remove(raw_filename(args.delete[0]))
                elif args.list is not None:
                    print_dir_listing(f.readdir(raw_filename(args.list[0])))
                else:
                    print("No command given, listing root directory:")
                    print_dir_listing(f.readdir())
            except KeyboardInterrupt:
                pass
Exemplo n.º 4
0
def main():
    """
    Get configuration, get driver, and build handler and start it.
    """
    args = get_args()
    command = args.command
    return_code = 0
    driver = serial_link.get_base_args_driver(args)
    with Handler(Framer(driver.read, driver.write, verbose=args.verbose)) as link:
        settings = Settings(link, timeout=args.timeout)
        with settings:
            if command == 'write':
                settings.write(args.section, args.setting, args.value, verbose=args.verbose)
            elif command == 'read':
                print(settings.read(args.section, args.setting, verbose=args.verbose))
            elif command == 'all':
                settings.read_all(verbose=True)
            elif command == 'save':
                settings.save()
            elif command == 'reset':
                settings.reset()
            elif command == 'read_to_file':
                settings.read_to_file(args.output, verbose=args.verbose)
            elif command == 'write_from_file':
                settings.write_from_file(args.filename, verbose=args.verbose)
            # If saving was requested, we have done a write command, and the write was requested, we save
            if command.startswith("write") and args.save_after_write:
                print("Saving Settings to Flash.")
                settings.save()
Exemplo n.º 5
0
def main():
    """
    Get configuration, get driver, and build handler and start it.
    """
    args = get_args()
    driver = serial_link.get_base_args_driver(args)
    # Driver with context
    # Handler with context
    with Handler(Framer(driver.read, driver.write, verbose=args.verbose)) as link:
        data = bytearray(open(args.file, 'rb').read())

        def progress_cb(size):
            sys.stdout.write("\rProgress: %d%%    \r" %
                             (100 * size / len(data)))
            sys.stdout.flush()

        print('Transferring image file...')
        FileIO(link).write(
            b"upgrade.image_set.bin", data, progress_cb=progress_cb)
        print('Committing file to flash...')
        link.add_callback(serial_link.log_printer, SBP_MSG_LOG)
        link.add_callback(serial_link.printer, SBP_MSG_PRINT_DEP)

        code = shell_command(link, b"upgrade_tool upgrade.image_set.bin", 300)
        if code != 0:
            print('Failed to perform upgrade (code = %d)' % code)
            return
        print('Resetting Piksi...')
        link(MsgReset(flags=0))
Exemplo n.º 6
0
def connection_from_args(args):
    cnx_data = None
    connect_error = None
    description = ''
    mode = ''
    port = getattr(args, 'port', None)
    baud = getattr(args, 'baud', None)

    if port is not None:
        if args.tcp:
            # Use the TPC driver and interpret port arg as host:port
            description = port
            mode = 'TCP/IP'
        elif args.file:
            # Use file and interpret port arg as the file
            print("Using file '%s'" % port)
            description = os.path.split(port)[-1]
            mode = 'file'
        else:
            if args.rtscts:
                print("using flow control")
            # Use the port passed and assume serial connection
            print("Using serial device '%s'" % port)
            description = os.path.split(port)[-1]
            description += (" @" + str(baud)) if baud else ""
            mode = 'serial'

        try:
            driver = s.get_base_args_driver(args)
        except Exception as e:  # noqa
            connect_error = e
        else:
            cnx_data = ConnectionData(
                driver=driver,
                description=description,
                mode=mode
            )
    return (cnx_data, connect_error)
Exemplo n.º 7
0
def connection_from_args(args):
    cnx_data = None
    connect_error = None
    description = ''
    mode = ''
    port = getattr(args, 'port', None)
    baud = getattr(args, 'baud', None)

    if port is not None:
        if args.tcp:
            # Use the TPC driver and interpret port arg as host:port
            description = port
            mode = 'TCP/IP'
        elif args.file:
            # Use file and interpret port arg as the file
            print("Using file '%s'" % port)
            description = os.path.split(port)[-1]
            mode = 'file'
        else:
            if args.rtscts:
                print("using flow control")
            # Use the port passed and assume serial connection
            print("Using serial device '%s'" % port)
            description = os.path.split(port)[-1]
            description += (" @" + str(baud)) if baud else ""
            mode = 'serial'

        try:
            driver = s.get_base_args_driver(args)
        except Exception as e:  # noqa
            connect_error = e
        else:
            cnx_data = ConnectionData(
                driver=driver,
                description=description,
                mode=mode
            )
    return (cnx_data, connect_error)
Exemplo n.º 8
0
def main():

    args = get_args()
    selected_driver = serial_link.get_base_args_driver(args)

    # Driver with context
    with selected_driver as driver:
        # Handler with context
        with Handler(Framer(driver.read, driver.write, args.verbose)) as link:
            f = FileIO(link)
            try:
                if args.write:
                    file_data = bytearray(open(args.write[0], 'rb').read())
                    f.write(raw_filename(args.write[1]), file_data, progress_cb=mk_progress_cb(len(file_data)))
                    sys.stdout.write("\n")
                    sys.stdout.flush()
                elif args.read:
                    if len(args.read) not in [1, 2]:
                        sys.stderr.write("Error: fileio read requires either 1 or 2 arguments, SOURCE and optionally DEST.")
                        sys.exit(1)
                    data = f.read(raw_filename(args.read[0]))
                    if len(args.read) == 2:
                        with open(args.read[1], ('w' if args.hex else 'wb')) as fd:
                            fd.write(hexdump(data) if args.hex else data)
                    elif args.hex:
                        print(hexdump(data))
                    else:
                        print(printable_text_from_device(data))
                elif args.delete:
                    f.remove(raw_filename(args.delete[0]))
                elif args.list is not None:
                    print_dir_listing(f.readdir(raw_filename(args.list[0])))
                else:
                    print("No command given, listing root directory:")
                    print_dir_listing(f.readdir())
            except KeyboardInterrupt:
                pass