How to use the urh.signalprocessing.Participant.Participant 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 / awre / test_awre_preprocessing.py View on Github external
def test_sync_word_finding_common_prefix(self):
        """
        Messages are very similiar (odd and even ones are the same)
        However, they do not have two different sync words!
        The algorithm needs to check for a common prefix of the two found sync words

        :return:
        """
        sync = "0x1337"
        num_messages = 10

        alice = Participant("Alice", address_hex="dead01")
        bob = Participant("Bob", address_hex="beef24")

        mb = MessageTypeBuilder("protocol_with_one_message_type")
        mb.add_label(FieldType.Function.PREAMBLE, 72)
        mb.add_label(FieldType.Function.SYNC, 16)
        mb.add_label(FieldType.Function.LENGTH, 8)
        mb.add_label(FieldType.Function.SRC_ADDRESS, 24)
        mb.add_label(FieldType.Function.DST_ADDRESS, 24)
        mb.add_label(FieldType.Function.SEQUENCE_NUMBER, 16)

        pg = ProtocolGenerator([mb.message_type],
                               syncs_by_mt={mb.message_type: "0x1337"},
                               preambles_by_mt={mb.message_type: "10" * 36},
                               participants=[alice, bob])

        random.seed(0)
github jopohl / urh / tests / awre / test_partially_labeled.py View on Github external
def __prepare_example_protocol(self) -> ProtocolAnalyzer:
        alice = Participant("Alice", "A", address_hex="1234")
        bob = Participant("Bob", "B", address_hex="cafe")

        mb = MessageTypeBuilder("data")
        mb.add_label(FieldType.Function.PREAMBLE, 8)
        mb.add_label(FieldType.Function.SYNC, 16)
        mb.add_label(FieldType.Function.LENGTH, 8)
        mb.add_label(FieldType.Function.TYPE, 8)
        mb.add_label(FieldType.Function.DST_ADDRESS, 16)
        mb.add_label(FieldType.Function.SRC_ADDRESS, 16)
        mb_ack = MessageTypeBuilder("ack")
        mb_ack.add_label(FieldType.Function.PREAMBLE, 8)
        mb_ack.add_label(FieldType.Function.SYNC, 16)
        mb_ack.add_label(FieldType.Function.LENGTH, 8)
        mb_ack.add_label(FieldType.Function.DST_ADDRESS, 16)

        num_messages = 50
github jopohl / urh / tests / test_signal_tab_GUI.py View on Github external
def test_context_menu_text_edit_protocol_view(self):
        self.add_signal_to_form("esaver.coco")
        self.form.signal_tab_controller.signal_frames[0].ui.cbProtoView.setCurrentIndex(2)
        text_edit = self.form.signal_tab_controller.signal_frames[0].ui.txtEdProto

        menu = text_edit.create_context_menu()
        line_wrap_action = next(action for action in menu.actions() if action.text().startswith("Linewrap"))
        checked = line_wrap_action.isChecked()
        line_wrap_action.trigger()

        menu = text_edit.create_context_menu()
        line_wrap_action = next(action for action in menu.actions() if action.text().startswith("Linewrap"))
        self.assertNotEqual(checked, line_wrap_action.isChecked())

        self.assertEqual(len([action for action in menu.actions() if action.text() == "Participant"]), 0)
        self.form.project_manager.participants.append(Participant("Alice", "A"))
        text_edit.selectAll()
        menu = text_edit.create_context_menu()
        self.assertEqual(len([action for action in menu.actions() if action.text() == "Participant"]), 1)
github jopohl / urh / tests / awre / AWRExperiments.py View on Github external
def _prepare_protocol_5() -> ProtocolGenerator:
        alice = Participant("Alice", address_hex="1337")
        bob = Participant("Bob", address_hex="beef")
        carl = Participant("Carl", address_hex="cafe")

        mb = MessageTypeBuilder("data")
        mb.add_label(FieldType.Function.PREAMBLE, 16)
        mb.add_label(FieldType.Function.SYNC, 16)
        mb.add_label(FieldType.Function.LENGTH, 8)
        mb.add_label(FieldType.Function.SRC_ADDRESS, 16)
        mb.add_label(FieldType.Function.DST_ADDRESS, 16)
        mb.add_label(FieldType.Function.SEQUENCE_NUMBER, 16)

        mb_ack = MessageTypeBuilder("ack")
        mb_ack.add_label(FieldType.Function.PREAMBLE, 16)
        mb_ack.add_label(FieldType.Function.SYNC, 16)
        mb_ack.add_label(FieldType.Function.LENGTH, 8)
        mb_ack.add_label(FieldType.Function.DST_ADDRESS, 16)
