From 5166b0317835b35d810506f36e1a957e58109515 Mon Sep 17 00:00:00 2001 From: Gerhard Sittig Date: Sun, 1 Jul 2018 15:30:30 +0200 Subject: uart: rephrase data bits to data value conversion Use the already available .databits[] information which holds sample data and bit time edge positions, and the common bitpack() routine. This shall increase readability of the bits to value conversion. [ best viewed with more context, like 'git diff -U5' ] --- decoders/uart/pd.py | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) (limited to 'decoders/uart/pd.py') diff --git a/decoders/uart/pd.py b/decoders/uart/pd.py index 8993271..6c3d85c 100644 --- a/decoders/uart/pd.py +++ b/decoders/uart/pd.py @@ -18,6 +18,7 @@ ## import sigrokdecode as srd +from common.srdhelper import bitpack from math import floor, ceil ''' @@ -229,15 +230,6 @@ class Decoder(srd.Decoder): if self.startsample[rxtx] == -1: self.startsample[rxtx] = self.samplenum - # Get the next data bit in LSB-first or MSB-first fashion. - if self.options['bit_order'] == 'lsb-first': - self.datavalue[rxtx] >>= 1 - self.datavalue[rxtx] |= \ - (signal << (self.options['num_data_bits'] - 1)) - else: - self.datavalue[rxtx] <<= 1 - self.datavalue[rxtx] |= (signal << 0) - self.putg([rxtx + 12, ['%d' % signal]]) # Store individual data bits and their start/end samplenumbers. @@ -249,6 +241,11 @@ class Decoder(srd.Decoder): if self.cur_data_bit[rxtx] < self.options['num_data_bits']: return + # Convert accumulated data bits to a data value. + bits = [b[0] for b in self.databits[rxtx]] + if self.options['bit_order'] == 'msb-first': + bits.reverse() + self.datavalue[rxtx] = bitpack(bits) self.putpx(rxtx, ['DATA', rxtx, (self.datavalue[rxtx], self.databits[rxtx])]) -- cgit v1.2.3-70-g09d2