blue_st_sdk.utils package

Submodules

blue_st_sdk.utils.ble_node_definitions module

ble_node_definitions

The ble_node_definitions module contains definitions related to the Bluetooth and recognized by the BlueSTSDK.

class blue_st_sdk.utils.ble_node_definitions.BLENodeDefinitions[source]

Bases: object

This class helps to get the list of services and characteristics available in the BlueST devices.

It defines the UUID and the name of the services and the characteristics available in the BlueST devices.

BASE_FEATURE_UUID = '-0001'

Base feature UUID.

BLUESTSDK_CHARACTERISTIC_UUID = '-11e1-ac36-0002a5d5c51b'

Characteristic UUIDs handled by this SDK must end with this value.

BLUESTSDK_SERVICE_UUID = '-11e1-9ab4-0002a5d5c51b'

Service UUIDs handled by this SDK must end with this value.

CONFIG_UUID = '-000F'

Config UUID.

DEBUG_UUID = '-000E'

Debug UUID.

EXTENDED_FEATURE_UUID = '-0002'

Extended feature UUID.

class blue_st_sdk.utils.ble_node_definitions.Config[source]

Bases: object

Service that allows to configure device’s parameters or features.

CONFIG_BLUESTSDK_SERVICE_UUID = UUID('00000000-000f-11e1-9ab4-0002a5d5c51b')

Control service UUID.

CONFIG_COMMAND_BLUESTSDK_SERVICE_UUID = UUID('00000002-000f-11e1-9ab4-0002a5d5c51b')

Control characteristic UUID through which you can send commands to a feature.

REGISTERS_ACCESS_UUID = UUID('00000001-000f-11e1-9ab4-0002a5d5c51b')

Control characteristic UUID through which you can manage registers, i.e. to read or write registers.

classmethod is_config_service(uuid)[source]

Checking whether the provided UUID is a valid config service UUID.

Args:
uuid (str): Service UUID.
Returns:
bool: True if the provided UUID is a valid config service UUID, False otherwise.
class blue_st_sdk.utils.ble_node_definitions.Debug[source]

Bases: object

Class to access stdout/stderr streams.

DEBUG_BLUESTSDK_SERVICE_UUID = UUID('00000000-000e-11e1-9ab4-0002a5d5c51b')

Debug service UUID.

DEBUG_STDERR_BLUESTSDK_SERVICE_UUID = UUID('00000002-000e-11e1-ac36-0002a5d5c51b')

Debug characteristic UUID where the node writes error messages.

DEBUG_STDINOUT_BLUESTSDK_SERVICE_UUID = UUID('00000001-000e-11e1-ac36-0002a5d5c51b')

Debug characteristic UUID where you can read and write messages.

classmethod is_debug_characteristic(uuid)[source]

Checking whether the provided UUID is a valid debug characteristic UUID.

Args:
uuid (str): Characteristic UUID.
Returns:
bool: True if the provided UUID is a valid debug characteristic UUID, False otherwise.
classmethod is_debug_service(uuid)[source]

Checking whether the provided UUID is a valid debug service UUID.

Args:
uuid (str): Service UUID.
Returns:
bool: True if the provided UUID is a valid debug service UUID, False otherwise.
class blue_st_sdk.utils.ble_node_definitions.FeatureCharacteristic[source]

Bases: object

This class defines the associations characteristic-feature.

A feature’s characteristic has the form ‘XXXXXXXX-0001-11e1-ac36-0002a5d5c51b’.

‘XXXXXXXX’ is a number in which only one bit has value ‘1’. In case multiple bits have value ‘1’ it means that this characteristic sends all the corresponding features’ values at the same time.

BASE_MASK_TO_FEATURE_DIC = {4: <class 'blue_st_sdk.features.feature_proximity_gesture.FeatureProximityGesture'>, 16: <class 'blue_st_sdk.features.feature_activity_recognition.FeatureActivityRecognition'>, 8192: <class 'blue_st_sdk.features.feature_stepper_motor.FeatureStepperMotor'>, 65536: <class 'blue_st_sdk.features.feature_temperature.FeatureTemperature'>, 262144: <class 'blue_st_sdk.features.feature_temperature.FeatureTemperature'>, 524288: <class 'blue_st_sdk.features.feature_humidity.FeatureHumidity'>, 1048576: <class 'blue_st_sdk.features.feature_pressure.FeaturePressure'>, 2097152: <class 'blue_st_sdk.features.feature_magnetometer.FeatureMagnetometer'>, 4194304: <class 'blue_st_sdk.features.feature_gyroscope.FeatureGyroscope'>, 8388608: <class 'blue_st_sdk.features.feature_accelerometer.FeatureAccelerometer'>, 33554432: <class 'blue_st_sdk.features.feature_proximity.FeatureProximity'>, 134217728: <class 'blue_st_sdk.features.audio.adpcm.feature_audio_adpcm.FeatureAudioADPCM'>, 536870912: <class 'blue_st_sdk.features.feature_switch.FeatureSwitch'>, 1073741824: <class 'blue_st_sdk.features.audio.adpcm.feature_audio_adpcm_sync.FeatureAudioADPCMSync'>}

