]> sigrok.org Git - libsigrokdecode.git/blobdiff - decoders/dcf77/dcf77.py
srd: PDs: Use strings for states, too.
[libsigrokdecode.git] / decoders / dcf77 / dcf77.py
index b7e029dab8ff3c270a327d1a59d5550179de84b8..eabceeeeecca4c8cc2cc45f3a50add51873719a7 100644 (file)
 ## Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
 ##
 
-#
 # DCF77 protocol decoder
-#
-# More information:
-# http://en.wikipedia.org/wiki/DCF77
-#
-
-#
-# Protocol output format:
-# TODO
-#
 
 import sigrokdecode as srd
 import calendar
 
-# States
-WAIT_FOR_RISING_EDGE = 0
-GET_BIT = 1
-
 # Annotation feed formats
 ANN_ASCII = 0
 
@@ -57,6 +43,9 @@ class Decoder(srd.Decoder):
     probes = [
         {'id': 'data', 'name': 'DATA', 'desc': 'DATA line'},
     ]
+    optional_probes = [
+        {'id': 'pon', 'name': 'PON', 'desc': 'TODO'},
+    ]
     options = {}
     annotations = [
         # ANN_ASCII
@@ -64,7 +53,7 @@ class Decoder(srd.Decoder):
     ]
 
     def __init__(self, **kwargs):
-        self.state = WAIT_FOR_RISING_EDGE
+        self.state = 'WAIT FOR RISING EDGE'
         self.oldval = None
         self.samplenum = 0
         self.bit_start = 0
@@ -211,11 +200,11 @@ class Decoder(srd.Decoder):
             raise Exception('Invalid DCF77 bit: %d' % c)
 
     def decode(self, ss, es, data):
-        for samplenum, (pon, val) in data: # FIXME
+        for samplenum, (val) in data: # TODO: Handle optional PON.
 
             self.samplenum += 1 # FIXME. Use samplenum. Off-by-one?
 
-            if self.state == WAIT_FOR_RISING_EDGE:
+            if self.state == 'WAIT FOR RISING EDGE':
                 # Wait until the next rising edge occurs.
                 if not (self.oldval == 0 and val == 1):
                     self.oldval = val
@@ -269,10 +258,10 @@ class Decoder(srd.Decoder):
                     self.handle_dcf77_bit(bit)
                     self.bitcount += 1
 
-                self.state = WAIT_FOR_RISING_EDGE
+                self.state = 'WAIT FOR RISING EDGE'
 
             else:
-                raise Exception('Invalid state: %s' % self.state)
+                raise Exception('Invalid state: %d' % self.state)
 
             self.oldval = val