]> sigrok.org Git - libsigrokdecode.git/commitdiff
caliper: refactor and unobfuscate timeout handling
authorGerhard Sittig <redacted>
Sat, 18 Jul 2020 17:02:18 +0000 (19:02 +0200)
committerGerhard Sittig <redacted>
Sat, 18 Jul 2020 18:36:15 +0000 (20:36 +0200)
Move math expressions with always identical values out of the loop, and
improve readability of the packet timeout condition in the process.

decoders/caliper/pd.py

index 6d07a8714654f8cf3395f301d1c0d28b5a887cf1..404e830ac1078ba2f37e85ab2972715b5631f429 100644 (file)
@@ -82,12 +82,14 @@ 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
         while True:
-            clk, data = self.wait([{0: 'r'}, {'skip': round(self.samplerate / 1000)}])
+            clk, data = self.wait([{0: 'r'}, {'skip': round(snum_per_ms)}])
 
             # Timeout after inactivity.
             if timeout_ms > 0:
-                if self.samplenum > self.es_cmd + (self.samplerate / (1000 / timeout_ms)):
+                if self.samplenum > self.es_cmd + timeout_snum:
                     if self.bits > 0:
                         self.putg(self.ss_cmd, self.samplenum, 1, [
                             'timeout with %s bits in buffer' % (self.bits),