X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=decoders%2Fpan1321%2Fpan1321.py;h=827269d9019162f9a6a946bd1415a7404bd4e8f0;hb=92d1aba34bbe661b388e874fda0a41f477d3e30d;hp=13f1226f4a80b624ec157345681abfe4acbef795;hpb=fd4aa8aaed83f9f0041647b913e48ef95c1aab55;p=libsigrokdecode.git diff --git a/decoders/pan1321/pan1321.py b/decoders/pan1321/pan1321.py index 13f1226..827269d 100644 --- a/decoders/pan1321/pan1321.py +++ b/decoders/pan1321/pan1321.py @@ -18,20 +18,10 @@ ## 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 @@ -41,20 +31,21 @@ class Decoder(srd.Decoder): id = 'pan1321' name = 'PAN1321' longname = 'Panasonic PAN1321' - desc = 'TODO.' - longdesc = 'TODO.' + desc = 'Bluetooth RF module with Serial Port Profile (SPP).' license = 'gplv2+' inputs = ['uart'] outputs = ['pan1321'] probes = [] - extra_probes = [] + optional_probes = [] options = {} annotations = [ - ['ASCII', 'TODO: description'], + ['Text (verbose)', 'Human-readable text (verbose)'], + ['Text', 'Human-readable text'], ] def __init__(self, **kwargs): self.cmd = ['', ''] + self.ss_block = None def start(self, metadata): # self.out_proto = self.add(srd.OUTPUT_PROTO, 'pan1321') @@ -63,43 +54,50 @@ class Decoder(srd.Decoder): def report(self): pass - def handle_host_command(self, ss, es, rxtx, s): + 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+JSEC'): pin = s[-4:] - self.put(ss, es, self.out_ann, - [ANN_ASCII, ['Host set the Bluetooth PIN to ' + pin]]) + self.putx([0, ['Host set the Bluetooth PIN to ' + pin]]) + self.putx([1, ['PIN = ' + pin]]) elif s.startswith('AT+JSLN'): name = s[s.find(',') + 1:] - self.put(ss, es, self.out_ann, - [ANN_ASCII, ['Host set the Bluetooth name to ' + name]]) + self.putx([0, ['Host set the Bluetooth name to ' + name]]) + self.putx([1, ['BT name = ' + name]]) else: - self.put(ss, es, self.out_ann, - [ANN_ASCII, ['Host sent unsupported command: %s' % s]]) + self.putx([0, ['Host sent unsupported command: %s' % s]]) + self.putx([1, ['Unsupported command: %s' % s]]) self.cmd[rxtx] = '' - def handle_device_reply(self, ss, es, rxtx, s): + def handle_device_reply(self, rxtx, s): if s == 'ROK': - self.put(ss, es, self.out_ann, - [ANN_ASCII, ['Device initialized correctly']]) + self.putx([0, ['Device initialized correctly']]) + self.putx([1, ['Init']]) elif s == 'OK': - self.put(ss, es, self.out_ann, - [ANN_ASCII, ['Device acknowledged last command']]) + self.putx([0, ['Device acknowledged last command']]) + self.putx([1, ['ACK']]) elif s.startswith('ERR'): error = s[s.find('=') + 1:] - self.put(ss, es, self.out_ann, - [ANN_ASCII, ['Device sent error code ' + error]]) + self.putx([0, ['Device sent error code ' + error]]) + self.putx([1, ['ERR = ' + error]]) else: - self.put(ss, es, self.out_ann, - [ANN_ASCII, ['Device sent an unknown reply: %s' % s]]) + self.putx([0, ['Device sent an unknown reply: %s' % s]]) + self.putx([1, ['Unknown reply: %s' % s]]) 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: + if ptype != 'DATA': return + # If this is the start of a command/reply, remember the start sample. + if self.cmd[rxtx] == '': + self.ss_block = ss + # Append a new (ASCII) byte to the currently built/parsed command. self.cmd[rxtx] += chr(pdata) @@ -110,9 +108,11 @@ class Decoder(srd.Decoder): # 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][:-2]) + self.es_block = es + self.handle_device_reply(rxtx, self.cmd[rxtx][:-2]) elif rxtx == TX: - self.handle_host_command(ss, es, rxtx, self.cmd[rxtx][:-2]) + self.es_block = es + self.handle_host_command(rxtx, self.cmd[rxtx][:-2]) else: raise Exception('Invalid rxtx value: %d' % rxtx)