def construct(profile, connections, num_devices=None): nonlocal app snapshot = get_event_stats_snapshot() app = profile.construct_app(connections) if num_devices is None: expected = len(profile.expected_devices) else: expected = num_devices assert DEVICE_REGISTERED_EVENT.wait(snapshot, num_expected=expected) == expected return app
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_normal_registration(): device_manager = DeviceManager(None, None) full_address_1 = FullAddress(connection_name='TantalusStage1Connection', device_address='TantalusStage1Address') full_address_2 = FullAddress(connection_name='TantalusStage2Connection', device_address='TantalusStage2Address') snapshot = get_event_stats_snapshot() device_manager.register_device(DeviceType.TANTALUS_STAGE_1_FLARE, None, full_address_1) device_manager.register_device(DeviceType.TANTALUS_STAGE_2_FLARE, None, full_address_2) assert DEVICE_REGISTERED_EVENT.wait(snapshot, num_expected=2, timeout=0) == 2 assert device_manager.get_full_address( DeviceType.TANTALUS_STAGE_1_FLARE) == full_address_1 assert device_manager.get_full_address( DeviceType.TANTALUS_STAGE_2_FLARE) == full_address_2
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