Esempio n. 1
0
    def saveas(self):
        # Ask for a name
        txt = ["Please enter a name:", self.e.chain[0]]
        ok, name = CustomDialog.dialog(self, txt, "input")

        if ok and name != "":
            self.e.chain[0] = name
            self.decoderchainUpdate()

            # If name is already there, overwrite existing
            for i in range(0, len(self.decodings)):
                if name == self.decodings[i].name:
                    self.ui.combobox_decodings.setCurrentIndex(i)
                    self.decodings[i] = encoding(self.chainstr)
                    self.set_e()
                    self.ui.saveas.setVisible(False)
                    self.save_to_file()
                    return

            self.decodings.append(encoding(self.chainstr))
            self.ui.combobox_decodings.addItem(self.chainstr[0])
            self.ui.combobox_decodings.setCurrentIndex(
                self.ui.combobox_decodings.count() - 1)
            self.set_e()
            self.save_to_file()
Esempio n. 2
0
    def __init__(self, name: str, decoding: encoding = encoding(["Non Return To Zero (NRZ)"])):
        self.name = name
        self.__decoding = decoding
        self.__labels = []
        self.__items = []

        self.loaded_from_file = False
Esempio n. 3
0
    def __init__(self,
                 plain_bits,
                 pause: int,
                 bit_alignment_positions,
                 rssi=0,
                 modulator_indx=0,
                 decoder=None,
                 fuzz_created=None,
                 bit_sample_pos=None,
                 bit_len=100,
                 exclude_from_decoding_labels=None):
        """

        :param pause: Pause NACH dem Block in Samples
        :type plain_bits: list[bool|Symbol]
        :type decoder: encoding
        :type bit_alignment_positions: list of int
        :param bit_alignment_positions: Für Ausrichtung der Hex Darstellung (Leere Liste für Standardverhalten)
        :param bit_len: Für Übernahme der Bitlänge in Modulator Dialog
        :param fuzz_created: Eine Liste von Tupeln von Start und End Indizes, wenn dieser Block durch Fuzzing erzeugt wurde
        :return:
        """
        self.__plain_bits = plain_bits
        self.pause = pause
        self.modulator_indx = modulator_indx
        self.rssi = rssi

        self.absolute_time = 0  # set in Compare Frame
        self.relative_time = 0  # set in Compare Frame

        self.__decoder = decoder if decoder else encoding(
            ["Non Return To Zero (NRZ)"])
        """:type: encoding """

        self.bit_alignment_positions = bit_alignment_positions
        self.fuzz_created = fuzz_created if fuzz_created is not None else []
        self.fuzz_labels = []
        """:type: list of ProtocolLabel """

        self.__decoded_bits = None
        self.__encoded_bits = None
        self.decoding_errors = 0

        self.exclude_from_decoding_labels = [] if exclude_from_decoding_labels is None else exclude_from_decoding_labels
        """:type: list of ProtocolLabel """

        self.bit_len = bit_len  # Für Übernahme in Modulator

        if bit_sample_pos is None:
            self.bit_sample_pos = []
        else:
            self.bit_sample_pos = bit_sample_pos
Esempio n. 4
0
    def test_whitening(self):
        e = encoding()

        # Test 1
        e.data_whitening_sync = e.hex2bit("67686768")
        original_inpt = e.hex2bit("aaaaaaaa67686768f9ca03909567ba76a8") + [
            False
        ]  # Korrektes Signal, bitgenau
        inpt = original_inpt.copy()
        #print (e.bit2hex(inpt))
        output, err = e.apply_data_whitening(True, inpt)
        #print (e.bit2hex(output), err)
        newinpt, err = e.apply_data_whitening(False, output)
        #print (e.bit2hex(newinpt), newinpt, err)
        self.assertEqual(original_inpt, newinpt)
Esempio n. 5
0
    def setUp(self):
        self.protocol = ProtocolAnalyzer(None)
        with open("./data/decoded_bits.txt") as f:
            for line in f:
                self.protocol.blocks.append(ProtocolBlock.from_plain_bits_str(line.replace("\n", ""), {}))
                self.protocol.blocks[-1].labelset = self.protocol.default_labelset

        self.assertEqual(self.protocol.num_blocks, 42)
        self.assertEqual(self.protocol.plain_hex_str[0][16:18], "2d")

        self.decodings = []
        self.decodings.append(encoding(['Non Return To Zero (NRZ)']))
        self.decodings.append(encoding(['Non Return To Zero Inverted (NRZ-I)', 'Invert']))
        self.decodings.append(encoding(['Manchester I', 'Edge Trigger']))
        self.decodings.append(encoding(['Manchester II', 'Edge Trigger', 'Invert']))
        self.decodings.append(encoding(['Differential Manchester', 'Edge Trigger', 'Differential Encoding',]))
        self.decodings.append(encoding(['DeWhitening Special', 'Remove Data Whitening (CC1101)', '0x9a7d9a7d;0x21;0x8']))
        self.decodings.append(encoding(['DeWhitening', 'Remove Data Whitening (CC1101)', '0x67686768;0x21;0x8']))
