From: Gerhard Sittig Date: Tue, 14 Mar 2017 18:15:31 +0000 (+0100) Subject: uart: Remove redundant "reached bit" checks X-Git-Tag: libsigrokdecode-0.5.0~58 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=080b528200abe354412aba63ddee5d76ac9c8e14;p=libsigrokdecode.git uart: Remove redundant "reached bit" checks After the decode() method got adjusted to call wait() with custom made conditions and to check .matched[] before inspecting samples, the check whether a bit time's sample point was reached has become obsolete. --- diff --git a/decoders/uart/pd.py b/decoders/uart/pd.py index c6e47ca..6a0dff9 100644 --- a/decoders/uart/pd.py +++ b/decoders/uart/pd.py @@ -195,30 +195,13 @@ class Decoder(srd.Decoder): bitpos += bitnum * self.bit_width return bitpos - # Return true if we reached the middle of the desired bit, false otherwise. - def reached_bit(self, rxtx, bitnum): - bitpos = self.get_sample_point(rxtx, bitnum) - if self.samplenum >= bitpos: - return True - return False - def wait_for_start_bit(self, rxtx, signal): - # The caller already has detected an edge. Strictly speaking this - # check on the current signal level is redundant. But it does not - # harm either. - if signal != 0: - return - # Save the sample number where the start bit begins. self.frame_start[rxtx] = self.samplenum self.state[rxtx] = 'GET START BIT' def get_start_bit(self, rxtx, signal): - # Skip samples until we're in the middle of the start bit. - if not self.reached_bit(rxtx, 0): - return - self.startbit[rxtx] = signal # The startbit must be 0. If not, we report an error and wait @@ -239,10 +222,6 @@ class Decoder(srd.Decoder): self.putg([rxtx + 2, ['Start bit', 'Start', 'S']]) def get_data_bits(self, rxtx, signal): - # Skip samples until we're in the middle of the desired data bit. - if not self.reached_bit(rxtx, 1 + self.cur_data_bit[rxtx]): - return - # Save the sample number of the middle of the first data bit. if self.startsample[rxtx] == -1: self.startsample[rxtx] = self.samplenum @@ -330,10 +309,6 @@ class Decoder(srd.Decoder): return None def get_parity_bit(self, rxtx, signal): - # Skip samples until we're in the middle of the parity bit. - if not self.reached_bit(rxtx, 1 + self.options['num_data_bits']): - return - self.paritybit[rxtx] = signal self.state[rxtx] = 'GET STOP BITS' @@ -349,12 +324,6 @@ class Decoder(srd.Decoder): # TODO: Currently only supports 1 stop bit. def get_stop_bits(self, rxtx, signal): - # Skip samples until we're in the middle of the stop bit(s). - skip_parity = 0 if self.options['parity_type'] == 'none' else 1 - b = 1 + self.options['num_data_bits'] + skip_parity - if not self.reached_bit(rxtx, b): - return - self.stopbit1[rxtx] = signal # Stop bits must be 1. If not, we report an error.