diff options
author | Gerhard Sittig <gerhard.sittig@gmx.net> | 2017-03-14 18:46:32 +0100 |
---|---|---|
committer | Gerhard Sittig <gerhard.sittig@gmx.net> | 2017-03-14 19:30:53 +0100 |
commit | 7d62e5b33a3404d319f42c81f3344240d430746a (patch) | |
tree | d8b359962e124979f707a9fdd56eb95ed7c08ee2 /decoders/uart | |
parent | 0de2810f223fefc9e3040adaa7f1b97616c6931d (diff) | |
download | libsigrokdecode-7d62e5b33a3404d319f42c81f3344240d430746a.tar.gz libsigrokdecode-7d62e5b33a3404d319f42c81f3344240d430746a.zip |
uart: Improve robustness of query API result processing
Since either of the UART signals (RX, TX) is optional, and in the
absence of Decoder.wait() conditions that "will never match", we cannot
construct a constant layout. Instead we need to explicitly keep track of
which item in the list of wait conditions corresponds to which signal.
Once the index in the list of wait conditions is known, inspection of
samples can depend on the Decoder.matched[] attribute. Before this
change, redundant reached_bit() checks kept us from processing samples
that should not have been inspected. Tests pass before and after this
very commit.
Diffstat (limited to 'decoders/uart')
-rw-r--r-- | decoders/uart/pd.py | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/decoders/uart/pd.py b/decoders/uart/pd.py index 2c0a7da..c6e47ca 100644 --- a/decoders/uart/pd.py +++ b/decoders/uart/pd.py @@ -423,15 +423,18 @@ class Decoder(srd.Decoder): opt = self.options inv = [opt['invert_rx'] == 'yes', opt['invert_tx'] == 'yes'] + cond_idx = [None] * len(has_pin) while True: conds = [] if has_pin[RX]: + cond_idx[RX] = len(conds) conds.append(self.get_wait_cond(RX, inv[RX])) if has_pin[TX]: + cond_idx[TX] = len(conds) conds.append(self.get_wait_cond(TX, inv[TX])) (rx, tx) = self.wait(conds) - if has_pin[RX]: + if cond_idx[RX] is not None and self.matched[cond_idx[RX]]: self.inspect_sample(RX, rx, inv[RX]) - if has_pin[TX]: + if cond_idx[TX] is not None and self.matched[cond_idx[TX]]: self.inspect_sample(TX, tx, inv[TX]) |