summaryrefslogtreecommitdiff
path: root/decoders/srd_usb.py
diff options
context:
space:
mode:
authorUwe Hermann <uwe@hermann-uwe.de>2012-01-12 21:43:19 +0100
committerUwe Hermann <uwe@hermann-uwe.de>2012-01-12 22:31:06 +0100
commiteb7082c98efad727d88e3ebeadcd496fa948475b (patch)
treeabfb7e7bab9bb56fc51cd182b7e8328bb697b40a /decoders/srd_usb.py
parent56202222ed83ff030239bb23be8296574674c4f7 (diff)
downloadlibsigrokdecode-eb7082c98efad727d88e3ebeadcd496fa948475b.tar.gz
libsigrokdecode-eb7082c98efad727d88e3ebeadcd496fa948475b.zip
srd: Decoders: Cosmetics and whitespace fixes.
- Remove superfluous whitespace. - Add URLs and more info. - Consistently use ' instead of " for Python strings.
Diffstat (limited to 'decoders/srd_usb.py')
-rw-r--r--decoders/srd_usb.py45
1 files changed, 23 insertions, 22 deletions
diff --git a/decoders/srd_usb.py b/decoders/srd_usb.py
index f7afa65..387fd06 100644
--- a/decoders/srd_usb.py
+++ b/decoders/srd_usb.py
@@ -52,28 +52,30 @@ syms = {
}
def bitstr_to_num(bitstr):
- if not bitstr: return 0
+ if not bitstr:
+ return 0
l = list(bitstr)
l.reverse()
return int(''.join(l), 2)
def packet_decode(packet):
pids = {
- '10000111':'OUT', # Tokens
- '10010110':'IN',
- '10100101':'SOF',
- '10110100':'SETUP',
- '11000011':'DATA0', # Data
- '11010010':'DATA1',
- '01001011':'ACK', # Handshake
- '01011010':'NAK',
- '01111000':'STALL',
- '01101001':'NYET',
+ '10000111': 'OUT', # Tokens
+ '10010110': 'IN',
+ '10100101': 'SOF',
+ '10110100': 'SETUP',
+ '11000011': 'DATA0', # Data
+ '11010010': 'DATA1',
+ '01001011': 'ACK', # Handshake
+ '01011010': 'NAK',
+ '01111000': 'STALL',
+ '01101001': 'NYET',
}
sync = packet[:8]
pid = packet[8:16]
pid = pids.get(pid, pid)
+
# Remove CRC.
if pid in ('OUT', 'IN', 'SOF', 'SETUP'):
data = packet[16:-5]
@@ -82,20 +84,20 @@ def packet_decode(packet):
else:
dev = bitstr_to_num(data[:7])
ep = bitstr_to_num(data[7:])
- data = "DEV %d EP %d" % (dev, ep)
+ data = 'DEV %d EP %d' % (dev, ep)
elif pid in ('DATA0', 'DATA1'):
data = packet[16:-16]
- tmp = ""
+ tmp = ''
while data:
- tmp += "%02X " % bitstr_to_num(data[:8])
+ tmp += '%02X ' % bitstr_to_num(data[:8])
data = data[8:]
data = tmp
else:
data = packet[16:]
- if sync != "00000001":
- return "SYNC INVALID!"
+ if sync != '00000001':
+ return 'SYNC INVALID!'
return pid + ' ' + data
@@ -110,7 +112,6 @@ class Decoder(srd.Decoder):
license = 'gplv2+'
inputs = ['logic']
outputs = ['usb']
- # Probe names with a set of defaults
probes = [
{'id': 'dp', 'name': 'D+', 'desc': 'USB D+ signal'},
{'id': 'dm', 'name': 'D-', 'desc': 'USB D- signal'},
@@ -125,7 +126,7 @@ class Decoder(srd.Decoder):
# self.out_proto = self.add(srd.OUTPUT_PROTO, 'usb')
self.out_ann = self.add(srd.OUTPUT_ANN, 'usb')
if self.rate < 48000000:
- raise Exception("Sample rate not sufficient for USB decoding")
+ raise Exception('Sample rate not sufficient for USB decoding')
# Initialise decoder state.
self.sym = J
self.scount = 0
@@ -159,11 +160,11 @@ class Decoder(srd.Decoder):
if self.sym == SE0:
if bitcount == 1:
# End-Of-Packet (EOP)
- out += [{"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.
- out += [{"type":"usb", "display":"RESET"}]
+ out += [{'type': 'usb', 'display': 'RESET'}]
self.scount = 0
self.sym = sym
self.packet = ''
@@ -175,7 +176,7 @@ class Decoder(srd.Decoder):
if bitcount < 6 and sym != SE0:
self.packet += '0'
elif bitcount > 6:
- out += [{"type":"usb", "display":"BIT STUFF ERROR"}]
+ out += [{'type': 'usb', 'display': 'BIT STUFF ERROR'}]
self.scount = 0
self.sym = sym