From 57ba804a912c0753aefcaf8eee2f19ad7f5e86e5 Mon Sep 17 00:00:00 2001 From: Gerhard Sittig Date: Fri, 22 Dec 2017 18:33:58 +0100 Subject: [PATCH] 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. --- decoders/usb_power_delivery/pd.py | 6 +++--- 1 file 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) -- 2.30.2