X-Git-Url: https://sigrok.org/gitweb/?p=libsigrokdecode.git;a=blobdiff_plain;f=decoders%2Fi2cfilter%2Fpd.py;h=1dc7fd1ddfc3e73cb1a2b53f3d38fa091aec0922;hp=009ab8708071f6798066f84d6f48016d0463cd40;hb=039b0db244e2e592a581a6c9b79a934bde136569;hpb=bbe6d87fa91938bafc81c19cb1ef868d1c29bb2b diff --git a/decoders/i2cfilter/pd.py b/decoders/i2cfilter/pd.py index 009ab87..1dc7fd1 100644 --- a/decoders/i2cfilter/pd.py +++ b/decoders/i2cfilter/pd.py @@ -18,14 +18,12 @@ ## along with this program; if not, see . ## -# Generic I²C 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 = 3 id = 'i2cfilter' name = 'I²C filter' longname = 'I²C filter' @@ -33,26 +31,25 @@ class Decoder(srd.Decoder): license = 'gplv3+' inputs = ['i2c'] outputs = ['i2c'] - probes = [] - optional_probes = [] - options = { - 'address': ['Address to filter out of the I²C 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): + self.reset() - def __init__(self, **kwargs): - self.state = None + def reset(self): self.curslave = -1 self.curdirection = None self.packets = [] # Local cache of I²C packets def start(self): - self.out_proto = self.register(srd.OUTPUT_PYTHON, proto_id='i2c') + 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).') # 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 @@ -88,9 +85,8 @@ class Decoder(srd.Decoder): # TODO: START->STOP chunks with both read and write (Repeat START) # 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 I²C packet to our cache. -