summaryrefslogtreecommitdiff
path: root/decoders
diff options
context:
space:
mode:
authorBert Vermeulen <bert@biot.com>2014-06-23 19:52:45 +0200
committerBert Vermeulen <bert@biot.com>2014-06-23 19:52:45 +0200
commitd2bdb1303679b97c3de5ce2d2d1f2b62c9828a3a (patch)
tree87afcf696b2a0f550367b3ff3f13259f03cfbb73 /decoders
parentd510f7b3d5d03c6fca5b6af4e184dc2f46da9a1a (diff)
downloadlibsigrokdecode-d2bdb1303679b97c3de5ce2d2d1f2b62c9828a3a.tar.gz
libsigrokdecode-d2bdb1303679b97c3de5ce2d2d1f2b62c9828a3a.zip
i2c: Generate proper exception for missing samplerate, and test for it.
Also remove some dead code.
Diffstat (limited to 'decoders')
-rw-r--r--decoders/i2c/pd.py9
-rw-r--r--decoders/i2c/test/test.conf5
2 files changed, 10 insertions, 4 deletions
diff --git a/decoders/i2c/pd.py b/decoders/i2c/pd.py
index 2d6e5c2..ced58cd 100644
--- a/decoders/i2c/pd.py
+++ b/decoders/i2c/pd.py
@@ -63,6 +63,9 @@ proto = {
'DATA WRITE': [9, 'Data write', 'DW'],
}
+class SamplerateError(Exception):
+ pass
+
class Decoder(srd.Decoder):
api_version = 2
id = 'i2c'
@@ -265,8 +268,8 @@ class Decoder(srd.Decoder):
self.bits = []
def decode(self, ss, es, data):
- if self.samplerate is None:
- raise Exception("Cannot decode without samplerate.")
+ if not self.samplerate:
+ raise SamplerateError("Cannot decode without samplerate.")
for (self.samplenum, pins) in data:
# Ignore identical samples early on (for performance reasons).
@@ -293,8 +296,6 @@ class Decoder(srd.Decoder):
elif self.state == 'FIND ACK':
if self.is_data_bit(scl, sda):
self.get_ack(scl, sda)
- else:
- raise Exception('Invalid state: %s' % self.state)
# Save current SDA/SCL values for the next round.
self.oldscl, self.oldsda = scl, sda
diff --git a/decoders/i2c/test/test.conf b/decoders/i2c/test/test.conf
index bd1068b..5c08e1d 100644
--- a/decoders/i2c/test/test.conf
+++ b/decoders/i2c/test/test.conf
@@ -20,3 +20,8 @@ test xfp
output i2c binary class address-read match xfp_address_read.binary
output i2c binary class address-write match xfp_address_write.binary
+test exceptions
+ protocol-decoder i2c
+ input misc/no-samplerate.sr
+ output i2c exception match SamplerateError
+