]> sigrok.org Git - libsigrokdecode.git/blobdiff - decoders/uart/pd.py
uart: Minor readability nit (position of start bit in calculation)
[libsigrokdecode.git] / decoders / uart / pd.py
index 0fa0e7ff442b8e307a883cbd9711b646be9372cd..b081724ac118074d4af41d449796bbf1fd693b62 100644 (file)
@@ -14,8 +14,7 @@
 ## GNU General Public License for more details.
 ##
 ## You should have received a copy of the GNU General Public License
-## along with this program; if not, write to the Free Software
-## Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
+## along with this program; if not, see <http://www.gnu.org/licenses/>.
 ##
 
 import sigrokdecode as srd
@@ -200,12 +199,6 @@ class Decoder(srd.Decoder):
             return True
         return False
 
-    def reached_bit_last(self, rxtx, bitnum):
-        bitpos = self.frame_start[rxtx] + ((bitnum + 1) * self.bit_width)
-        if self.samplenum >= bitpos:
-            return True
-        return False
-
     def wait_for_start_bit(self, rxtx, old_signal, signal):
         # The start bit is always 0 (low). As the idle UART (and the stop bit)
         # level is 1 (high), the beginning of a start bit is a falling edge.
@@ -243,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.
@@ -266,11 +259,15 @@ 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
+        # the STOP bits if parity is not applicable.
         self.state[rxtx] = 'GET PARITY BIT'
+        if self.options['parity_type'] == 'none':
+            self.state[rxtx] = 'GET STOP BITS'
 
         self.putpx(rxtx, ['DATA', rxtx,
             (self.datavalue[rxtx], self.databits[rxtx])])
@@ -329,13 +326,8 @@ class Decoder(srd.Decoder):
         return None
 
     def get_parity_bit(self, rxtx, signal):
-        # If no parity is used/configured, skip to the next state immediately.
-        if self.options['parity_type'] == 'none':
-            self.state[rxtx] = 'GET STOP BITS'
-            return
-
         # 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
@@ -355,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