X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=decoders%2Fusb_packet%2Fpd.py;h=489e58eb81419b10b548de0d12865413acfc5ad4;hb=d0d63deadf5b841199c42721bc498fc5c9a86126;hp=8a8503eab535e0876fd8da5985ca16e67f433517;hpb=0e3cb15e814f20b201709688ab4eaa6eee54dc40;p=libsigrokdecode.git diff --git a/decoders/usb_packet/pd.py b/decoders/usb_packet/pd.py index 8a8503e..489e58e 100644 --- a/decoders/usb_packet/pd.py +++ b/decoders/usb_packet/pd.py @@ -15,8 +15,7 @@ ## 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 . ## import sigrokdecode as srd @@ -33,7 +32,9 @@ Packet: - 'ADDR', - 'EP', - 'CRC5', + - 'CRC5 ERROR', - 'CRC16', + - 'CRC16 ERROR', - 'EOP', - 'FRAMENUM', - 'DATABYTE', @@ -111,7 +112,7 @@ pids = { # Special '00111100': ['PRE', 'Host-issued preamble; enables downstream bus traffic to low-speed devices'], - '00111100': ['ERR', 'Split transaction error handshake'], + #'00111100': ['ERR', 'Split transaction error handshake'], '00011110': ['SPLIT', 'HS split transaction token'], '00101101': ['PING', 'HS flow control probe for a bulk/control EP'], '00001111': ['Reserved', 'Reserved PID'], @@ -145,7 +146,7 @@ def bitstr_to_num(bitstr): def reverse_number(num, count): out = list(count * '0') for i in range(0, count): - if (num >> i & 1): + if num >> i & 1: out[i] = '1'; return int(''.join(out), 2) @@ -154,7 +155,7 @@ def calc_crc5(bitstr): crc5 = 0x1f for bit in bitstr: crc5 <<= 1 - if (int(bit) != (crc5 >> 5)): + if int(bit) != (crc5 >> 5): crc5 ^= poly5 crc5 &= 0x1f crc5 ^= 0x1f @@ -165,14 +166,14 @@ def calc_crc16(bitstr): crc16 = 0xffff for bit in bitstr: crc16 <<= 1 - if (int(bit) != (crc16 >> 16)): + if int(bit) != (crc16 >> 16): crc16 ^= poly16 crc16 &= 0xffff crc16 ^= 0xffff return reverse_number(crc16, 16) class Decoder(srd.Decoder): - api_version = 2 + api_version = 3 id = 'usb_packet' name = 'USB packet' longname = 'Universal Serial Bus (LS/FS) packet' @@ -221,6 +222,9 @@ class Decoder(srd.Decoder): ) def __init__(self): + self.reset() + + def reset(self): self.bits = [] self.packet = [] self.packet_summary = '' @@ -279,7 +283,7 @@ class Decoder(srd.Decoder): self.packet.append(pid) self.packet_summary += pidname - if pidname in ('OUT', 'IN', 'SOF', 'SETUP', 'PRE', 'PING'): + if pidname in ('OUT', 'IN', 'SOF', 'SETUP', 'PING'): if len(packet) < 32: self.putp([28, ['Invalid packet (shorter than 32 bits)']]) return @@ -314,7 +318,7 @@ class Decoder(srd.Decoder): crc5 = bitstr_to_num(packet[27:31 + 1]) crc5_calc = calc_crc5(packet[16:27]) self.ss, self.es = self.bits[27][1], self.bits[31][2] - if (crc5 == crc5_calc): + if crc5 == crc5_calc: self.putpb(['CRC5', crc5]) self.putb([6, ['CRC5: 0x%02X' % crc5, 'CRC5', 'C']]) else: @@ -346,7 +350,7 @@ class Decoder(srd.Decoder): crc16 = bitstr_to_num(packet[-16:]) crc16_calc = calc_crc16(packet[16:-16]) self.ss, self.es = self.bits[-16][1], self.bits[-1][2] - if (crc16 == crc16_calc): + if crc16 == crc16_calc: self.putpb(['CRC16', crc16]) self.putb([9, ['CRC16: 0x%04X' % crc16, 'CRC16', 'C']]) else: @@ -355,6 +359,8 @@ class Decoder(srd.Decoder): self.packet.append(crc16) elif pidname in ('ACK', 'NAK', 'STALL', 'NYET', 'ERR'): pass # Nothing to do, these only have SYNC+PID+EOP fields. + elif pidname in ('PRE'): + pass # Nothing to do, PRE only has SYNC+PID fields. else: pass # TODO: Handle 'SPLIT' and possibly 'Reserved' packets. @@ -369,7 +375,7 @@ class Decoder(srd.Decoder): (ptype, pdata) = data # We only care about certain packet types for now. - if ptype not in ('SOP', 'BIT', 'EOP'): + if ptype not in ('SOP', 'BIT', 'EOP', 'ERR'): return # State machine. @@ -381,7 +387,7 @@ class Decoder(srd.Decoder): elif self.state == 'GET BIT': if ptype == 'BIT': self.bits.append([pdata, ss, es]) - elif ptype == 'EOP': + elif ptype == 'EOP' or ptype == 'ERR': self.es_packet = es self.handle_packet() self.packet, self.packet_summary = [], ''