]> sigrok.org Git - libsigrokdecode.git/commitdiff
Various small decoder script fixes.
authorUwe Hermann <redacted>
Fri, 23 Apr 2010 23:33:52 +0000 (01:33 +0200)
committerUwe Hermann <redacted>
Fri, 23 Apr 2010 23:33:52 +0000 (01:33 +0200)
scripts/i2c.py
scripts/transitioncounter.py

index 602b01099401380fecb1838b7901cfc84a792cbc..5a41a58018841abd2eb0f5a91c300c58f2118a76 100644 (file)
 # TODO: Implement support for inverting SDA/SCL levels (0->1 and 1->0).
 # TODO: Implement support for detecting various bus errors.
 
 # TODO: Implement support for inverting SDA/SCL levels (0->1 and 1->0).
 # TODO: Implement support for detecting various bus errors.
 
-# TODO: Return two buffers, one with structured data for the GUI to parse
-#       and display, and one with human-readable ASCII output.
-
 def decode(inbuf):
        """I2C protocol decoder"""
 
 def decode(inbuf):
        """I2C protocol decoder"""
 
+       # FIXME: Get the data in the correct format in the first place.
+       inbuf = [ord(x) for x in inbuf]
+
        # FIXME: This should be passed in as metadata, not hardcoded here.
        signals = (2, 5)
        channels = 8
        # FIXME: This should be passed in as metadata, not hardcoded here.
        signals = (2, 5)
        channels = 8
@@ -84,16 +84,13 @@ def decode(inbuf):
        scl_bit, sda_bit = signals
 
        # Get SCL/SDA bit values (0/1 for low/high) of the first sample.
        scl_bit, sda_bit = signals
 
        # Get SCL/SDA bit values (0/1 for low/high) of the first sample.
-       s = ord(inbuf[0])
+       s = inbuf[0]
        oldscl = (s & (1 << scl_bit)) >> scl_bit
        oldsda = (s & (1 << sda_bit)) >> sda_bit
 
        # Loop over all samples.
        # TODO: Handle LAs with more/less than 8 channels.
        for samplenum, s in enumerate(inbuf[1:]): # We skip the first byte...
        oldscl = (s & (1 << scl_bit)) >> scl_bit
        oldsda = (s & (1 << sda_bit)) >> sda_bit
 
        # Loop over all samples.
        # TODO: Handle LAs with more/less than 8 channels.
        for samplenum, s in enumerate(inbuf[1:]): # We skip the first byte...
-               s = ord(s) # FIXME
-
                # Get SCL/SDA bit values (0/1 for low/high).
                scl = (s & (1 << scl_bit)) >> scl_bit
                sda = (s & (1 << sda_bit)) >> sda_bit
                # Get SCL/SDA bit values (0/1 for low/high).
                scl = (s & (1 << scl_bit)) >> scl_bit
                sda = (s & (1 << sda_bit)) >> sda_bit
@@ -148,19 +145,17 @@ def decode(inbuf):
 
        return o
 
 
        return o
 
-# This is just a draft.
 def register():
        return {
                'id': 'i2c',
                'name': 'I2C',
                'desc': 'Inter-Integrated Circuit (I2C) bus',
 def register():
        return {
                'id': 'i2c',
                'name': 'I2C',
                'desc': 'Inter-Integrated Circuit (I2C) bus',
-               'func': 'decode',
                'inputformats': ['raw'],
                'signalnames':  {
                                'SCL': 'Serial clock line',
                                'SDA': 'Serial data line',
                                },
                'inputformats': ['raw'],
                'signalnames':  {
                                'SCL': 'Serial clock line',
                                'SDA': 'Serial data line',
                                },
-               'outputformats': ['i2c', 'ascii'],
+               'outputformats': ['i2c'],
        }
 
 # Use psyco (if available) as it results in huge performance improvements.
        }
 
 # Use psyco (if available) as it results in huge performance improvements.
index 4064d2f5debc71da5dd732d3afd6f20d418a09c6..a6d331e85fc1af676d87edbebdce96c28d343a0a 100644 (file)
@@ -35,10 +35,7 @@ def decode(inbuf):
        rising = [0] * channels
        falling = [0] * channels
 
        rising = [0] * channels
        falling = [0] * channels
 
-       # print len(inbuf)
-       # print type(inbuf)
-
-       # Presets...
+       # Initial values.
        oldbyte = inbuf[0]
        for i in range(channels):
                oldbit[i] = (oldbyte & (1 << i)) >> i
        oldbyte = inbuf[0]
        for i in range(channels):
                oldbit[i] = (oldbyte & (1 << i)) >> i
@@ -59,6 +56,7 @@ def decode(inbuf):
                        elif (oldbit[i] == 1 and curbit == 0):
                                falling[i] += 1
                        oldbit[i] = curbit
                        elif (oldbit[i] == 1 and curbit == 0):
                                falling[i] += 1
                        oldbit[i] = curbit
+               oldbyte = s
 
        # Total number of transitions is the sum of rising and falling edges.
        for i in range(channels):
 
        # Total number of transitions is the sum of rising and falling edges.
        for i in range(channels):
@@ -81,8 +79,7 @@ def register():
        return {
                'id': 'transitioncounter',
                'name': 'Transition counter',
        return {
                'id': 'transitioncounter',
                'name': 'Transition counter',
-               'desc': 'TODO',
-               'func': 'decode',
+               'desc': 'Count rising/falling edges',
                'inputformats': ['raw'],
                'signalnames': {}, # FIXME
                'outputformats': ['transitioncounts'],
                'inputformats': ['raw'],
                'signalnames': {}, # FIXME
                'outputformats': ['transitioncounts'],