Exemplo n.º 1
0
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 config_mock_set_values(self) -> bytearray:
        """

        :return: data_arr
        :rtype: bytearray
        """
        assert len(REQUIRED_FLARE) == VERSION_ID_LEN
        return radio_packets.config(self._current_millis(), False,
                                    self.device_id, REQUIRED_FLARE)
Exemplo n.º 3
0
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)
Exemplo n.º 4
0
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
Exemplo n.º 5
0
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