esp-nimble-cpp 2.0.2
|
The model of a BLE Characteristic. More...
#include <NimBLECharacteristic.h>
Inherits NimBLELocalValueAttribute.
Public Member Functions | |
NimBLECharacteristic (const char *uuid, uint16_t properties=NIMBLE_PROPERTY::READ|NIMBLE_PROPERTY::WRITE, uint16_t maxLen=BLE_ATT_ATTR_MAX_LEN, NimBLEService *pService=nullptr) | |
Construct a characteristic. | |
NimBLECharacteristic (const NimBLEUUID &uuid, uint16_t properties=NIMBLE_PROPERTY::READ|NIMBLE_PROPERTY::WRITE, uint16_t maxLen=BLE_ATT_ATTR_MAX_LEN, NimBLEService *pService=nullptr) | |
Construct a characteristic. | |
~NimBLECharacteristic () | |
Destructor. | |
std::string | toString () const |
Return a string representation of the characteristic. | |
void | addDescriptor (NimBLEDescriptor *pDescriptor) |
Add a descriptor to the characteristic. | |
void | removeDescriptor (NimBLEDescriptor *pDescriptor, bool deleteDsc=false) |
Remove a descriptor from the characteristic. | |
uint16_t | getProperties () const |
Get the properties of the characteristic. | |
void | setCallbacks (NimBLECharacteristicCallbacks *pCallbacks) |
Set the callback handlers for this characteristic. | |
bool | indicate (uint16_t connHandle=BLE_HS_CONN_HANDLE_NONE) const |
Send an indication. | |
bool | indicate (const uint8_t *value, size_t length, uint16_t connHandle=BLE_HS_CONN_HANDLE_NONE) const |
Send an indication. | |
bool | notify (uint16_t connHandle=BLE_HS_CONN_HANDLE_NONE) const |
Send a notification. | |
bool | notify (const uint8_t *value, size_t length, uint16_t connHandle=BLE_HS_CONN_HANDLE_NONE) const |
Send a notification. | |
NimBLEDescriptor * | createDescriptor (const char *uuid, uint32_t properties=NIMBLE_PROPERTY::READ|NIMBLE_PROPERTY::WRITE, uint16_t maxLen=BLE_ATT_ATTR_MAX_LEN) |
Create a new BLE Descriptor associated with this characteristic. | |
NimBLEDescriptor * | createDescriptor (const NimBLEUUID &uuid, uint32_t properties=NIMBLE_PROPERTY::READ|NIMBLE_PROPERTY::WRITE, uint16_t maxLen=BLE_ATT_ATTR_MAX_LEN) |
Create a new BLE Descriptor associated with this characteristic. | |
NimBLE2904 * | create2904 () |
Create a Characteristic Presentation Format Descriptor for this characteristic. | |
NimBLEDescriptor * | getDescriptorByUUID (const char *uuid) const |
Return the BLE Descriptor for the given UUID. | |
NimBLEDescriptor * | getDescriptorByUUID (const NimBLEUUID &uuid) const |
Return the BLE Descriptor for the given UUID. | |
NimBLEDescriptor * | getDescriptorByHandle (uint16_t handle) const |
Return the BLE Descriptor for the given handle. | |
NimBLEService * | getService () const |
Get the service that owns this characteristic. | |
NimBLECharacteristicCallbacks * | getCallbacks () const |
Get the callback handlers for this characteristic. | |
template<typename T > | |
bool | notify (const T &v, uint16_t connHandle=BLE_HS_CONN_HANDLE_NONE) const |
Template to send a notification with a value from a struct or array. | |
template<typename T > | |
bool | notify (const T &s, uint16_t connHandle=BLE_HS_CONN_HANDLE_NONE) const |
Template to send a notification with a value from a class that has a c_str() and length() method. | |
template<typename T > | |
bool | notify (const T &v, uint16_t connHandle=BLE_HS_CONN_HANDLE_NONE) const |
Template to send a notification with a value from a class that has a data() and size() method. | |
template<typename T > | |
bool | indicate (const T &v, uint16_t connHandle=BLE_HS_CONN_HANDLE_NONE) const |
Template to send an indication with a value from a struct or array. | |
template<typename T > | |
bool | indicate (const T &s, uint16_t connHandle=BLE_HS_CONN_HANDLE_NONE) const |
Template to send a indication with a value from a class that has a c_str() and length() method. | |
template<typename T > | |
bool | indicate (const T &v, uint16_t connHandle=BLE_HS_CONN_HANDLE_NONE) const |
Template to send a indication with a value from a class that has a data() and size() method. | |
The model of a BLE Characteristic.
A BLE Characteristic is an identified value container that manages a value. It is exposed by a BLE service and can be read and written to by a BLE client.
NimBLECharacteristic::NimBLECharacteristic | ( | const char * | uuid, |
uint16_t | properties = NIMBLE_PROPERTY::READ | NIMBLE_PROPERTY::WRITE , |
||
uint16_t | maxLen = BLE_ATT_ATTR_MAX_LEN , |
||
NimBLEService * | pService = nullptr |
||
) |
Construct a characteristic.
[in] | uuid | - UUID (const char*) for the characteristic. |
[in] | properties | - Properties for the characteristic. |
[in] | maxLen | - The maximum length in bytes that the characteristic value can hold. (Default: 512 bytes for esp32, 20 for all others). |
[in] | pService | - pointer to the service instance this characteristic belongs to. |
NimBLECharacteristic::NimBLECharacteristic | ( | const NimBLEUUID & | uuid, |
uint16_t | properties = NIMBLE_PROPERTY::READ | NIMBLE_PROPERTY::WRITE , |
||
uint16_t | maxLen = BLE_ATT_ATTR_MAX_LEN , |
||
NimBLEService * | pService = nullptr |
||
) |
Construct a characteristic.
[in] | uuid | - UUID for the characteristic. |
[in] | properties | - Properties for the characteristic. |
[in] | maxLen | - The maximum length in bytes that the characteristic value can hold. (Default: 512 bytes for esp32, 20 for all others). |
[in] | pService | - pointer to the service instance this characteristic belongs to. |
void NimBLECharacteristic::addDescriptor | ( | NimBLEDescriptor * | pDescriptor | ) |
Add a descriptor to the characteristic.
[in] | pDescriptor | A pointer to the descriptor to add. |
NimBLE2904 * NimBLECharacteristic::create2904 | ( | ) |
Create a Characteristic Presentation Format Descriptor for this characteristic.
NimBLEDescriptor * NimBLECharacteristic::createDescriptor | ( | const char * | uuid, |
uint32_t | properties = NIMBLE_PROPERTY::READ | NIMBLE_PROPERTY::WRITE , |
||
uint16_t | maxLen = BLE_ATT_ATTR_MAX_LEN |
||
) |
Create a new BLE Descriptor associated with this characteristic.
[in] | uuid | - The UUID of the descriptor. |
[in] | properties | - The properties of the descriptor. |
[in] | maxLen | - The max length in bytes of the descriptor value. |
NimBLEDescriptor * NimBLECharacteristic::createDescriptor | ( | const NimBLEUUID & | uuid, |
uint32_t | properties = NIMBLE_PROPERTY::READ | NIMBLE_PROPERTY::WRITE , |
||
uint16_t | maxLen = BLE_ATT_ATTR_MAX_LEN |
||
) |
Create a new BLE Descriptor associated with this characteristic.
[in] | uuid | - The UUID of the descriptor. |
[in] | properties | - The properties of the descriptor. |
[in] | maxLen | - The max length in bytes of the descriptor value. |
NimBLEDescriptor * NimBLECharacteristic::getDescriptorByHandle | ( | uint16_t | handle | ) | const |
Return the BLE Descriptor for the given handle.
[in] | handle | The handle of the descriptor. |
NimBLEDescriptor * NimBLECharacteristic::getDescriptorByUUID | ( | const char * | uuid | ) | const |
Return the BLE Descriptor for the given UUID.
[in] | uuid | The UUID of the descriptor. |
NimBLEDescriptor * NimBLECharacteristic::getDescriptorByUUID | ( | const NimBLEUUID & | uuid | ) | const |
Return the BLE Descriptor for the given UUID.
[in] | uuid | The UUID of the descriptor. |
uint16_t NimBLECharacteristic::getProperties | ( | ) | const |
Get the properties of the characteristic.
|
inline |
Template to send a indication with a value from a class that has a c_str() and length() method.
[in] | s | The value to send. |
[in] | connHandle | Optional, a connection handle to send the notification to. |
|
inline |
Template to send an indication with a value from a struct or array.
[in] | v | The value to send. |
[in] | connHandle | Optional, a connection handle to send the notification to. |
<type> size must be evaluatable by sizeof()
.
|
inline |
Template to send a indication with a value from a class that has a data() and size() method.
[in] | v | The value to send. |
[in] | connHandle | Optional, a connection handle to send the notification to. |
bool NimBLECharacteristic::indicate | ( | const uint8_t * | value, |
size_t | length, | ||
uint16_t | connHandle = BLE_HS_CONN_HANDLE_NONE |
||
) | const |
Send an indication.
[in] | value | A pointer to the data to send. |
[in] | length | The length of the data to send. |
[in] | connHandle | Connection handle to send an individual indication, or BLE_HS_CONN_HANDLE_NONE to send the indication to all subscribed clients. |
bool NimBLECharacteristic::indicate | ( | uint16_t | connHandle = BLE_HS_CONN_HANDLE_NONE | ) | const |
Send an indication.
[in] | connHandle | Connection handle to send an individual indication, or BLE_HS_CONN_HANDLE_NONE to send the indication to all subscribed clients. |
|
inline |
Template to send a notification with a value from a class that has a c_str() and length() method.
[in] | s | The value to send. |
[in] | connHandle | Optional, a connection handle to send the notification to. |
|
inline |
Template to send a notification with a value from a struct or array.
[in] | v | The value to send. |
[in] | connHandle | Optional, a connection handle to send the notification to. |
<type> size must be evaluatable by sizeof()
.
|
inline |
Template to send a notification with a value from a class that has a data() and size() method.
[in] | v | The value to send. |
[in] | connHandle | Optional, a connection handle to send the notification to. |
bool NimBLECharacteristic::notify | ( | const uint8_t * | value, |
size_t | length, | ||
uint16_t | connHandle = BLE_HS_CONN_HANDLE_NONE |
||
) | const |
Send a notification.
[in] | value | A pointer to the data to send. |
[in] | length | The length of the data to send. |
[in] | connHandle | Connection handle to send an individual notification, or BLE_HS_CONN_HANDLE_NONE to send the notification to all subscribed clients. |
bool NimBLECharacteristic::notify | ( | uint16_t | connHandle = BLE_HS_CONN_HANDLE_NONE | ) | const |
Send a notification.
[in] | connHandle | Connection handle to send an individual notification, or BLE_HS_CONN_HANDLE_NONE to send the notification to all subscribed clients. |
void NimBLECharacteristic::removeDescriptor | ( | NimBLEDescriptor * | pDescriptor, |
bool | deleteDsc = false |
||
) |
Remove a descriptor from the characteristic.
[in] | pDescriptor | A pointer to the descriptor instance to remove from the characteristic. |
[in] | deleteDsc | If true it will delete the descriptor instance and free it's resources. |
void NimBLECharacteristic::setCallbacks | ( | NimBLECharacteristicCallbacks * | pCallbacks | ) |
Set the callback handlers for this characteristic.
[in] | pCallbacks | An instance of a NimBLECharacteristicCallbacks class used to define any callbacks for the characteristic. |
std::string NimBLECharacteristic::toString | ( | ) | const |
Return a string representation of the characteristic.