Exemplo n.º 1
0
 def parse(self):
     index = self.buffer.find(b'\xb5\x62')
     if index >= 0:
         self.start += index
         result = UbloxMessage.validate(self.buffer[self.start:])
         if result['valid']:
             msgFormat, msgData, remainder = UbloxMessage.parse(
                 self.buffer[self.start:])
             self.buffer = remainder if remainder is not None else b''
             self.start = 0
             self.handle_message(msgFormat, msgData)
         else:
             # Invalid message, move past sync bytes
             if result['lengthMatch']:
                 self.buffer = self.buffer[self.start + 2:]
     # Discard all but the last byte
     else:
         self.buffer = self.buffer[-1:]
         self.start = 0
Exemplo n.º 2
0
 def parse(self):
     self.logger.debug('in UbloxReader.parse()')
     if len(self.buffer) < 8:
         self.logger.debug('UbloxReader.parse(): not enough data in buffer')
         return
     index = self.buffer.find(b'\xb5\x62')
     if index >= 0:
         self.start += index
         msgTime = time.time()
         self.logger.debug('UbloxReader.parse(): sending for validation')
         result = UbloxMessage.validate(self.buffer[self.start:])
         if result['valid']:
             rawMessage = self.buffer[self.start:]
             self.logger.debug('UbloxReader.parse(): sending to UbloxMessage.parse()')
             msgFormat, msgData, remainder = UbloxMessage.parse(rawMessage)
             rawMessage = rawMessage[:len(rawMessage) - len(remainder)] if remainder is not None else rawMessage[:len(rawMessage)]
             self.buffer = remainder if remainder is not None else b''
             self.start = 0
             if msgFormat is not None:
                 self.logger.debug('UbloxReader.parse(): sending to UbloxReader.handleMessage()')
                 self.handleMessage(msgTime, msgFormat, msgData, rawMessage)
                 return
         else:
             # Invalid message, move past sync bytes
             if result['lengthMatch'] or ((result['length'] is not None) and (result['length'] > 4096)):
                 if result['lengthMatch']:
                     self.logger.debug('UbloxReader.parse(): invalid message in buffer, moving past sync')
                 else:
                     self.logger.debug('UbloxReader.parse(): invalid length ({}) - enforcing max length of 4096 bytes'.format(result['length']))
                 self.buffer = self.buffer[self.start+2:]
                 return
             else:
                 self.logger.debug('Ublox.parse(): Header indicates a message of length {}, buffer only has {} bytes'.format(result['length'], len(self.buffer)))
                 return
     # Discard all but the last byte
     else:
         self.logger.debug('UbloxReader.parse(): could not find sync in buffer, discarding all but the last byte')
         self.buffer = self.buffer[-1:]
         self.start = 0
         return