summaryrefslogtreecommitdiff
path: root/decoders
diff options
context:
space:
mode:
authorUwe Hermann <uwe@hermann-uwe.de>2014-03-05 23:44:14 +0100
committerUwe Hermann <uwe@hermann-uwe.de>2014-03-05 23:44:14 +0100
commit16211e24f7a34590f02e9f8a327b1eb3647c7c62 (patch)
treeedd88ed6c99ba7087af8b6cbfe2190ef4e0b6ed6 /decoders
parent92d992d2e50a1996fa2f436f5217b5a9fb3b7e62 (diff)
downloadlibsigrokdecode-16211e24f7a34590f02e9f8a327b1eb3647c7c62.tar.gz
libsigrokdecode-16211e24f7a34590f02e9f8a327b1eb3647c7c62.zip
ir_rc5: Don't throw exception upon invalid edge distances.
Instead, reset the state machine and continue with the rest of the data.
Diffstat (limited to 'decoders')
-rw-r--r--decoders/ir_rc5/pd.py12
1 files changed, 9 insertions, 3 deletions
diff --git a/decoders/ir_rc5/pd.py b/decoders/ir_rc5/pd.py
index 25a4576..cd94eae 100644
--- a/decoders/ir_rc5/pd.py
+++ b/decoders/ir_rc5/pd.py
@@ -125,7 +125,11 @@ class Decoder(srd.Decoder):
elif distance in range(s - margin, s + margin + 1):
return 's'
else:
- raise Exception('Invalid edge distance: %d' % distance)
+ return 'e' # Error, invalid edge distance.
+
+ def reset_decoder_state(self):
+ self.edges, self.bits, self.bits_ss_es = [], [], []
+ self.state = 'IDLE'
def decode(self, ss, es, data):
if self.samplerate is None:
@@ -146,6 +150,9 @@ class Decoder(srd.Decoder):
self.old_ir = self.ir
continue
edge = self.edge_type()
+ if edge == 'e':
+ self.reset_decoder_state() # Reset state machine upon errors.
+ continue
if self.state == 'MID1':
self.state = 'START1' if edge == 's' else 'MID0'
bit = None if edge == 's' else 0
@@ -169,8 +176,7 @@ class Decoder(srd.Decoder):
if len(self.bits) == 14 + 1:
self.handle_bits()
- self.edges, self.bits, self.bits_ss_es = [], [], []
- self.state = 'IDLE'
+ self.reset_decoder_state()
self.old_ir = self.ir