Esempio n. 6
0
    def setUp(self):
        self.old_sym_len = constants.SETTINGS.value('rel_symbol_length', type=int)
        constants.SETTINGS.setValue('rel_symbol_length', 0) # Disable Symbols for this Test

        QTest.qWait(10)

        self.form = MainController()
        self.form.add_signalfile("./data/rwe_steckdose_anlernen.complex")
        QTest.qWait(10)
        self.form.signal_tab_controller.signal_frames[0].ui.spinBoxNoiseTreshold.setValue(0.06)
        self.form.signal_tab_controller.signal_frames[0].ui.spinBoxNoiseTreshold.editingFinished.emit()
        self.form.signal_tab_controller.signal_frames[0].ui.spinBoxCenterOffset.setValue(-0.0127)
        self.form.signal_tab_controller.signal_frames[0].ui.spinBoxCenterOffset.editingFinished.emit()
        self.form.signal_tab_controller.signal_frames[0].ui.spinBoxInfoLen.setValue(100)
        self.form.signal_tab_controller.signal_frames[0].ui.spinBoxInfoLen.editingFinished.emit()
        QTest.qWait(10)

        self.sframe = self.form.signal_tab_controller.signal_frames[0]
        self.cframe = self.form.compare_frame_controller
        self.gframe = self.form.generator_tab_controller

        # Dewhitening mit SyncByte 0x9a7d9a7d, Data Whitening Poly 0x21, Compute and apply CRC16 via X0r,
        # Rest auf False anlegen und setzen
        self.form.ui.tabWidget.setCurrentIndex(1)
        self.cframe.ui.cbProtoView.setCurrentIndex(1) # Hex
        QTest.qWait(10)
        decoding = encoding(["Data Whitening", constants.DECODING_DATAWHITENING, "0x9a7d9a7d;0x21;0x8"])
        self.cframe.decodings.append(decoding)
        self.cframe.ui.cbDecoding.addItem(decoding.name)
        self.cframe.set_decoding(decoding)

        # CRC Check
        QTest.qWait(10)
        self.assertEqual(self.cframe.protocol_model.display_data[0][-4:], "0000")

        # Serial Part 1: Bits 207-226 (Dezimal: 91412) (20 Bits)
        self.cframe.add_protocol_label(206, 225, 0, 0, False, edit_label_name = False)
        self.assertEqual(int(self.cframe.groups[0].labels[0].reference_bits,2), 91412)

        # Zeros: Bits 227-244 (18 Bits)
        self.cframe.add_protocol_label(226, 243, 0, 0, False, edit_label_name = False)
        self.assertEqual(int(self.cframe.groups[0].labels[1].reference_bits,2), 0)

        # Serial Part 2: Bit 245 - 264 (Dezimal: 1034678) (20 Bits)
        self.cframe.add_protocol_label(244, 263, 0, 0, False, edit_label_name = False)
        self.assertEqual(int(self.cframe.groups[0].labels[2].reference_bits, 2), 1034678)
        QTest.qWait(10)

        self.form.ui.tabWidget.setCurrentIndex(2)
        item = self.gframe.tree_model.rootItem.children[0].children[0]
        index = self.gframe.tree_model.createIndex(0, 0, item)
        rect = self.gframe.ui.treeProtocols.visualRect(index)

        self.assertEqual(len(self.gframe.ui.treeProtocols.selectedIndexes()), 0)
        QTest.mousePress(self.gframe.ui.treeProtocols.viewport(), Qt.LeftButton, pos = rect.center())
        self.assertEqual(self.gframe.ui.treeProtocols.selectedIndexes()[0], index)
        mimedata = self.gframe.tree_model.mimeData(self.gframe.ui.treeProtocols.selectedIndexes())
        self.gframe.table_model.dropMimeData(mimedata, 1, -1, -1, self.gframe.table_model.createIndex(0, 0))
        QTest.qWait(10)

        self.assertEqual(self.gframe.table_model.row_count, 1)
        self.assertEqual(len(self.gframe.table_model.protocol.protocol_labels), 3)