GATT Current Time Service (CTS) Client

The CTS Client module can be used to retrieve the current time from a connected peer that is running the GATT server with the Current Time Service.

The CTS Client is used in the Bluetooth: Peripheral CTS client sample.

API documentation

Header file: include/bluetooth/services/cts_client.h
Source file: subsys/bluetooth/services/cts_client.c
group bt_gatt_cts_c

Current Time Service Client module.

Typedefs

typedef void (*bt_cts_read_cb)(struct bt_cts_client *cts_c, struct bt_cts_current_time *current_time, int err)

Read complete callback.

This function is called when the read operation finishes.

Parameters
  • cts_c: Current Time Service client structure.

  • current_time: The current time value that was read.

  • err: Error code.

typedef void (*bt_cts_notify_cb)(struct bt_cts_client *cts_c, struct bt_cts_current_time *current_time)

Value notification callback.

This function is called every time the server sends a notification for a changed value.

Parameters
  • cts_c: Current Time Service client structure.

  • current_time: The notified current time value.

Functions

int bt_cts_client_init(struct bt_cts_client *cts_c)

Function for initializing the Current Time Service client.

Parameters
  • [out] cts_c: Current Time Service client structure. This structure must be supplied by the application. It is initialized by this function and can later be used to identify this particular client instance.

Return Value
  • 0: If the client was initialized successfully. Otherwise, a (negative) error code is returned.

int bt_cts_read_current_time(struct bt_cts_client *cts_c, bt_cts_read_cb func)

Function for reading the peer’s Current Time Service Current Time characteristic.

Parameters
  • [in] cts_c: Current Time Service client structure.

  • [in] func: The callback function.

Return Value
  • 0: If all operations are successful. Otherwise, a (negative) error code is returned.

int bt_cts_subscribe_current_time(struct bt_cts_client *cts_c, bt_cts_notify_cb func)

Subscribe to the current time value change notification.

Parameters
  • [in] cts_c: Current Time Service client structure.

  • [in] func: The callback function.

Return Value
  • 0: If the operation was successful. Otherwise, a (negative) error code is returned.

int bt_cts_unsubscribe_current_time(struct bt_cts_client *cts_c)

Remove the subscription.

Parameters
  • [in] cts_c: Current Time Service client structure.

Return Value
  • 0: If the operation was successful. Otherwise, a (negative) error code is returned.

int bt_cts_handles_assign(struct bt_gatt_dm *dm, struct bt_cts_client *cts_c)

Function for assigning handles to this instance of cts_c.

Call this function when a link has been established with a peer 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.

Parameters
  • [in] dm: Discovery object.

  • [out] cts_c: Current Time Service client structure.

Return Value
  • 0: If the operation is successful. Otherwise, a (negative) error code is returned.

struct bt_cts_exact_time_256
#include <cts_client.h>

“Exact Time 256” field of the Current Time characteristic.

struct bt_cts_adjust_reason
#include <cts_client.h>

“Adjust Reason” field of the Current Time characteristic.

struct bt_cts_current_time
#include <cts_client.h>

Data structure for the Current Time characteristic.

struct bt_cts_client
#include <cts_client.h>

Current Time Service client structure. This structure contains status information for the client.

Public Members

struct bt_conn *conn

Connection object.

uint16_t handle_ct

Handle of the Current Time Characteristic.

uint16_t handle_ct_ccc

Handle of the CCCD of the Current Time Characteristic.

atomic_t state

Internal state.

struct bt_gatt_read_params read_params

Read parameters.

struct bt_gatt_subscribe_params notify_params

Notification parameters.

bt_cts_read_cb read_cb

Read value callback.

bt_cts_notify_cb notify_cb

Notification callback.