def test_status_ping_packet(qtbot, single_connection_tantalus): app = single_connection_tantalus connection = app.connections['DEBUG_CONNECTION'] packet = radio_packets.status_ping( 0xFFFFFFFF, radio_packets.StatusType.CRITICAL_FAILURE, 0xFF, 0xFF, 0xFF, 0xFF) snapshot = get_event_stats_snapshot() connection.receive(packet) assert BUNDLE_ADDED_EVENT.wait(snapshot) == 1 assert app.rocket_data.last_value_by_device( DeviceType.TANTALUS_STAGE_1_FLARE, DataEntryIds.TIME) == 0xFFFFFFFF assert (app.rocket_data.last_value_by_device( DeviceType.TANTALUS_STAGE_1_FLARE, DataEntryIds.OVERALL_STATUS) == DataEntryValues.CRITICAL_FAILURE) for sensor in SENSOR_TYPES: assert app.rocket_data.last_value_by_device( DeviceType.TANTALUS_STAGE_1_FLARE, sensor) == 1 for other in OTHER_STATUS_TYPES: assert app.rocket_data.last_value_by_device( DeviceType.TANTALUS_STAGE_1_FLARE, other) == 1
def test_config_packet(qtbot, single_connection_tantalus): app = single_connection_tantalus connection = app.connections['DEBUG_CONNECTION'] version_id = REQUIRED_FLARE assert len( version_id) == VERSION_ID_LEN # make sure test val is acceptable packet = radio_packets.config(0xFFFFFFFF, True, 0x00, version_id) snapshot = get_event_stats_snapshot() connection.receive(packet) assert CONFIG_EVENT.wait(snapshot) == 1 assert BUNDLE_ADDED_EVENT.wait(snapshot) == 1 assert app.rocket_data.last_value_by_device( DeviceType.TANTALUS_STAGE_1_FLARE, DataEntryIds.TIME) == 0xFFFFFFFF assert app.rocket_data.last_value_by_device( DeviceType.TANTALUS_STAGE_1_FLARE, DataEntryIds.IS_SIM) == True assert app.rocket_data.last_value_by_device( DeviceType.TANTALUS_STAGE_1_FLARE, DataEntryIds.DEVICE_TYPE) == DeviceType.TANTALUS_STAGE_1_FLARE assert app.rocket_data.last_value_by_device( DeviceType.TANTALUS_STAGE_1_FLARE, DataEntryIds.VERSION_ID) == version_id
def test_bulk_sensor_packet(qtbot, single_connection_tantalus): app = single_connection_tantalus connection = app.connections['DEBUG_CONNECTION'] state_input = 0x09 sensor_inputs = (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, state_input) packet = radio_packets.bulk_sensor(*sensor_inputs) snapshot = get_event_stats_snapshot() with qtbot.waitSignal( app.ReadThread.sig_received ): # Needed otherwise signals wont process because UI is in same thread connection.receive(packet) assert STATE_EVENT.wait(snapshot) == 1 assert BULK_SENSOR_EVENT.wait(snapshot) == 1 assert BUNDLE_ADDED_EVENT.wait(snapshot) == 1 def get_val(val): return app.rocket_data.last_value_by_device( DeviceType.TANTALUS_STAGE_1_FLARE, val) vals_to_get = ( DataEntryIds.CALCULATED_ALTITUDE, DataEntryIds.ACCELERATION_X, DataEntryIds.ACCELERATION_Y, DataEntryIds.ACCELERATION_Z, DataEntryIds.ORIENTATION_1, DataEntryIds.ORIENTATION_2, DataEntryIds.ORIENTATION_3, DataEntryIds.LATITUDE, DataEntryIds.LONGITUDE, ) last_values = tuple(map(get_val, vals_to_get)) # Only check items in tuple vals_to_get assert sensor_inputs[1:-1] == last_values # Special check for state state_val = get_val(DataEntryIds.STATE) assert STATE_IDS[state_input] == state_val assert LABLES_UPDATED_EVENT.wait(snapshot) >= 1 assert app.AltitudeLabel.text() == '2.00 m' assert app.GPSLabel.text() == '9.00000\xb0, 10.00000\xb0' assert app.StateLabel.text() == STATE_IDS[state_input].name
def test_message_packet(qtbot, single_connection_tantalus, caplog): app = single_connection_tantalus connection = app.connections['DEBUG_CONNECTION'] packet = radio_packets.message(0xFFFFFFFF, "test_message") snapshot = get_event_stats_snapshot() connection.receive(packet) assert BUNDLE_ADDED_EVENT.wait(snapshot) == 1 assert app.rocket_data.last_value_by_device( DeviceType.TANTALUS_STAGE_1_FLARE, DataEntryIds.TIME) == 0xFFFFFFFF assert app.rocket_data.last_value_by_device( DeviceType.TANTALUS_STAGE_1_FLARE, DataEntryIds.MESSAGE) == "test_message" assert "test_message" in caplog.text
def flush_packets(main_app: MainApp, device_type: DeviceType): """ Wait a few update cycles to flush any old packets out :param rocket_data: :param device_type: :return: """ received = 0 last_time = 0 while received < 5: snapshot = get_event_stats_snapshot() assert BUNDLE_ADDED_EVENT.wait(snapshot) >= 1 assert CONNECTION_MESSAGE_READ_EVENT.wait(snapshot) >= 1 # To ensure that we're only considering packets from specific device new_time = main_app.rocket_data.last_value_by_device(device_type, DataEntryIds.TIME) if new_time != last_time: # No guarantee that packets come in chronological order received += 1 last_time = new_time
def test_multi_connection_receive(qtbot, test_app): con_a = DebugConnection( 'TANTALUS_STAGE_1_ADDRESS', DEVICE_TYPE_TO_ID[DeviceType.TANTALUS_STAGE_1_FLARE], generate_radio_packets=False) con_b = DebugConnection( 'TANTALUS_STAGE_2_ADDRESS', DEVICE_TYPE_TO_ID[DeviceType.TANTALUS_STAGE_2_FLARE], generate_radio_packets=False) snapshot = get_event_stats_snapshot() app = test_app(TantalusProfile(), { 'DEBUG_CONNECTION_1': con_a, 'DEBUG_CONNECTION_2': con_b }, num_devices=2) con_a.receive( radio_packets.single_sensor(0xFFFFFFFF, SubpacketIds.PRESSURE, 1)) con_b.receive( radio_packets.single_sensor(0xFFFFFFFF, SubpacketIds.PRESSURE, 2)) # Fake some other device on same connection con_a.device_address = 'OTHER_ADDRESS' sample_version = '1234567890123456789012345678901234567890' con_a.receive( radio_packets.config(0xFFFFFFFF, True, DEVICE_TYPE_TO_ID[DeviceType.CO_PILOT_FLARE], sample_version)) con_a.receive( radio_packets.single_sensor(0xFFFFFFFF, SubpacketIds.PRESSURE, 3)) assert DEVICE_REGISTERED_EVENT.wait(snapshot, num_expected=3) == 3 assert BUNDLE_ADDED_EVENT.wait(snapshot, num_expected=6) == 6 assert app.rocket_data.last_value_by_device( DeviceType.TANTALUS_STAGE_1_FLARE, DataEntryIds.PRESSURE) == 1 assert app.rocket_data.last_value_by_device( DeviceType.TANTALUS_STAGE_2_FLARE, DataEntryIds.PRESSURE) == 2 assert app.rocket_data.last_value_by_device(DeviceType.CO_PILOT_FLARE, DataEntryIds.PRESSURE) == 3
def test_gps_packet(qtbot, single_connection_tantalus): app = single_connection_tantalus connection = app.connections['DEBUG_CONNECTION'] gps_inputs = (0xFFFFFFFF, 1, 2, 3) packet = radio_packets.gps(*gps_inputs) snapshot = get_event_stats_snapshot() connection.receive(packet) assert BUNDLE_ADDED_EVENT.wait(snapshot) == 1 assert app.rocket_data.last_value_by_device( DeviceType.TANTALUS_STAGE_1_FLARE, DataEntryIds.TIME) == 0xFFFFFFFF assert app.rocket_data.last_value_by_device( DeviceType.TANTALUS_STAGE_1_FLARE, DataEntryIds.LATITUDE) == 1 assert app.rocket_data.last_value_by_device( DeviceType.TANTALUS_STAGE_1_FLARE, DataEntryIds.LONGITUDE) == 2 assert app.rocket_data.last_value_by_device( DeviceType.TANTALUS_STAGE_1_FLARE, DataEntryIds.GPS_ALTITUDE) == 3
def test_register_after_data(qtbot, test_app): con = DebugConnection('TANTALUS_STAGE_1_ADDRESS', DEVICE_TYPE_TO_ID[DeviceType.TANTALUS_STAGE_1_FLARE], generate_radio_packets=False) app = test_app(TantalusProfile(), {'DEBUG_CONNECTION': con}, num_devices=1) snapshot = get_event_stats_snapshot() # Fake stage 2 on same connection con.device_address = 'TANTALUS_STAGE_2_ADDRESS' con.receive( radio_packets.single_sensor(0xFFFFFFFF, SubpacketIds.PRESSURE, 1)) assert BUNDLE_ADDED_EVENT.wait(snapshot) == 1 # Cause device to register con.receive( radio_packets.config( 0xFFFFFFFF, True, DEVICE_TYPE_TO_ID[DeviceType.TANTALUS_STAGE_2_FLARE], REQUIRED_FLARE)) assert DEVICE_REGISTERED_EVENT.wait(snapshot) == 1 assert app.rocket_data.last_value_by_device( DeviceType.TANTALUS_STAGE_2_FLARE, DataEntryIds.PRESSURE) == 1
def test_orientation_packet(qtbot, single_connection_tantalus): app = single_connection_tantalus connection = app.connections['DEBUG_CONNECTION'] orientation_inputs = (0xFFFFFFFF, 1, 2, 3, 4) packet = radio_packets.orientation(*orientation_inputs) snapshot = get_event_stats_snapshot() connection.receive(packet) assert BUNDLE_ADDED_EVENT.wait(snapshot) == 1 assert app.rocket_data.last_value_by_device( DeviceType.TANTALUS_STAGE_1_FLARE, DataEntryIds.TIME) == 0xFFFFFFFF assert app.rocket_data.last_value_by_device( DeviceType.TANTALUS_STAGE_1_FLARE, DataEntryIds.ORIENTATION_1) == 1 assert app.rocket_data.last_value_by_device( DeviceType.TANTALUS_STAGE_1_FLARE, DataEntryIds.ORIENTATION_2) == 2 assert app.rocket_data.last_value_by_device( DeviceType.TANTALUS_STAGE_1_FLARE, DataEntryIds.ORIENTATION_3) == 3 assert app.rocket_data.last_value_by_device( DeviceType.TANTALUS_STAGE_1_FLARE, DataEntryIds.ORIENTATION_4) == 4