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_c.h
Source file: subsys/bluetooth/services/latency_c.c
group bt_gatt_latency_c

API for the BLE GATT Latency Client.

Functions

int bt_gatt_latency_c_init(struct bt_gatt_latency_c *latency, const struct bt_gatt_latency_c_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_gatt_latency_c_handles_assign(struct bt_gatt_dm *dm, struct bt_gatt_latency_c *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_gatt_latency_c_request(struct bt_gatt_latency_c *latency, const void *data, u16_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_gatt_latency_c_cb
#include <latency_c.h>

Latency client callback structure.

Public Members

void (*latency_response)(const void *buf, u16_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_gatt_latency_c
#include <latency_c.h>

Latency client structure.

Public Members

u16_t handle

Characteristic handle.

struct bt_gatt_write_params latency_params

Latency parameter.

struct bt_conn *conn

Connection object.

atomic_t state

Internal state.