TX = 1
class Decoder(srd.Decoder):
+ api_version = 1
id = 'pan1321'
name = 'PAN1321'
longname = 'Panasonic PAN1321'
inputs = ['uart']
outputs = ['pan1321']
probes = []
+ extra_probes = []
options = {}
annotations = [
['ASCII', 'TODO: description'],
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:
self.put(ss, es, self.out_ann,
- [ANN_ASCII, ['Host sent unsupported command']])
+ [ANN_ASCII, ['Host sent unsupported command: %s' % s]])
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'):
[ANN_ASCII, ['Device sent error code ' + error]])
else:
self.put(ss, es, self.out_ann,
- [ANN_ASCII, ['Device sent an unknown reply']])
+ [ANN_ASCII, ['Device sent an unknown reply: %s' % s]])
self.cmd[rxtx] = ''
def decode(self, ss, es, data):
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:
- pass # TODO: Error.
+ raise Exception('Invalid rxtx value: %d' % rxtx)