esp-nimble-cpp  1.4.1
NimBLEDescriptor Class Reference

A model of a BLE descriptor. More...

Inherited by NimBLE2904.

Public Member Functions

 NimBLEDescriptor (const char *uuid, uint16_t properties, uint16_t max_len, NimBLECharacteristic *pCharacteristic=nullptr)
 Construct a descriptor. More...
 
 NimBLEDescriptor (NimBLEUUID uuid, uint16_t properties, uint16_t max_len, NimBLECharacteristic *pCharacteristic=nullptr)
 Construct a descriptor. More...
 
 ~NimBLEDescriptor ()
 NimBLEDescriptor destructor.
 
uint16_t getHandle ()
 Get the BLE handle for this descriptor. More...
 
NimBLEUUID getUUID ()
 Get the UUID of the descriptor.
 
std::string toString ()
 Return a string representation of the descriptor. More...
 
void setCallbacks (NimBLEDescriptorCallbacks *pCallbacks)
 Set the callback handlers for this descriptor. More...
 
NimBLECharacteristicgetCharacteristic ()
 Get the characteristic this descriptor belongs to. More...
 
size_t getLength ()
 Get the length of the value of this descriptor. More...
 
NimBLEAttValue getValue (time_t *timestamp=nullptr)
 Get the value of this descriptor. More...
 
std::string getStringValue ()
 Get the value of this descriptor as a string. More...
 
void setValue (const uint8_t *data, size_t size)
 Set the value of the descriptor. More...
 
void setValue (const std::vector< uint8_t > &vec)
 Set the value of the descriptor from a std::vector<uint8_t>.
. More...
 
template<typename T >
void setValue (const T &s)
 Template to set the characteristic value to <type>val. More...
 
template<typename T >
getValue (time_t *timestamp=nullptr, bool skipSizeCheck=false)
 Template to convert the descriptor data to <type>. More...
 

Detailed Description

A model of a BLE descriptor.

Constructor & Destructor Documentation

◆ NimBLEDescriptor() [1/2]

NimBLEDescriptor::NimBLEDescriptor ( const char *  uuid,
uint16_t  properties,
uint16_t  max_len,
NimBLECharacteristic pCharacteristic = nullptr 
)

Construct a descriptor.

Parameters
[in]uuid- UUID (const char*) for the descriptor.
[in]properties- Properties for the descriptor.
[in]max_len- The maximum length in bytes that the descriptor value can hold. (Default: 512 bytes for esp32, 20 for all others).
[in]pCharacteristic- pointer to the characteristic instance this descriptor belongs to.

◆ NimBLEDescriptor() [2/2]

NimBLEDescriptor::NimBLEDescriptor ( NimBLEUUID  uuid,
uint16_t  properties,
uint16_t  max_len,
NimBLECharacteristic pCharacteristic = nullptr 
)

Construct a descriptor.

Parameters
[in]uuid- UUID (const char*) for the descriptor.
[in]properties- Properties for the descriptor.
[in]max_len- The maximum length in bytes that the descriptor value can hold. (Default: 512 bytes for esp32, 20 for all others).
[in]pCharacteristic- pointer to the characteristic instance this descriptor belongs to.

Member Function Documentation

◆ getCharacteristic()

NimBLECharacteristic * NimBLEDescriptor::getCharacteristic ( )

Get the characteristic this descriptor belongs to.

Returns
A pointer to the characteristic this descriptor belongs to.

◆ getHandle()

uint16_t NimBLEDescriptor::getHandle ( )

Get the BLE handle for this descriptor.

Returns
The handle for this descriptor.

◆ getLength()

size_t NimBLEDescriptor::getLength ( )

Get the length of the value of this descriptor.

Returns
The length (in bytes) of the value of this descriptor.

◆ getStringValue()

std::string NimBLEDescriptor::getStringValue ( )

Get the value of this descriptor as a string.

Returns
A std::string instance containing a copy of the descriptor's value.

◆ getValue() [1/2]

NimBLEAttValue NimBLEDescriptor::getValue ( time_t *  timestamp = nullptr)

Get the value of this descriptor.

Returns
The NimBLEAttValue of this descriptor.

◆ getValue() [2/2]

template<typename T >
T NimBLEDescriptor::getValue ( time_t *  timestamp = nullptr,
bool  skipSizeCheck = false 
)
inline

Template to convert the descriptor data to <type>.

Template Parameters
TThe type to convert the data to.
Parameters
[in]timestamp(Optional) A pointer to a time_t struct to store the time the value was read.
[in]skipSizeCheck(Optional) If true it will skip checking if the data size is less than sizeof(<type>).
Returns
The data converted to <type> or NULL if skipSizeCheck is false and the data is less than sizeof(<type>).

Use: getValue<type>(&timestamp, skipSizeCheck);

◆ setCallbacks()

void NimBLEDescriptor::setCallbacks ( NimBLEDescriptorCallbacks pCallbacks)

Set the callback handlers for this descriptor.

Parameters
[in]pCallbacksAn instance of a callback structure used to define any callbacks for the descriptor.

◆ setValue() [1/3]

void NimBLEDescriptor::setValue ( const std::vector< uint8_t > &  vec)

Set the value of the descriptor from a std::vector<uint8_t>.
.

Parameters
[in]vecThe std::vector<uint8_t> reference to set the descriptor value from.

◆ setValue() [2/3]

template<typename T >
void NimBLEDescriptor::setValue ( const T &  s)
inline

Template to set the characteristic value to <type>val.

Parameters
[in]sThe value to set.

◆ setValue() [3/3]

void NimBLEDescriptor::setValue ( const uint8_t *  data,
size_t  length 
)

Set the value of the descriptor.

Parameters
[in]dataThe data to set for the descriptor.
[in]lengthThe length of the data in bytes.

◆ toString()

std::string NimBLEDescriptor::toString ( )

Return a string representation of the descriptor.

Returns
A string representation of the descriptor.