Example #1
0
 def check_frame(self):
     """
     Check if the next frame is available. Return True if we were
     successful.
     """
     try:
         self.populate_header()
         frame_size = self.header['len']
         data = self.buffer[:frame_size - 2]
         crc = self.buffer[frame_size - 2:frame_size]
         crc_val = (crc[0] << 8) + crc[1]
         return check_crc(data, crc_val)
     except (IndexError, KeyError):
         return False
Example #2
0
 def check_frame(self):
     """
     Check if the next frame is available. Return True if we were
     successful.
     """
     try:
         self.populate_header()
         frame_size = self.header['len']
         data = self.buffer[:frame_size - 2]
         crc = self.buffer[frame_size - 2:frame_size]
         crc_val = (crc[0] << 8) + crc[1]
         return check_crc(data, crc_val)
     except (IndexError, KeyError):
         return False
Example #3
0
    def check_frame(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 check_crc(data, self.header['crc'])
        return False
Example #4
0
    def check_frame(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 check_crc(data, self.header['crc'])
        return False
Example #5
0
 def test_cyclic_redundancy_check(self):
     """ Test the cyclic redundancy check code """
     self.assertTrue(check_crc(self.data, 0xe2db))
     self.assertTrue(check_crc(self.string, 0x889e))
Example #6
0
 def test_cyclic_redundancy_check(self):
     """ Test the cyclic redundancy check code """
     self.assertTrue(check_crc(self.data, 0xe2db))
     self.assertTrue(check_crc(self.string, 0x889e))