diff options
author | Uwe Hermann <uwe@hermann-uwe.de> | 2012-06-13 19:26:02 +0200 |
---|---|---|
committer | Uwe Hermann <uwe@hermann-uwe.de> | 2012-06-14 01:21:01 +0200 |
commit | f9b0356bb8e5eeeb406c8be998f0746548a1e2dd (patch) | |
tree | 4fcb101bbf3cca81bd959484c1a656679e2d97ca /decoders/pan1321/pan1321.py | |
parent | 140149cb9803789402328b01a378d43d59c5d8a7 (diff) | |
download | libsigrokdecode-f9b0356bb8e5eeeb406c8be998f0746548a1e2dd.tar.gz libsigrokdecode-f9b0356bb8e5eeeb406c8be998f0746548a1e2dd.zip |
srd: pan1321: Output correct start/end sample values.
Diffstat (limited to 'decoders/pan1321/pan1321.py')
-rw-r--r-- | decoders/pan1321/pan1321.py | 39 |
1 files changed, 21 insertions, 18 deletions
diff --git a/decoders/pan1321/pan1321.py b/decoders/pan1321/pan1321.py index 773e02d..670a48e 100644 --- a/decoders/pan1321/pan1321.py +++ b/decoders/pan1321/pan1321.py @@ -44,6 +44,7 @@ class Decoder(srd.Decoder): def __init__(self, **kwargs): self.cmd = ['', ''] + self.ss_block = None def start(self, metadata): # self.out_proto = self.add(srd.OUTPUT_PROTO, 'pan1321') @@ -52,34 +53,30 @@ 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, - [0, ['Host set the Bluetooth PIN to ' + pin]]) + self.putx([0, ['Host set the Bluetooth PIN to ' + pin]]) elif s.startswith('AT+JSLN'): name = s[s.find(',') + 1:] - self.put(ss, es, self.out_ann, - [0, ['Host set the Bluetooth name to ' + name]]) + self.putx([0, ['Host set the Bluetooth name to ' + name]]) else: - self.put(ss, es, self.out_ann, - [0, ['Host sent unsupported command: %s' % s]]) + self.putx([0, ['Host sent 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, - [0, ['Device initialized correctly']]) + self.putx([0, ['Device initialized correctly']]) elif s == 'OK': - self.put(ss, es, self.out_ann, - [0, ['Device acknowledged last command']]) + self.putx([0, ['Device acknowledged last command']]) elif s.startswith('ERR'): error = s[s.find('=') + 1:] - self.put(ss, es, self.out_ann, - [0, ['Device sent error code ' + error]]) + self.putx([0, ['Device sent error code ' + error]]) else: - self.put(ss, es, self.out_ann, - [0, ['Device sent an unknown reply: %s' % s]]) + self.putx([0, ['Device sent an unknown reply: %s' % s]]) self.cmd[rxtx] = '' def decode(self, ss, es, data): @@ -89,6 +86,10 @@ class Decoder(srd.Decoder): 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) @@ -99,9 +100,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) |