GATT Latency Client

The Latency Client can be used 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 wait for a response to count the time spend of a GATT Write operation.

Latency Characteristic

To send data to the Latency Characteristic, use the send API of this module. The sending procedure is asynchronous, so the data to be sent must remain valid until a dedicated callback notifies you that the Write Request has been completed.

API documentation

Header file: include/bluetooth/services/latency_client.h
Source file: 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
  • [in] latency: Latency client instance.

  • [in] cb: Callbacks.

Return Value
  • 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
  • [in] dm: Discovery object.

  • [inout] latency: Latency client instance.

Return Value
  • 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
  • [in] latency: Latency client instance.

  • [in] data: Data.

  • [in] len: Data length.

Return Value
  • 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.

Parameters
  • [in] buf: Latency data.

  • [in] len: Latency data length.

struct bt_latency_client
#include <latency_client.h>

Latency client structure.

Public Members

uint16_t handle

Characteristic handle.

struct bt_gatt_write_params latency_params

Latency parameter.

struct bt_conn *conn

Connection object.

atomic_t state

Internal state.