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/i2cdemux/Makefile.am | 2 +- decoders/i2cdemux/__init__.py | 2 +- decoders/i2cdemux/i2cdemux.py | 87 ------------------------------------------- decoders/i2cdemux/pd.py | 87 +++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 89 insertions(+), 89 deletions(-) delete mode 100644 decoders/i2cdemux/i2cdemux.py create mode 100644 decoders/i2cdemux/pd.py (limited to 'decoders/i2cdemux') diff --git a/decoders/i2cdemux/Makefile.am b/decoders/i2cdemux/Makefile.am index d305394..bc45d02 100644 --- a/decoders/i2cdemux/Makefile.am +++ b/decoders/i2cdemux/Makefile.am @@ -20,7 +20,7 @@ pkgdatadir = $(DECODERS_DIR)/i2cdemux -dist_pkgdata_DATA = __init__.py i2cdemux.py +dist_pkgdata_DATA = __init__.py pd.py CLEANFILES = *.pyc diff --git a/decoders/i2cdemux/__init__.py b/decoders/i2cdemux/__init__.py index 445a88e..1e5afbd 100644 --- a/decoders/i2cdemux/__init__.py +++ b/decoders/i2cdemux/__init__.py @@ -25,5 +25,5 @@ Takes an I2C stream as input and outputs multiple I2C streams, each stream containing only I2C packets for one specific I2C slave. ''' -from .i2cdemux import * +from .pd import * diff --git a/decoders/i2cdemux/i2cdemux.py b/decoders/i2cdemux/i2cdemux.py deleted file mode 100644 index bb47f23..0000000 --- a/decoders/i2cdemux/i2cdemux.py +++ /dev/null @@ -1,87 +0,0 @@ -## -## This file is part of the sigrok project. -## -## 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 2 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, write to the Free Software -## Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -## - -# Generic I2C demultiplexing protocol decoder - -import sigrokdecode as srd - -class Decoder(srd.Decoder): - api_version = 1 - id = 'i2cdemux' - name = 'I2C demux' - longname = 'I2C demultiplexer' - desc = 'Demux I2C 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 - 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 - - # 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. - # 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. - self.packets.append([ss, es, data]) - - if cmd in ('ADDRESS READ', 'ADDRESS WRITE'): - if databyte in self.slaves: - self.stream = self.slaves.index(databyte) - return - - # 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.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. - for p in self.packets: - self.put(p[0], p[1], self.out_proto[self.stream], p[2]) - - self.packets = [] - self.stream = -1 - else: - pass # Do nothing, only add the I2C packet to our cache. - diff --git a/decoders/i2cdemux/pd.py b/decoders/i2cdemux/pd.py new file mode 100644 index 0000000..bb47f23 --- /dev/null +++ b/decoders/i2cdemux/pd.py @@ -0,0 +1,87 @@ +## +## This file is part of the sigrok project. +## +## 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 2 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, write to the Free Software +## Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +## + +# Generic I2C demultiplexing protocol decoder + +import sigrokdecode as srd + +class Decoder(srd.Decoder): + api_version = 1 + id = 'i2cdemux' + name = 'I2C demux' + longname = 'I2C demultiplexer' + desc = 'Demux I2C 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 + 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 + + # 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. + # 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. + self.packets.append([ss, es, data]) + + if cmd in ('ADDRESS READ', 'ADDRESS WRITE'): + if databyte in self.slaves: + self.stream = self.slaves.index(databyte) + return + + # 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.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. + for p in self.packets: + self.put(p[0], p[1], self.out_proto[self.stream], p[2]) + + self.packets = [] + self.stream = -1 + else: + pass # Do nothing, only add the I2C packet to our cache. + -- cgit v1.2.3-70-g09d2