- def get_data_sample(self, owr):
- # Skip samples until we're in the middle of the start bit.
- if not self.reached_data_sample():
- return
-
- self.data_sample = owr
-
- self.cur_data_bit = 0
- self.databyte = 0
- self.startsample = -1
-
- self.state = 'GET DATA BITS'
-
- self.put(self.cycle_start, self.samplenum, self.out_proto,
- ['STARTBIT', self.startbit])
- self.put(self.cycle_start, self.samplenum, self.out_ann,
- [ANN_ASCII, ['Start bit', 'Start', 'S']])
-
- def get_data_bits(self, owr):
- # Skip samples until we're in the middle of the desired data bit.
- if not self.reached_bit(self.cur_data_bit + 1):
- return
-
- # Save the sample number where the data byte starts.
- if self.startsample == -1:
- self.startsample = self.samplenum
-
- # Get the next data bit in LSB-first or MSB-first fashion.
- if self.options['bit_order'] == 'lsb-first':
- self.databyte >>= 1
- self.databyte |= \
- (owr << (self.options['num_data_bits'] - 1))
- elif self.options['bit_order'] == 'msb-first':
- self.databyte <<= 1
- self.databyte |= (owr << 0)
- else:
- raise Exception('Invalid bit order value: %s',
- self.options['bit_order'])
-
- # Return here, unless we already received all data bits.
- # TODO? Off-by-one?
- if self.cur_data_bit < self.options['num_data_bits'] - 1:
- self.cur_data_bit += 1
- return
-
- self.state = 'GET PARITY BIT'
-
- self.put(self.startsample, self.samplenum - 1, self.out_proto,
- ['DATA', self.databyte])
-
- self.putx([ANN_ASCII, [chr(self.databyte)]])
- self.putx([ANN_DEC, [str(self.databyte)]])
- self.putx([ANN_HEX, [hex(self.databyte),
- hex(self.databyte)[2:]]])
- self.putx([ANN_OCT, [oct(self.databyte),
- oct(self.databyte)[2:]]])
- self.putx([ANN_BITS, [bin(self.databyte),
- bin(self.databyte)[2:]]])
-