github jopohl / urh / tests / awre / AWRExperiments.py View on Github external
def _prepare_protocol_6() -> ProtocolGenerator:
        alice = Participant("Alice", address_hex="24")
        broadcast = Participant("Bob", address_hex="ff")

        mb = MessageTypeBuilder("data")
        mb.add_label(FieldType.Function.SYNC, 16)
        mb.add_label(FieldType.Function.LENGTH, 8)
        mb.add_label(FieldType.Function.SRC_ADDRESS, 8)
        mb.add_label(FieldType.Function.SEQUENCE_NUMBER, 8)

        pg = ProtocolGenerator([mb.message_type],
                               syncs_by_mt={mb.message_type: "0x8e88"},
                               preambles_by_mt={mb.message_type: "10" * 8},
                               participants=[alice, broadcast])

        return pg
github jopohl / urh / tests / awre / test_partially_labeled.py View on Github external
def __prepare_example_protocol(self) -> ProtocolAnalyzer:
        alice = Participant("Alice", "A", address_hex="1234")
        bob = Participant("Bob", "B", address_hex="cafe")

        mb = MessageTypeBuilder("data")
        mb.add_label(FieldType.Function.PREAMBLE, 8)
        mb.add_label(FieldType.Function.SYNC, 16)
        mb.add_label(FieldType.Function.LENGTH, 8)
        mb.add_label(FieldType.Function.TYPE, 8)
        mb.add_label(FieldType.Function.DST_ADDRESS, 16)
        mb.add_label(FieldType.Function.SRC_ADDRESS, 16)
        mb_ack = MessageTypeBuilder("ack")
        mb_ack.add_label(FieldType.Function.PREAMBLE, 8)
        mb_ack.add_label(FieldType.Function.SYNC, 16)
        mb_ack.add_label(FieldType.Function.LENGTH, 8)
        mb_ack.add_label(FieldType.Function.DST_ADDRESS, 16)

        num_messages = 50
github jopohl / urh / src / urh / models / SimulatorParticipantListModel.py View on Github external
from PyQt5.QtCore import Qt, QModelIndex, QAbstractListModel, pyqtSignal

from urh.signalprocessing.Participant import Participant
from urh.simulator.SimulatorConfiguration import SimulatorConfiguration


class SimulatorParticipantListModel(QAbstractListModel):

    participant_simulate_changed = pyqtSignal(Participant)

    def __init__(self, config: SimulatorConfiguration, parent=None):
        super().__init__(parent)
        self.simulator_config = config

    def update(self):
        self.beginResetModel()
        self.endResetModel()

    def rowCount(self, parent: QModelIndex = None, *args, **kwargs):
        return len(self.simulator_config.active_participants)

    def data(self, index: QModelIndex, role=Qt.DisplayRole):
        i = index.row()
        participant = self.simulator_config.active_participants[i]
github jopohl / urh / src / urh / simulator / SimulatorMessage.py View on Github external
def new_from_xml(cls, tag: ET.Element, participants, decoders=None, message_types=None):
        msg = Message.new_from_xml(tag.find("message"),
                                   participants=participants,
                                   decoders=decoders,
                                   message_types=message_types)
        destination = Participant.find_matching(tag.get("destination_id", ""), participants)
        return SimulatorMessage(destination, msg.plain_bits, msg.pause, msg.message_type, msg.decoder, msg.participant,
                                timestamp=msg.timestamp)
github jopohl / urh / src / urh / signalprocessing / ProtocolAnalyzer.py View on Github external
def from_xml_tag(self, root: ET.Element, read_bits=False, participants=None, decodings=None):
        if not root:
            return None

        decoders = Encoding.read_decoders_from_xml_tag(root) if decodings is None else decodings

        if participants is None:
            participants = Participant.read_participants_from_xml_tag(root)

        if read_bits:
            self.messages[:] = []

        try:
            message_types = []
            for message_type_tag in root.find("message_types").findall("message_type"):
                message_types.append(MessageType.from_xml(message_type_tag))
        except AttributeError:
            message_types = []

        for message_type in message_types:
            if message_type not in self.message_types:
                self.message_types.append(message_type)

        try:
github jopohl / urh / src / urh / signalprocessing / ProtocolAnalyzer.py View on Github external
def to_xml_tag(self, decodings, participants, tag_name="protocol",
                   include_message_type=False, write_bits=False, messages=None, modulators=None) -> ET.Element:
        root = ET.Element(tag_name)
        messages = self.messages if messages is None else messages

        # Save modulators
        if modulators is not None:  # For protocol analyzer container
            root.append(Modulator.modulators_to_xml_tag(modulators))

        root.append(Encoding.decodings_to_xml_tag(decodings))
        root.append(Participant.participants_to_xml_tag(participants))

        # Save data
        data_tag = ET.SubElement(root, "messages")
        for i, message in enumerate(messages):
            message_tag = message.to_xml(decoders=decodings,
                                         include_message_type=include_message_type,
                                         write_bits=write_bits)
            data_tag.append(message_tag)

        # Save message types separatively as not saved in messages already
        if not include_message_type:
            message_types_tag = ET.SubElement(root, "message_types")
            for message_type in self.message_types:
                message_types_tag.append(message_type.to_xml())

        return root