Exemple #1
0
 def check_permutations(self, data):
     for p in list(permutations(data)):
         strData = ""
         for i in range(4):
             strData += p[i]
                         
         decoded_data = decodeCrc16(strData)
         if decoded_data[4] == decoded_data[5]:
             return decoded_data
     return None
Exemple #2
0
 def run(self):
     while(1):
         data = self.communicator.read(1)
         
         self.data.append(data)
         
         if len(self.data) == 4:
             self.window.appendRaw(self.data)
             
             strData = ""
             for i in range(4):
                 strData += self.data[i]
                 
             decoded_data = decodeCrc16(strData)
             
             # Good CRC
             if decoded_data[4] == decoded_data[5]:
                 
                 print "Good CRC"
                 
                 for i in range(4):
                     self.data.pop(0)
                     
                 heading = decoded_data[1]
                 depth = decoded_data[2]
                 light = decoded_data[3]
                 crc = decoded_data[4]
                 calculated_crc = decoded_data[5]
                 first_byte = decoded_data[6]
                 second_byte = decoded_data[7]
                 first_crc = decoded_data[8]
                 second_crc = decoded_data[9]
             
                 self.window.appendParsed(heading, depth, light)
                 self.window.setHeading(heading)
                 self.window.setDepth(depth)
                 self.window.setLight(ON if light == 1 else OFF)
                     
                 self.serializer.write([heading, depth, light, crc, calculated_crc, first_byte, second_byte, first_crc, second_crc])
             else:
                 permutated_data = None
                 #permutated_data = self.check_permutations(self.data)
                 if permutated_data != None:
                     print "A permutation was good!"
                     
                     heading = decoded_data[1]
                     depth = decoded_data[2]
                     light = decoded_data[3]
                     crc = decoded_data[4]
                     calculated_crc = decoded_data[5]
                     first_byte = decoded_data[6]
                     second_byte = decoded_data[7]
                     first_crc = decoded_data[8]
                     second_crc = decoded_data[9]
                 
                     self.window.appendParsed(heading, depth, light)
                     self.window.setHeading(heading)
                     self.window.setDepth(depth)
                     self.window.setLight(ON if light == 1 else OFF)
                         
                     self.serializer.write([heading, depth, light, crc, calculated_crc, first_byte, second_byte, first_crc, second_crc])
                 else:
                     discarded_data = self.data.pop(0)
                     print "Did not found permutation, discarded " + discarded_data
     print "Exited acquisition loop"