Ejemplo n.º 1
0
 def checkFrame(self):
     '''
     Check if the next frame is available. Return True if we were
     successful.
     '''
     try:
         self.populateHeader()
         frame_size = self.__header['len']
         data = self.__buffer[:frame_size - 2]
         crc = self.__buffer[frame_size - 2:frame_size]
         crc_val = (ord(crc[0]) << 8) + ord(crc[1])
         return checkCRC(data, crc_val)
     except (IndexError, KeyError):
         return False
Ejemplo n.º 2
0
    def checkFrame(self):
        ''' Check and decode the next frame

        :returns: True if we are successful, False otherwise
        '''
        start = self.__buffer.find(self.__start)
        if start == -1: return False
        if start > 0 :  # go ahead and skip old bad data
            self.__buffer = self.__buffer[start:]

        end = self.__buffer.find(self.__end)
        if (end != -1):
            self.__header['len'] = end
            self.__header['uid'] = struct.unpack('>B', self.__buffer[1:2])
            self.__header['crc'] = struct.unpack('>H', self.__buffer[end - 2:end])[0]
            data = self.__buffer[start + 1:end - 2]
            return checkCRC(data, self.__header['crc'])
        return False