summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGerhard Sittig <gerhard.sittig@gmx.net>2017-12-22 18:33:58 +0100
committerGerhard Sittig <gerhard.sittig@gmx.net>2017-12-22 18:57:14 +0100
commit57ba804a912c0753aefcaf8eee2f19ad7f5e86e5 (patch)
tree4c6e9f872d1aa9228f57bf713b7d06395e3c944b
parent10aeb8ea8b183394cebc0033f048f49f4262b57d (diff)
downloadlibsigrokdecode-57ba804a912c0753aefcaf8eee2f19ad7f5e86e5.tar.gz
libsigrokdecode-57ba804a912c0753aefcaf8eee2f19ad7f5e86e5.zip
usb_power_delivery: enforce numerical order of RDO/PDO flag annotations
Annotations of the USB power delivery decoder contain multiple text fragments that correspond to several flags in bit fields. The Python runtime did not guarantee an order of emission and made the test suite fail. Sort the order in which RDO and PDO flags related text fragments get constructed and concatenated. Print text for higher bit positions first as this might feel more intuitive to users. This fixes part of bug #1090.
-rw-r--r--decoders/usb_power_delivery/pd.py6
1 files changed, 3 insertions, 3 deletions
diff --git a/decoders/usb_power_delivery/pd.py b/decoders/usb_power_delivery/pd.py
index a2d6b4d..ef9a97c 100644
--- a/decoders/usb_power_delivery/pd.py
+++ b/decoders/usb_power_delivery/pd.py
@@ -228,7 +228,7 @@ class Decoder(srd.Decoder):
op_ma = ((rdo >> 10) & 0x3ff) * 10
max_ma = (rdo & 0x3ff) * 10
flags = ''
- for f in RDO_FLAGS.keys():
+ for f in sorted(RDO_FLAGS.keys(), reverse = True):
if rdo & f:
flags += ' ' + RDO_FLAGS[f]
return '[%d]%d/%d mA%s' % (pos, op_ma, max_ma, flags)
@@ -252,7 +252,7 @@ class Decoder(srd.Decoder):
else:
p = ''
flags = ''
- for f in PDO_FLAGS.keys():
+ for f in sorted(PDO_FLAGS.keys(), reverse = True):
if pdo & f:
flags += ' ' + PDO_FLAGS[f]
return '%s%s%s' % (PDO_TYPE[t], p, flags)
@@ -276,7 +276,7 @@ class Decoder(srd.Decoder):
else:
p = ''
flags = ''
- for f in PDO_FLAGS.keys():
+ for f in sorted(PDO_FLAGS.keys(), reverse = True):
if pdo & f:
flags += ' ' + PDO_FLAGS[f]
return '%s%s%s' % (PDO_TYPE[t], p, flags)