diff options
author | Gerhard Sittig <gerhard.sittig@gmx.net> | 2017-12-22 18:51:00 +0100 |
---|---|---|
committer | Gerhard Sittig <gerhard.sittig@gmx.net> | 2017-12-22 18:59:11 +0100 |
commit | f30fdbb692c00d2dc2b9199384d17a49e886a7c9 (patch) | |
tree | 39ea15ba6f5f3408d440567caf9f20c59f93e135 /decoders | |
parent | 279331bd318c853e3aaac746167eb81179771750 (diff) | |
download | libsigrokdecode-f30fdbb692c00d2dc2b9199384d17a49e886a7c9.tar.gz libsigrokdecode-f30fdbb692c00d2dc2b9199384d17a49e886a7c9.zip |
usb_power_delivery: enforce check order for start-of-packet sequences
The list of a dictionary's keys need not reproduce in identical order
everywhere. Make sure to run all start-of-packet sequence checks in the
decoder implementation in a specific order on each machine, such that
annotations get emitted with identical content and in the same order for
each execution of the decoder.
This fixes the remaining part of bug #1090.
Diffstat (limited to 'decoders')
-rw-r--r-- | decoders/usb_power_delivery/pd.py | 25 |
1 files changed, 17 insertions, 8 deletions
diff --git a/decoders/usb_power_delivery/pd.py b/decoders/usb_power_delivery/pd.py index de6f394..c182498 100644 --- a/decoders/usb_power_delivery/pd.py +++ b/decoders/usb_power_delivery/pd.py @@ -101,14 +101,23 @@ EOP = 0x16 SYNC_CODES = [SYNC1, SYNC2, SYNC3] HRST_CODES = [RST1, RST1, RST1, RST2] +SOP_SEQUENCES = [ + (SYNC1, SYNC1, SYNC1, SYNC2), + (SYNC1, SYNC1, SYNC3, SYNC3), + (SYNC1, SYNC3, SYNC1, SYNC3), + (SYNC1, RST2, RST2, SYNC3), + (SYNC1, RST2, SYNC3, SYNC2), + (RST1, SYNC1, RST1, SYNC3), + (RST1, RST1, RST1, RST2), +] START_OF_PACKETS = { - (SYNC1, SYNC1, SYNC1, SYNC2): 'SOP', - (SYNC1, SYNC1, SYNC3, SYNC3): "SOP'", - (SYNC1, SYNC3, SYNC1, SYNC3): 'SOP"', - (SYNC1, RST2, RST2, SYNC3): "SOP' Debug", - (SYNC1, RST2, SYNC3, SYNC2): 'SOP" Debug', - (RST1, SYNC1, RST1, SYNC3): 'Cable Reset', - (RST1, RST1, RST1, RST2): 'Hard Reset', + SOP_SEQUENCES[0]: 'SOP', + SOP_SEQUENCES[1]: "SOP'", + SOP_SEQUENCES[2]: 'SOP"', + SOP_SEQUENCES[3]: "SOP' Debug", + SOP_SEQUENCES[4]: 'SOP" Debug', + SOP_SEQUENCES[5]: 'Cable Reset', + SOP_SEQUENCES[6]: 'Hard Reset', } SYM_NAME = [ @@ -403,7 +412,7 @@ class Decoder(srd.Decoder): def find_corrupted_sop(self, k): # Start of packet are valid even if they have only 3 correct symbols # out of 4. - for seq in START_OF_PACKETS.keys(): + for seq in SOP_SEQUENCES: if [k[i] == seq[i] for i in range(len(k))].count(True) >= 3: return START_OF_PACKETS[seq] return None |