summaryrefslogtreecommitdiff
path: root/decoders
diff options
context:
space:
mode:
authorGerhard Sittig <gerhard.sittig@gmx.net>2020-08-12 18:47:01 +0200
committerGerhard Sittig <gerhard.sittig@gmx.net>2020-08-12 19:43:18 +0200
commitd7c2340885909a619acfe590201f71faefae7843 (patch)
tree2ad8163b8b7d3c68edb6619c2228ccf29bd388a1 /decoders
parent2bb149e691be4e1abf664a346b0d97c3eac0ad3b (diff)
downloadlibsigrokdecode-d7c2340885909a619acfe590201f71faefae7843.tar.gz
libsigrokdecode-d7c2340885909a619acfe590201f71faefae7843.zip
sdq: only use samplerate and options values after validity check
Move the calculation which involves the samplerate as well as user provided options out of the meta packet reception and to the top of the decode() method. Especially only use the samplerate after it was tested for availability.
Diffstat (limited to 'decoders')
-rw-r--r--decoders/sdq/pd.py7
1 files changed, 4 insertions, 3 deletions
diff --git a/decoders/sdq/pd.py b/decoders/sdq/pd.py
index 1dc9c1c..d8df89f 100644
--- a/decoders/sdq/pd.py
+++ b/decoders/sdq/pd.py
@@ -75,9 +75,6 @@ class Decoder(srd.Decoder):
def metadata(self, key, value):
if key == srd.SRD_CONF_SAMPLERATE:
self.samplerate = value
- self.bit_width = float(self.samplerate) / float(self.options['bitrate'])
- self.half_bit_width = self.bit_width / 2.0
- self.break_threshold = self.bit_width * 1.2 # Break if the line is low for longer than this
def handle_bit(self, bit):
self.bits.append(bit)
@@ -98,6 +95,10 @@ class Decoder(srd.Decoder):
def decode(self):
if not self.samplerate:
raise SamplerateError('Cannot decode without samplerate.')
+ self.bit_width = float(self.samplerate) / float(self.options['bitrate'])
+ self.half_bit_width = self.bit_width / 2.0
+ # BREAK if the line is low for longer than this.
+ self.break_threshold = self.bit_width * 1.2
while True:
if self.state == 'INIT':