]> sigrok.org Git - libsigrokdecode.git/commitdiff
srd: Add experimental uart_dump decoder.
authorUwe Hermann <redacted>
Wed, 13 Jun 2012 23:14:10 +0000 (01:14 +0200)
committerUwe Hermann <redacted>
Wed, 13 Jun 2012 23:32:32 +0000 (01:32 +0200)
This PD stacks on top of the UART protocol decoder, and ouputs the
decoded UART data in the "canonical" format, one byte after the other
without any metadata (start bits, stop bits, parity bits, errors) and
without any sample-numbers and such. This is basically what you would
see in a terminal program, such as minicom.

Per default it outputs to stdout, but using the 'filename' option
and/or the 'filename_rx'/'filename_tx' options it can also output to
files.

Using the 'tx' and 'rx' options you can also select whether both, or
only one of the data direction's data should be output.

Example:

  sigrok-cli -i foo.sr \
             -a uart:rx=0:tx=1,uart_dump:rx=no:tx=yes:filename=foo.txt \
             -s uart,uart_dump

This PD is just an experiment for now, it's possible that it will be
replaced / reimplemented via a different sigrok facility later on.

configure.ac
decoders/Makefile.am
decoders/uart_dump/Makefile.am [new file with mode: 0644]
decoders/uart_dump/__init__.py [new file with mode: 0644]
decoders/uart_dump/uart_dump.py [new file with mode: 0644]

index 6dfaee26c4b72514dc66d2e2583ff2f4ed8ca3c5..be2946e865a41e2f4f22eb26c9bcb3b1ea4e43ca 100644 (file)
@@ -166,6 +166,7 @@ AC_CONFIG_FILES([Makefile
                 decoders/spi/Makefile
                 decoders/transitioncounter/Makefile
                 decoders/uart/Makefile
                 decoders/spi/Makefile
                 decoders/transitioncounter/Makefile
                 decoders/uart/Makefile
+                decoders/uart_dump/Makefile
                 decoders/usb/Makefile
                ])
 
                 decoders/usb/Makefile
                ])
 
index 371b7c39613dfe8283b8008132f0efc43291b79c..60cd853aa80d5b665ed7c56e353da1a6ba21cd34 100644 (file)
@@ -38,5 +38,6 @@ SUBDIRS = \
        spi \
        transitioncounter \
        uart \
        spi \
        transitioncounter \
        uart \
+       uart_dump \
        usb
 
        usb
 
diff --git a/decoders/uart_dump/Makefile.am b/decoders/uart_dump/Makefile.am
new file mode 100644 (file)
index 0000000..d95618c
--- /dev/null
@@ -0,0 +1,26 @@
+##
+## This file is part of the sigrok project.
+##
+## Copyright (C) 2012 Uwe Hermann <uwe@hermann-uwe.de>
+##
+## 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
+## the Free Software Foundation; either version 2 of the License, or
+## (at your option) any later version.
+##
+## This program is distributed in the hope that it will be useful,
+## but WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+## 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
+##
+
+pkgdatadir = $(DECODERS_DIR)/uart_dump
+
+dist_pkgdata_DATA = __init__.py uart_dump.py
+
+CLEANFILES = *.pyc
+
diff --git a/decoders/uart_dump/__init__.py b/decoders/uart_dump/__init__.py
new file mode 100644 (file)
index 0000000..06a6d95
--- /dev/null
@@ -0,0 +1,29 @@
+##
+## This file is part of the sigrok project.
+##
+## Copyright (C) 2012 Uwe Hermann <uwe@hermann-uwe.de>
+##
+## 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
+## the Free Software Foundation; either version 2 of the License, or
+## (at your option) any later version.
+##
+## This program is distributed in the hope that it will be useful,
+## but WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+## 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
+##
+
+'''
+TODO.
+
+Details:
+TODO
+'''
+
+from .uart_dump import *
+
diff --git a/decoders/uart_dump/uart_dump.py b/decoders/uart_dump/uart_dump.py
new file mode 100644 (file)
index 0000000..6ed0b61
--- /dev/null
@@ -0,0 +1,110 @@
+##
+## This file is part of the sigrok project.
+##
+## Copyright (C) 2012 Uwe Hermann <uwe@hermann-uwe.de>
+##
+## 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
+## the Free Software Foundation; either version 2 of the License, or
+## (at your option) any later version.
+##
+## This program is distributed in the hope that it will be useful,
+## but WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+## 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
+##
+
+import sigrokdecode as srd
+import os
+import sys
+
+RX = 0
+TX = 1
+
+class Decoder(srd.Decoder):
+    api_version = 1
+    id = 'uart_dump'
+    name = 'UART dump'
+    longname = 'UART dump'
+    desc = 'Output decoded UART data to a file.'
+    license = 'gplv2+'
+    inputs = ['uart']
+    outputs = [] # TODO?
+    probes = []
+    optional_probes = []
+    options = {
+        'rx': ['Output RX data?', 'yes'],
+        'tx': ['Output TX data?', 'yes'],
+        'filename': ['File name for RX and TX data', '-'],
+        'filename_rx': ['File name for RX data', 'none'],
+        'filename_tx': ['File name for TX data', 'none'],
+    }
+    annotations = []
+
+    def __init__(self, **kwargs):
+        self.f = None
+        self.f_rx = None
+        self.f_tx = None
+
+    def file_open(self, filename):
+        if filename == 'none':
+            return None
+        elif filename == '-':
+            return sys.stdout
+        else:
+            return open(filename, 'w')
+
+    def start(self, metadata):
+        # The user can specify 'filename' (gets both RX and TX data), and/or
+        # 'filename_rx' (for RX data only), and/or 'filename_tx', respectively.
+
+        # Default is to output RX and TX to 'filename', with 'filename_rx' and
+        # 'filename_tx' being unused.
+
+        # If multiple 'filename*' options are specified, the user must NOT
+        # use the same file for any of them.
+
+        # A filename of 'none' is not allowed (has special meaning). A filename
+        # of '-' means 'stdout'.
+
+        self.f = self.file_open(self.options['filename'])
+        self.f_rx = self.file_open(self.options['filename_rx'])
+        self.f_tx = self.file_open(self.options['filename_tx'])
+
+    def report(self):
+        pass
+
+    def decode(self, ss, es, data):
+        ptype, rxtx, pdata = data
+
+        # Ignore all UART packets except the actual data packets (i.e., we
+        # do not print start bits, parity bits, stop bits, errors, and so on).
+        if ptype != 'DATA':
+            return
+
+        # TODO: Configurable format.
+        c = chr(pdata)
+
+        # TODO: Error handling.
+
+        # Output RX and/or TX to 'filename'.
+        if self.f != None:
+            if self.options['rx'] == 'yes' and rxtx == RX:
+                self.f.write(c)
+            if self.options['tx'] == 'yes' and rxtx == TX:
+                self.f.write(c)
+
+        # Output RX data to 'filename_rx'.
+        if self.f_rx != None:
+            if self.options['rx'] == 'yes' and rxtx == RX:
+                self.f_rx.write(c)
+
+        # Output TX data to 'filename_tx'.
+        if self.f_tx != None:
+            if self.options['tx'] == 'yes' and rxtx == TX:
+                self.f_tx.write(c)
+