GATT Latency Client
You can use the Latency Client to interact with a connected peer that is running the Latency service with the GATT Latency Service. It writes data to the Latency characteristic and waits for a response to count the time spent of a GATT Write operation.
Latency Characteristic
To request latency data from the Latency Characteristic, use the bt_latency_request()
function.
The request sending procedure is asynchronous, so the request data to be sent must remain valid until a dedicated callback notifies you that the write request has been completed.
API documentation
include/bluetooth/services/latency_client.h
subsys/bluetooth/services/latency_client.c
- group bt_latency_c
API for the Bluetooth LE GATT Latency Client.
Functions
-
int bt_latency_client_init(struct bt_latency_client *latency, const struct bt_latency_client_cb *cb)
Initialize the GATT latency client.
- Parameters:
latency – [in] Latency client instance.
cb – [in] Callbacks.
- Return values:
0 – If the operation was successful. Otherwise, a negative error code is returned.
(-EINVAL) – Special error code used when the input parameters are invalid.
(-EALREADY) – Special error code used when the latency client has been initialed.
-
int bt_latency_handles_assign(struct bt_gatt_dm *dm, struct bt_latency_client *latency)
Assign handles to the latency client instance.
This function should be called when a link with a peer has been established, to associate the link to this instance of the module. This makes it possible to handle several links and associate each link to a particular instance of this module. The GATT attribute handles are provided by the GATT Discovery Manager.
- Parameters:
dm – [in] Discovery object.
latency – [inout] Latency client instance.
- Return values:
0 – If the operation was successful. Otherwise, a negative error code is returned.
(-ENOTSUP) – Special error code used when the UUID of the service does not match the expected UUID.
(-EINVAL) – Special error code used when the UUID characteristic or value descriptor not found.
-
int bt_latency_request(struct bt_latency_client *latency, const void *data, uint16_t len)
Write data to the server.
- Parameters:
latency – [in] Latency client instance.
data – [in] Data.
len – [in] Data length.
- Return values:
0 – If the operation was successful. Otherwise, a negative error code is returned.
(-EALREADY) – Special error code used when the asynchronous request is waiting for a response.
-
struct bt_latency_client_cb
- #include <latency_client.h>
Latency client callback structure.
Public Members
-
void (*latency_response)(const void *buf, uint16_t len)
Latency received callback.
This function is called when a GATT write response has been received by the Latency characteristic.
It is mandatory for an application to handle the write response when measuring the latency.
- Param buf:
[in] Latency data.
- Param len:
[in] Latency data length.
-
void (*latency_response)(const void *buf, uint16_t len)
-
int bt_latency_client_init(struct bt_latency_client *latency, const struct bt_latency_client_cb *cb)