diff options
author | Gerhard Sittig <gerhard.sittig@gmx.net> | 2017-03-14 17:10:28 +0100 |
---|---|---|
committer | Gerhard Sittig <gerhard.sittig@gmx.net> | 2017-03-14 19:27:42 +0100 |
commit | 5e3c79fdf6fa757daaff69794fcc0bea1ab7a285 (patch) | |
tree | 0efd74219b2d98b8bf2d07ce312b2dc0274c7cfb /decoders | |
parent | 1078af01aeee50c9ad9633dd477e9de575521012 (diff) | |
download | libsigrokdecode-5e3c79fdf6fa757daaff69794fcc0bea1ab7a285.tar.gz libsigrokdecode-5e3c79fdf6fa757daaff69794fcc0bea1ab7a285.zip |
uart: Minor readability nit (position of start bit in calculation)
Rephrase the bit slot index calculation for UART frames such that it
becomes more apparent whether a start bit is involved or whether an
array index needs adjustment due to Python range semantics.
This shall improve readability, and reduce the probability of off-by-one
errors during maintenance.
Diffstat (limited to 'decoders')
-rw-r--r-- | decoders/uart/pd.py | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/decoders/uart/pd.py b/decoders/uart/pd.py index 51b0504..b081724 100644 --- a/decoders/uart/pd.py +++ b/decoders/uart/pd.py @@ -236,7 +236,7 @@ class Decoder(srd.Decoder): 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, self.cur_data_bit[rxtx] + 1): + 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. @@ -259,8 +259,8 @@ class Decoder(srd.Decoder): self.databits[rxtx].append([signal, s - halfbit, s + halfbit]) # Return here, unless we already received all data bits. - if self.cur_data_bit[rxtx] < self.options['num_data_bits'] - 1: - self.cur_data_bit[rxtx] += 1 + self.cur_data_bit[rxtx] += 1 + if self.cur_data_bit[rxtx] < self.options['num_data_bits']: return # Skip to either reception of the parity bit, or reception of @@ -327,7 +327,7 @@ class Decoder(srd.Decoder): 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, self.options['num_data_bits'] + 1): + if not self.reached_bit(rxtx, 1 + self.options['num_data_bits']): return self.paritybit[rxtx] = signal @@ -347,7 +347,7 @@ class Decoder(srd.Decoder): 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 = self.options['num_data_bits'] + 1 + skip_parity + b = 1 + self.options['num_data_bits'] + skip_parity if not self.reached_bit(rxtx, b): return |