X-Git-Url: https://sigrok.org/gitweb/?p=libsigrokdecode.git;a=blobdiff_plain;f=decoders%2Fi2cfilter%2Fpd.py;h=1a9f43328b6a37c8f09b39695f75b405c4d62e93;hp=9c9c43aff8d5240994cfffd42331725e6f9b8183;hb=22fc7ace72f3165c98208a8f544156e04a709639;hpb=24c74fd30fb161837c5f8b01baf3c0fe2dfa4ed5 diff --git a/decoders/i2cfilter/pd.py b/decoders/i2cfilter/pd.py index 9c9c43a..1a9f433 100644 --- a/decoders/i2cfilter/pd.py +++ b/decoders/i2cfilter/pd.py @@ -1,5 +1,5 @@ ## -## This file is part of the sigrok project. +## This file is part of the libsigrokdecode project. ## ## Copyright (C) 2012 Bert Vermeulen ## Copyright (C) 2012 Uwe Hermann @@ -18,56 +18,47 @@ ## along with this program; if not, see . ## -# Generic I2C filtering protocol decoder - # TODO: Support for filtering out multiple slave/direction pairs? import sigrokdecode as srd class Decoder(srd.Decoder): - api_version = 1 + api_version = 2 id = 'i2cfilter' - name = 'I2C filter' - longname = 'I2C filter' - desc = 'Filter out addresses/directions in an I2C stream.' + name = 'I²C filter' + longname = 'I²C filter' + desc = 'Filter out addresses/directions in an I²C stream.' license = 'gplv3+' inputs = ['i2c'] outputs = ['i2c'] - probes = [] - optional_probes = [] - options = { - 'address': ['Address to filter out of the I2C stream', 0], - 'direction': ['Direction to filter (read/write/both)', 'both'] - } - annotations = [] + options = ( + {'id': 'address', 'desc': 'Address to filter out of the I²C stream', + 'default': 0}, + {'id': 'direction', 'desc': 'Direction to filter', 'default': 'both', + 'values': ('read', 'write', 'both')} + ) def __init__(self, **kwargs): - self.state = None self.curslave = -1 self.curdirection = None - self.packets = [] # Local cache of I2C packets + self.packets = [] # Local cache of I²C packets - def start(self, metadata): - self.out_proto = self.add(srd.OUTPUT_PROTO, 'i2c') + def start(self): + self.out_python = self.register(srd.OUTPUT_PYTHON, proto_id='i2c') if self.options['address'] not in range(0, 127 + 1): raise Exception('Invalid slave (must be 0..127).') - if self.options['direction'] not in ('both', 'read', 'write'): - raise Exception('Invalid direction (valid: read/write/both).') - - def report(self): - pass - # Grab I2C packets into a local cache, until an I2C STOP condition + # Grab I²C packets into a local cache, until an I²C STOP condition # packet comes along. At some point before that STOP condition, there # will have been an ADDRESS READ or ADDRESS WRITE which contains the - # I2C address of the slave that the master wants to talk to. + # I²C address of the slave that the master wants to talk to. # If that slave shall be filtered, output the cache (all packets from # START to STOP) as proto 'i2c', otherwise drop it. def decode(self, ss, es, data): cmd, databyte = data - # Add the I2C packet to our local cache. + # Add the I²C packet to our local cache. self.packets.append([ss, es, data]) if cmd in ('ADDRESS READ', 'ADDRESS WRITE'): @@ -89,11 +80,11 @@ class Decoder(srd.Decoder): return # TODO: START->STOP chunks with both read and write (Repeat START) - # Otherwise, send out the whole chunk of I2C packets. + # Otherwise, send out the whole chunk of I²C packets. for p in self.packets: - self.put(p[0], p[1], self.out_proto, p[2]) + self.put(p[0], p[1], self.out_python, p[2]) self.packets = [] else: - pass # Do nothing, only add the I2C packet to our cache. + pass # Do nothing, only add the I²C packet to our cache.