]> sigrok.org Git - libsigrokdecode.git/blobdiff - decoders/usb_signalling/pd.py
usb_packet: Major rewrite, e.g. to prepare for GUI usage.
[libsigrokdecode.git] / decoders / usb_signalling / pd.py
index 3a5e395f74a09495ad21930f7ab624a9bff0f9f3..61844f7605bc7dc04d4e53a84e9a02f85840800c 100644 (file)
 
 import sigrokdecode as srd
 
+'''
+Protocol output format:
+
+Packet:
+[<ptype>, <pdata>]
+
+<ptype>, <pdata>:
+ - 'SOP', None
+ - 'SYM', <sym>
+ - 'BIT', <bit>
+ - 'STUFF BIT', None
+ - 'EOP', None
+ - 'PACKET', <packet>
+
+<sym>:
+ - 'J', 'K', 'SE0', or 'SE1'
+
+<bit>:
+ - 0 or 1
+ - Note: Symbols like SE0, SE1, and the J that's part of EOP don't yield 'BIT'.
+
+<packet>:
+ - A string consisting of '1' and '0' characters, e.g. '11010100'.
+ - The packet contains only "real" bits, no stuff bits (and no SOF/EOP).
+'''
+
 # Low-/full-speed symbols.
 # Note: Low-speed J and K are inverted compared to the full-speed J and K!
 symbols = {
@@ -139,10 +165,12 @@ class Decoder(srd.Decoder):
     def handle_bit(self, sym, b):
         if self.consecutive_ones == 6 and b == '0':
             # Stuff bit. Don't add to the packet, reset self.consecutive_ones.
+            self.putpb(['STUFF BIT', None])
             self.putb([4, ['SB: %s/%s' % (sym, b)]])
             self.consecutive_ones = 0
         else:
             # Normal bit. Add it to the packet, update self.consecutive_ones.
+            self.putpb(['BIT', b])
             self.putb([3, ['%s/%s' % (sym, b)]])
             self.packet += b
             if b == '1':
@@ -162,8 +190,9 @@ class Decoder(srd.Decoder):
             # Got an EOP, i.e. we now have a full packet.
             self.putpm(['EOP', None])
             self.putm([2, ['EOP']])
-            self.putpb(['PACKET', self.packet])
-            self.putb([5, ['PACKET: %s' % self.packet]])
+            self.ss_block = self.ss_sop
+            self.putpm(['PACKET', self.packet])
+            self.putm([5, ['PACKET: %s' % self.packet]])
             self.bitnum, self.packet, self.syms, self.state = 0, '', [], 'IDLE'
             self.consecutive_ones = 0