Skip to content

Commit

Permalink
add bcd display type
Browse files Browse the repository at this point in the history
  • Loading branch information
jopohl committed Jan 8, 2018
1 parent be1c8bc commit a89a395
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
7 changes: 6 additions & 1 deletion src/urh/models/LabelValueTableModel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
3 changes: 2 additions & 1 deletion src/urh/signalprocessing/ProtocoLabel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
3 changes: 3 additions & 0 deletions tests/test_analysis_tab_GUI.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

0 comments on commit a89a395

Please sign in to comment.