How to use the urh.signalprocessing.ProtocolAnalyzer.ProtocolAnalyzer function in urh

To help you get started, we’ve selected a few urh examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github jopohl / urh / tests / test_awre.py View on Github external
def test_format_finding_enocean(self):
        enocean_protocol = ProtocolAnalyzer(None)
        with open(get_path_for_data_file("enocean_bits.txt")) as f:
            for line in f:
                enocean_protocol.messages.append(Message.from_plain_bits_str(line.replace("\n", "")))
                enocean_protocol.messages[-1].message_type = enocean_protocol.default_message_type

        preamble_start = 3
        preamble_end = 10
        sof_start = 11
        sof_end = 14

        preamble_label = ProtocolLabel(name=self.preamble_field_type.caption, field_type=self.preamble_field_type,
                                       start=preamble_start, end=preamble_end, color_index=0)
        sync_label = ProtocolLabel(name=self.sync_field_type.caption, field_type=self.sync_field_type,
                                   start=sof_start, end=sof_end, color_index=1)

        ff = FormatFinder(enocean_protocol, self.participants, field_types=self.field_types)
github jopohl / urh / tests / awre / test_address_engine.py View on Github external
def test_paper_example(self):
        alice = Participant("Alice", "A")
        bob = Participant("Bob", "B")
        participants = [alice, bob]
        msg1 = Message.from_plain_hex_str("aabb1234")
        msg1.participant = alice
        msg2 = Message.from_plain_hex_str("aabb6789")
        msg2.participant = alice
        msg3 = Message.from_plain_hex_str("bbaa4711")
        msg3.participant = bob
        msg4 = Message.from_plain_hex_str("bbaa1337")
        msg4.participant = bob

        protocol = ProtocolAnalyzer(None)
        protocol.messages.extend([msg1, msg2, msg3, msg4])
        self.save_protocol("paper_example", protocol)

        bitvectors = FormatFinder.get_bitvectors_from_messages(protocol.messages)
        hexvectors = FormatFinder.get_hexvectors(bitvectors)
        address_engine = AddressEngine(hexvectors, participant_indices=[participants.index(msg.participant) for msg in
                                                                        protocol.messages])
github jopohl / urh / tests / test_protocol_analyzer.py View on Github external
def test_get_rssi_of_message(self):
        signal = Signal(get_path_for_data_file("two_participants.coco"), "RSSI-Test")
        signal.modulation_type = "FSK"
        signal.samples_per_symbol = 100
        signal.center = -0.0507

        proto_analyzer = ProtocolAnalyzer(signal)
        proto_analyzer.get_protocol_from_signal()
        self.assertEqual(proto_analyzer.num_messages, 18)
        messages = proto_analyzer.messages
        self.assertLess(messages[0].rssi, messages[1].rssi)
        self.assertGreater(messages[1].rssi, messages[2].rssi)
        self.assertLess(messages[2].rssi, messages[3].rssi)
        self.assertLess(messages[-2].rssi, messages[-1].rssi)
github jopohl / urh / tests / test_modulator.py View on Github external
modulator.parameters[0] = -90
                modulator.parameters[1] = 90

            modulator.modulate(self.modulation_data, self.pause).tofile(filename)

            signal = Signal(filename, modulation)
            signal.modulation_type = modulation
            signal.samples_per_symbol = self.samples_per_symbol
            if modulation == "ASK":
                signal.center = 0.5
            elif modulation == "FSK":
                signal.center = 0.0097
            elif modulation == "PSK":
                signal.center = 0
            self.assertEqual(signal.num_samples, self.total_samples, msg=modulation)
            pa = ProtocolAnalyzer(signal)
            pa.get_protocol_from_signal()
            self.assertEqual(1, len(pa.messages), msg=modulation)
            self.assertEqual(self.modulation_data, pa.messages[0].plain_bits, msg=modulation)
github jopohl / urh / tests / test_protocol_analyzer.py View on Github external
def test_binary_format(self):
        pa = ProtocolAnalyzer(None)
        pa.messages.append(Message([1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 1, 1, 0, 1, 1], 0, pa.default_message_type))
        pa.messages.append(Message([1, 1, 1, 0, 1], 0, pa.default_message_type))

        filename = os.path.join(tempfile.gettempdir(), "test_proto.bin")
        pa.to_binary(filename, use_decoded=True)

        pa.from_binary(filename)
        self.assertEqual(len(pa.messages), 3)
        self.assertEqual(pa.plain_bits_str[2], "111000111001101111101000")