Map from base feature’s masks to feature’s classes.

BLUESTSDK_BASE_FEATURES_UUID = '-0001-11e1-ac36-0002a5d5c51b'

Base feature UUIDs handled by this SDK must end with this value.

BLUESTSDK_EXTENDED_FEATURES_UUID = '-0002-11e1-ac36-0002a5d5c51b'

Extended feature UUIDs handled by this SDK must end with this value.

EXTENDED_MASK_TO_FEATURE_DIC = {3: <class 'blue_st_sdk.features.feature_audio_scene_classification.FeatureAudioSceneClassification'>}

Map from extended feature’s masks to feature’s classes.

SENSOR_TILE_BOX_MASK_TO_FEATURE_DIC = {4: <class 'blue_st_sdk.features.feature_proximity_gesture.FeatureProximityGesture'>, 16: <class 'blue_st_sdk.features.feature_activity_recognition.FeatureActivityRecognition'>, 65536: <class 'blue_st_sdk.features.feature_temperature.FeatureTemperature'>, 262144: <class 'blue_st_sdk.features.feature_temperature.FeatureTemperature'>, 524288: <class 'blue_st_sdk.features.feature_humidity.FeatureHumidity'>, 1048576: <class 'blue_st_sdk.features.feature_pressure.FeaturePressure'>, 2097152: <class 'blue_st_sdk.features.feature_magnetometer.FeatureMagnetometer'>, 4194304: <class 'blue_st_sdk.features.feature_gyroscope.FeatureGyroscope'>, 8388608: <class 'blue_st_sdk.features.feature_accelerometer.FeatureAccelerometer'>, 33554432: <class 'blue_st_sdk.features.feature_proximity.FeatureProximity'>, 134217728: <class 'blue_st_sdk.features.audio.adpcm.feature_audio_adpcm.FeatureAudioADPCM'>, 536870912: <class 'blue_st_sdk.features.feature_switch.FeatureSwitch'>, 1073741824: <class 'blue_st_sdk.features.audio.adpcm.feature_audio_adpcm_sync.FeatureAudioADPCMSync'>}

Map from SensorTile.box feature’s masks to feature’s classes.

classmethod extract_feature_mask(uuid)[source]

“Extract the fist 32 bits from the characteristic’s UUID.

Args:
uuid (UUID): Characteristic’s UUID. Refer to UUID: for more information.
Returns:
int: The first 32 bit of the characteristic’s UUID.
classmethod get_extended_feature_class(uuid)[source]

Getting the extended feature class from a UUID.

Args:
uuid (UUID): Characteristic’s UUID. Refer to UUID: for more information.
Returns:
type: The feature’s class if found, “None” otherwise.
classmethod is_base_feature_characteristic(uuid)[source]

Checking whether the UUID is a valid feature UUID.

Args:
uuid (str): Characteristic’s UUID.
Returns:
bool: True if the UUID is a valid feature UUID, False otherwise.
classmethod is_extended_feature_characteristic(uuid)[source]

Checking whether the UUID is a valid extended feature UUID.

Args:
uuid (str): Characteristic’s UUID.
Returns:
bool: True if the UUID is a valid extended feature UUID, False otherwise.
class blue_st_sdk.utils.ble_node_definitions.Services[source]

Bases: object

This class helps to get list of services available in the BlueST devices.

It defines the UUID and the name of the services available in the BlueST devices.

A valid service UUID has the form ‘00000000-XXXX-11e1-9ab4-0002a5d5c51b’, where ‘XXXX’ is the service identifier.

BLUESTSDK_SERVICE_UUID_FORMAT = '00000000-[0-9a-fA-F]{4}-11e1-9ab4-0002a5d5c51b'

Format of the blue_st_sdk’s service UUID.

classmethod is_known_service(uuid)[source]

Checking whether the service is handled by this SDK, i.e. if the uuid has the ‘00000000-YYYY-11e1-9ab4-0002a5d5c51b’ format.

Args:
uuid (str): UUID of the service under test.
Returns:
bool: True if the UUID ends with blue_st_sdk.utils.ble_node_definitions.BLENodeDefinitions.BLUESTSDK_SERVICE_UUID, False otherwise.

blue_st_sdk.utils.blue_st_exceptions module

blue_st_exceptions

