X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=decoders%2Fi2cdemux%2Fpd.py;h=d28763b2f55a32c9a37b743da3cc997b2f7f6086;hb=4539e9ca58966ce3c9cad4801b16c315e86ace01;hp=bb47f230a66f0ec834a7381fb87ee4baaf3a5d81;hpb=24c74fd30fb161837c5f8b01baf3c0fe2dfa4ed5;p=libsigrokdecode.git diff --git a/decoders/i2cdemux/pd.py b/decoders/i2cdemux/pd.py index bb47f23..d28763b 100644 --- a/decoders/i2cdemux/pd.py +++ b/decoders/i2cdemux/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 Uwe Hermann ## @@ -14,51 +14,41 @@ ## 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, write to the Free Software -## Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +## along with this program; if not, see . ## -# Generic I2C demultiplexing protocol decoder - import sigrokdecode as srd class Decoder(srd.Decoder): - api_version = 1 + api_version = 2 id = 'i2cdemux' - name = 'I2C demux' - longname = 'I2C demultiplexer' - desc = 'Demux I2C packets into per-slave-address streams.' + name = 'I²C demux' + longname = 'I²C demultiplexer' + desc = 'Demux I²C packets into per-slave-address streams.' license = 'gplv2+' inputs = ['i2c'] outputs = [] # TODO: Only known at run-time. - probes = [] - optional_probes = [] - options = {} - annotations = [] - def __init__(self, **kwargs): - self.packets = [] # Local cache of I2C packets + def __init__(self): + self.packets = [] # Local cache of I²C packets self.slaves = [] # List of known slave addresses self.stream = -1 # Current output stream self.streamcount = 0 # Number of created output streams - def start(self, metadata): - self.out_proto = [] - - def report(self): - pass + def start(self): + self.out_python = [] - # 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. # We use this slave address to figure out which output stream should # get the whole chunk of packets (from START to STOP). 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'): @@ -68,20 +58,19 @@ class Decoder(srd.Decoder): # We're never seen this slave, add a new stream. self.slaves.append(databyte) - self.out_proto.append(self.add(srd.OUTPUT_PROTO, - 'i2c-%s' % hex(databyte))) + self.out_python.append(self.register(srd.OUTPUT_PYTHON, + proto_id='i2c-%s' % hex(databyte))) self.stream = self.streamcount self.streamcount += 1 elif cmd == 'STOP': if self.stream == -1: raise Exception('Invalid stream!') # FIXME? - # Send the whole chunk of I2C packets to the correct stream. + # Send the whole chunk of I²C packets to the correct stream. for p in self.packets: - self.put(p[0], p[1], self.out_proto[self.stream], p[2]) + self.put(p[0], p[1], self.out_python[self.stream], p[2]) self.packets = [] self.stream = -1 else: - pass # Do nothing, only add the I2C packet to our cache. - + pass # Do nothing, only add the I²C packet to our cache.