X-Git-Url: https://sigrok.org/gitweb/?p=libsigrokdecode.git;a=blobdiff_plain;f=decoders%2Fdcf77%2Fdcf77.py;h=c4132e956689b24c98ff77cac5152f3732ff19ed;hp=3a8134ff289b5f2d8ef5a54bec2840e005257125;hb=2fcd7c22852436c3226de9007e88cb305cce1b00;hpb=a465436e627578f69c403de75a89522dfd883217 diff --git a/decoders/dcf77/dcf77.py b/decoders/dcf77/dcf77.py index 3a8134f..c4132e9 100644 --- a/decoders/dcf77/dcf77.py +++ b/decoders/dcf77/dcf77.py @@ -23,9 +23,6 @@ import sigrokdecode as srd import calendar -# Annotation feed formats -ANN_TEXT = 0 - # Return the specified BCD number (max. 8 bits) as integer. def bcd2int(b): return (b & 0x0f) + ((b >> 4) * 10) @@ -43,17 +40,19 @@ class Decoder(srd.Decoder): {'id': 'data', 'name': 'DATA', 'desc': 'DATA line'}, ] optional_probes = [ - {'id': 'pon', 'name': 'PON', 'desc': 'TODO'}, + {'id': 'pon', 'name': 'PON', 'desc': 'Power on'}, ] options = {} annotations = [ - # ANN_TEXT ['Text', 'Human-readable text'], + ['Warnings', 'Human-readable warnings'], ] def __init__(self, **kwargs): self.state = 'WAIT FOR RISING EDGE' + self.oldpins = None self.oldval = None + self.oldpon = None self.samplenum = 0 self.bit_start = 0 self.bit_start_old = 0 @@ -199,7 +198,32 @@ class Decoder(srd.Decoder): 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, pins) in data: + + # Ignore identical samples early on (for performance reasons). + if self.oldpins == pins: + continue + self.oldpins, (val, pon) = pins, pins + + # 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. @@ -225,13 +249,13 @@ class Decoder(srd.Decoder): self.bitcount = 0 self.bit_start_old = self.bit_start self.dcf77_bitnumber_is_known = 1 - # Don't switch to GET_BIT state this time. + # Don't switch to 'GET BIT' state this time. continue self.bit_start_old = self.bit_start - self.state = GET_BIT + self.state = 'GET BIT' - elif self.state == GET_BIT: + elif self.state == 'GET BIT': # Wait until the next falling edge occurs. if not (self.oldval == 1 and val == 0): self.oldval = val @@ -250,7 +274,7 @@ class Decoder(srd.Decoder): else: bit = -1 # TODO: Error? - # TODO: There's no bit 59, make sure none is decoded. + # There's no bit 59, make sure none is decoded. if bit in (0, 1) and self.bitcount in range(0, 58 + 1): self.handle_dcf77_bit(bit) self.bitcount += 1