From: Stefan BrĂ¼ns Date: Fri, 13 Nov 2015 03:11:37 +0000 (+0100) Subject: usb_signalling: detect bit stuffing errors X-Git-Tag: libsigrokdecode-0.4.0~31 X-Git-Url: http://sigrok.org/gitweb/?p=libsigrokdecode.git;a=commitdiff_plain;h=033d6221f3d0cd607bb11031a2764a293bf4bff1 usb_signalling: detect bit stuffing errors More than six consecutive 1's are an error --- diff --git a/decoders/usb_signalling/pd.py b/decoders/usb_signalling/pd.py index 4af2eff..8e9723e 100644 --- a/decoders/usb_signalling/pd.py +++ b/decoders/usb_signalling/pd.py @@ -33,12 +33,13 @@ Packet: - 'BIT', - 'STUFF BIT', None - 'EOP', None + - 'ERR', None : - 'J', 'K', 'SE0', or 'SE1' : - - 0 or 1 + - '0' or '1' - Note: Symbols like SE0, SE1, and the J that's part of EOP don't yield 'BIT'. ''' @@ -102,9 +103,10 @@ class Decoder(srd.Decoder): ('eop', 'End of packet (EOP)'), ('bit', 'Bit'), ('stuffbit', 'Stuff bit'), + ('error', 'Error'), ) annotation_rows = ( - ('bits', 'Bits', (4, 5, 6, 7)), + ('bits', 'Bits', (4, 5, 6, 7, 8)), ('symbols', 'Symbols', (0, 1, 2, 3)), ) @@ -168,6 +170,7 @@ class Decoder(srd.Decoder): if sym != 'K': self.oldsym = sym return + self.consecutive_ones = 0 self.ss_sop = self.samplenum self.samplepos = self.ss_sop - (self.bitwidth / 2) + 0.5 self.set_new_target_samplenum() @@ -176,11 +179,16 @@ class Decoder(srd.Decoder): self.state = 'GET BIT' def handle_bit(self, sym, b): - if self.consecutive_ones == 6 and b == '0': - # Stuff bit. - self.putpb(['STUFF BIT', None]) - self.putb([7, ['Stuff bit: %s' % b, 'SB: %s' % b, '%s' % b]]) - self.consecutive_ones = 0 + if self.consecutive_ones == 6: + if b == '0': + # Stuff bit. + self.putpb(['STUFF BIT', None]) + self.putb([7, ['Stuff bit: 0', 'SB: 0', '0']]) + self.consecutive_ones = 0 + else: + self.putpb(['ERR', None]) + self.putb([8, ['Bit stuff error', 'BS ERR', 'B']]) + self.state = 'IDLE' else: # Normal bit (not a stuff bit). self.putpb(['BIT', b]) @@ -202,7 +210,6 @@ class Decoder(srd.Decoder): self.putpm(['EOP', None]) self.putm([5, ['EOP', 'E']]) self.syms, self.state = [], 'IDLE' - self.consecutive_ones = 0 self.bitwidth = float(self.samplerate) / float(self.bitrate) def get_bit(self, sym):