if self.options['edges']:
self.turns.set(self.samplenum, self.count.get() // self.options['edges'])
- if self.samplerate is not None:
+ if self.samplerate:
period = (curtime - prevtime) / self.samplerate
freq = abs(phasedelta_raw) / period
# 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.
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 = ''
import sigrokdecode as srd
+class SamplerateError(Exception):
+ pass
+
class Decoder(srd.Decoder):
api_version = 3
id = 'pwm'
self.reset()
def reset(self):
+ self.samplerate = None
self.ss_block = self.es_block = None
def metadata(self, key, value):
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
def metadata(self, key, value):
if key == srd.SRD_CONF_SAMPLERATE:
self.samplerate = value
- self.secs_per_sample = float(1) / float(self.samplerate)
+ if self.samplerate:
+ self.secs_per_sample = float(1) / float(self.samplerate)
def start(self):
self.out_binary = self.register(srd.OUTPUT_BINARY)
import sigrokdecode as srd
+class SamplerateError(Exception):
+ pass
+
class Decoder(srd.Decoder):
api_version = 3
id = 'wiegand'
self.reset()
def reset(self):
+ self.samplerate = None
self._samples_per_bit = 10
self._d0_prev = None
def metadata(self, key, value):
'Receive decoder metadata about the data stream.'
if key == srd.SRD_CONF_SAMPLERATE:
- ms_per_sample = 1000 * (1.0 / value)
- ms_per_bit = float(self.options['bitwidth_ms'])
- self._samples_per_bit = int(max(1, int(ms_per_bit / ms_per_sample)))
+ self.samplerate = value
+ if self.samplerate:
+ ms_per_sample = 1000 * (1.0 / self.samplerate)
+ ms_per_bit = float(self.options['bitwidth_ms'])
+ self._samples_per_bit = int(max(1, int(ms_per_bit / ms_per_sample)))
def _update_state(self, state, bit=None):
'Update state and bit values when they change.'
self._bits = []
def decode(self):
+ if not self.samplerate:
+ raise SamplerateError('Cannot decode without samplerate.')
while True:
# TODO: Come up with more appropriate self.wait() conditions.
(d0, d1) = self.wait()