- # Note: self.samplenum is the absolute sample number, whereas
- # self.scount only counts the number of samples since the
- # last change in the D+/D- lines.
- self.scount += 1
-
- # Ignore identical samples early on (for performance reasons).
- if self.oldpins == pins:
- continue
- self.oldpins, (dp, dm) = pins, pins
-
- if self.options['signalling'] == 'low-speed':
- sym = symbols_ls[dp, dm]
- elif self.options['signalling'] == 'full-speed':
- sym = symbols_fs[dp, dm]
-
- self.put(0, 0, self.out_ann, [0, [sym]])
- self.put(0, 0, self.out_proto, ['SYM', sym])
-
- # Wait for a symbol change (i.e., change in D+/D- lines).
- if sym == self.sym:
- continue
-
- ## # Debug code:
- ## self.syms.append(sym + ' ')
- ## if len(self.syms) == 16:
- ## self.put(0, 0, self.out_ann, [0, [''.join(self.syms)]])
- ## self.syms = []
- # continue
-
- # How many bits since the last transition?
- if self.packet != '' or self.sym != 'J':
- if self.options['signalling'] == 'low-speed':
- bitrate = 1500000 # 1.5Mb/s (+/- 1.5%)
- elif self.options['signalling'] == 'full-speed':
- bitrate = 12000000 # 12Mb/s (+/- 0.25%)
- bitcount = int((self.scount - 1) * bitrate / self.samplerate)
+ def wait_for_sop(self, sym):
+ # Wait for a Start of Packet (SOP), i.e. a J->K symbol change.
+ if sym != 'K':
+ self.oldsym = sym
+ return
+ self.consecutive_ones = 0
+ self.samplepos = self.samplenum - (self.bitwidth / 2) + 0.5
+ self.set_new_target_samplenum()
+ self.putpx(['SOP', None])
+ self.putx([4, ['SOP', 'S']])
+ self.state = 'GET BIT'
+
+ def handle_bit(self, b):
+ 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])
+ self.putb([6, ['%s' % b]])
+ if b == '1':
+ self.consecutive_ones += 1