summaryrefslogtreecommitdiff
path: root/decoders/morse
diff options
context:
space:
mode:
authorGerhard Sittig <gerhard.sittig@gmx.net>2018-01-28 20:49:48 +0100
committerGerhard Sittig <gerhard.sittig@gmx.net>2018-01-28 20:49:48 +0100
commit15a8a05595c72d328abdea8e3b23f1b558cc46bf (patch)
treedf65ff2c6163724aa5f49275086963fa3660b6a5 /decoders/morse
parent956721de58552b05776c8613449f2907196e61e9 (diff)
downloadlibsigrokdecode-15a8a05595c72d328abdea8e3b23f1b558cc46bf.tar.gz
libsigrokdecode-15a8a05595c72d328abdea8e3b23f1b558cc46bf.zip
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.
Diffstat (limited to 'decoders/morse')
-rw-r--r--decoders/morse/pd.py11
1 files changed, 9 insertions, 2 deletions
diff --git a/decoders/morse/pd.py b/decoders/morse/pd.py
index a1e3c23..3048332 100644
--- a/decoders/morse/pd.py
+++ b/decoders/morse/pd.py
@@ -154,8 +154,6 @@ class Decoder(srd.Decoder):
# Annotate symbols, emit symbols, handle timeout via token.
timeunit = self.options['timeunit']
- if self.samplerate is None:
- self.samplerate = 1.0
self.wait({0: 'r'})
prevtime = self.samplenum # Time of an actual edge.
@@ -217,6 +215,15 @@ class Decoder(srd.Decoder):
yield None # Pass through flush of 5+ space.
def decode(self):
+
+ # Strictly speaking there is no point in running this decoder
+ # when the sample rate is unknown or zero. But the previous
+ # implementation already fell back to a rate of 1 in that case.
+ # We stick with this approach, to not introduce new constraints
+ # for existing use scenarios.
+ if not self.samplerate:
+ self.samplerate = 1.0
+
# Annotate letters, group into words.
s0 = s1 = None
word = ''