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_participants_list(self): alice = Participant("Alice", "A") bob = Participant("Bob", "B") 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(destination=alice, plain_bits=array("B", [1, 0, 1, 1]), pause=100, message_type=mt) msg2 = SimulatorMessage(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]) stc = self.form.simulator_tab_controller # type: SimulatorTabController model = stc.ui.listViewSimulate.model() self.assertEqual(model.rowCount(), 2) self.assertEqual(model.data(model.index(0, 0)), "Alice (A)") self.assertEqual(model.data(model.index(1, 0)), "Bob (B)") self.assertFalse(self.form.project_manager.participants[0].simulate) self.assertEqual(model.data(model.index(0, 0), role=Qt.CheckStateRole), Qt.Unchecked) self.assertFalse(self.form.project_manager.participants[1].simulate) self.assertEqual(model.data(model.index(1, 0), role=Qt.CheckStateRole), Qt.Unchecked) model.setData(model.index(0, 0), Qt.Checked, role=Qt.CheckStateRole) self.assertTrue(self.form.project_manager.participants[0].simulate)
def create_message(self, destination, plain_bits, pause, message_type, decoder, source): if destination is None: destination = self.simulator_config.broadcast_part sim_message = SimulatorMessage(destination=destination, plain_bits=plain_bits, pause=pause, message_type=MessageType(message_type.name), decoder=decoder, source=source) for lbl in message_type: sim_label = SimulatorProtocolLabel(copy.deepcopy(lbl)) sim_message.insert_child(-1, sim_label) return sim_message
def load_item_from_xml(self, xml_tag: ET.Element, message_types) -> SimulatorItem: if xml_tag.tag == "simulator_message": item = SimulatorMessage.new_from_xml( xml_tag, self.participants, self.project_manager.decodings, message_types) elif xml_tag.tag == "simulator_label": item = SimulatorProtocolLabel.from_xml( xml_tag, self.project_manager.field_types_by_caption) elif xml_tag.tag == "simulator_trigger_command_action": item = SimulatorTriggerCommandAction.from_xml(xml_tag) elif xml_tag.tag == "simulator_sleep_action": item = SimulatorSleepAction.from_xml(xml_tag) elif xml_tag.tag == "simulator_counter_action": item = SimulatorCounterAction.from_xml(xml_tag) elif xml_tag.tag == "simulator_rule": item = SimulatorRule.from_xml(xml_tag) elif xml_tag.tag == "simulator_rule_condition": item = SimulatorRuleCondition.from_xml(xml_tag) elif xml_tag.tag == "simulator_goto_action": item = SimulatorGotoAction.from_xml(xml_tag) elif xml_tag.tag in ("message", "label", "checksum_label"): return None else: raise ValueError("Unknown simulator item tag: {}".format( xml_tag.tag)) for child_tag in xml_tag: child = self.load_item_from_xml(child_tag, message_types) if child is not None: item.add_child(child) return item
def load_item_from_xml(self, xml_tag: ET.Element, message_types) -> SimulatorItem: if xml_tag.tag == "simulator_message": item = SimulatorMessage.new_from_xml(xml_tag, self.participants, self.project_manager.decodings, message_types) elif xml_tag.tag == "simulator_label": item = SimulatorProtocolLabel.from_xml(xml_tag, self.project_manager.field_types_by_caption) elif xml_tag.tag == "simulator_trigger_command_action": item = SimulatorTriggerCommandAction.from_xml(xml_tag) elif xml_tag.tag == "simulator_sleep_action": item = SimulatorSleepAction.from_xml(xml_tag) elif xml_tag.tag == "simulator_counter_action": item = SimulatorCounterAction.from_xml(xml_tag) elif xml_tag.tag == "simulator_rule": item = SimulatorRule.from_xml(xml_tag) elif xml_tag.tag == "simulator_rule_condition": item = SimulatorRuleCondition.from_xml(xml_tag) elif xml_tag.tag == "simulator_goto_action": item = SimulatorGotoAction.from_xml(xml_tag) elif xml_tag.tag in ("message", "label", "checksum_label"): return None else: raise ValueError("Unknown simulator item tag: {}".format(xml_tag.tag)) for child_tag in xml_tag: child = self.load_item_from_xml(child_tag, message_types) if child is not None: item.add_child(child) return item
def test_performance(self): self.form = MainController() self.cfc = self.form.compare_frame_controller self.stc = self.form.simulator_tab_controller self.gtc = self.form.generator_tab_controller self.form.add_signalfile(get_path_for_data_file("esaver.complex16s")) self.sframe = self.form.signal_tab_controller.signal_frames[0] self.sim_frame = self.form.simulator_tab_controller self.form.ui.tabWidget.setCurrentIndex(3) self.cfc.proto_analyzer.auto_assign_labels() self.network_sdr_plugin_sender = NetworkSDRInterfacePlugin(raw_mode=True) part_a = Participant("Device A", shortname="A", color_index=0) part_b = Participant("Device B", shortname="B", color_index=1) part_b.simulate = True self.form.project_manager.participants.append(part_a) self.form.project_manager.participants.append(part_b) self.form.project_manager.project_updated.emit() sniffer = ProtocolSniffer(100, 0.01, 0.01, 0.1, 5, "FSK", 1, NetworkSDRInterfacePlugin.NETWORK_SDR_NAME, BackendHandler(), network_raw_mode=True) sender = EndlessSender(BackendHandler(), NetworkSDRInterfacePlugin.NETWORK_SDR_NAME) simulator = Simulator(self.stc.simulator_config, self.gtc.modulators, self.stc.sim_expression_parser, self.form.project_manager, sniffer=sniffer, sender=sender) pause = 100 msg_a = SimulatorMessage(part_b, [1, 0] * 16 + [1, 1, 0, 0] * 8 + [0, 0, 1, 1] * 8 + [1, 0, 1, 1, 1, 0, 0, 1, 1, 1] * 4, pause=pause, message_type=MessageType("empty_message_type"), source=part_a) msg_b = SimulatorMessage(part_a, [1, 0] * 16 + [1, 1, 0, 0] * 8 + [1, 1, 0, 0] * 8 + [1, 0, 1, 1, 1, 0, 0, 1, 1, 1] * 4, pause=pause, message_type=MessageType("empty_message_type"), source=part_b) self.stc.simulator_config.add_items([msg_a, msg_b], 0, None) self.stc.simulator_config.update_active_participants() port = self.get_free_port() sniffer = simulator.sniffer sniffer.rcv_device.set_server_port(port) self.network_sdr_plugin_sender.client_port = port sender = simulator.sender port = self.get_free_port() sender.device.set_client_port(port) sender.device._VirtualDevice__dev.name = "simulator_sender" current_index = Value("L") elapsed = Value("f") target_num_samples = 13600 + pause receive_process = Process(target=receive, args=(port, current_index, target_num_samples, elapsed)) receive_process.daemon = True receive_process.start() # Ensure receiver is running time.sleep(2) # spy = QSignalSpy(self.network_sdr_plugin_receiver.rcv_index_changed) simulator.start() modulator = Modulator("test_modulator") modulator.samples_per_symbol = 100 modulator.carrier_freq_hz = 55e3 # yappi.start() self.network_sdr_plugin_sender.send_raw_data(modulator.modulate(msg_a.encoded_bits), 1) time.sleep(0.5) # send some zeros to simulate the end of a message self.network_sdr_plugin_sender.send_raw_data(np.zeros(self.num_zeros_for_pause, dtype=np.complex64), 1) time.sleep(0.5) receive_process.join(15) logger.info("PROCESS TIME: {0:.2f}ms".format(elapsed.value)) # self.assertEqual(current_index.value, target_num_samples) self.assertLess(elapsed.value, 200) # timeout = spy.wait(2000) # yappi.get_func_stats().print_all() # yappi.get_thread_stats().print_all()
def test_performance(self): part_a = Participant("Device A", shortname="A", color_index=0) part_b = Participant("Device B", shortname="B", color_index=1) part_b.simulate = True self.form.project_manager.participants.append(part_a) self.form.project_manager.participants.append(part_b) self.form.project_manager.project_updated.emit() sniffer = ProtocolSniffer(100, 0.01, 0.001, 5, 1, NetworkSDRInterfacePlugin.NETWORK_SDR_NAME, BackendHandler(), network_raw_mode=True, real_time=True) sender = EndlessSender(BackendHandler(), NetworkSDRInterfacePlugin.NETWORK_SDR_NAME) simulator = Simulator(self.stc.simulator_config, self.gtc.modulators, self.stc.sim_expression_parser, self.form.project_manager, sniffer=sniffer, sender=sender) msg_a = SimulatorMessage(part_b, [1, 0] * 16 + [1, 1, 0, 0] * 8 + [0, 0, 1, 1] * 8 + [1, 0, 1, 1, 1, 0, 0, 1, 1, 1] * 4, 100000, MessageType("empty_message_type"), source=part_a) msg_b = SimulatorMessage(part_a, [1, 0] * 16 + [1, 1, 0, 0] * 8 + [1, 1, 0, 0] * 8 + [1, 0, 1, 1, 1, 0, 0, 1, 1, 1] * 4, 100000, MessageType("empty_message_type"), source=part_b) self.stc.simulator_config.add_items([msg_a, msg_b], 0, None) self.stc.simulator_config.update_active_participants() port = self.__get_free_port() sniffer = simulator.sniffer sniffer.rcv_device.set_server_port(port) self.network_sdr_plugin_sender.client_port = port sender = simulator.sender port = self.__get_free_port() sender.device.set_client_port(port) sender.device._VirtualDevice__dev.name = "simulator_sender" current_index = Value("L") elapsed = Value("f") target_num_samples = 113600 receive_process = Process(target=receive, args=(port, current_index, target_num_samples, elapsed)) receive_process.daemon = True receive_process.start() # Ensure receiver is running time.sleep(1) # spy = QSignalSpy(self.network_sdr_plugin_receiver.rcv_index_changed) simulator.start() modulator = Modulator("test_modulator") modulator.samples_per_bit = 100 modulator.carrier_freq_hz = 55e3 modulator.modulate(msg_a.encoded_bits) # yappi.start() self.network_sdr_plugin_sender.send_raw_data( modulator.modulated_samples, 1) QTest.qWait(100) receive_process.join(10) print("PROCESS TIME: {0:.2f}ms".format(elapsed.value)) self.assertEqual(current_index.value, target_num_samples) self.assertLess(elapsed.value, 200)