def test_multi_connection_commands(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) con_a.send = MagicMock() con_b.send = MagicMock() snapshot = get_event_stats_snapshot() app = test_app(TantalusProfile(), { 'DEBUG_CONNECTION_1': con_a, 'DEBUG_CONNECTION_2': con_b }, num_devices=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)) assert DEVICE_REGISTERED_EVENT.wait(snapshot, num_expected=3) == 3 # Send commands to each and assert called snapshot = get_event_stats_snapshot() app.send_command("tantalus_stage_1_flare.arm") COMMAND_SENT_EVENT.wait(snapshot) con_a.send.assert_called_with('TANTALUS_STAGE_1_ADDRESS', ANY) snapshot = get_event_stats_snapshot() app.send_command("tantalus_stage_2_flare.arm") COMMAND_SENT_EVENT.wait(snapshot) con_b.send.assert_called_with('TANTALUS_STAGE_2_ADDRESS', ANY) snapshot = get_event_stats_snapshot() app.send_command("co_pilot_flare.arm") COMMAND_SENT_EVENT.wait(snapshot) con_a.send.assert_called_with('OTHER_ADDRESS', ANY)
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_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