The blue_st_exceptions module defines exceptions raised by the BlueSTSDK.

exception blue_st_sdk.utils.blue_st_exceptions.BlueSTInvalidAdvertisingDataException(msg)[source]

Bases: exceptions.Exception

Exception raised whenever an advertising data has a format not recognized by the BlueSTSDK.

__init__(msg)[source]

Constructor

Args:
msg (str): The message to raise.
exception blue_st_sdk.utils.blue_st_exceptions.BlueSTInvalidDataException(msg)[source]

Bases: exceptions.Exception

Exception raised whenever a feature’s data are not complete.

__init__(msg)[source]

Constructor

Args:
msg (str): The message to raise.
exception blue_st_sdk.utils.blue_st_exceptions.BlueSTInvalidFeatureBitMaskException(msg)[source]

Bases: exceptions.Exception

Exception raised whenever a bitmask has more than 1 bit set to “1”.

__init__(msg)[source]

Constructor

Args:
msg (str): The message to raise.
exception blue_st_sdk.utils.blue_st_exceptions.BlueSTInvalidOperationException(msg)[source]

Bases: exceptions.Exception

Exception raised whenever the operation requested is not supported.

__init__(msg)[source]

Constructor

Args:
msg (str): The message to raise.

blue_st_sdk.utils.dict_put_single_element module

dict_put_single_element

The dict_put_single_element module contains tools to map keys to list of elements.

class blue_st_sdk.utils.dict_put_single_element.DictPutSingleElement(*args, **kwargs)[source]

Bases: _abcoll.MutableMapping

Utility class to map keys to list of elements.

It works like a dictionary with an exception: the “put()” method inserts a single element at a time instead of a list of elements.

__init__(*args, **kwargs)[source]

Constructor.

put(key, value)[source]

Add a single element to the list associated to the given key.

Args:
key: Key. value: Element to be added to the list of elements associated to the given key.
put_all(dictionary)[source]

Add all the key-value pairs of the given dictionary to this dictionary.

Args:
dictionary (dict): A dictionary of key-value pairs to be added.

blue_st_sdk.utils.number_conversion module

number_conversion

The number_conversion module contains tools to convert features’ data to numbers.

class blue_st_sdk.utils.number_conversion.BigEndian[source]

Bases: object

This class implements the conversion from array of bytes to different formats, and viceversa, in Big Endian base order.

classmethod bytes_to_float(data, start=0)[source]

Return the floating point value of four bytes of the array in Big Endian base order.

Args:
data (str): Input array of bytes that contains the value to convert. start (int): Start index in the array of the value to convert.
Returns:
The corresponding numerical value.
classmethod bytes_to_int16(data, start=0)[source]

Return the signed short value of two bytes of the array in Big Endian base order.

Args:
data (str): Input array of bytes that contains the value to convert. start (int): Start index in the array of the value to convert.
Returns:
The corresponding numerical value.
classmethod bytes_to_int32(data, start=0)[source]

Return the signed integer value of four bytes of the array in Big Endian base order.

Args:
data (str): Input array of bytes that contains the value to convert. start (int): Start index in the array of the value to convert.
Returns:
The corresponding numerical value.
classmethod bytes_to_uint16(data, start=0)[source]

Return the unsigned short value of two bytes of the array in Big Endian base order.

Args:
data (str): Input array of bytes that contains the value to convert. start (int): Start index in the array of the value to convert.
Returns:
The corresponding numerical value.
classmethod bytes_to_uint32(data, start=0)[source]

Return the unsigned integer value of four bytes of the array in Big Endian base order.

Args:
data (str): Input array of bytes that contains the value to convert. start (int): Start index in the array of the value to convert.
Returns:
The corresponding numerical value.
classmethod float_to_bytes(value)[source]

Return the four bytes array corresponding to the floating point value in Big Endian base order.

Args:
value (int): Value to convert.
Returns:
The corresponding array of bytes.
classmethod int16_to_bytes(value)[source]

Return the two bytes array corresponding to the signed short value in Big Endian base order.

Args:
value (int): Value to convert.
Returns:
The corresponding array of bytes.
classmethod int32_to_bytes(value)[source]

Return the four bytes array corresponding to the signed integer value in Big Endian base order.

Args:
value (int): Value to convert.
Returns:
The corresponding array of bytes.
classmethod uint16_to_bytes(value)[source]

Return the two bytes array corresponding to the unsigned short value in Big Endian base order.

Args:
value (int): Value to convert.
Returns:
The corresponding array of bytes.
classmethod uint32_to_bytes(value)[source]

Return the four bytes array corresponding to the unsigned integer value in Big Endian base order.

Args:
value (int): Value to convert.
Returns:
The corresponding array of bytes.
class blue_st_sdk.utils.number_conversion.LittleEndian[source]

