]> sigrok.org Git - libsigrokdecode.git/blobdiff - decoders/gpib/pd.py
Add decoder: signature analysis
[libsigrokdecode.git] / decoders / gpib / pd.py
index 0712966a5074433dd357fefd2ddd3599a78085a5..f3497f4c21e06e9176c186602850c37476c54af3 100644 (file)
 ## 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 <http://www.gnu.org/licenses/>.
 ##
 
 import sigrokdecode as srd
 
 class Decoder(srd.Decoder):
-    api_version = 2
+    api_version = 3
     id = 'gpib'
     name = 'GPIB'
     longname = 'General Purpose Interface Bus'
-    desc = 'IEEE-488 GPIB / HPIB protocol.'
+    desc = 'IEEE-488 General Purpose Interface Bus (GPIB / HPIB).'
     license = 'gplv2+'
     inputs = ['logic']
-    outputs = ['gpib']
+    outputs = []
+    tags = ['PC']
     channels = (
         {'id': 'dio1' , 'name': 'DIO1', 'desc': 'Data I/O bit 1'},
         {'id': 'dio2' , 'name': 'DIO2', 'desc': 'Data I/O bit 2'},
@@ -47,9 +47,6 @@ class Decoder(srd.Decoder):
         {'id': 'atn', 'name': 'ATN', 'desc': 'Attention'},
         {'id': 'ren', 'name': 'REN', 'desc': 'Remote enable'},
     )
-    options = (
-        {'id': 'sample_total', 'desc': 'Total number of samples', 'default': 0},
-    )
     annotations = (
         ('items', 'Items'),
         ('gpib', 'DAT/CMD'),
@@ -62,14 +59,15 @@ class Decoder(srd.Decoder):
     )
 
     def __init__(self):
-        self.olddav = None
+        self.reset()
+
+    def reset(self):
         self.items = []
         self.itemcount = 0
         self.saved_item = None
         self.saved_ATN = False
         self.saved_EOI = False
         self.samplenum = 0
-        self.oldpins = None
         self.ss_item = self.es_item = None
         self.first = True
 
@@ -161,29 +159,13 @@ class Decoder(srd.Decoder):
 
         self.itemcount, self.items = 0, []
 
-    def find_falling_dav_edge(self, dav, datapins):
-        # Ignore sample if the DAV pin hasn't changed.
-        if dav == self.olddav:
-            return
-        self.olddav = dav
-        # Sample on falling DAV edge.
-        if dav == 1:
-            return
-
-        # Found the correct DAV edge, now get the bits.
-        self.handle_bits(datapins)
-
-    def decode(self, ss, es, data):
-        lsn = self.options['sample_total']
-
-        for (self.samplenum, pins) in data:
-            if lsn > 0:
-                if (lsn - self.samplenum) == 1: # Show the last data word.
-                    self.handle_bits(pins)
-
-            # Ignore identical samples early on (for performance reasons).
-            if self.oldpins == pins:
-                continue
-            self.oldpins = pins
+    def decode(self):
 
-            self.find_falling_dav_edge(pins[9], pins)
+        # Inspect samples at falling edge of DAV. But make sure to also
+        # start inspection when the capture happens to start with low
+        # DAV level.
+        waitcond = [{9: 'l'}]
+        while True:
+            pins = self.wait(waitcond)
+            self.handle_bits(pins)
+            waitcond[0][9] = 'f'