Exemple #1
0
def test_message_format_test_packets(chip):
    expected_packets = chip.get_configuration_packets(Packet.CONFIG_READ_PACKET)
    expected_messages = [b'\x01\x00'+b'D'+b'\x02'+b'\x00'*4 + packet.bytes() + b'\x00' for packet in expected_packets]
    ts_packet = TimestampPacket(timestamp=123456789)
    expected_packets += [ts_packet]
    expected_messages += [b'\x01\x00'+b'T'+b'\x00'*5 + ts_packet.bytes() + b'\x00']
    print(expected_packets[-1])
    print(expected_messages[-1])
    print(dataserver_message_decode(expected_messages)[-1])
    print(expected_messages[-1])
    print(dataserver_message_encode(expected_packets)[-1])
    assert expected_messages == dataserver_message_encode(expected_packets)
    assert expected_packets == dataserver_message_decode(expected_messages)
Exemple #2
0
def test_decode(zmq_io_obj):
    io_chain = 1
    test_packet = Packet(b'\x01' * Packet.num_bytes)
    test_packet.chip_key = Key(1, io_chain, test_packet.chip_id)
    test_bytes = dataserver_message_encode([test_packet])
    expected = [test_packet]
    assert zmq_io_obj.decode(test_bytes) == expected
def test_decode(zmq_io_obj):
    chip_id = 64
    io_chain = 1
    test_packet = Packet(b'\x00\x01\x02\x03\x04\x05\x06')
    test_packet.chip_key = Key(1, io_chain, chip_id)
    test_bytes = dataserver_message_encode([test_packet])
    expected = [test_packet]
    assert zmq_io_obj.decode(test_bytes) == expected
def test_decode(multizmq_io_obj):
    chip_id = 64
    io_chain = 1
    io_group = list(multizmq_io_obj._io_group_table)[0]
    address = str(multizmq_io_obj._io_group_table[io_group])
    test_packet = Packet(b'\x00\x01\x02\x03\x04\x05\x06')
    test_packet.io_group = io_group
    test_packet.io_channel = io_chain
    test_bytes = dataserver_message_encode([test_packet])
    expected = [test_packet]
    assert multizmq_io_obj.decode(test_bytes, address=address) == expected