summaryrefslogtreecommitdiff
path: root/decoders
diff options
context:
space:
mode:
authorGerhard Sittig <gerhard.sittig@gmx.net>2017-12-15 19:26:29 +0100
committerUwe Hermann <uwe@hermann-uwe.de>2018-02-13 18:44:03 +0100
commit8accc30bf5d98aa958af839511d57e0e1ddefe94 (patch)
treef282fd289d3322ddbae689f8f42a3134d024ecfc /decoders
parent0173a8baba2fb3eb87f03931c420c76697dc2f06 (diff)
downloadlibsigrokdecode-8accc30bf5d98aa958af839511d57e0e1ddefe94.tar.gz
libsigrokdecode-8accc30bf5d98aa958af839511d57e0e1ddefe94.zip
i2c: make input samplerate optional
Absence of a samplerate for the input stream should not be fatal. The protocol decodes fine, we just cannot determine a bitrate for frames. This addresses part of bug 1076.
Diffstat (limited to 'decoders')
-rw-r--r--decoders/i2c/pd.py13
1 files changed, 4 insertions, 9 deletions
diff --git a/decoders/i2c/pd.py b/decoders/i2c/pd.py
index b633397..e70c27d 100644
--- a/decoders/i2c/pd.py
+++ b/decoders/i2c/pd.py
@@ -61,9 +61,6 @@ proto = {
'DATA WRITE': [9, 'Data write', 'DW'],
}
-class SamplerateError(Exception):
- pass
-
class Decoder(srd.Decoder):
api_version = 3
id = 'i2c'
@@ -238,9 +235,10 @@ class Decoder(srd.Decoder):
def handle_stop(self, pins):
# Meta bitrate
- elapsed = 1 / float(self.samplerate) * (self.samplenum - self.pdu_start + 1)
- bitrate = int(1 / elapsed * self.pdu_bits)
- self.put(self.ss_byte, self.samplenum, self.out_bitrate, bitrate)
+ if self.samplerate:
+ elapsed = 1 / float(self.samplerate) * (self.samplenum - self.pdu_start + 1)
+ bitrate = int(1 / elapsed * self.pdu_bits)
+ self.put(self.ss_byte, self.samplenum, self.out_bitrate, bitrate)
cmd = 'STOP'
self.ss, self.es = self.samplenum, self.samplenum
@@ -252,9 +250,6 @@ class Decoder(srd.Decoder):
self.bits = []
def decode(self):
- if not self.samplerate:
- raise SamplerateError('Cannot decode without samplerate.')
-
while True:
# State machine.
if self.state == 'FIND START':