Example #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))
Example #2
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))
def check_online_boards(fdesc, boards):
    """
    Returns a set containing the online boards.
    """
    online_boards = set()

    utils.write_command(fdesc, commands.encode_ping(), boards)
    reader = utils.read_can_datagrams(fdesc)

    for dt in reader:
        if dt is None:
            break
        _, _, src = dt
        online_boards.add(src)

    return online_boards
Example #4
0
def ping_board(fdesc, destination):
    """
    Checks if a board is up.

    Returns True if it is online, false otherwise.
    """
    write_command(fdesc, commands.encode_ping(), [destination])

    reader = read_can_datagrams(fdesc)
    answer = next(reader)

    # Timeout
    if answer is None:
        return False

    return True
Example #5
0
def ping_board(fdesc, destination):
    """
    Checks if a board is up.

    Returns True if it is online, false otherwise.
    """
    write_command(fdesc, commands.encode_ping(), [destination])

    reader = read_can_datagrams(fdesc)
    answer = next(reader)

    # Timeout
    if answer is None:
        return False

    return True
Example #6
0
    def test_sends_correct_command(self, write_command, read_datagram):
        port = object()
        ping_board(port, 1)

        write_command.assert_any_call(port, commands.encode_ping(), [1])
Example #7
0
    def test_sends_correct_command(self, write_command, read_datagram):
        port = object()
        ping_board(port, 1)

        write_command.assert_any_call(port, commands.encode_ping(), [1])