diff options
author | Bert Vermeulen <bert@biot.com> | 2013-10-30 22:25:45 +0100 |
---|---|---|
committer | Bert Vermeulen <bert@biot.com> | 2013-10-30 22:41:22 +0100 |
commit | f372d597739a30e0106aebc8225c1edebf6d93e3 (patch) | |
tree | f4fccac01ff2de612c1ee6163cfe19491c1cd2be /decoders/uart/pd.py | |
parent | ed41649709abc02362df526cbd725775000e8199 (diff) | |
download | libsigrokdecode-f372d597739a30e0106aebc8225c1edebf6d93e3.tar.gz libsigrokdecode-f372d597739a30e0106aebc8225c1edebf6d93e3.zip |
Receive samplerate via metadata(), not start()
Diffstat (limited to 'decoders/uart/pd.py')
-rw-r--r-- | decoders/uart/pd.py | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/decoders/uart/pd.py b/decoders/uart/pd.py index 6ecc8cf..ab96886 100644 --- a/decoders/uart/pd.py +++ b/decoders/uart/pd.py @@ -118,6 +118,7 @@ class Decoder(srd.Decoder): self.put(s - halfbit, s + halfbit, self.out_proto, data) def __init__(self, **kwargs): + self.samplerate = None self.samplenum = 0 self.frame_start = [-1, -1] self.startbit = [-1, -1] @@ -130,14 +131,15 @@ class Decoder(srd.Decoder): self.oldbit = [1, 1] self.oldpins = [1, 1] - def start(self, metadata): - self.samplerate = metadata['samplerate'] + def start(self): self.out_proto = self.add(srd.OUTPUT_PROTO, 'uart') self.out_ann = self.add(srd.OUTPUT_ANN, 'uart') - # The width of one UART bit in number of samples. - self.bit_width = \ - float(self.samplerate) / float(self.options['baudrate']) + def metadata(self, key, value): + if key == srd.SRD_CONF_SAMPLERATE: + self.samplerate = value; + # The width of one UART bit in number of samples. + self.bit_width = float(self.samplerate) / float(self.options['baudrate']) def report(self): pass @@ -280,6 +282,8 @@ class Decoder(srd.Decoder): self.putg([4, ['Stop bit', 'Stop', 'T']]) def decode(self, ss, es, data): + if self.samplerate is None: + raise Exception("Cannot decode without samplerate.") # TODO: Either RX or TX could be omitted (optional probe). for (self.samplenum, pins) in data: |