Bases: object

This class implements the conversion from array of bytes to different formats, and viceversa, in Little Endian base order.

classmethod bytes_to_float(data, start=0)[source]

Return the floating point value of four bytes of the array in Little Endian base order.

Args:
data (str): Input array of bytes that contains the value to convert. start (int): Start index in the array of the value to convert.
Returns:
The corresponding numerical value.
classmethod bytes_to_int16(data, start=0)[source]

Return the signed short value of two bytes of the array in Little Endian base order.

Args:
data (str): Input array of bytes that contains the value to convert. start (int): Start index in the array of the value to convert.
Returns:
The corresponding numerical value.
classmethod bytes_to_int32(data, start=0)[source]

Return the signed integer value of four bytes of the array in Little Endian base order.

Args:
data (str): Input array of bytes that contains the value to convert. start (int): Start index in the array of the value to convert.
Returns:
The corresponding numerical value.
classmethod bytes_to_uint16(data, start=0)[source]

Return the unsigned short value of two bytes of the array in Little Endian base order.

Args:
data (str): Input array of bytes that contains the value to convert. start (int): Start index in the array of the value to convert.
Returns:
The corresponding numerical value.
classmethod bytes_to_uint32(data, start=0)[source]

Return the unsigned integer value of four bytes of the array in Little Endian base order.

Args:
data (str): Input array of bytes that contains the value to convert. start (int): Start index in the array of the value to convert.
Returns:
The corresponding numerical value.
classmethod float_to_bytes(value)[source]

Return the four bytes array corresponding to the floating point value in Little Endian base order.

Args:
value (float): Value to convert.
Returns:
The corresponding array of bytes.
classmethod int16_to_bytes(value)[source]

Return the two bytes array corresponding to the signed short value in Little Endian base order.

Args:
value (int): Value to convert.
Returns:
The corresponding array of bytes.
classmethod int32_to_bytes(value)[source]

Return the four bytes array corresponding to the signed integer value in Little Endian base order.

Args:
value (int): Value to convert.
Returns:
The corresponding array of bytes.
classmethod uint16_to_bytes(value)[source]

Return the two bytes array corresponding to the unsigned short value in Little Endian base order.

Args:
value (int): Value to convert.
Returns:
The corresponding array of bytes.
classmethod uint32_to_bytes(value)[source]

Return the four bytes array corresponding to the unsigned integer value in Little Endian base order.

Args:
value (int): Value to convert.
Returns:
The corresponding array of bytes.
class blue_st_sdk.utils.number_conversion.NumberConversion[source]

Bases: object

This class helps to convert array of bytes to different formats, and viceversa.

classmethod byte_to_uint8(data, index=0)[source]

Returns the short value of the unsigned byte value in position “index”.

Args:
data (str): Array of bytes that contains the value to convert. index (int): Position of the value to convert.
Returns:
int: The corresponding numerical value.

blue_st_sdk.utils.python_utils module

python_utils

The python_utils module defines utility functions related to the Python language.

blue_st_sdk.utils.python_utils.get_class(class_name)[source]

Get a class from the class name throuth the ‘reflection’ property.

blue_st_sdk.utils.python_utils.lock(self)[source]

To be used to gain exclusive access to a block of code from different threads.

blue_st_sdk.utils.python_utils.lock_for_object(obj, locks={})[source]

To be used to gain exclusive access to a shared object from different threads.

blue_st_sdk.utils.python_utils.synchronized(call)[source]

To be used to synchronize a method called on the same object from different threads.

blue_st_sdk.utils.python_utils.synchronized_with_attr(lock_name)[source]

To be used to synchronize a method called on the same object from different threads.

blue_st_sdk.utils.unwrap_timestamp module

unwrap_timestamp

The unwrap_timestamp module contains tools to unwrap timestamp values.

class blue_st_sdk.utils.unwrap_timestamp.UnwrapTimestamp[source]

Bases: object

Class that unwraps a timestamp.

__init__()[source]

Constructor.

unwrap(**kwds)[source]

Add a multiple of (1 << 16) to the timestamp to reset it, if needed.

Args:
timestamp (int): Timestamp.
Returns:
int: The unwrapped timestamp.

blue_st_sdk.utils.uuid_to_feature_map module

uuid_to_feature_map

The uuid_to_feature_map module contains tools to map UUIDs to list of features.

class blue_st_sdk.utils.uuid_to_feature_map.UUIDToFeatureMap[source]

Bases: blue_st_sdk.utils.dict_put_single_element.DictPutSingleElement

Utility class to map UUIDs to list of features.

It works like a dictionary with an exception: the “put()” method inserts a single feature at a time instead of a list of features.

__init__()[source]

Constructor.

Module contents