From 15a8a05595c72d328abdea8e3b23f1b558cc46bf Mon Sep 17 00:00:00 2001 From: Gerhard Sittig Date: Sun, 28 Jan 2018 20:49:48 +0100 Subject: graycode, morse, pwm, usb_request, wiegand: cope with absent sample rate Improve robustness of some more protocol decoders. Few of them never checked for the availability of a sample rate in the first place, others checked for the presence of a spec but would not cope with a value of 0. Some checked the value only after processing it, which could result in runtime errors. This change is motivated by bug #1118. --- decoders/pwm/pd.py | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'decoders/pwm') diff --git a/decoders/pwm/pd.py b/decoders/pwm/pd.py index 2301523..9770445 100644 --- a/decoders/pwm/pd.py +++ b/decoders/pwm/pd.py @@ -20,6 +20,9 @@ import sigrokdecode as srd +class SamplerateError(Exception): + pass + class Decoder(srd.Decoder): api_version = 3 id = 'pwm' @@ -52,6 +55,7 @@ class Decoder(srd.Decoder): self.reset() def reset(self): + self.samplerate = None self.ss_block = self.es_block = None def metadata(self, key, value): @@ -89,6 +93,9 @@ class Decoder(srd.Decoder): self.put(self.ss_block, self.es_block, self.out_binary, data) def decode(self): + if not self.samplerate: + raise SamplerateError('Cannot decode without samplerate.') + num_cycles = 0 average = 0 -- cgit v1.2.3-70-g09d2