X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=decoders%2Ftransitioncounter.py;h=9a5641d682fd8e9d6436205c88c3698d6eedf7ee;hb=f6555179b242357f9c75b1f6178537de2001cd98;hp=1b105186116f69b859429b6e9c8fb06db109c06f;hpb=b41ae47fa350bc0b6c81f0411cc12b9741a7e4e0;p=libsigrokdecode.git diff --git a/decoders/transitioncounter.py b/decoders/transitioncounter.py index 1b10518..9a5641d 100644 --- a/decoders/transitioncounter.py +++ b/decoders/transitioncounter.py @@ -18,18 +18,21 @@ ## Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA ## +import sigrok + class Sample(): def __init__(self, data): self.data = data def probe(self, probe): - s = ord(self.data[probe / 8]) & (1 << (probe % 8)) + s = ord(self.data[int(probe / 8)]) & (1 << (probe % 8)) return True if s else False def sampleiter(data, unitsize): for i in range(0, len(data), unitsize): yield(Sample(data[i:i+unitsize])) -class Decoder(): +class Decoder(sigrok.Decoder): + id = 'transitioncounter' name = 'Transition counter' longname = '...' desc = 'Counts rising/falling edges in the signal.' @@ -42,12 +45,10 @@ class Decoder(): probes = {} options = {} - def __init__(self, unitsize, **kwargs): - # Metadata comes in here, we don't care for now. - # print kwargs - self.unitsize = unitsize - + def __init__(self, **kwargs): self.probes = Decoder.probes.copy() + self.output_protocol = None + self.output_annotation = None # TODO: Don't hardcode the number of channels. self.channels = 8 @@ -58,15 +59,20 @@ class Decoder(): self.rising = [0] * self.channels self.falling = [0] * self.channels + def start(self, metadata): + self.unitsize = metadata['unitsize'] + # self.output_protocol = self.output_new(2) + self.output_annotation = self.output_new(1) + def report(self): pass - def decode(self, data): + def decode(self, timeoffset, duration, data): """Counts the low->high and high->low transitions in the specified channel(s) of the signal.""" # We should accept a list of samples and iterate... - for sample in sampleiter(data["data"], self.unitsize): + for sample in sampleiter(data, self.unitsize): # TODO: Eliminate the need for ord(). s = ord(sample.data) @@ -106,14 +112,8 @@ class Decoder(): outdata = [] for i in range(self.channels): outdata += [[self.transitions[i], self.rising[i], self.falling[i]]] - sigrok.put(outdata) - -# Use psyco (if available) as it results in huge performance improvements. -try: - import psyco - psyco.bind(decode) -except ImportError: - pass -import sigrok + if outdata != []: + # self.put(self.output_protocol, 0, 0, out_proto) + self.put(self.output_annotation, 0, 0, outdata)