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 | |
parent | afff6b1a0be19c4f0976309cae571a0c3e41c157 (diff) | |
download | libsigrokdecode-fd4aa8aaed83f9f0041647b913e48ef95c1aab55.tar.gz libsigrokdecode-fd4aa8aaed83f9f0041647b913e48ef95c1aab55.zip |
srd: PDs: Cleanups, simplifications, small fixes.
-rw-r--r-- | decoders/pan1321/pan1321.py | 13 | ||||
-rw-r--r-- | decoders/spi/spi.py | 10 | ||||
-rw-r--r-- | decoders/uart/uart.py | 3 |
3 files changed, 15 insertions, 11 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) diff --git a/decoders/spi/spi.py b/decoders/spi/spi.py index 7789e34..a06498b 100644 --- a/decoders/spi/spi.py +++ b/decoders/spi/spi.py @@ -125,22 +125,24 @@ class Decoder(srd.Decoder): if deasserted: self.cs_was_deasserted_during_data_word = 1 + ws = self.options['wordsize'] + # Receive MOSI bit into our shift register. if self.options['bitorder'] == MSB_FIRST: - self.mosidata |= mosi << (self.options['wordsize'] - 1 - self.bitcount) + self.mosidata |= mosi << (ws - 1 - self.bitcount) else: self.mosidata |= mosi << self.bitcount # Receive MISO bit into our shift register. if self.options['bitorder'] == MSB_FIRST: - self.misodata |= miso << (self.options['wordsize'] - 1 - self.bitcount) + self.misodata |= miso << (ws - 1 - self.bitcount) else: self.misodata |= miso << self.bitcount self.bitcount += 1 - # Continue to receive if not a byte yet. - if self.bitcount != self.options['wordsize']: + # Continue to receive if not enough bits were received, yet. + if self.bitcount != ws: continue self.put(self.start_sample, self.samplenum, self.out_proto, diff --git a/decoders/uart/uart.py b/decoders/uart/uart.py index 7cefe74..abf596e 100644 --- a/decoders/uart/uart.py +++ b/decoders/uart/uart.py @@ -310,7 +310,8 @@ class Decoder(srd.Decoder): # Get the next data bit in LSB-first or MSB-first fashion. if self.options['bit_order'] == LSB_FIRST: self.databyte[rxtx] >>= 1 - self.databyte[rxtx] |= (signal << (self.options['num_data_bits'] - 1)) + self.databyte[rxtx] |= \ + (signal << (self.options['num_data_bits'] - 1)) elif self.options['bit_order'] == MSB_FIRST: self.databyte[rxtx] <<= 1 self.databyte[rxtx] |= (signal << 0) |