summaryrefslogtreecommitdiff
path: root/decoders
diff options
context:
space:
mode:
authorUwe Hermann <uwe@hermann-uwe.de>2012-01-03 18:33:43 +0100
committerUwe Hermann <uwe@hermann-uwe.de>2012-01-03 19:33:53 +0100
commitb327337fcc92b9e6e8703ded4caa61cb8734534a (patch)
treeed20f54eb3c52eb68af6048452a49f7def39a96c /decoders
parentffe880e79ccd98de803706e0a02c0df2574e29ee (diff)
downloadlibsigrokdecode-b327337fcc92b9e6e8703ded4caa61cb8734534a.tar.gz
libsigrokdecode-b327337fcc92b9e6e8703ded4caa61cb8734534a.zip
srd: Quick hack to make the USB decoder work again.
Diffstat (limited to 'decoders')
-rw-r--r--decoders/srd_usb.py26
1 files changed, 18 insertions, 8 deletions
diff --git a/decoders/srd_usb.py b/decoders/srd_usb.py
index b0fa4e5..a223dbb 100644
--- a/decoders/srd_usb.py
+++ b/decoders/srd_usb.py
@@ -46,7 +46,7 @@ class Sample():
def __init__(self, data):
self.data = data
def probe(self, probe):
- s = ord(self.data[probe / 8]) & (1 << (probe % 8))
+ s = ord(self.data[int(probe / 8)]) & (1 << (probe % 8))
return True if s else False
def sampleiter(data, unitsize):
@@ -127,10 +127,14 @@ class Decoder(sigrok.Decoder):
def __init__(self):
self.probes = Decoder.probes.copy()
+ self.output_protocol = None
+ self.output_annotation = None
def start(self, metadata):
self.unitsize = metadata['unitsize']
self.rate = metadata['samplerate']
+ # self.output_protocol = self.output_new(2)
+ self.output_annotation = self.output_new(1)
if self.rate < 48000000:
raise Exception("Sample rate not sufficient for USB decoding")
# Initialise decoder state.
@@ -138,8 +142,10 @@ class Decoder(sigrok.Decoder):
self.scount = 0
self.packet = ''
- def decode(self, data):
- for sample in sampleiter(data['data'], self.unitsize):
+ def decode(self, timeoffset, duration, data):
+ out = []
+
+ for sample in sampleiter(data, self.unitsize):
self.scount += 1
@@ -157,18 +163,18 @@ class Decoder(sigrok.Decoder):
# How many bits since the last transition?
if self.packet or self.sym != J:
- bitcount = (self.scount - 1) * 12000000 / self.rate
+ bitcount = int((self.scount - 1) * 12000000 / self.rate)
else:
bitcount = 0
if self.sym == SE0:
if bitcount == 1:
# End-Of-Packet (EOP)
- self.put({"type":"usb", "data":self.packet,
- "display":packet_decode(self.packet)})
+ out += [{"type":"usb", "data":self.packet,
+ "display":packet_decode(self.packet)}]
else:
# Longer than EOP, assume reset.
- self.put({"type":"usb", "display":"RESET"})
+ out += [{"type":"usb", "display":"RESET"}]
self.scount = 0
self.sym = sym
self.packet = ''
@@ -180,8 +186,12 @@ class Decoder(sigrok.Decoder):
if bitcount < 6 and sym != SE0:
self.packet += '0'
elif bitcount > 6:
- self.put({"type":"usb", "display":"BIT STUFF ERROR"})
+ out += [{"type":"usb", "display":"BIT STUFF ERROR"}]
self.scount = 0
self.sym = sym
+ if out != []:
+ # self.put(self.output_protocol, 0, 0, out_proto)
+ self.put(self.output_annotation, 0, 0, out)
+