summaryrefslogtreecommitdiff
path: root/decoders
diff options
context:
space:
mode:
authorKristoffer Sjöberg <ksjoberg@q1.se>2011-11-13 03:11:40 +0100
committerGareth McMullin <gareth@blacksphere.co.nz>2011-11-20 16:31:47 +1300
commit9d29ffadbe10efe400b1ced74636b8ee203f1e48 (patch)
tree4ebeba513d74584efe2dbb7093433ff29207f8a3 /decoders
parent71a133c83c0df02d8c016ec8c192f070ad8a37fd (diff)
downloadlibsigrokdecode-9d29ffadbe10efe400b1ced74636b8ee203f1e48.tar.gz
libsigrokdecode-9d29ffadbe10efe400b1ced74636b8ee203f1e48.zip
Pass multiple samples to the protocol decoder and adapt transitioncounter.py to work with this.
Diffstat (limited to 'decoders')
-rw-r--r--decoders/transitioncounter.py39
1 files changed, 20 insertions, 19 deletions
diff --git a/decoders/transitioncounter.py b/decoders/transitioncounter.py
index 23b443e..996cf2e 100644
--- a/decoders/transitioncounter.py
+++ b/decoders/transitioncounter.py
@@ -36,7 +36,7 @@ def decode(sampledata):
channels = 8
# FIXME: Get the data in the correct format in the first place.
- s = ord(sampledata['data'])
+ inbuf = [ord(x) for x in sampledata['data']]
if lastsample == None:
oldbit = [0] * channels
@@ -45,30 +45,31 @@ def decode(sampledata):
falling = [0] * channels
# Initial values.
- lastsample = s
+ lastsample = inbuf[0]
for i in range(channels):
oldbit[i] = (lastsample & (1 << i)) >> i
# TODO: Handle LAs with more/less than 8 channels.
- # Optimization: Skip identical bytes (no transitions).
- if lastsample != s:
- for i in range(channels):
- curbit = (s & (1 << i)) >> i
- # Optimization: Skip identical bits (no transitions).
- if oldbit[i] == curbit:
- continue
- elif (oldbit[i] == 0 and curbit == 1):
- rising[i] += 1
- elif (oldbit[i] == 1 and curbit == 0):
- falling[i] += 1
- oldbit[i] = curbit
+ for s in inbuf:
+ # Optimization: Skip identical bytes (no transitions).
+ if lastsample != s:
+ for i in range(channels):
+ curbit = (s & (1 << i)) >> i
+ # Optimization: Skip identical bits (no transitions).
+ if oldbit[i] == curbit:
+ continue
+ elif (oldbit[i] == 0 and curbit == 1):
+ rising[i] += 1
+ elif (oldbit[i] == 1 and curbit == 0):
+ falling[i] += 1
+ oldbit[i] = curbit
- # Total number of transitions is the sum of rising and falling edges.
- for i in range(channels):
- transitions[i] = rising[i] + falling[i]
+ # Total number of transitions is the sum of rising and falling edges.
+ for i in range(channels):
+ transitions[i] = rising[i] + falling[i]
- lastsample = s
- print(transitions)
+ lastsample = s
+ print(transitions)
sigrok.put(sampledata)