From: Uwe Hermann Date: Fri, 26 Aug 2016 13:13:21 +0000 (+0200) Subject: guess_bitrate: Convert to PD API version 3. X-Git-Tag: libsigrokdecode-0.5.0~111 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=3aa79ba32865780d3fc2506e47036b200921d947;p=libsigrokdecode.git guess_bitrate: Convert to PD API version 3. --- diff --git a/decoders/guess_bitrate/pd.py b/decoders/guess_bitrate/pd.py index 92d3520..6dc9a97 100644 --- a/decoders/guess_bitrate/pd.py +++ b/decoders/guess_bitrate/pd.py @@ -1,7 +1,7 @@ ## ## This file is part of the libsigrokdecode project. ## -## Copyright (C) 2013 Uwe Hermann +## Copyright (C) 2013-2016 Uwe Hermann ## ## This program is free software; you can redistribute it and/or modify ## it under the terms of the GNU General Public License as published by @@ -24,7 +24,7 @@ class SamplerateError(Exception): pass class Decoder(srd.Decoder): - api_version = 2 + api_version = 3 id = 'guess_bitrate' name = 'Guess bitrate' longname = 'Guess bitrate/baudrate' @@ -43,7 +43,6 @@ class Decoder(srd.Decoder): self.put(self.ss_edge, self.samplenum, self.out_ann, data) def __init__(self): - self.olddata = None self.ss_edge = None self.first_transition = True self.bitwidth = None @@ -51,25 +50,19 @@ class Decoder(srd.Decoder): def start(self): self.out_ann = self.register(srd.OUTPUT_ANN) + self.initial_pins = [1] # TODO: Not generally correct. + def metadata(self, key, value): if key == srd.SRD_CONF_SAMPLERATE: self.samplerate = value - def decode(self, ss, es, data): + def decode(self): if not self.samplerate: raise SamplerateError('Cannot decode without samplerate.') - for (self.samplenum, pins) in data: - - data = pins[0] - # Wait for any transition on the data line. - if data == self.olddata: - continue - - # Initialize first self.olddata with the first sample value. - if self.olddata is None: - self.olddata = data - continue + while True: + # Wait for any transition/edge on the data line. + self.wait({0: 'e'}) # Get the smallest distance between two transitions # and use that to calculate the bitrate/baudrate. @@ -83,5 +76,3 @@ class Decoder(srd.Decoder): bitrate = int(float(self.samplerate) / float(b)) self.putx([0, ['%d' % bitrate]]) self.ss_edge = self.samplenum - - self.olddata = data