X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;ds=inline;f=decoders%2Fpan1321%2Fpd.py;h=6c931147a1eddab7a793df702b5109f0116942ae;hb=a8a139edd96701b0a26234665dadb253d2ea5b7d;hp=3799612bb2fd230157291a177fa9b5aac187c9a9;hpb=db9ebbc2143f4b744b273ed0d5bbfd4b02aa8db9;p=libsigrokdecode.git
diff --git a/decoders/pan1321/pd.py b/decoders/pan1321/pd.py
index 3799612..6c93114 100644
--- a/decoders/pan1321/pd.py
+++ b/decoders/pan1321/pd.py
@@ -14,12 +14,9 @@
## 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
+## along with this program; if not, see .
##
-# Panasonic PAN1321 Bluetooth module protocol decoder
-
import sigrokdecode as srd
# ...
@@ -27,39 +24,46 @@ RX = 0
TX = 1
class Decoder(srd.Decoder):
- api_version = 1
+ api_version = 3
id = 'pan1321'
name = 'PAN1321'
longname = 'Panasonic PAN1321'
desc = 'Bluetooth RF module with Serial Port Profile (SPP).'
license = 'gplv2+'
inputs = ['uart']
- outputs = ['pan1321']
- probes = []
- optional_probes = []
- options = {}
- annotations = [
- ['Text (verbose)', 'Human-readable text (verbose)'],
- ['Text', 'Human-readable text'],
- ['Warnings', 'Human-readable warnings'],
- ]
-
- def __init__(self, **kwargs):
+ outputs = []
+ tags = ['Wireless/RF']
+ annotations = (
+ ('text-verbose', 'Human-readable text (verbose)'),
+ ('text', 'Human-readable text'),
+ ('warnings', 'Human-readable warnings'),
+ )
+
+ def __init__(self):
+ self.reset()
+
+ def reset(self):
self.cmd = ['', '']
self.ss_block = None
- 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 start(self):
+ self.out_ann = self.register(srd.OUTPUT_ANN)
def putx(self, data):
self.put(self.ss_block, self.es_block, self.out_ann, data)
def handle_host_command(self, rxtx, s):
- if s.startswith('AT+JPRO'):
+ if s.startswith('AT+JAAC'):
+ # AT+JAAC= (0 or 1)
+ p = s[s.find('=') + 1:]
+ if p not in ('0', '1'):
+ self.putx([2, ['Warning: Invalid JAAC parameter "%s"' % p]])
+ return
+ x = 'Auto' if (p == '1') else 'Don\'t auto'
+ self.putx([0, ['%s-accept new connections' % x]])
+ self.putx([1, ['%s-accept connections' % x]])
+ elif s.startswith('AT+JPRO'):
+ # AT+JPRO= (0 or 1)
p = s[s.find('=') + 1:]
if p not in ('0', '1'):
self.putx([2, ['Warning: Invalid JPRO parameter "%s"' % p]])
@@ -69,16 +73,43 @@ class Decoder(srd.Decoder):
self.putx([0, ['%s production mode' % x]])
self.putx([1, ['Production mode = %s' % onoff]])
elif s.startswith('AT+JRES'):
+ # AT+JRES
if s != 'AT+JRES': # JRES has no params.
self.putx([2, ['Warning: Invalid JRES usage.']])
return
self.putx([0, ['Triggering a software reset']])
self.putx([1, ['Reset']])
+ elif s.startswith('AT+JSDA'):
+ # AT+JSDA=, (l: length in bytes, d: data)
+ # l is (max?) 3 decimal digits and ranges from 1 to MTU size.
+ # Data can be ASCII or binary values (l bytes total).
+ l, d = s[s.find('=') + 1:].split(',')
+ if not l.isnumeric():
+ self.putx([2, ['Warning: Invalid data length "%s".' % l]])
+ if int(l) != len(d):
+ self.putx([2, ['Warning: Data length mismatch (%d != %d).' % \
+ (int(l), len(d))]])
+ # TODO: Warn if length > MTU size (which is firmware-dependent
+ # and is negotiated by both Bluetooth devices upon connection).
+ b = ''.join(['%02x ' % ord(c) for c in d])[:-1]
+ self.putx([0, ['Sending %d data bytes: %s' % (int(l), b)]])
+ self.putx([1, ['Send %d = %s' % (int(l), b)]])
elif s.startswith('AT+JSEC'):
+ # AT+JSEC=,,,,
+ # secmode: Security mode 1 or 3 (default).
+ # linkkey_info: Must be 1 or 2. Has no function according to docs.
+ # pintype: 1: variable pin (default), 2: fixed pin.
+ # pinlen: PIN length (2 decimal digits). Max. PIN length is 16.
+ # pin: The Bluetooth PIN ('pinlen' chars). Used if pintype=2.
+ # Note: AT+JSEC (if used) must be the first command after reset.
+ # TODO: Parse all the other parameters.
pin = s[-4:]
self.putx([0, ['Host set the Bluetooth PIN to "' + pin + '"']])
self.putx([1, ['PIN = ' + pin]])
elif s.startswith('AT+JSLN'):
+ # AT+JSLN=,
+ # namelen: Friendly name length (2 decimal digits). Max. len is 18.
+ # name: The Bluetooth "friendly name" ('namelen' ASCII characters).
name = s[s.find(',') + 1:]
self.putx([0, ['Host set the Bluetooth name to "' + name + '"']])
self.putx([1, ['BT name = ' + name]])
@@ -108,6 +139,9 @@ class Decoder(srd.Decoder):
if ptype != 'DATA':
return
+ # We're only interested in the byte value (not individual bits).
+ pdata = pdata[0]
+
# If this is the start of a command/reply, remember the start sample.
if self.cmd[rxtx] == '':
self.ss_block = ss
@@ -116,7 +150,7 @@ class Decoder(srd.Decoder):
self.cmd[rxtx] += chr(pdata)
# Get packets/bytes until an \r\n sequence is found (end of command).
- if self.cmd[rxtx][-1:] != '\n':
+ if self.cmd[rxtx][-2:] != '\r\n':
return
# Handle host commands and device replies.
@@ -126,8 +160,5 @@ class Decoder(srd.Decoder):
self.handle_device_reply(rxtx, self.cmd[rxtx][:-2])
elif rxtx == TX:
self.handle_host_command(rxtx, self.cmd[rxtx][:-2])
- else:
- raise Exception('Invalid rxtx value: %d' % rxtx)
self.cmd[rxtx] = ''
-