]> sigrok.org Git - libsigrokdecode.git/blobdiff - decoders/uart/pd.py
uart: Immediately skip reception of parity bits when not applicable
[libsigrokdecode.git] / decoders / uart / pd.py
index 093f3fca92ac04339aecfcce4d5087b58bf99847..51b0504201e56e4fe883aac06baa9925fdeb83ee 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
@@ -102,7 +101,7 @@ class Decoder(srd.Decoder):
             'values': (0.0, 0.5, 1.0, 1.5)},
         {'id': 'bit_order', 'desc': 'Bit order', 'default': 'lsb-first',
             'values': ('lsb-first', 'msb-first')},
-        {'id': 'format', 'desc': 'Data format', 'default': 'ascii',
+        {'id': 'format', 'desc': 'Data format', 'default': 'hex',
             'values': ('ascii', 'dec', 'hex', 'oct', 'bin')},
         {'id': 'invert_rx', 'desc': 'Invert RX?', 'default': 'no',
             'values': ('yes', 'no')},
@@ -179,6 +178,7 @@ class Decoder(srd.Decoder):
         self.out_python = self.register(srd.OUTPUT_PYTHON)
         self.out_binary = self.register(srd.OUTPUT_BINARY)
         self.out_ann = self.register(srd.OUTPUT_ANN)
+        self.bw = (self.options['num_data_bits'] + 7) // 8
 
     def metadata(self, key, value):
         if key == srd.SRD_CONF_SAMPLERATE:
@@ -199,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.
@@ -269,7 +263,11 @@ class Decoder(srd.Decoder):
             self.cur_data_bit[rxtx] += 1
             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])])
@@ -279,8 +277,9 @@ class Decoder(srd.Decoder):
         if formatted is not None:
             self.putx(rxtx, [rxtx, [formatted]])
 
-        self.putbin(rxtx, [rxtx, bytes([b])])
-        self.putbin(rxtx, [2, bytes([b])])
+        bdata = b.to_bytes(self.bw, byteorder='big')
+        self.putbin(rxtx, [rxtx, bdata])
+        self.putbin(rxtx, [2, bdata])
 
         self.databits[rxtx] = []
 
@@ -327,11 +326,6 @@ 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):
             return