diff options
author | Uwe Hermann <uwe@hermann-uwe.de> | 2019-11-12 22:20:45 +0100 |
---|---|---|
committer | Uwe Hermann <uwe@hermann-uwe.de> | 2019-11-12 23:03:32 +0100 |
commit | 0878d4ba87bbef61248942e856528ebfb18f38eb (patch) | |
tree | 94b4a907a674241734f1214af38aadd3aa448fb5 | |
parent | ab0522b8722c883275c2d695471b0746ab7372a0 (diff) | |
download | libsigrokdecode-0878d4ba87bbef61248942e856528ebfb18f38eb.tar.gz libsigrokdecode-0878d4ba87bbef61248942e856528ebfb18f38eb.zip |
uart: Add [rx|tx]_packet_len options.
Similar to the recently added [rx|tx]_packet_delimiter options, these
emit summary annotations ("packets") when a certain number of data values
have been decoded.
This is a convenience feature which can be useful when a user wants to
view data which doesn't have a specified delimiter value (as last data
value in the "packet"), but rather fixed-length "packets".
This is just an (intentionally very simple) helper/convenience improvement
and is NOT meant to replace "proper" stacked decoders for UART-based protocols.
-rw-r--r-- | decoders/uart/pd.py | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/decoders/uart/pd.py b/decoders/uart/pd.py index 0a0d307..1639727 100644 --- a/decoders/uart/pd.py +++ b/decoders/uart/pd.py @@ -116,6 +116,8 @@ class Decoder(srd.Decoder): 'default': -1}, {'id': 'tx_packet_delimiter', 'desc': 'TX packet delimiter (decimal)', 'default': -1}, + {'id': 'rx_packet_len', 'desc': 'RX packet length', 'default': -1}, + {'id': 'tx_packet_len', 'desc': 'TX packet length', 'default': -1}, ) annotations = ( ('rx-data', 'RX data'), @@ -261,16 +263,18 @@ class Decoder(srd.Decoder): self.state[rxtx] = 'GET DATA BITS' def handle_packet(self, rxtx): - opt = ('rx' if (rxtx == RX) else 'tx') + '_packet_delimiter' - delim = self.options[opt] - if delim == -1: + d = 'rx' if (rxtx == RX) else 'tx' + delim = self.options[d + '_packet_delimiter'] + plen = self.options[d + '_packet_len'] + if delim == -1 and plen == -1: return - # Cache data values until we see the delimiter. + # Cache data values until we see the delimiter and/or the specified + # packet length has been reached (whichever happens first). if len(self.packet_cache[rxtx]) == 0: self.ss_packet[rxtx] = self.startsample[rxtx] self.packet_cache[rxtx].append(self.datavalue[rxtx]) - if self.datavalue[rxtx] == delim: + if self.datavalue[rxtx] == delim or len(self.packet_cache[rxtx]) == plen: self.es_packet[rxtx] = self.samplenum s = '' for b in self.packet_cache[rxtx]: |