Exemplo n.º 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.BlueSTInvalidDataException`
                if the data array has not enough data to read.
        """
        if len(data) - offset < self.DATA_LENGTH_BYTES:
            raise BlueSTInvalidDataException(
                'There are no %d bytes available to read.' \
                % (self.DATA_LENGTH_BYTES))
        sample = None
        value = LittleEndian.bytes_to_uint16(data, offset)
        if self._is_low_range_sensor(value):
            sample = self._get_low_range_sample(timestamp, value)
        else:
            sample = self._get_high_range_sample(timestamp, value)
        return ExtractedData(sample, self.DATA_LENGTH_BYTES)
    def extract_data(self, timestamp, data, offset):
        """Extract the data from the feature's raw data.

        Args:
            data (bytearray): The data read from the feature (a 20 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 decoded bytes, 20 bytes per packet (None until an opus packet has 
            been reconstructed, then filled with the 320 decoded shorts array).

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

        data_byte = bytearray(data)

        data_pkt = self.mBVOpusProtocolManager.getDecodedPacket(data_byte)

        sample = Sample(data_pkt, self.get_fields_description(), None)
        return ExtractedData(sample, len(data_byte))
    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.BlueSTInvalidDataException`
                if the data array has not enough data to read.
        """
        if len(data) - offset < self.DATA_LENGTH_BYTES:
            raise BlueSTInvalidDataException(
                'There are no %s bytes available to read.' \
                % (self.DATA_LENGTH_BYTES))
        sample = Sample([
            LittleEndian.bytes_to_int16(data, offset),
            LittleEndian.bytes_to_int16(data, offset + 2),
            LittleEndian.bytes_to_int16(data, offset + 4)
        ], self.get_fields_description(), timestamp)
        return ExtractedData(sample, self.DATA_LENGTH_BYTES)
    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.BlueSTInvalidDataException`
                if the data array has not enough data to read.
        """
        if len(data) - offset < self.DATA_LENGTH_BYTES:
            raise BlueSTInvalidDataException(
                'There is no %s byte available to read.' \
                % (self.DATA_LENGTH_BYTES))
        if len(data) - offset == self.DATA_LENGTH_BYTES:
            # Extract the activity from the feature's raw data.
            sample = Sample(
                [NumberConversion.byte_to_uint8(data, offset),
                 datetime.now()], self.get_fields_description(), timestamp)
            return ExtractedData(sample, self.DATA_LENGTH_BYTES)
        else:
            # Extract the activity and the algorithm from the feature's raw data.
            sample = Sample([
                NumberConversion.byte_to_uint8(data, offset),
                datetime.now(),
                NumberConversion.byte_to_uint8(data, offset + 1)
            ], self.get_fields_description(), timestamp)
            return ExtractedData(sample, self.DATA_LENGTH_BYTES + 1)
Exemplo n.º 5
0
    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.BlueSTInvalidDataException`
                if the data array has not enough data to read.
        """
        if len(data) != self.DATA_LENGTH_BYTES:
            raise BlueSTInvalidDataException(
                '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)
    def extract_data(self, timestamp, data, offset):
        """Extract the data from the feature's raw data.

        Args:
            data (bytearray): The data read from the feature (a 20 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 (20)  and the extracted data (audio info, the 40
            shorts array).

        Raises:
            :exc:`blue_st_sdk.utils.blue_st_exceptions.BlueSTInvalidDataException`
                if the data array has not enough data to read.
        """
        if len(data) != self.DATA_LENGTH_BYTES:
            raise BlueSTInvalidDataException(
                'There are no %d bytes available to read.' \
                % (self.DATA_LENGTH_BYTES))
        
        data_byte = bytearray(data)
        
        data_pkt = [None] * self.AUDIO_PACKAGE_SIZE
        for x in range(0, int(self.AUDIO_PACKAGE_SIZE / 2)):
            data_pkt[2*x] = self.engine_adpcm.decode((data_byte[x] & 0x0F), \
                self.bv_sync_manager)
            data_pkt[(2*x)+1] = self.engine_adpcm.decode(((data_byte[x] >> 4) \
                & 0x0F), self.bv_sync_manager)
        
        sample = Sample(
            data_pkt,
            self.get_fields_description(),
            None)
        return ExtractedData(sample, self.DATA_LENGTH_BYTES)
    def extract_data(self, timestamp, data, offset):
        """Extract the data from the feature's raw data.
        In this case it reads a 16-bit signed integer value.

        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.BlueSTInvalidDataException`
                if the data array has not enough data to read.
        """
        if (len(data) - offset < self.DATA_LENGTH_BYTES):
            raise BlueSTInvalidDataException(
                'There are no %d bytes available to read.' \
                % (self.DATA_LENGTH_BYTES))

        offset = offset
        flags = data[offset]
        offset += 1

        if self.has8BitHeartRate(flags):
            hr = data[offset]
            offset += 1
        else:
            hr = LittleEndian.bytes_to_uint16(data, offset)
            offset += 2

        if self.hasEnergyExpended(flags):
            ee = LittleEndian.bytes_to_uint16(data, offset)
            offset += 2
        else:
            ee = -1

        if self.hasRRInterval(flags):
            rri = LittleEndian.bytes_to_uint16(data, offset) / 1024.0
            offset += 2
        else:
            rri = float('nan')

        return ExtractedData(
            Sample(timestamp, [hr, ee, rri], getFieldsDescription()),
            offset - offset)
    def extract_data(self, timestamp, data, offset):
        """Extract the beamforming direction from the node raw data, it will
           read a uint8 containing the beamforming direction value.
        
        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:`Exception` if the data array has not enough data to read.
        """
        if len(data) - offset < self.DATA_LENGTH_BYTES:
            raise BlueSTInvalidDataException('There are no %d bytes available to read.' \
                % (self.DATA_LENGTH_BYTES))
        sample = Sample([NumberConversion.byteToUInt8(data, offset)],
                        self.get_fields_description(), timestamp)
        return ExtractedData(sample, self.DATA_LENGTH_BYTES)