From 64c29e28e0efa184319f7831b3eca18c7f73f7d0 Mon Sep 17 00:00:00 2001 From: Uwe Hermann Date: Sun, 15 Jan 2012 15:36:01 +0100 Subject: srd: Each PD now has its own subdirectory. --- decoders/pan1321/Makefile.am | 26 ++++++++++ decoders/pan1321/__init__.py | 22 +++++++++ decoders/pan1321/pan1321.py | 115 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 163 insertions(+) create mode 100644 decoders/pan1321/Makefile.am create mode 100644 decoders/pan1321/__init__.py create mode 100644 decoders/pan1321/pan1321.py (limited to 'decoders/pan1321') diff --git a/decoders/pan1321/Makefile.am b/decoders/pan1321/Makefile.am new file mode 100644 index 0000000..6997ed5 --- /dev/null +++ b/decoders/pan1321/Makefile.am @@ -0,0 +1,26 @@ +## +## 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 +## + +pkgdatadir = $(DECODERS_DIR)/pan1321 + +dist_pkgdata_DATA = __init__.py pan1321.py + +CLEANFILES = *.pyc + diff --git a/decoders/pan1321/__init__.py b/decoders/pan1321/__init__.py new file mode 100644 index 0000000..abbcf5d --- /dev/null +++ b/decoders/pan1321/__init__.py @@ -0,0 +1,22 @@ +## +## 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 +## + +from .pan1321 import * + diff --git a/decoders/pan1321/pan1321.py b/decoders/pan1321/pan1321.py new file mode 100644 index 0000000..55676ce --- /dev/null +++ b/decoders/pan1321/pan1321.py @@ -0,0 +1,115 @@ +## +## 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 +## + +# +# Panasonic PAN1321 Bluetooth module protocol decoder +# +# TODO +# + +import sigrokdecode as srd + +# Annotation feed formats +ANN_ASCII = 0 + +# UART 'data' packet type. +T_DATA = 1 + +# ... +RX = 0 +TX = 1 + +class Decoder(srd.Decoder): + id = 'pan1321' + name = 'PAN1321' + longname = 'Panasonic PAN1321' + desc = 'TODO.' + longdesc = 'TODO.' + license = 'gplv2+' + inputs = ['uart'] + outputs = ['pan1321'] + probes = [] + options = {} + annotations = [ + ['ASCII', 'TODO: description'], + ] + + def __init__(self, **kwargs): + self.cmd = ['', ''] + + def start(self, metadata): + # self.out_proto = self.add(srd.OUTPUT_PROTO, 'pan1321') + self.out_ann = self.add(srd.OUTPUT_ANN, 'pan1321') + + def report(self): + pass + + def handle_host_command(self, ss, es, rxtx, s): + if s.startswith('AT+JSEC'): + pin = s[s.find('\r\n') - 4:len(s) - 2] + self.put(ss, es, self.out_ann, + [ANN_ASCII, ['Host set the Bluetooth PIN to ' + pin]]) + elif s.startswith('AT+JSLN'): + name = s[s.find(',') + 1:-2] + self.put(ss, es, self.out_ann, + [ANN_ASCII, ['Host set the Bluetooth name to ' + name]]) + else: + self.put(ss, es, self.out_ann, + [ANN_ASCII, ['Host sent unsupported command']]) + self.cmd[rxtx] = '' + + def handle_device_reply(self, ss, es, rxtx, s): + if s == 'ROK\r\n': + self.put(ss, es, self.out_ann, + [ANN_ASCII, ['Device initialized correctly']]) + elif s == 'OK\r\n': + self.put(ss, es, self.out_ann, + [ANN_ASCII, ['Device acknowledged last command']]) + elif s.startswith('ERR'): + error = s[s.find('=') + 1:] + self.put(ss, es, self.out_ann, + [ANN_ASCII, ['Device sent error code ' + error]]) + else: + self.put(ss, es, self.out_ann, + [ANN_ASCII, ['Device sent an unknown reply']]) + self.cmd[rxtx] = '' + + def decode(self, ss, es, data): + ptype, rxtx, pdata = data + + # For now, ignore all UART packets except the actual data packets. + if ptype != T_DATA: + return + + # Append a new (ASCII) byte to the currently built/parsed command. + self.cmd[rxtx] += chr(pdata) + + # Get packets/bytes until an \r\n sequence is found (end of command). + if self.cmd[rxtx][-1:] != '\n': + return + + # Handle host commands and device replies. + if rxtx == RX: + self.handle_device_reply(ss, es, rxtx, self.cmd[rxtx]) + elif rxtx == TX: + self.handle_host_command(ss, es, rxtx, self.cmd[rxtx]) + else: + pass # TODO: Error. + -- cgit v1.2.3-70-g09d2