summaryrefslogtreecommitdiff
path: root/decoders/can
diff options
context:
space:
mode:
authorBert Vermeulen <bert@biot.com>2013-10-30 22:25:45 +0100
committerBert Vermeulen <bert@biot.com>2013-10-30 22:41:22 +0100
commitf372d597739a30e0106aebc8225c1edebf6d93e3 (patch)
treef4fccac01ff2de612c1ee6163cfe19491c1cd2be /decoders/can
parented41649709abc02362df526cbd725775000e8199 (diff)
downloadlibsigrokdecode-f372d597739a30e0106aebc8225c1edebf6d93e3.tar.gz
libsigrokdecode-f372d597739a30e0106aebc8225c1edebf6d93e3.zip
Receive samplerate via metadata(), not start()
Diffstat (limited to 'decoders/can')
-rw-r--r--decoders/can/pd.py13
1 files changed, 9 insertions, 4 deletions
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