diff options
author | Gerhard Sittig <gerhard.sittig@gmx.net> | 2018-07-01 15:30:30 +0200 |
---|---|---|
committer | Uwe Hermann <uwe@hermann-uwe.de> | 2018-07-15 20:16:39 +0200 |
commit | 5166b0317835b35d810506f36e1a957e58109515 (patch) | |
tree | 41f0af3912336890bc655eb15ad527cd850d8f56 /decoders/uart/pd.py | |
parent | c7172e5fa77d5cd56f206c4991762ce33ef78eba (diff) | |
download | libsigrokdecode-5166b0317835b35d810506f36e1a957e58109515.tar.gz libsigrokdecode-5166b0317835b35d810506f36e1a957e58109515.zip |
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' ]
Diffstat (limited to 'decoders/uart/pd.py')
-rw-r--r-- | decoders/uart/pd.py | 15 |
1 files changed, 6 insertions, 9 deletions
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])]) |