From: Gerhard Sittig Date: Fri, 15 Dec 2017 18:26:29 +0000 (+0100) Subject: i2c: make input samplerate optional X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=8accc30bf5d98aa958af839511d57e0e1ddefe94;p=libsigrokdecode.git 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. --- 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':