]> sigrok.org Git - libsigrokdecode.git/blobdiff - decoders/onewire_link/pd.py
uart/i2cfilter: Don't check multiple-choice options.
[libsigrokdecode.git] / decoders / onewire_link / pd.py
index aa1cb2e16a13744c2ddc86953ce2ee8655a7e05b..c8d6cd75406d7dbc3c045113e226dd703bc7c10c 100644 (file)
 
 import sigrokdecode as srd
 
+class SamplerateError(Exception):
+    pass
+
 class Decoder(srd.Decoder):
-    api_version = 1
+    api_version = 2
     id = 'onewire_link'
     name = '1-Wire link layer'
     longname = '1-Wire serial communication bus (link layer)'
@@ -185,8 +188,8 @@ class Decoder(srd.Decoder):
                  % (time_min*1000000, time_max*1000000)]])
 
     def decode(self, ss, es, data):
-        if self.samplerate is None:
-            raise Exception("Cannot decode without samplerate.")
+        if not self.samplerate:
+            raise SamplerateError('Cannot decode without samplerate.')
         for (self.samplenum, (owr, pwr)) in data:
             # State machine.
             if self.state == 'WAIT FOR FALLING EDGE':
@@ -251,10 +254,10 @@ class Decoder(srd.Decoder):
                     # Save the sample number for the rising edge.
                     self.rise = self.samplenum
                     self.putfr([2, ['Reset', 'Rst', 'R']])
-                    self.state = "WAIT FOR PRESENCE DETECT"
+                    self.state = 'WAIT FOR PRESENCE DETECT'
                 # Otherwise this is assumed to be a data bit.
                 else:
-                    self.state = "WAIT FOR FALLING EDGE"
+                    self.state = 'WAIT FOR FALLING EDGE'
             elif self.state == 'WAIT FOR PRESENCE DETECT':
                 # Sample presence status.
                 t = self.samplenum - self.rise
@@ -278,5 +281,3 @@ class Decoder(srd.Decoder):
 
                 # Wait for next slot.
                 self.state = 'WAIT FOR FALLING EDGE'
-            else:
-                raise Exception('Invalid state: %s' % self.state)