Exemplo n.º 1
0
    def test_default_crcs(self):
        crc_label = ChecksumLabel(
            "crc_label", 25, 120, 0,
            FieldType("crc", FieldType.Function.CHECKSUM))
        crc_widget_controller = ChecksumWidget(
            crc_label, Message([0] * 150, 0, MessageType("test")), 0)

        default_crc_polynomials = GenericCRC.DEFAULT_POLYNOMIALS
        special_crcs = ChecksumWidget.SPECIAL_CRCS

        self.assertEqual(
            len(default_crc_polynomials) + len(special_crcs),
            crc_widget_controller.ui.comboBoxCRCFunction.count())
        for i, default_polynomial_name in enumerate(default_crc_polynomials):
            self.assertEqual(
                default_polynomial_name,
                crc_widget_controller.ui.comboBoxCRCFunction.itemText(i))

        for i, special_crc in enumerate(special_crcs):
            self.assertEqual(
                special_crc,
                crc_widget_controller.ui.comboBoxCRCFunction.itemText(
                    i + len(default_crc_polynomials)))

        crc_widget_controller.ui.comboBoxCRCFunction.setCurrentIndex(1)
        self.assertNotEqual(
            crc_widget_controller.ui.comboBoxCRCFunction.currentText(),
            "8_standard")
        crc_widget_controller.ui.comboBoxCRCFunction.setCurrentText(
            "8_standard")
        self.assertEqual(
            crc_widget_controller.ui.comboBoxCRCFunction.currentText(),
            "8_standard")
        self.assertEqual(crc_widget_controller.ui.lineEditCRCPolynomial.text(),
                         "d5")
Exemplo n.º 2
0
    def test_configure_crc_parameters(self):
        crc_label = ChecksumLabel(
            "crc_label", 25, 120, 0,
            FieldType("crc", FieldType.Function.CHECKSUM))

        crc_widget_controller = ChecksumWidget(
            crc_label, Message([0] * 150, 0, MessageType("test")), 0)

        crc = GenericCRC(
            polynomial=list(GenericCRC.DEFAULT_POLYNOMIALS.keys())[0])
        self.assertEqual(crc_widget_controller.ui.lineEditCRCPolynomial.text(),
                         crc.polynomial_as_hex_str)
        self.assertEqual(crc_widget_controller.ui.lineEditStartValue.text(),
                         util.bit2hex(crc.start_value))
        self.assertEqual(crc_widget_controller.ui.lineEditFinalXOR.text(),
                         util.bit2hex(crc.final_xor))

        crc_widget_controller.ui.comboBoxCRCFunction.setCurrentIndex(2)
        crc.polynomial = crc.choose_polynomial(2)
        self.assertEqual(crc_widget_controller.ui.lineEditCRCPolynomial.text(),
                         crc.polynomial_as_hex_str)

        crc_widget_controller.ui.lineEditCRCPolynomial.setText("abcde")
        crc_widget_controller.ui.lineEditCRCPolynomial.editingFinished.emit()
        self.assertEqual(crc_label.checksum.polynomial,
                         array.array("B", [1]) + util.hex2bit("abcde"))

        crc_widget_controller.ui.lineEditStartValue.setText("12345")
        crc_widget_controller.ui.lineEditStartValue.editingFinished.emit()
        self.assertEqual(util.bit2hex(crc_label.checksum.start_value), "12345")

        crc_widget_controller.ui.lineEditFinalXOR.setText("cccaa")
        crc_widget_controller.ui.lineEditFinalXOR.editingFinished.emit()
        self.assertEqual(util.bit2hex(crc_label.checksum.final_xor), "cccaa")
Exemplo n.º 3
0
    def on_table_item_link_clicked(self, row: int, column: int):
        try:
            lbl = self.simulator_message_field_model.message_type[row]  # type: SimulatorProtocolLabel
            assert lbl.is_checksum_label
            assert isinstance(self.active_item, SimulatorMessage)
        except (IndexError, AssertionError):
            return

        d = QDialog(parent=self)
        layout = QHBoxLayout()
        layout.addWidget(ChecksumWidget(lbl.label, self.active_item, self.ui.cbViewType.currentIndex()))
        d.setLayout(layout)
        d.show()
Exemplo n.º 4
0
    def configure_special_config_tabs(self):
        self.ui.tabWidgetAdvancedSettings.clear()
        for lbl in self.model.message_type:  # type: ProtocolLabel
            if lbl.field_type is not None and lbl.field_type.function in self.SPECIAL_CONFIG_TYPES:
                if isinstance(lbl, ChecksumLabel):
                    w = ChecksumWidget(lbl, self.model.message,
                                       self.model.proto_view)
                    self.ui.tabWidgetAdvancedSettings.addTab(w, lbl.name)
                else:
                    logger.error("No Special Config Dialog for field type " +
                                 lbl.field_type.caption)

        if self.ui.tabWidgetAdvancedSettings.count() > 0:
            self.ui.tabWidgetAdvancedSettings.setCurrentIndex(0)
            self.ui.tabWidgetAdvancedSettings.setFocus()

        self.ui.groupBoxAdvancedSettings.setVisible(
            self.ui.tabWidgetAdvancedSettings.count() > 0)
Exemplo n.º 5
0
    def test_enocean_checksum(self):
        checksum_label = ChecksumLabel(
            "checksum_label", 50, 100, 0,
            FieldType("crc", FieldType.Function.CHECKSUM))
        crc_widget_controller = ChecksumWidget(
            checksum_label, Message([0] * 100, 0, MessageType("test")), 0)

        crc_widget_controller.ui.comboBoxCategory.setCurrentIndex(1)
        self.assertEqual(
            crc_widget_controller.ui.stackedWidget.currentWidget(),
            crc_widget_controller.ui.page_wsp)

        self.assertTrue(
            crc_widget_controller.ui.radioButtonWSPAuto.isChecked())

        crc_widget_controller.ui.radioButtonWSPChecksum8.click()

        self.assertEqual(checksum_label.checksum.mode,
                         WSPChecksum.ChecksumMode.checksum8)
Exemplo n.º 6
0
    def test_configure_crc_ranges(self):
        checksum_label = ChecksumLabel(
            "checksum_label", 50, 100, 0,
            FieldType("crc", FieldType.Function.CHECKSUM))

        crc_widget_controller = ChecksumWidget(
            checksum_label, Message([0] * 100, 0, MessageType("test")), 0)
        model = crc_widget_controller.data_range_table_model
        self.assertEqual(model.data(model.index(0, 0)), 1)
        self.assertEqual(model.data(model.index(0, 1)), 50)
        self.assertEqual(model.rowCount(), 1)

        crc_widget_controller.ui.btnAddRange.click()
        self.assertEqual(model.rowCount(), 2)
        crc_widget_controller.ui.btnAddRange.click()
        self.assertEqual(model.rowCount(), 3)

        crc_widget_controller.ui.btnRemoveRange.click()
        self.assertEqual(model.rowCount(), 2)
        crc_widget_controller.ui.btnRemoveRange.click()
        self.assertEqual(model.rowCount(), 1)
        crc_widget_controller.ui.btnRemoveRange.click()
        self.assertEqual(model.rowCount(), 1)