X-Git-Url: http://sigrok.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=decoders%2Fuart%2Fpd.py;h=f1c832364539fcac8d386f2a12cc41bfb5069ef0;hb=cd8eb52870200196b12d6950eead62d46864cd00;hp=89027806bf63a0da710114a5bca5225d36dd8b29;hpb=be465111b552c7c2a2262ac49758a30a8bf1b1d5;p=libsigrokdecode.git diff --git a/decoders/uart/pd.py b/decoders/uart/pd.py index 8902780..f1c8323 100644 --- a/decoders/uart/pd.py +++ b/decoders/uart/pd.py @@ -1,7 +1,7 @@ ## ## This file is part of the libsigrokdecode project. ## -## Copyright (C) 2011-2013 Uwe Hermann +## Copyright (C) 2011-2014 Uwe Hermann ## ## This program is free software; you can redistribute it and/or modify ## it under the terms of the GNU General Public License as published by @@ -18,8 +18,6 @@ ## Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA ## -# UART protocol decoder - import sigrokdecode as srd ''' @@ -97,13 +95,18 @@ class Decoder(srd.Decoder): # TODO: Options to invert the signal(s). } annotations = [ - ['RX data', 'UART RX data'], - ['TX data', 'UART TX data'], - ['Start bits', 'UART start bits'], - ['Parity bits', 'UART parity bits'], - ['Stop bits', 'UART stop bits'], - ['Warnings', 'Warnings'], + ['rx-data', 'UART RX data'], + ['tx-data', 'UART TX data'], + ['start-bits', 'UART start bits'], + ['parity-bits', 'UART parity bits'], + ['stop-bits', 'UART stop bits'], + ['warnings', 'Warnings'], ] + binary = ( + ('rx', 'RX dump'), + ('tx', 'TX dump'), + ('rxtx', 'RX/TX dump'), + ) def putx(self, rxtx, data): s, halfbit = self.startsample[rxtx], int(self.bit_width / 2) @@ -117,6 +120,10 @@ class Decoder(srd.Decoder): s, halfbit = self.samplenum, int(self.bit_width / 2) self.put(s - halfbit, s + halfbit, self.out_proto, data) + def putbin(self, rxtx, data): + s, halfbit = self.startsample[rxtx], int(self.bit_width / 2) + self.put(s - halfbit, self.samplenum + halfbit, self.out_bin, data) + def __init__(self, **kwargs): self.samplerate = None self.samplenum = 0 @@ -133,6 +140,7 @@ class Decoder(srd.Decoder): def start(self): self.out_proto = self.register(srd.OUTPUT_PYTHON) + self.out_bin = self.register(srd.OUTPUT_BINARY) self.out_ann = self.register(srd.OUTPUT_ANN) def metadata(self, key, value): @@ -141,9 +149,6 @@ class Decoder(srd.Decoder): # The width of one UART bit in number of samples. self.bit_width = float(self.samplerate) / float(self.options['baudrate']) - def report(self): - pass - # Return true if we reached the middle of the desired bit, false otherwise. def reached_bit(self, rxtx, bitnum): # bitpos is the samplenumber which is in the middle of the @@ -225,7 +230,8 @@ class Decoder(srd.Decoder): b, f = self.databyte[rxtx], self.options['format'] if f == 'ascii': - self.putx(rxtx, [rxtx, [chr(b)]]) + c = chr(b) if chr(b).isprintable() else '[%02X]' % b + self.putx(rxtx, [rxtx, [c]]) elif f == 'dec': self.putx(rxtx, [rxtx, [str(b)]]) elif f == 'hex': @@ -237,6 +243,9 @@ class Decoder(srd.Decoder): else: raise Exception('Invalid data format option: %s' % f) + self.putbin(rxtx, (rxtx, bytes([b]))) + self.putbin(rxtx, (2, bytes([b]))) + 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':