From a89a39504dfebb6cfdc7f733f6f951289024e37d Mon Sep 17 00:00:00 2001 From: Johannes Pohl Date: Mon, 8 Jan 2018 14:03:45 +0100 Subject: [PATCH] add bcd display type --- src/urh/models/LabelValueTableModel.py | 7 ++++++- src/urh/signalprocessing/ProtocoLabel.py | 3 ++- tests/test_analysis_tab_GUI.py | 3 +++ 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/urh/models/LabelValueTableModel.py b/src/urh/models/LabelValueTableModel.py index c79e29cd2f..03fcb5351e 100644 --- a/src/urh/models/LabelValueTableModel.py +++ b/src/urh/models/LabelValueTableModel.py @@ -97,11 +97,16 @@ def data(self, index: QModelIndex, role=Qt.DisplayRole): except IndexError: return None - if lbl.display_format_index == 3: # decimal + if lbl.display_format_index in (3, 4): # decimal or bcd try: data = str(int(data, 2)) except ValueError: return None + if lbl.display_format_index == 4: + # bcd + code = ["0000", "0001", "0010", "0011", "0100", + "0101", "0110", "0111", "1000", "1001"] + data = "".join(code[int(digit)] for digit in data) if calculated_crc is not None: data += " (should be {0})".format( diff --git a/src/urh/signalprocessing/ProtocoLabel.py b/src/urh/signalprocessing/ProtocoLabel.py index cd5206ab4e..e0afd56b69 100644 --- a/src/urh/signalprocessing/ProtocoLabel.py +++ b/src/urh/signalprocessing/ProtocoLabel.py @@ -14,7 +14,8 @@ class ProtocolLabel(object): start and end always refer to bit view! """ - DISPLAY_FORMATS = ["Bit", "Hex", "ASCII", "Decimal"] + DISPLAY_FORMATS = ["Bit", "Hex", "ASCII", + "Decimal", "Binary Coded Decimal (BCD)"] SEARCH_TYPES = ["Number", "Bits", "Hex", "ASCII"] __slots__ = ("__name", "start", "end", "apply_decoding", "color_index", "show", "fuzz_me", "fuzz_values", diff --git a/tests/test_analysis_tab_GUI.py b/tests/test_analysis_tab_GUI.py index b7655195fe..a5611c8cdf 100644 --- a/tests/test_analysis_tab_GUI.py +++ b/tests/test_analysis_tab_GUI.py @@ -275,4 +275,7 @@ def test_label_value_table(self): self.assertEqual(model.data(model.index(0, 1)), "Decimal") self.assertEqual(model.data(model.index(0, 2)), "2151") + model.setData(model.index(0, 1), 4, role=Qt.EditRole) + self.assertEqual(model.data(model.index(0, 1)), "Binary Coded Decimal (BCD)") + self.assertEqual(model.data(model.index(0, 2)), "0010000101010001")