From 24c74fd30fb161837c5f8b01baf3c0fe2dfa4ed5 Mon Sep 17 00:00:00 2001 From: Uwe Hermann Date: Wed, 21 Nov 2012 22:43:02 +0100 Subject: All PDs: Name the files pd.py consistently. The Python module name is determined by the directory name (e.g. dcf77), the *.py file names in that directory don't matter and can be kept consistent. --- decoders/i2cfilter/Makefile.am | 2 +- decoders/i2cfilter/__init__.py | 2 +- decoders/i2cfilter/i2cfilter.py | 99 ----------------------------------------- decoders/i2cfilter/pd.py | 99 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 101 insertions(+), 101 deletions(-) delete mode 100644 decoders/i2cfilter/i2cfilter.py create mode 100644 decoders/i2cfilter/pd.py (limited to 'decoders/i2cfilter') diff --git a/decoders/i2cfilter/Makefile.am b/decoders/i2cfilter/Makefile.am index 5b90489..ff7abc4 100644 --- a/decoders/i2cfilter/Makefile.am +++ b/decoders/i2cfilter/Makefile.am @@ -19,7 +19,7 @@ pkgdatadir = $(DECODERS_DIR)/i2cfilter -dist_pkgdata_DATA = __init__.py i2cfilter.py +dist_pkgdata_DATA = __init__.py pd.py CLEANFILES = *.pyc diff --git a/decoders/i2cfilter/__init__.py b/decoders/i2cfilter/__init__.py index 6443f5b..9a0b256 100644 --- a/decoders/i2cfilter/__init__.py +++ b/decoders/i2cfilter/__init__.py @@ -34,5 +34,5 @@ Both of these are optional; if no options are specified the entire payload of the I2C session will be output. ''' -from .i2cfilter import * +from .pd import * diff --git a/decoders/i2cfilter/i2cfilter.py b/decoders/i2cfilter/i2cfilter.py deleted file mode 100644 index 9c9c43a..0000000 --- a/decoders/i2cfilter/i2cfilter.py +++ /dev/null @@ -1,99 +0,0 @@ -## -## This file is part of the sigrok project. -## -## Copyright (C) 2012 Bert Vermeulen -## Copyright (C) 2012 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 -## the Free Software Foundation; either version 3 of the License, or -## (at your option) any later version. -## -## This program is distributed in the hope that it will be useful, -## but WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -## GNU General Public License for more details. -## -## You should have received a copy of the GNU General Public License -## 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 - id = 'i2cfilter' - name = 'I2C filter' - longname = 'I2C filter' - desc = 'Filter out addresses/directions in an I2C 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 = [] - - def __init__(self, **kwargs): - self.state = None - self.curslave = -1 - self.curdirection = None - self.packets = [] # Local cache of I2C packets - - def start(self, metadata): - self.out_proto = self.add(srd.OUTPUT_PROTO, '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 - # 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. - # 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. - self.packets.append([ss, es, data]) - - if cmd in ('ADDRESS READ', 'ADDRESS WRITE'): - self.curslave = databyte - self.curdirection = cmd[8:].lower() - elif cmd in ('STOP', 'START REPEAT'): - # If this chunk was not for the correct slave, drop it. - if self.options['address'] == 0: - pass - elif self.curslave != self.options['address']: - self.packets = [] - return - - # If this chunk was not in the right direction, drop it. - if self.options['direction'] == 'both': - pass - elif self.options['direction'] != self.curdirection: - self.packets = [] - return - - # TODO: START->STOP chunks with both read and write (Repeat START) - # Otherwise, send out the whole chunk of I2C packets. - for p in self.packets: - self.put(p[0], p[1], self.out_proto, p[2]) - - self.packets = [] - else: - pass # Do nothing, only add the I2C packet to our cache. - diff --git a/decoders/i2cfilter/pd.py b/decoders/i2cfilter/pd.py new file mode 100644 index 0000000..9c9c43a --- /dev/null +++ b/decoders/i2cfilter/pd.py @@ -0,0 +1,99 @@ +## +## This file is part of the sigrok project. +## +## Copyright (C) 2012 Bert Vermeulen +## Copyright (C) 2012 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 +## the Free Software Foundation; either version 3 of the License, or +## (at your option) any later version. +## +## This program is distributed in the hope that it will be useful, +## but WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +## GNU General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## 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 + id = 'i2cfilter' + name = 'I2C filter' + longname = 'I2C filter' + desc = 'Filter out addresses/directions in an I2C 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 = [] + + def __init__(self, **kwargs): + self.state = None + self.curslave = -1 + self.curdirection = None + self.packets = [] # Local cache of I2C packets + + def start(self, metadata): + self.out_proto = self.add(srd.OUTPUT_PROTO, '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 + # 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. + # 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. + self.packets.append([ss, es, data]) + + if cmd in ('ADDRESS READ', 'ADDRESS WRITE'): + self.curslave = databyte + self.curdirection = cmd[8:].lower() + elif cmd in ('STOP', 'START REPEAT'): + # If this chunk was not for the correct slave, drop it. + if self.options['address'] == 0: + pass + elif self.curslave != self.options['address']: + self.packets = [] + return + + # If this chunk was not in the right direction, drop it. + if self.options['direction'] == 'both': + pass + elif self.options['direction'] != self.curdirection: + self.packets = [] + return + + # TODO: START->STOP chunks with both read and write (Repeat START) + # Otherwise, send out the whole chunk of I2C packets. + for p in self.packets: + self.put(p[0], p[1], self.out_proto, p[2]) + + self.packets = [] + else: + pass # Do nothing, only add the I2C packet to our cache. + -- cgit v1.2.3-70-g09d2