예제 #1
0
async def test_junction_protobuf(event_loop, shutdown, init_tcp_junction):
    origins = [
        cmd.Leds(red='on'),
        ns.msg.Config(host=ns.my_ip_address()),
        ns.msg.Profile('pippo', 'pluto'),
        ns.msg.Ack(1)
    ]

    port1, port2 = await init_tcp_junction()

    #start the clients
    reader1, writer1 = await asyncio.open_connection('0.0.0.0', port1)
    reader2, writer2 = await asyncio.open_connection('0.0.0.0', port2)

    for origin in origins:

        proto_msg = ns.marshall(origin)

        writer1.write(proto_msg)

        recv_msg = await ns.msg_receive(ns.Channel(reader2, writer2))

        LOG.debug("msg delivered!: %s", recv_msg)

        received = ns.unmarshall(recv_msg)

    await shutdown()
예제 #2
0
def handle_event(event, uart):
    """manage events from board
    """
    if (event.name == 'BOARD_INIT'):
        profile = ns.msg.Profile(
            os.environ['TEST_UID'], pwd=os.environ['TEST_PWD'])
        uart.write(ns.marshall(profile))

        board_cfg = ns.msg.Config(host=ns.my_ip_address(),
                                  network=tc.network, board=tc.board)
        uart.write(ns.marshall(board_cfg))

        return 1

    if (event.name == 'BOARD_READY'):
        return 1

    if (event.name == 'SERIAL_TIMEOUT'):
        assert 0
예제 #3
0
def trampoline(junction_port, port, network, board, dev):

    junction_address = ns.my_ip_address()
    LOG.debug("server ip: %s", junction_address)
    srv_address = input(
        "server address ([%s]):" % junction_address) or junction_address

    server_address = ns.msg.Config(host=srv_address,
                                   port=port,
                                   board=board,
                                   network=network)

    if dev:
        main_serial(dev, server_address)
    else:
        loop = asyncio.get_event_loop()

        loop.run_until_complete(main(junction_port, server_address))
        loop.close()
예제 #4
0
def handle_event(event, uart):
    """react to board events
    """

    if (event.name == 'CONN_FAILED_OK'):
        # configure the board with the bocia settings
        host_ip = ns.my_ip_address()
        cfg = ns.msg.Config(network=tc.network, board=tc.board, host=host_ip)
        uart.write(ns.marshall(cfg))

    if event.name == 'CONN_FAILED_ERR':
        return 0

    if event.name == 'TEST_OK':
        return 1

    if event.name == 'IP_ACQUIRED':
        return 1

    if (event.name == 'BOARD_READY'):
        # WLAN uid/password setup
        profile = ns.msg.Profile(os.environ['TEST_UID'],
                                 pwd=os.environ['TEST_PWD'])
        uart.write(ns.marshall(profile))

    if (event.name == 'TEST_RESULT'):
        print("event received: {} - arg1: {}".format(event.name, event.arg1))
        # arg2 contains the number of test failures
        #assert(event.arg2 == 1)

    if (event.name == 'PROTOBUF'):
        print("handle_event: {}".format(event.obj))

        # time to end successfully the test
        # return 1

    if (event.name == 'SERIAL_TIMEOUT'):
        assert (0)