]> sigrok.org Git - libsigrokdecode.git/commitdiff
srd: PDs: Cleanups, simplifications, small fixes.
authorUwe Hermann <redacted>
Sat, 28 Jan 2012 18:08:13 +0000 (19:08 +0100)
committerUwe Hermann <redacted>
Sat, 28 Jan 2012 18:08:13 +0000 (19:08 +0100)
decoders/pan1321/pan1321.py
decoders/spi/spi.py
decoders/uart/uart.py

index f383e00ccd4923fa53382085514fd58b7c7810ff..13f1226f4a80b624ec157345681abfe4acbef795 100644 (file)
@@ -65,11 +65,11 @@ class Decoder(srd.Decoder):
 
     def handle_host_command(self, ss, es, rxtx, s):
         if s.startswith('AT+JSEC'):
 
     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'):
             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 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):
         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']])
             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'):
             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.
             return
 
         # Handle host commands and device replies.
+        # We remove trailing \r\n from the strings before handling them.
         if rxtx == RX:
         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:
         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)
 
         else:
             raise Exception('Invalid rxtx value: %d' % rxtx)
 
index 7789e34c36cb96c1495a1e9af2fbf42753565331..a06498bcac092c7bcb500dc7b799413add38a448 100644 (file)
@@ -125,22 +125,24 @@ class Decoder(srd.Decoder):
                 if deasserted:
                     self.cs_was_deasserted_during_data_word = 1
 
                 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:
             # 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:
             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
 
             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,
                 continue
 
             self.put(self.start_sample, self.samplenum, self.out_proto,
index 7cefe740bff73d389bc6d1dbe4a5155f35ce957f..abf596e6aa26d53e5d526ccfde1f19581384cf28 100644 (file)
@@ -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
         # 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)
         elif self.options['bit_order'] == MSB_FIRST:
             self.databyte[rxtx] <<= 1
             self.databyte[rxtx] |= (signal << 0)