summaryrefslogtreecommitdiff
path: root/decoders/can
diff options
context:
space:
mode:
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