]> sigrok.org Git - libsigrokdecode.git/blobdiff - decoders/pan1321/pan1321.py
srd: PDs: Kill obsolete 'longdesc' entries.
[libsigrokdecode.git] / decoders / pan1321 / pan1321.py
index f383e00ccd4923fa53382085514fd58b7c7810ff..eed24cdf6272674db9df2749323ad69fe3a2c9a2 100644 (file)
 ## 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
@@ -42,12 +35,11 @@ class Decoder(srd.Decoder):
     name = 'PAN1321'
     longname = 'Panasonic PAN1321'
     desc = 'TODO.'
-    longdesc = 'TODO.'
     license = 'gplv2+'
     inputs = ['uart']
     outputs = ['pan1321']
     probes = []
-    extra_probes = []
+    optional_probes = []
     options = {}
     annotations = [
         ['ASCII', 'TODO: description'],
@@ -65,11 +57,11 @@ class Decoder(srd.Decoder):
 
     def handle_host_command(self, ss, es, rxtx, s):
         if s.startswith('AT+JSEC'):
-            pin = s[s.find('\r\n') - 4:len(s) - 2]
+            pin = s[-4:]
             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]
+            name = s[s.find(',') + 1:]
             self.put(ss, es, self.out_ann,
                      [ANN_ASCII, ['Host set the Bluetooth name to ' + name]])
         else:
@@ -78,10 +70,10 @@ class Decoder(srd.Decoder):
         self.cmd[rxtx] = ''
 
     def handle_device_reply(self, ss, es, rxtx, s):
-        if s == 'ROK\r\n':
+        if s == 'ROK':
             self.put(ss, es, self.out_ann,
                      [ANN_ASCII, ['Device initialized correctly']])
-        elif s == 'OK\r\n':
+        elif s == 'OK':
             self.put(ss, es, self.out_ann,
                      [ANN_ASCII, ['Device acknowledged last command']])
         elif s.startswith('ERR'):
@@ -97,7 +89,7 @@ class Decoder(srd.Decoder):
         ptype, rxtx, pdata = data
 
         # For now, ignore all UART packets except the actual data packets.
-        if ptype != T_DATA:
+        if ptype != 'DATA':
             return
 
         # Append a new (ASCII) byte to the currently built/parsed command.
@@ -108,10 +100,11 @@ class Decoder(srd.Decoder):
             return
 
         # Handle host commands and device replies.
+        # We remove trailing \r\n from the strings before handling them.
         if rxtx == RX:
-            self.handle_device_reply(ss, es, rxtx, self.cmd[rxtx])
+            self.handle_device_reply(ss, es, rxtx, self.cmd[rxtx][:-2])
         elif rxtx == TX:
-            self.handle_host_command(ss, es, rxtx, self.cmd[rxtx])
+            self.handle_host_command(ss, es, rxtx, self.cmd[rxtx][:-2])
         else:
             raise Exception('Invalid rxtx value: %d' % rxtx)