github jopohl / urh / tests / test_auto_assignments.py View on Github external
def test_two_assign_participants_by_rssi(self):
        rssis = [[0.65389872, 0.13733707, 0.1226876, 0.73320961, 0.64940965, 0.12463234, 0.12296994,
                  0.68053716, 0.66020358, 0.12428901, 0.12312815, 0.69160986, 0.65582329, 0.12536003,
                  0.12587067, 0.66315573, 0.66313261, 0.12816505, 0.13491708, 0.66950738, 0.14047238],
                 [0.26651502, 0.2073856, 0.13547869, 0.25948182, 0.28204739, 0.13716124, 0.13526952,
                  0.24828221, 0.25431305, 0.13681877, 0.13650328, 0.28083691, 0.25550124, 0.13498682,
                  0.13611424, 0.2629154, 0.26388499, 0.13780586, 0.13561584, 0.27228078, 0.1356563]]

        proto1 = ProtocolAnalyzer(None)
        proto2 = ProtocolAnalyzer(None)

        for i in range(0, len(rssis[0])):
            message = copy.deepcopy(self.protocol.messages[i])
            message.participant = None
            proto1.messages.append(message)
            proto1.messages[i].rssi = rssis[0][i]

        self.assertEqual(len(proto1.messages), 21)

        for i in range(0, len(rssis[1])):
            message = copy.deepcopy(self.protocol.messages[21 + i])
            message.participant = None
            proto2.messages.append(message)
            proto2.messages[i].rssi = rssis[1][i]
github jopohl / urh / tests / awre / AWRETestCase.py View on Github external
def get_format_finder_from_protocol_file(self, filename: str, clear_participant_addresses=True, return_messages=False):
        proto_file = get_path_for_data_file(filename)
        protocol = ProtocolAnalyzer(signal=None, filename=proto_file)
        protocol.from_xml_file(filename=proto_file, read_bits=True)

        self.clear_message_types(protocol.messages)

        ff = FormatFinder(protocol.messages)
        if clear_participant_addresses:
            ff.known_participant_addresses.clear()

        if return_messages:
            return ff, protocol.messages
        else:
            return ff
github jopohl / urh / src / urh / controller / dialogs / DecoderDialog.py View on Github external
def set_signal(self):
        indx = self.ui.combobox_signals.currentIndex()
        if indx != 0:
            self.ui.inpt.setReadOnly(True)
        else:
            self.ui.inpt.setReadOnly(False)
            self.ui.inpt.setText("10010110")
            self.decoder_update()
            return

        self.setCursor(Qt.WaitCursor)

        signal = self.signals[indx - 1]
        pa = ProtocolAnalyzer(signal)
        pa.get_protocol_from_signal()
        self.ui.inpt.setText("".join(pa.plain_bits_str))
        self.ui.inpt.setCursorPosition(0)

        if signal is not None and pa.messages:
            last_message = pa.messages[-1]
            lookup = {i: msg.bit_sample_pos for i, msg in enumerate(pa.messages)}

            plot_data = signal.qad[lookup[0][0]:lookup[pa.num_messages - 1][len(last_message) - 1]]
            self.ui.graphicsView_signal.plot_data(plot_data)

        self.ui.graphicsView_signal.centerOn(0, 0)
        self.unsetCursor()
github jopohl / urh / src / urh / controller / MainController.py View on Github external
def add_signal(self, signal, group_id=0, index=-1):
        self.setCursor(Qt.WaitCursor)
        pa = ProtocolAnalyzer(signal)
        sig_frame = self.signal_tab_controller.add_signal_frame(pa, index=index)
        pa = self.compare_frame_controller.add_protocol(pa, group_id)

        signal.blockSignals(True)
        has_entry = self.project_manager.read_project_file_for_signal(signal)

        if self.ui.actionAuto_detect_new_signals.isChecked() and not has_entry and not signal.changed:
            sig_frame.ui.stackedWidget.setCurrentWidget(sig_frame.ui.pageLoading)
            qApp.processEvents()
            signal.auto_detect(detect_modulation=True, detect_noise=False)
            sig_frame.ui.stackedWidget.setCurrentWidget(sig_frame.ui.pageSignal)

        signal.blockSignals(False)

        self.signal_protocol_dict[sig_frame] = pa
github jopohl / urh / src / urh / models / ProtocolTreeItem.py View on Github external
def protocol(self):
        if isinstance(self.__itemData, ProtocolAnalyzer):
            if self.copy_data:
                if self.__data_copy is None:
                    self.__data_copy = copy.deepcopy(self.__itemData)  # type: ProtocolAnalyzer

                    # keep message types
                    self.__data_copy.message_types = self.__itemData.message_types
                    nrz = Encoding([""])
                    for i, message in enumerate(self.__data_copy.messages):  # type: Message
                        decoded_bits = message.decoded_bits
                        message.decoder = nrz
                        message.plain_bits = decoded_bits
                        message.message_type = self.__itemData.messages[i].message_type

                    self.__data_copy.qt_signals.show_state_changed.connect(self.__itemData.qt_signals.show_state_changed.emit)

                return self.__data_copy