Representation of a characteristic discovered. More...
#include <DiscoveredCharacteristic.h>
Data Structures | |
struct | Properties_t |
Properties of a discovered characteristic. More... | |
Public Member Functions | |
ble_error_t | read (uint16_t offset=0) const |
Initiate a read of the characteristic value. More... | |
ble_error_t | read (uint16_t offset, const ble::ReadCallback_t &onRead) const |
Initiate a read of the characteristic value and pass the response to its completion callback. More... | |
ble_error_t | writeWoResponse (uint16_t length, const uint8_t *value) const |
Perform a write without response procedure. More... | |
ble_error_t | discoverDescriptors (const CharacteristicDescriptorDiscovery::DiscoveryCallback_t &onDescriptorDiscovered, const CharacteristicDescriptorDiscovery::TerminationCallback_t &onTermination) const |
Initiate a discovery of the characteristic descriptors. More... | |
ble_error_t | write (uint16_t length, const uint8_t *value) const |
Initiate a write procedure of the characteristic value. More... | |
ble_error_t | write (uint16_t length, const uint8_t *value, const ble::WriteCallback_t &onWrite) const |
Initiate a write procedure of the characteristic value. More... | |
const UUID & | getUUID () const |
Get the UUID of the discovered characteristic. More... | |
const Properties_t & | getProperties () const |
Get the properties of this characteristic. More... | |
GattAttribute::Handle_t | getDeclHandle () const |
Get the declaration handle of this characteristic. More... | |
GattAttribute::Handle_t | getValueHandle () const |
Get the attribute handle of the characteristic value. More... | |
GattAttribute::Handle_t | getLastHandle () const |
Return the last attribute handle of the characteristic definition. More... | |
ble::GattClient * | getGattClient () |
Get the ble::GattClient, which can operate on this characteristic. More... | |
const ble::GattClient * | getGattClient () const |
Get the ble::GattClient, which can operate on this characteristic. More... | |
ble::connection_handle_t | getConnectionHandle () const |
Get the connection handle to the GattServer containing this characteristic. More... | |
Protected Attributes | |
ble::GattClient * | gattc |
Pointer to the underlying ble::GattClient for this DiscoveredCharacteristic object. More... | |
UUID | uuid |
Discovered characteristic's UUID. More... | |
Properties_t | props |
Hold the configured properties of the discovered characteristic. More... | |
GattAttribute::Handle_t | declHandle |
Value handle of the discovered characteristic's declaration attribute. More... | |
GattAttribute::Handle_t | valueHandle |
Value handle of the discovered characteristic's value attribute. More... | |
GattAttribute::Handle_t | lastHandle |
Value handle of the discovered characteristic's last attribute. More... | |
ble::connection_handle_t | connHandle |
Handle of the connection where the characteristic was discovered. More... | |
Friends | |
bool | operator== (const DiscoveredCharacteristic &lhs, const DiscoveredCharacteristic &rhs) |
"Equal to" operator for DiscoveredCharacteristic. More... | |
bool | operator!= (const DiscoveredCharacteristic &lhs, const DiscoveredCharacteristic &rhs) |
"Not equal to" operator for DiscoveredCharacteristic. More... | |
Representation of a characteristic discovered.
The ble::GattClient discovery procedure initiated with ble::GattClient::launchServiceDiscovery() generates instances of this class.
It exposes the main attributes of the discovered characteristic:
It important to note that the value of the characteristic - if it is accessible - is not fetched at discovery time.
The main operations the class offers are reading, writing and discovering the descriptors of the characteristic discovered.
Reading a discovered characteristic can be accomplished in two different fashions:
If the user has a callback registered for the data read operation in the ble::GattClient, then a call to the read(uint16_t) function will initiate a read of the characteristic. Results of the operation will be pass on the callback registered by ble::GattClient::onDataRead(), which processes all the responses to read requests. The read request for a given characteristic can be identified by the connection handle and the attribute handle, which are present in GattReadCallbackParams.
Another overload (read(uint16_t, const ble::ReadCallback_t&)) of the read function accepts a completion callback as a last parameter. That completion callback will be invoked automatically once the response to the read request for that given characteristic has been received. However, convenience came at the expense of dynamic memory usage for the time of the transaction.
Similarly, two versions of the write() API are exposed. One where the user has to register a callback handling write response through the function ble::GattClient::onDataWritten() and another one that accepts a completion callback in input.
It is also possible to send a write command, which is not acknowledged by the peer server by using the function writeWoResponse().
Finally, descriptors of the characteristic can be discovered by invoking the function discoverDescriptors, which is shorthand for calling ble::GattClient::discoverCharacteristicDescriptors. That discovery is necessary to enable or disable characteristic notification or indication that is achieved by writing on the Client Characteristic Configuration Descriptor (CCCD).
Definition at line 94 of file gatt/DiscoveredCharacteristic.h.
ble_error_t discoverDescriptors | ( | const CharacteristicDescriptorDiscovery::DiscoveryCallback_t & | onDescriptorDiscovered, |
const CharacteristicDescriptorDiscovery::TerminationCallback_t & | onTermination | ||
) | const |
Initiate a discovery of the characteristic descriptors.
When a descriptor is discovered, the callback onDescriptorDiscovered is invoked with the descriptor discovered as parameter. When the process ends, the callback onTermination is invoked.
[in] | onDescriptorDiscovered | Callback is invoked when a descriptor is discovered. |
[in] | onTermination | Callback is invoked when the discovery process ends. |
ble::connection_handle_t getConnectionHandle | ( | ) | const |
Get the connection handle to the GattServer containing this characteristic.
Definition at line 545 of file gatt/DiscoveredCharacteristic.h.
GattAttribute::Handle_t getDeclHandle | ( | ) | const |
Get the declaration handle of this characteristic.
The declaration handle is the first handle of a characteristic definition. The value accessible at this handle contains the following informations:
Definition at line 480 of file gatt/DiscoveredCharacteristic.h.
ble::GattClient* getGattClient | ( | ) |
Get the ble::GattClient, which can operate on this characteristic.
Definition at line 523 of file gatt/DiscoveredCharacteristic.h.
const ble::GattClient* getGattClient | ( | ) | const |
Get the ble::GattClient, which can operate on this characteristic.
Definition at line 533 of file gatt/DiscoveredCharacteristic.h.
GattAttribute::Handle_t getLastHandle | ( | ) | const |
Return the last attribute handle of the characteristic definition.
The attribute layout of a characteristic definition is:
The last attribute handle is used internally to discover characteristic descriptors. The discovery operates on the range [ValueHandle + 1 : LastHandle].
Definition at line 513 of file gatt/DiscoveredCharacteristic.h.
const Properties_t& getProperties | ( | ) | const |
Get the properties of this characteristic.
Definition at line 460 of file gatt/DiscoveredCharacteristic.h.
const UUID& getUUID | ( | ) | const |
Get the UUID of the discovered characteristic.
Definition at line 450 of file gatt/DiscoveredCharacteristic.h.
GattAttribute::Handle_t getValueHandle | ( | ) | const |
Get the attribute handle of the characteristic value.
This handle is used to read or write the value of the characteristic.
Definition at line 492 of file gatt/DiscoveredCharacteristic.h.
ble_error_t read | ( | uint16_t | offset = 0 | ) | const |
Initiate a read of the characteristic value.
The characteristic value is read in its entirety from the value attribute of the characteristic.
Read responses will be passed to the callback registered in ble::GattClient::onDataRead(). Read responses to read requests that this function call initiates will have their GattReadCallbackParams::connHandle field equal to the value returned by getConnectionHandle() and their GattReadCallbackParams::handle field equal to the value returned by getValueHandle().
[in] | offset | The position - in the characteristic value bytes stream
|
ble_error_t read | ( | uint16_t | offset, |
const ble::ReadCallback_t & | onRead | ||
) | const |
Initiate a read of the characteristic value and pass the response to its completion callback.
[in] | offset | The position - in the characteristic value bytes stream
|
[in] | onRead | Completion callback which will accept the response of the read request. The callback is copied; it is unnecessary to keep it in memory after the call. |
ble_error_t write | ( | uint16_t | length, |
const uint8_t * | value | ||
) | const |
Initiate a write procedure of the characteristic value.
Unlike write without responses (see writeWoResponse()), an acknowledgment is expected for this procedure. The response of the peer GATT server to the write request is passed to callbacks registered in ble::GattClient::onDataWritten().
Similarly to read responses, responses to write request of this characteristic can be identified by their connection handle ( GattWriteCallbackParams::connHandle), which is equal to the value returned by getConnectionHandle() and their attribute handle ( GattWriteCallbackParams::handle), which is equal to the value returned by getValueHandle().
[in] | length | The amount of data being written. |
[in] | value | The bytes being written. |
ble_error_t write | ( | uint16_t | length, |
const uint8_t * | value, | ||
const ble::WriteCallback_t & | onWrite | ||
) | const |
Initiate a write procedure of the characteristic value.
Same as write(uint16_t, const uint8_t *) const but accepts a completion callback, which is invoked when the server response is received.
[in] | length | The amount of bytes to write. |
[in] | value | The bytes to write. |
[in] | onWrite | Continuation callback of the write procedure. |
ble_error_t writeWoResponse | ( | uint16_t | length, |
const uint8_t * | value | ||
) | const |
Perform a write without response procedure.
[in] | length | The amount of data being written. |
[in] | value | The bytes being written. |
|
friend |
"Not equal to" operator for DiscoveredCharacteristic.
[in] | lhs | The right hand side of the expression. |
[in] | rhs | The left hand side of the expression. |
Definition at line 578 of file gatt/DiscoveredCharacteristic.h.
|
friend |
"Equal to" operator for DiscoveredCharacteristic.
[in] | lhs | The left hand side of the equality expression. |
[in] | rhs | The right hand side of the equality expression. |
Definition at line 558 of file gatt/DiscoveredCharacteristic.h.
|
protected |
Handle of the connection where the characteristic was discovered.
Definition at line 633 of file gatt/DiscoveredCharacteristic.h.
|
protected |
Value handle of the discovered characteristic's declaration attribute.
Definition at line 618 of file gatt/DiscoveredCharacteristic.h.
|
protected |
Pointer to the underlying ble::GattClient for this DiscoveredCharacteristic object.
Definition at line 600 of file gatt/DiscoveredCharacteristic.h.
|
protected |
Value handle of the discovered characteristic's last attribute.
Definition at line 628 of file gatt/DiscoveredCharacteristic.h.
|
protected |
Hold the configured properties of the discovered characteristic.
Definition at line 613 of file gatt/DiscoveredCharacteristic.h.
|
protected |
Discovered characteristic's UUID.
Definition at line 606 of file gatt/DiscoveredCharacteristic.h.
|
protected |
Value handle of the discovered characteristic's value attribute.
Definition at line 623 of file gatt/DiscoveredCharacteristic.h.