diff options
author | Uwe Hermann <uwe@hermann-uwe.de> | 2012-01-28 19:08:13 +0100 |
---|---|---|
committer | Uwe Hermann <uwe@hermann-uwe.de> | 2012-01-28 19:08:13 +0100 |
commit | fd4aa8aaed83f9f0041647b913e48ef95c1aab55 (patch) | |
tree | f7120186d2c040eec1fe7c4640e97c5969bb4afb /decoders/pan1321/pan1321.py | |
parent | afff6b1a0be19c4f0976309cae571a0c3e41c157 (diff) | |
download | libsigrokdecode-fd4aa8aaed83f9f0041647b913e48ef95c1aab55.tar.gz libsigrokdecode-fd4aa8aaed83f9f0041647b913e48ef95c1aab55.zip |
srd: PDs: Cleanups, simplifications, small fixes.
Diffstat (limited to 'decoders/pan1321/pan1321.py')
-rw-r--r-- | decoders/pan1321/pan1321.py | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/decoders/pan1321/pan1321.py b/decoders/pan1321/pan1321.py index f383e00..13f1226 100644 --- a/decoders/pan1321/pan1321.py +++ b/decoders/pan1321/pan1321.py @@ -65,11 +65,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 +78,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'): @@ -108,10 +108,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) |