- def decode(self, ss, es, data):
- for (self.samplenum, pins) in data:
-
- # 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
-
- sym = symbols[self.options['signalling']][dp, dm]
-
- self.putx([0, [sym]])
- self.putp(['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.putx([0, [''.join(self.syms)]])
- ## self.syms = []
- # continue
-
- # How many bits since the last transition?
- if self.packet != '' or self.sym != 'J':
- bitcount = int((self.scount - 1) / self.bitwidth)
+ def putpm(self, data):
+ s, h = self.samplenum, self.halfbit
+ self.put(self.ss_block - h, s + h, self.out_python, data)
+
+ def putm(self, data):
+ s, h = self.samplenum, self.halfbit
+ self.put(self.ss_block - h, s + h, self.out_ann, data)
+
+ def putpb(self, data):
+ s, h = self.samplenum, self.halfbit
+ self.put(s - h, s + h, self.out_python, data)
+
+ def putb(self, data):
+ s, h = self.samplenum, self.halfbit
+ self.put(s - h, s + h, self.out_ann, data)
+
+ def set_new_target_samplenum(self):
+ bitpos = self.ss_sop + (self.bitwidth / 2)
+ bitpos += self.bitnum * self.bitwidth
+ self.samplenum_target = int(bitpos)
+
+ 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.ss_sop = self.samplenum
+ self.set_new_target_samplenum()
+ self.putpx(['SOP', None])
+ self.putx([4, ['SOP', 'S']])
+ 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.putb([sym_idx[sym], ['%s' % sym]])
+ self.consecutive_ones = 0
+ else:
+ # Normal bit (not a stuff bit).
+ self.putpb(['BIT', b])
+ self.putb([6, ['%s' % b]])
+ self.putb([sym_idx[sym], ['%s' % sym]])
+ if b == '1':
+ self.consecutive_ones += 1