]> sigrok.org Git - libsigrokdecode.git/commitdiff
srd: dcf77: Initial PON handling.
authorUwe Hermann <redacted>
Fri, 8 Jun 2012 19:39:09 +0000 (21:39 +0200)
committerUwe Hermann <redacted>
Fri, 8 Jun 2012 21:56:26 +0000 (23:56 +0200)
decoders/dcf77/dcf77.py

index e84b3db0e5f05034e4527b05ee617679deeff251..4da9bc422d55472f4ea8044d61563e05e74a8b65 100644 (file)
@@ -40,16 +40,18 @@ class Decoder(srd.Decoder):
         {'id': 'data', 'name': 'DATA', 'desc': 'DATA line'},
     ]
     optional_probes = [
         {'id': 'data', 'name': 'DATA', 'desc': 'DATA line'},
     ]
     optional_probes = [
-        {'id': 'pon', 'name': 'PON', 'desc': 'TODO'},
+        {'id': 'pon', 'name': 'PON', 'desc': 'Power on'},
     ]
     options = {}
     annotations = [
         ['Text', 'Human-readable text'],
     ]
     options = {}
     annotations = [
         ['Text', 'Human-readable text'],
+        ['Warnings', 'Human-readable warnings'],
     ]
 
     def __init__(self, **kwargs):
         self.state = 'WAIT FOR RISING EDGE'
         self.oldval = None
     ]
 
     def __init__(self, **kwargs):
         self.state = 'WAIT FOR RISING EDGE'
         self.oldval = None
+        self.oldpon = None
         self.samplenum = 0
         self.bit_start = 0
         self.bit_start_old = 0
         self.samplenum = 0
         self.bit_start = 0
         self.bit_start_old = 0
@@ -195,7 +197,27 @@ class Decoder(srd.Decoder):
             raise Exception('Invalid DCF77 bit: %d' % c)
 
     def decode(self, ss, es, data):
             raise Exception('Invalid DCF77 bit: %d' % c)
 
     def decode(self, ss, es, data):
-        for (self.samplenum, (val)) in data: # TODO: Handle optional PON.
+        for (self.samplenum, (val, pon)) in data:
+
+            # Always remember the old PON state.
+            if self.oldpon != pon:
+                self.oldpon = pon
+
+            # Warn if PON goes low.
+            if self.oldpon == 1 and pon == 0:
+                self.pon_ss = self.samplenum
+                self.put(self.samplenum, self.samplenum, self.out_ann,
+                         [1, ['Warning: PON goes low, DCF77 reception '
+                         'no longer possible']])
+            elif self.oldpon == 0 and pon == 1:
+                self.put(self.samplenum, self.samplenum, self.out_ann,
+                         [0, ['PON goes high, DCF77 reception now possible']])
+                self.put(self.pon_ss, self.samplenum, self.out_ann,
+                         [1, ['Warning: PON low, DCF77 reception disabled']])
+
+            # Ignore samples where PON == 0, they can't contain DCF77 signals.
+            if pon == 0:
+                continue
 
             if self.state == 'WAIT FOR RISING EDGE':
                 # Wait until the next rising edge occurs.
 
             if self.state == 'WAIT FOR RISING EDGE':
                 # Wait until the next rising edge occurs.