From f372d597739a30e0106aebc8225c1edebf6d93e3 Mon Sep 17 00:00:00 2001 From: Bert Vermeulen Date: Wed, 30 Oct 2013 22:25:45 +0100 Subject: Receive samplerate via metadata(), not start() --- decoders/can/pd.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'decoders/can') diff --git a/decoders/can/pd.py b/decoders/can/pd.py index 61b0a74..91ccf42 100644 --- a/decoders/can/pd.py +++ b/decoders/can/pd.py @@ -60,15 +60,18 @@ class Decoder(srd.Decoder): ] def __init__(self, **kwargs): + self.samplerate = None self.reset_variables() - def start(self, metadata): + def start(self): # self.out_proto = self.add(srd.OUTPUT_PROTO, 'can') self.out_ann = self.add(srd.OUTPUT_ANN, 'can') - self.samplerate = metadata['samplerate'] - self.bit_width = float(self.samplerate) / float(self.options['bitrate']) - self.bitpos = (self.bit_width / 100.0) * self.options['sample_point'] + 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.bitpos = (self.bit_width / 100.0) * self.options['sample_point'] def report(self): pass @@ -362,6 +365,8 @@ class Decoder(srd.Decoder): self.curbit += 1 def decode(self, ss, es, data): + if self.samplerate is None: + raise Exception("Cannot decode without samplerate.") for (self.samplenum, pins) in data: (can_rx,) = pins -- cgit v1.2.3-70-g09d2