def setUp(self): super().setUp() alice = Participant("Alice", "A") bob = Participant("Bob", "B") alice.simulate = True bob.simulate = True self.form.project_manager.participants.append(alice) self.form.project_manager.participants.append(bob) self.form.project_manager.project_updated.emit() mt = self.form.compare_frame_controller.proto_analyzer.default_message_type msg1 = SimulatorMessage(source=bob, destination=alice, plain_bits=array("B", [1, 0, 1, 1]), pause=100, message_type=mt) msg2 = SimulatorMessage(source=alice, destination=bob, plain_bits=array("B", [1, 0, 1, 1]), pause=100, message_type=mt) simulator_manager = self.form.simulator_tab_controller.simulator_config simulator_manager.add_items([msg1, msg2], 0, simulator_manager.rootItem) simulator_manager.add_label(5, 15, "test", parent_item=simulator_manager.rootItem.children[0]) print(self.form.simulator_tab_controller.simulator_config.tx_needed) self.dialog = SimulatorDialog(self.form.simulator_tab_controller.simulator_config, self.form.generator_tab_controller.modulators, self.form.simulator_tab_controller.sim_expression_parser, self.form.project_manager) if self.SHOW: self.dialog.show()
def get_simulator_dialog(self) -> SimulatorDialog: protos = [ p for proto_list in self.tree_model.protocols.values() for p in proto_list ] signals = [p.signal for p in protos if p.signal is not None] s = SimulatorDialog(self.simulator_config, self.project_manager.modulators, self.sim_expression_parser, self.project_manager, signals=signals, signal_tree_model=self.tree_model, parent=self) s.rx_parameters_changed.connect( self.project_manager.on_simulator_rx_parameters_changed) s.sniff_parameters_changed.connect( self.project_manager.on_simulator_sniff_parameters_changed) s.tx_parameters_changed.connect( self.project_manager.on_simulator_tx_parameters_changed) s.open_in_analysis_requested.connect( self.open_in_analysis_requested.emit) s.rx_file_saved.connect(self.rx_file_saved.emit) return s
def setUp(self): super().setUp() alice = Participant("Alice", "A") bob = Participant("Bob", "B") alice.simulate = True bob.simulate = True self.form.project_manager.participants.append(alice) self.form.project_manager.participants.append(bob) self.form.project_manager.project_updated.emit() mt = self.form.compare_frame_controller.proto_analyzer.default_message_type msg1 = SimulatorMessage(source=bob, destination=alice, plain_bits=array("B", [1, 0, 1, 1]), pause=100, message_type=mt) msg2 = SimulatorMessage(source=alice, destination=bob, plain_bits=array("B", [1, 0, 1, 1]), pause=100, message_type=mt) simulator_manager = self.form.simulator_tab_controller.simulator_config simulator_manager.add_items([msg1, msg2], 0, simulator_manager.rootItem) simulator_manager.add_label(5, 15, "test", parent_item=simulator_manager.rootItem.children[0]) print(self.form.simulator_tab_controller.simulator_config.tx_needed) self.dialog = SimulatorDialog(self.form.simulator_tab_controller.simulator_config, self.form.generator_tab_controller.modulators, self.form.simulator_tab_controller.sim_expression_parser, self.form.project_manager) if self.SHOW: self.dialog.show()
def on_show_simulate_dialog_action_triggered(self): if not self.simulator_config.protocol_valid(): QMessageBox.critical(self, self.tr("Invalid protocol configuration"), self.tr( "There are some problems with your protocol configuration. Please fix them first.")) return if not len(self.simulator_config.get_all_messages()): QMessageBox.critical(self, self.tr("No messages found"), self.tr("Please add at least one message.")) return num_simulated = len([p for p in self.project_manager.participants if p.simulate]) if num_simulated == 0: if self.ui.listViewSimulate.model().rowCount() == 0: QMessageBox.critical(self, self.tr("No active participants"), self.tr("You have no active participants.<br>" "Please add a participant in the <i>Participants tab</i> and " "assign it to at least one message as <i>source</i> or <i>destination.</i>")) return else: QMessageBox.critical(self, self.tr("No participant for simulation selected"), self.tr("Please check at least one participant from the " "<i>Simulate these participants</i> list.")) return try: s = SimulatorDialog(self.simulator_config, self.project_manager.modulators, self.sim_expression_parser, self.project_manager, parent=self) s.rx_parameters_changed.connect(self.project_manager.on_simulator_rx_parameters_changed) s.sniff_parameters_changed.connect(self.project_manager.on_simulator_sniff_parameters_changed) s.tx_parameters_changed.connect(self.project_manager.on_simulator_tx_parameters_changed) s.exec_() except Exception as e: Errors.generic_error("An error occurred", str(e))
class TestSimulatorDialog(QtTestCase): def setUp(self): super().setUp() alice = Participant("Alice", "A") bob = Participant("Bob", "B") alice.simulate = True bob.simulate = True self.form.project_manager.participants.append(alice) self.form.project_manager.participants.append(bob) self.form.project_manager.project_updated.emit() mt = self.form.compare_frame_controller.proto_analyzer.default_message_type msg1 = SimulatorMessage(source=bob, destination=alice, plain_bits=array("B", [1, 0, 1, 1]), pause=100, message_type=mt) msg2 = SimulatorMessage(source=alice, destination=bob, plain_bits=array("B", [1, 0, 1, 1]), pause=100, message_type=mt) simulator_manager = self.form.simulator_tab_controller.simulator_config simulator_manager.add_items([msg1, msg2], 0, simulator_manager.rootItem) simulator_manager.add_label(5, 15, "test", parent_item=simulator_manager.rootItem.children[0]) print(self.form.simulator_tab_controller.simulator_config.tx_needed) self.dialog = SimulatorDialog(self.form.simulator_tab_controller.simulator_config, self.form.generator_tab_controller.modulators, self.form.simulator_tab_controller.sim_expression_parser, self.form.project_manager) if self.SHOW: self.dialog.show() def test_set_rx_parameters(self): rx_settings_widget = self.dialog.device_settings_rx_widget bh = BackendContainer("test", {Backends.native}, True, True) self.assertTrue(bh.is_enabled) rx_settings_widget.backend_handler.device_backends["test"] = bh rx_settings_widget.ui.cbDevice.addItem("test") rx_settings_widget.ui.cbDevice.setCurrentText("test") self.assertEqual(rx_settings_widget.device.name, "test") self.assertEqual(rx_settings_widget.device.backend, Backends.native) simulator = self.dialog.simulator self.__edit_spinbox_value(rx_settings_widget.ui.spinBoxFreq, 500e6) self.assertEqual(simulator.sniffer.rcv_device.frequency, 500e6) self.__edit_spinbox_value(rx_settings_widget.ui.spinBoxSampleRate, 4e6) self.assertEqual(simulator.sniffer.rcv_device.sample_rate, 4e6) self.__edit_spinbox_value(rx_settings_widget.ui.spinBoxBandwidth, 5e6) self.assertEqual(simulator.sniffer.rcv_device.bandwidth, 5e6) self.__edit_spinbox_value(rx_settings_widget.ui.spinBoxGain, 15) self.assertEqual(simulator.sniffer.rcv_device.gain, 15) self.__edit_spinbox_value(rx_settings_widget.ui.spinBoxIFGain, 10) self.assertEqual(simulator.sniffer.rcv_device.if_gain, 10) self.__edit_spinbox_value(rx_settings_widget.ui.spinBoxBasebandGain, 11) self.assertEqual(simulator.sniffer.rcv_device.baseband_gain, 11) self.__edit_spinbox_value(rx_settings_widget.ui.spinBoxFreqCorrection, 22) self.assertEqual(simulator.sniffer.rcv_device.freq_correction, 22) rx_settings_widget.ui.lineEditIP.setText("4.4.4.4") rx_settings_widget.ui.lineEditIP.editingFinished.emit() self.assertEqual(simulator.sniffer.rcv_device.ip, "4.4.4.4") def test_set_sniff_parameters(self): sniff_settings_widget = self.dialog.sniff_settings_widget simulator = self.dialog.simulator self.__edit_spinbox_value(sniff_settings_widget.ui.spinbox_sniff_BitLen, 111) self.assertEqual(simulator.sniffer.signal.bit_len, 111) self.__edit_spinbox_value(sniff_settings_widget.ui.spinbox_sniff_Center, 0.1337) self.assertEqual(simulator.sniffer.signal.qad_center, 0.1337) self.__edit_spinbox_value(sniff_settings_widget.ui.spinbox_sniff_ErrorTolerance, 13) self.assertEqual(simulator.sniffer.signal.tolerance, 13) self.__edit_spinbox_value(sniff_settings_widget.ui.spinbox_sniff_Noise, 0.1234) self.assertEqual(simulator.sniffer.signal.noise_threshold, 0.1234) sniff_settings_widget.ui.combox_sniff_Modulation.setCurrentText("PSK") self.assertEqual(simulator.sniffer.signal.modulation_type_str, "PSK") decodings = [sniff_settings_widget.ui.comboBox_sniff_encoding.itemText(i) for i in range(sniff_settings_widget.ui.comboBox_sniff_encoding.count())] sniff_settings_widget.ui.comboBox_sniff_encoding.setCurrentIndex(2) self.assertEqual(simulator.sniffer.decoder.name, decodings[2]) def test_set_tx_parameters(self): tx_settings_widget = self.dialog.device_settings_tx_widget simulator = self.dialog.simulator bh = BackendContainer("test", {Backends.native}, True, True) self.assertTrue(bh.is_enabled) tx_settings_widget.backend_handler.device_backends["test"] = bh tx_settings_widget.ui.cbDevice.addItem("test") tx_settings_widget.ui.cbDevice.setCurrentText("test") self.assertEqual(tx_settings_widget.device.name, "test") self.assertEqual(tx_settings_widget.device.backend, Backends.native) self.__edit_spinbox_value(tx_settings_widget.ui.spinBoxFreq, 300e6) self.assertEqual(simulator.sender.device.frequency, 300e6) self.__edit_spinbox_value(tx_settings_widget.ui.spinBoxSampleRate, 5e6) self.assertEqual(simulator.sender.device.sample_rate, 5e6) self.__edit_spinbox_value(tx_settings_widget.ui.spinBoxBandwidth, 3e6) self.assertEqual(simulator.sender.device.bandwidth, 3e6) self.__edit_spinbox_value(tx_settings_widget.ui.spinBoxGain, 16) self.assertEqual(simulator.sender.device.gain, 16) self.__edit_spinbox_value(tx_settings_widget.ui.spinBoxIFGain, 13) self.assertEqual(simulator.sender.device.if_gain, 13) self.__edit_spinbox_value(tx_settings_widget.ui.spinBoxBasebandGain, 10) self.assertEqual(simulator.sender.device.baseband_gain, 10) self.__edit_spinbox_value(tx_settings_widget.ui.spinBoxFreqCorrection, 33) self.assertEqual(simulator.sender.device.freq_correction, 33) tx_settings_widget.ui.lineEditIP.setText("1.2.6.2") tx_settings_widget.ui.lineEditIP.editingFinished.emit() self.assertEqual(simulator.sender.device.ip, "1.2.6.2") def __edit_spinbox_value(self, spinbox, value): spinbox.setValue(value) spinbox.editingFinished.emit()
class TestSimulatorDialog(QtTestCase): def setUp(self): super().setUp() alice = Participant("Alice", "A") bob = Participant("Bob", "B") alice.simulate = True bob.simulate = True self.form.project_manager.participants.append(alice) self.form.project_manager.participants.append(bob) self.form.project_manager.project_updated.emit() mt = self.form.compare_frame_controller.proto_analyzer.default_message_type msg1 = SimulatorMessage(source=bob, destination=alice, plain_bits=array("B", [1, 0, 1, 1]), pause=100, message_type=mt) msg2 = SimulatorMessage(source=alice, destination=bob, plain_bits=array("B", [1, 0, 1, 1]), pause=100, message_type=mt) simulator_manager = self.form.simulator_tab_controller.simulator_config simulator_manager.add_items([msg1, msg2], 0, simulator_manager.rootItem) simulator_manager.add_label(5, 15, "test", parent_item=simulator_manager.rootItem.children[0]) print(self.form.simulator_tab_controller.simulator_config.tx_needed) self.dialog = SimulatorDialog(self.form.simulator_tab_controller.simulator_config, self.form.generator_tab_controller.modulators, self.form.simulator_tab_controller.sim_expression_parser, self.form.project_manager) if self.SHOW: self.dialog.show() def test_set_rx_parameters(self): rx_settings_widget = self.dialog.device_settings_rx_widget bh = BackendContainer("test", {Backends.native}, True, True) self.assertTrue(bh.is_enabled) rx_settings_widget.backend_handler.device_backends["test"] = bh rx_settings_widget.ui.cbDevice.addItem("test") rx_settings_widget.ui.cbDevice.setCurrentText("test") self.assertEqual(rx_settings_widget.device.name, "test") self.assertEqual(rx_settings_widget.device.backend, Backends.native) simulator = self.dialog.simulator self.__edit_spinbox_value(rx_settings_widget.ui.spinBoxFreq, 500e6) self.assertEqual(simulator.sniffer.rcv_device.frequency, 500e6) self.__edit_spinbox_value(rx_settings_widget.ui.spinBoxSampleRate, 4e6) self.assertEqual(simulator.sniffer.rcv_device.sample_rate, 4e6) self.__edit_spinbox_value(rx_settings_widget.ui.spinBoxBandwidth, 5e6) self.assertEqual(simulator.sniffer.rcv_device.bandwidth, 5e6) self.__edit_spinbox_value(rx_settings_widget.ui.spinBoxGain, 15) self.assertEqual(simulator.sniffer.rcv_device.gain, 15) self.__edit_spinbox_value(rx_settings_widget.ui.spinBoxIFGain, 24) self.assertEqual(simulator.sniffer.rcv_device.if_gain, 24) self.__edit_spinbox_value(rx_settings_widget.ui.spinBoxBasebandGain, 11) self.assertEqual(simulator.sniffer.rcv_device.baseband_gain, 11) self.__edit_spinbox_value(rx_settings_widget.ui.spinBoxFreqCorrection, 22) self.assertEqual(simulator.sniffer.rcv_device.freq_correction, 22) rx_settings_widget.ui.lineEditIP.setText("4.4.4.4") rx_settings_widget.ui.lineEditIP.editingFinished.emit() self.assertEqual(simulator.sniffer.rcv_device.ip, "4.4.4.4") def test_set_sniff_parameters(self): sniff_settings_widget = self.dialog.sniff_settings_widget simulator = self.dialog.simulator self.__edit_spinbox_value(sniff_settings_widget.ui.spinbox_sniff_BitLen, 111) self.assertEqual(simulator.sniffer.signal.bit_len, 111) self.__edit_spinbox_value(sniff_settings_widget.ui.spinbox_sniff_Center, 0.1337) self.assertEqual(simulator.sniffer.signal.qad_center, 0.1337) self.__edit_spinbox_value(sniff_settings_widget.ui.spinbox_sniff_ErrorTolerance, 13) self.assertEqual(simulator.sniffer.signal.tolerance, 13) self.__edit_spinbox_value(sniff_settings_widget.ui.spinbox_sniff_Noise, 0.1234) self.assertEqual(simulator.sniffer.signal.noise_threshold, 0.1234) sniff_settings_widget.ui.combox_sniff_Modulation.setCurrentText("PSK") self.assertEqual(simulator.sniffer.signal.modulation_type_str, "PSK") decodings = [sniff_settings_widget.ui.comboBox_sniff_encoding.itemText(i) for i in range(sniff_settings_widget.ui.comboBox_sniff_encoding.count())] sniff_settings_widget.ui.comboBox_sniff_encoding.setCurrentIndex(2) self.assertEqual(simulator.sniffer.decoder.name, decodings[2]) def test_set_tx_parameters(self): tx_settings_widget = self.dialog.device_settings_tx_widget simulator = self.dialog.simulator bh = BackendContainer("test", {Backends.native}, True, True) self.assertTrue(bh.is_enabled) tx_settings_widget.backend_handler.device_backends["test"] = bh tx_settings_widget.ui.cbDevice.addItem("test") tx_settings_widget.ui.cbDevice.setCurrentText("test") self.assertEqual(tx_settings_widget.device.name, "test") self.assertEqual(tx_settings_widget.device.backend, Backends.native) self.__edit_spinbox_value(tx_settings_widget.ui.spinBoxFreq, 300e6) self.assertEqual(simulator.sender.device.frequency, 300e6) self.__edit_spinbox_value(tx_settings_widget.ui.spinBoxSampleRate, 5e6) self.assertEqual(simulator.sender.device.sample_rate, 5e6) self.__edit_spinbox_value(tx_settings_widget.ui.spinBoxBandwidth, 3e6) self.assertEqual(simulator.sender.device.bandwidth, 3e6) self.__edit_spinbox_value(tx_settings_widget.ui.spinBoxGain, 16) self.assertEqual(simulator.sender.device.gain, 16) self.__edit_spinbox_value(tx_settings_widget.ui.spinBoxIFGain, 13) self.assertEqual(simulator.sender.device.if_gain, 13) self.__edit_spinbox_value(tx_settings_widget.ui.spinBoxBasebandGain, 10) self.assertEqual(simulator.sender.device.baseband_gain, 10) self.__edit_spinbox_value(tx_settings_widget.ui.spinBoxFreqCorrection, 33) self.assertEqual(simulator.sender.device.freq_correction, 33) tx_settings_widget.ui.lineEditIP.setText("1.2.6.2") tx_settings_widget.ui.lineEditIP.editingFinished.emit() self.assertEqual(simulator.sender.device.ip, "1.2.6.2") def __edit_spinbox_value(self, spinbox, value): spinbox.setValue(value) spinbox.editingFinished.emit()