Exemple #1
0
    def extract_data(self, timestamp, data, offset):
        """Extract the data from the feature's raw data.
        
        Args:
            timestamp (int): Data's timestamp.
            data (str): The data read from the feature.
            offset (int): Offset where to start reading data.
        
        Returns:
            :class:`blue_st_sdk.feature.ExtractedData`: Container of the number
            of bytes read and the extracted data.

        Raises:
            :exc:`blue_st_sdk.utils.blue_st_exceptions.InvalidDataException`
                if the data array has not enough data to read.
        """
        if len(data) - offset < self.DATA_LENGTH_BYTES:
            raise InvalidDataException(
                'There are no %d bytes available to read.' \
                % (self.DATA_LENGTH_BYTES))
        sample = Sample(
            [LittleEndian.bytes_to_int32(data, offset) / self.SCALE_FACTOR],
            self.get_fields_description(),
            timestamp)
        return ExtractedData(sample, self.DATA_LENGTH_BYTES)
    def extract_data(self, timestamp, data, offset):
        """Extract the audio sync data from the feature's raw data.
           In this case it reads a short integer (adpcm_index) and an integer
           (adpcm_predsample).

        Args:
            data (bytearray): The data read from the feature (a 6 bytes array).
            offset (int): Offset where to start reading data (0 by default).
        
        Returns:
            :class:`blue_st_sdk.feature.ExtractedData`: Container of the number
            of bytes read (6)  and the extracted data (audio sync info, a short
            and an int).

        Raises:
            :exc:`blue_st_sdk.utils.blue_st_exceptions.InvalidDataException`
                if the data array has not enough data to read.
        """
        if len(data) != self.DATA_LENGTH_BYTES:
            raise InvalidDataException(
                'There are no %d bytes available to read.' \
                % (self.DATA_LENGTH_BYTES))

        sample = Sample([
            LittleEndian.bytes_to_int16(data, 0),
            LittleEndian.bytes_to_int32(data, 2)
        ], self.get_fields_description(), None)
        return ExtractedData(sample, self.DATA_LENGTH_BYTES)
Exemple #3
0
    def update(self, data):
        """Update the value of the CRC.

        Size of data in bytes must be multiple of 4.

        Args:
            data (bytearray): Data to compute the CRC value of.

        Raises:
            :exc:`ValueError` if the length of the data is not multiple of 4.
        """
        if len(data) % 4 != 0:
            raise ValueError('Size of data to compute the CRC on must be \
                multiple of 4 [bytes].')

        for i in range(0, len(data), 4):
            tmp = LittleEndian.bytes_to_int32(data, i * 4)
            self._current_crc = self._crc32_fast(self._current_crc, tmp)