Exemplo n.º 1
0
def test_serialize_serverinfo_message():
    """Test parsing a NatNet 3.0 packet containing a ServerInfo message."""
    packet = open('test_data/serverinfo_packet_v3.bin', 'rb').read()
    # Zero uninitialised part of app_name buffer
    packet = packet[:11] + b'\0' * (256 - len('Motive') - 1) + packet[260:]

    connection_info = ConnectionInfo(data_port=1511,
                                     multicast=True,
                                     multicast_address=u'239.255.42.99')
    server_info = ServerInfoMessage(app_name=u'Motive',
                                    app_version=Version(2, 1),
                                    natnet_version=Version(3),
                                    high_resolution_clock_frequency=3312787,
                                    connection_info=connection_info)
    assert serialize(server_info) == packet
Exemplo n.º 2
0
def test_serialize_modeldef_message():
    """Test serializing a ModelDefinitionsMessage."""
    packet = open('test_data/modeldef_packet_v3.bin', 'rb').read()

    msg = ModelDefinitionsMessage(models=[
        RigidBodyDescription(name='RaceQuad',
                             id_=2,
                             parent_id=-1,
                             offset_from_parent=(0.0, 0.0, 0.0),
                             marker_positions=[(0.1611589938402176,
                                                0.03505159914493561,
                                                -0.03218130022287369),
                                               (-0.0308190006762743,
                                                0.03978189826011658,
                                                -0.021990099921822548),
                                               (0.1875309944152832,
                                                -0.03338329866528511,
                                                0.1480810046195984),
                                               (-0.0748715028166771,
                                                6.686070264549926e-05,
                                                0.03292329981923103),
                                               (-0.05803820118308067,
                                                -0.03194189816713333,
                                                -0.13680699467658997)],
                             required_active_labels=[0, 0, 0, 0, 0]),
        MarkersetDescription(name='RaceQuad',
                             marker_names=[
                                 'Marker1', 'Marker2', 'Marker3', 'Marker4',
                                 'Marker5'
                             ]),
        MarkersetDescription(name='all',
                             marker_names=[
                                 'RaceQuad_1', 'RaceQuad_2', 'RaceQuad_3',
                                 'RaceQuad_4', 'RaceQuad_5'
                             ])
    ])
    serialized_msg = serialize(msg)
    print(len(serialized_msg), len(packet))
    assert serialized_msg == packet
def test_serialize_echoresponse_message():
    """Test serializing an EchoResponse message."""
    expected = open('test_data/echoresponse_packet_v3.bin', 'rb').read()
    actual = serialize(EchoResponseMessage(278554190, 1416498545924))

    assert actual == expected
Exemplo n.º 4
0
def test_serialize_connect_message():
    """Test serializing a Connect message."""
    expected = open('test_data/connect_packet_v3.bin', 'rb').read()
    actual = serialize(ConnectMessage('NatNetLib', Version(3), Version(3)))

    assert actual == expected
Exemplo n.º 5
0
def test_serialize_discovery_message():
    """Test serializing a Discovery message."""
    expected = open('test_data/discovery_packet_v3.bin', 'rb').read()
    actual = serialize(DiscoveryMessage('NatNetLib', Version(3), Version(3)))

    assert actual == expected
Exemplo n.º 6
0
def test_serialize_requestmodeldef_message():
    """Test serializing a RequestModelDefinitions message."""
    expected = open('test_data/requestmodeldef_packet_v3.bin', 'rb').read()
    actual = serialize(RequestModelDefinitionsMessage())

    assert actual == expected
Exemplo n.º 7
0
def test_serialize_mocapframe_message():
    """Test serializing a MocapFrameMessage."""
    packet = open('test_data/mocapframe_packet_v3.bin', 'rb').read()

    rigid_body = RigidBody(id_=2,
                           position=(0.17444664239883423, 1.4471313953399658,
                                     -0.7343040108680725),
                           orientation=(-0.05459423363208771,
                                        0.509948194026947, 0.04370357096195221,
                                        -0.8573576807975769),
                           mean_error=0.0005152203375473619,
                           params=1)
    markers = [
        LabelledMarker(model_id=2,
                       marker_id=1,
                       position=(0.12721621990203857, 1.5050275325775146,
                                 -0.8858283758163452),
                       size=0.021439820528030396,
                       params=10,
                       residual=0.00020748283714056015),
        LabelledMarker(model_id=2,
                       marker_id=2,
                       position=(0.20898520946502686, 1.4832806587219238,
                                 -0.7121866345405579),
                       size=0.020884789526462555,
                       params=10,
                       residual=0.000539067666977644),
        LabelledMarker(model_id=2,
                       marker_id=3,
                       position=(-0.04574164003133774, 1.4310429096221924,
                                 -0.8313022255897522),
                       size=0.020809074863791466,
                       params=10,
                       residual=0.000689117528963834),
        LabelledMarker(model_id=2,
                       marker_id=4,
                       position=(0.18133828043937683, 1.4358338117599487,
                                 -0.6535942554473877),
                       size=0.019269507378339767,
                       params=10,
                       residual=0.0003837273397948593),
        LabelledMarker(model_id=2,
                       marker_id=5,
                       position=(0.32139891386032104, 1.4146512746810913,
                                 -0.7529537677764893),
                       size=0.021224740892648697,
                       params=10,
                       residual=0.0006357387755997479),
        LabelledMarker(model_id=0,
                       marker_id=50007,
                       position=(0.17081165313720703, 1.5076590776443481,
                                 -0.840234637260437),
                       size=0.0201573446393013,
                       params=18,
                       residual=0.0005593782989308238)
    ]
    timing_info = TimingInfo(timecode=0,
                             timecode_subframe=0,
                             timestamp=1356.1166666666666,
                             camera_mid_exposure_timestamp=1416497730518,
                             camera_data_received_timestamp=1416497745808,
                             transmit_timestamp=1416497748722)
    msg = MocapFrameMessage(frame_number=162734,
                            markersets=[],
                            rigid_bodies=[rigid_body],
                            skeletons=[],
                            labelled_markers=markers,
                            force_plates=[],
                            devices=[],
                            timing_info=timing_info,
                            params=0)
    old_serialize = msg.serialize
    msg.serialize = lambda: old_serialize(include_unlabelled=True)
    serialized_msg = serialize(msg)
    print(len(serialized_msg), len(packet))
    assert serialized_msg == packet
def test_serialize_echorequest_message():
    """Test serializing an EchoRequest message."""
    expected = open('test_data/echorequest_packet_v3.bin', 'rb').read()
    actual = serialize(EchoRequestMessage(278554190))

    assert actual == expected