From: Uwe Hermann Date: Tue, 10 Jan 2012 01:37:44 +0000 (+0100) Subject: srd: Add Panasonic PAN1321 decoder (on top of UART). X-Git-Tag: libsigrokdecode-0.1.0~183 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=5cc2d7bbc075ef6048bd5cd4e36533e874efb6a7;p=libsigrokdecode.git srd: Add Panasonic PAN1321 decoder (on top of UART). This is just a first prototype implementation, it's not finished at all. --- diff --git a/decoders/Makefile.am b/decoders/Makefile.am index c27d69f..afb6a1b 100644 --- a/decoders/Makefile.am +++ b/decoders/Makefile.am @@ -22,14 +22,15 @@ pkgdatadir = $(DECODERS_DIR) # Please keep this list in alphabetical order. dist_pkgdata_DATA = \ + ddc.py \ i2c.py \ mx25lxx05d.py \ nunchuk.py \ + pan1321.py \ spi.py \ srd_usb.py \ transitioncounter.py \ uart.py \ - ddc.py CLEANFILES = *.pyc diff --git a/decoders/pan1321.py b/decoders/pan1321.py new file mode 100644 index 0000000..edd4162 --- /dev/null +++ b/decoders/pan1321.py @@ -0,0 +1,94 @@ +## +## This file is part of the sigrok project. +## +## Copyright (C) 2012 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 +## 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 +# + +import sigrokdecode + +# Annotation feed formats +ANN_ASCII = 0 + +# UART 'data' packet type. +T_DATA = 1 + +class Decoder(sigrokdecode.Decoder): + id = 'pan1321' + name = 'Panasonic PAN1321' + longname = 'TODO.' + desc = 'TODO.' + longdesc = 'TODO.' + author = 'Uwe Hermann' + email = 'uwe@hermann-uwe.de' + license = 'gplv2+' + inputs = ['uart'] + outputs = ['pan1321'] + # probes = [ + # ] + options = { + } + annotation = [ + # ANN_ASCII + ["ASCII", "TODO: description"], + ] + + def __init__(self, **kwargs): + # self.out_proto = None + self.out_ann = None + self.cmd = '' + + def start(self, metadata): + # self.out_proto = self.add(sigrokdecode.SRD_OUTPUT_PROTOCOL, 'pan1321') + self.out_ann = self.add(sigrokdecode.SRD_OUTPUT_ANNOTATION, 'pan1321') + + def report(self): + pass + + def decode(self, ss, es, data): + ptype, pdata = data + + # For now, ignore all UART packets except the actual data packets. + if ptype != T_DATA: + return + + # Append new (ASCII) byte to the current command. + self.cmd += chr(pdata) + + # Get packets/bytes until an \r\n sequence is found (end of command). + if chr(pdata) != '\n': + return + + s = self.cmd + + # FIXME: This is just a quick hack. + if s.startswith('AT+JSEC'): + pin = s[s.find('\r\n') - 4:len(s) - 2] + self.put(ss, es, self.out_ann, + [ANN_ASCII, ['Setting Bluetooth PIN to ' + pin]]) + elif s.startswith('AT+JSLN'): + name = s[s.find(',') + 1:-2] + self.put(ss, es, self.out_ann, + [ANN_ASCII, ['Setting Bluetooth name to ' + name]]) + else: + self.put(ss, es, self.out_ann, [ANN_ASCII, ['Unsupported command']]) + + self.cmd = '' +