diff options
author | Gerhard Sittig <gerhard.sittig@gmx.net> | 2018-04-22 10:07:07 +0200 |
---|---|---|
committer | Uwe Hermann <uwe@hermann-uwe.de> | 2018-04-24 21:28:59 +0200 |
commit | 40935087ca8a2c63fb224228c3f7dcbe74d48d20 (patch) | |
tree | c62845e45b24a889ab58b3cebdb19f7b101af5b2 /decoders | |
parent | aad263bb83593a66d4a834b30acf8e8a2f1b5c4c (diff) | |
download | libsigrokdecode-40935087ca8a2c63fb224228c3f7dcbe74d48d20.tar.gz libsigrokdecode-40935087ca8a2c63fb224228c3f7dcbe74d48d20.zip |
dcf77: annotate invalid dow and month fields, do not abort execution
Emit error annotations for invalid day of the week or month numbers,
instead of aborting decoder execution with an exception.
Implementation detail: Neither the Python 'in' keyword nor a .get()
method are available. That's why we have to catch the IndexError
exception.
This fixes bug #1173.
Diffstat (limited to 'decoders')
-rw-r--r-- | decoders/dcf77/pd.py | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/decoders/dcf77/pd.py b/decoders/dcf77/pd.py index 4789b66..3a97d82 100644 --- a/decoders/dcf77/pd.py +++ b/decoders/dcf77/pd.py @@ -210,9 +210,13 @@ class Decoder(srd.Decoder): self.tmp |= (bit << (c - 42)) if c == 44: d = bcd2int(self.tmp) - dn = calendar.day_name[d - 1] # day_name[0] == Monday - self.putb([13, ['Day of week: %d (%s)' % (d, dn), - 'DoW: %d (%s)' % (d, dn)]]) + try: + dn = calendar.day_name[d - 1] # day_name[0] == Monday + self.putb([13, ['Day of week: %d (%s)' % (d, dn), + 'DoW: %d (%s)' % (d, dn)]]) + except IndexError: + self.putb([19, ['Day of week: %d (%s)' % (d, 'invalid'), + 'DoW: %d (%s)' % (d, 'inv')]]) elif c in range(45, 49 + 1): # Month (1-12): DCF77 bits 45-49 (BCD format). if c == 45: @@ -222,9 +226,13 @@ class Decoder(srd.Decoder): self.tmp |= (bit << (c - 45)) if c == 49: m = bcd2int(self.tmp) - mn = calendar.month_name[m] # month_name[1] == January - self.putb([14, ['Month: %d (%s)' % (m, mn), - 'Mon: %d (%s)' % (m, mn)]]) + try: + mn = calendar.month_name[m] # month_name[1] == January + self.putb([14, ['Month: %d (%s)' % (m, mn), + 'Mon: %d (%s)' % (m, mn)]]) + except IndexError: + self.putb([19, ['Month: %d (%s)' % (m, 'invalid'), + 'Mon: %d (%s)' % (m, 'inv')]]) elif c in range(50, 57 + 1): # Year (0-99): DCF77 bits 50-57 (BCD format). if c == 50: |