diff options
author | Gerhard Sittig <gerhard.sittig@gmx.net> | 2020-07-18 20:05:42 +0200 |
---|---|---|
committer | Gerhard Sittig <gerhard.sittig@gmx.net> | 2020-07-18 20:39:48 +0200 |
commit | 9e208e00f7b90c7ded552e84bcc5540be39f3e48 (patch) | |
tree | d25eb17be55d06acd018d523af3c7a721bf4896d /decoders/caliper | |
parent | 95435ac233c861b51da34862894f2db7a681be3c (diff) | |
download | libsigrokdecode-9e208e00f7b90c7ded552e84bcc5540be39f3e48.tar.gz libsigrokdecode-9e208e00f7b90c7ded552e84bcc5540be39f3e48.zip |
caliper: use common code for packet timeout
The previous implementation unconditionally waited for up to 1ms, and
optionally handled the user configured timeout period. Use common code
instead to handle the full span of the timeout period. Which somewhat
unclutters the .decode() routine's body by eliminating an unnecessary
step in the sequence. This change also reduces indentation, and prefers
Python's .format() over the old syntax.
Diffstat (limited to 'decoders/caliper')
-rw-r--r-- | decoders/caliper/pd.py | 35 |
1 files changed, 18 insertions, 17 deletions
diff --git a/decoders/caliper/pd.py b/decoders/caliper/pd.py index 0133b22..ff7d314 100644 --- a/decoders/caliper/pd.py +++ b/decoders/caliper/pd.py @@ -81,24 +81,25 @@ class Decoder(srd.Decoder): timeout_ms = self.options['timeout_ms'] want_unit = self.options['unit'] show_all = self.options['changes'] == 'no' - snum_per_ms = self.samplerate / 1000 - timeout_snum = timeout_ms * snum_per_ms + wait_cond = [{0: 'r'}] + if timeout_ms: + snum_per_ms = self.samplerate / 1000 + timeout_snum = timeout_ms * snum_per_ms + wait_cond.append({'skip': round(timeout_snum)}) while True: - clk, data = self.wait([{0: 'r'}, {'skip': round(snum_per_ms)}]) - - # Timeout after inactivity. - if timeout_ms > 0: - if self.samplenum > self.es + timeout_snum: - if self.number_bits or self.flags_bits: - count = len(self.number_bits) + len(self.flags_bits) - self.putg(self.ss, self.samplenum, 1, [ - 'timeout with %s bits in buffer' % (count), - 'timeout', - ]) - self.reset() - - # Do nothing if there was timeout without rising clock edge. - if self.matched == (False, True): + # Sample data at the rising clock edge. Optionally timeout + # after inactivity for a user specified period. Present the + # number of unprocessed bits to the user for diagnostics. + clk, data = self.wait(wait_cond) + if timeout_ms and not self.matched[0]: + if self.number_bits or self.flags_bits: + count = len(self.number_bits) + len(self.flags_bits) + self.putg(self.ss, self.samplenum, 1, [ + 'timeout with {} bits in buffer'.format(count), + 'timeout ({} bits)'.format(count), + 'timeout', + ]) + self.reset() continue # Store position of first bit and last activity. |