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 GattClient::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 GattClient::WriteCallback_t &onWrite) const |
Initiate a write procedure of the characteristic value. More... | |
const UUID & | getUUID (void) const |
Get the UUID of the discovered characteristic. More... | |
const Properties_t & | getProperties (void) const |
Get the properties of this characteristic. More... | |
GattAttribute::Handle_t | getDeclHandle (void) const |
Get the declaration handle of this characteristic. More... | |
GattAttribute::Handle_t | getValueHandle (void) const |
Get the attribute handle of the characteristic value. More... | |
GattAttribute::Handle_t | getLastHandle (void) const |
Return the last attribute handle of the characteristic definition. More... | |
GattClient * | getGattClient () |
Get the GattClient, which can operate on this characteristic. More... | |
const GattClient * | getGattClient () const |
Get the 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 | |
GattClient * | gattc |
Pointer to the underlying 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 GattClient discovery procedure initiated with 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 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 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 GattClient::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 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 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 89 of file 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 540 of file DiscoveredCharacteristic.h.
GattAttribute::Handle_t getDeclHandle | ( | void | ) | 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 475 of file DiscoveredCharacteristic.h.
GattClient* getGattClient | ( | void | ) |
Get the GattClient, which can operate on this characteristic.
Definition at line 518 of file DiscoveredCharacteristic.h.
const GattClient* getGattClient | ( | void | ) | const |
Get the GattClient, which can operate on this characteristic.
Definition at line 528 of file DiscoveredCharacteristic.h.
GattAttribute::Handle_t getLastHandle | ( | void | ) | 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 508 of file DiscoveredCharacteristic.h.
const Properties_t& getProperties | ( | void | ) | const |
Get the properties of this characteristic.
Definition at line 455 of file DiscoveredCharacteristic.h.
const UUID& getUUID | ( | void | ) | const |
Get the UUID of the discovered characteristic.
Definition at line 445 of file DiscoveredCharacteristic.h.
GattAttribute::Handle_t getValueHandle | ( | void | ) | 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 487 of file 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 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 GattClient::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 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 GattClient::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 573 of file 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 553 of file DiscoveredCharacteristic.h.
|
protected |
Handle of the connection where the characteristic was discovered.
Definition at line 628 of file DiscoveredCharacteristic.h.
|
protected |
Value handle of the discovered characteristic's declaration attribute.
Definition at line 613 of file DiscoveredCharacteristic.h.
|
protected |
Pointer to the underlying GattClient for this DiscoveredCharacteristic object.
Definition at line 595 of file DiscoveredCharacteristic.h.
|
protected |
Value handle of the discovered characteristic's last attribute.
Definition at line 623 of file DiscoveredCharacteristic.h.
|
protected |
Hold the configured properties of the discovered characteristic.
Definition at line 608 of file DiscoveredCharacteristic.h.
|
protected |
Discovered characteristic's UUID.
Definition at line 601 of file DiscoveredCharacteristic.h.
|
protected |
Value handle of the discovered characteristic's value attribute.
Definition at line 618 of file DiscoveredCharacteristic.h.