Exemplo n.º 1
0
def main():
    args = parse_commandline_args()
    connection = utils.open_connection(args)

    if args.all:
        scan_queue = list()

        # Broadcast ping
        utils.write_command(connection, commands.encode_ping(),
                            list(range(1, 128)))
        reader = utils.read_can_datagrams(connection)
        while True:
            dt = next(reader)

            if dt is None:  # Timeout
                break

            _, _, src = dt
            scan_queue.append(src)

    else:
        scan_queue = args.ids

    # Broadcast ask for config
    configs = utils.write_command_retry(connection,
                                        commands.encode_read_config(),
                                        scan_queue)

    for id, raw_config in configs.items():
        configs[id] = msgpack.unpackb(raw_config, encoding="ascii")

    print(json.dumps(configs, indent=4, sort_keys=True))
Exemplo n.º 2
0
def main():
    """
    Entry point of the application.
    """
    args = parse_commandline_args()
    with open(args.binary_file, 'rb') as input_file:
        binary = input_file.read()

    serial_port = utils.open_connection(args)

    online_boards = check_online_boards(serial_port, args.ids)

    if online_boards != set(args.ids):
        offline_boards = [str(i) for i in set(args.ids) - online_boards]
        print("Boards {} are offline, aborting..."
              .format(", ".join(offline_boards)))
        exit(2)

    print("Flashing firmware (size: {} bytes)".format(len(binary)))
    flash_binary(serial_port, binary, args.base_address, args.device_class,
                 args.ids, page_size=args.page_size)

    print("Verifying firmware...")
    valid_nodes_set = set(check_binary(serial_port, binary,
                                       args.base_address, args.ids))
    nodes_set = set(args.ids)

    if valid_nodes_set == nodes_set:
        print("OK")
    else:
        verification_failed(nodes_set - valid_nodes_set)

    if args.run:
        run_application(serial_port, args.ids)
Exemplo n.º 3
0
def main():
    args = parse_commandline_args()
    connection = utils.open_connection(args)

    if args.all:
        scan_queue = list()

        # Broadcast ping
        utils.write_command(connection, commands.encode_ping(), list(range(1, 128)))
        reader = utils.read_can_datagrams(connection)
        while True:
            dt = next(reader)

            if dt is None: # Timeout
                break

            _, _, src = dt
            scan_queue.append(src)

    else:
        scan_queue = args.ids

    # Broadcast ask for config
    configs = utils.write_command_retry(connection,
                                        commands.encode_read_config(),
                                        scan_queue)

    for id, raw_config in configs.items():
        configs[id] = msgpack.unpackb(raw_config, encoding='ascii')

    print(json.dumps(configs, indent=4, sort_keys=True))
Exemplo n.º 4
0
def main():
    args = parse_commandline_args()
    connection = utils.open_connection(args)
    if args.all is True:
        ids = list(range(1, 128))
    else:
        ids = args.ids

    utils.write_command(connection, commands.encode_jump_to_main(), ids)
Exemplo n.º 5
0
def main():
    args = parse_commandline_args()
    connection = utils.open_connection(args)

    config = {"ID": args.new}
    utils.write_command_retry(
        connection, commands.encode_update_config(config), [args.old]
    )
    utils.write_command_retry(connection, commands.encode_save_config(), [args.new])
Exemplo n.º 6
0
def main():
    args = parse_commandline_args()
    connection = utils.open_connection(args)
    if args.all is True:
        ids = list(range(1, 128))
    else:
        ids = args.ids

    utils.write_command(connection, commands.encode_jump_to_main(), ids)
Exemplo n.º 7
0
def main():
    args = parse_commandline_args()
    config = json.loads(args.file.read())

    if "ID" in config.keys():
        print("This tool cannot be used to change node IDs.")
        print("Use bootloader_change_id.py instead.")
        sys.exit(1)

    connection = utils.open_connection(args)
    utils.config_update_and_save(connection, config, args.ids)
Exemplo n.º 8
0
def main():
    args = parse_commandline_args()
    connection = utils.open_connection(args)

    config = {"ID": args.new}
    utils.write_command_retry(connection,
                              commands.encode_update_config(config),
                              [args.old])
    utils.write_command_retry(connection,
                              commands.encode_save_config(),
                              [args.new])
Exemplo n.º 9
0
def main():
    args = parse_commandline_args()
    config = json.loads(args.file.read())

    if "ID" in config.keys():
        print("This tool cannot be used to change node IDs.")
        print("Use bootloader_change_id.py instead.")
        sys.exit(1)

    connection = utils.open_connection(args)
    utils.config_update_and_save(connection, config, args.ids)