nRF Connect SDK API 2.8.99
Loading...
Searching...
No Matches
time_srv.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2020 Nordic Semiconductor ASA
3 *
4 * SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5 */
6
14#ifndef BT_MESH_TIME_SRV_H__
15#define BT_MESH_TIME_SRV_H__
16
17#include <bluetooth/mesh/time.h>
19#include <time.h>
20
21
22#ifdef __cplusplus
23extern "C" {
24#endif
25
26struct bt_mesh_time_srv;
27struct tm;
28
35#define BT_MESH_TIME_SRV_INIT(_time_update_cb) \
36 { \
37 .time_update_cb = _time_update_cb, \
38 .pub = { .update = _bt_mesh_time_srv_update_handler, \
39 .msg = NET_BUF_SIMPLE(BT_MESH_MODEL_BUF_LEN( \
40 BT_MESH_TIME_OP_TIME_SET, \
41 BT_MESH_TIME_MSG_LEN_TIME_SET)) }, \
42 }
43
53#define BT_MESH_MODEL_TIME_SRV(_srv, ...) \
54 BT_MESH_MODEL_METADATA_CB( \
55 BT_MESH_MODEL_ID_TIME_SRV, _bt_mesh_time_srv_op, &(_srv)->pub, \
56 BT_MESH_MODEL_USER_DATA(struct bt_mesh_time_srv, _srv), \
57 &_bt_mesh_time_srv_cb, __VA_ARGS__), \
58 BT_MESH_MODEL_CB(BT_MESH_MODEL_ID_TIME_SETUP_SRV, \
59 _bt_mesh_time_setup_srv_op, \
60 &(_srv)->setup_pub, \
61 BT_MESH_MODEL_USER_DATA( \
62 struct bt_mesh_time_srv, _srv), \
63 &_bt_mesh_time_setup_srv_cb)
64
66#define BT_MESH_CLOCK_ACCURACY_METADATA_ID 0x0007
67
69#define BT_MESH_TIMEKEEPING_RESERVE_METADATA_ID 0x0008
70
76#define BT_MESH_CLOCK_ACCURACY_METADATA(clock_accuracy) \
77 BT_MESH_MODELS_METADATA_ENTRY(3, BT_MESH_CLOCK_ACCURACY_METADATA_ID, \
78 ((uint8_t[]){BT_BYTES_LIST_LE24(clock_accuracy)}))
79
85#define BT_MESH_TIMEKEEPING_RESERVE_METADATA(timekeeping_reserve) \
86 BT_MESH_MODELS_METADATA_ENTRY(3, BT_MESH_TIMEKEEPING_RESERVE_METADATA_ID, \
87 ((uint8_t[]){BT_BYTES_LIST_LE24(timekeeping_reserve)}))
88
100
103 /* State at last sync point */
104 struct {
105 /* Device uptime at last sync point */
106 int64_t uptime;
107 /* Time status at last sync point */
110 /* Zone change update context */
112 /* UTC-delta change update context */
114 /* The Time Role of the Server instance */
116 /* The timestamp of the last published Time Status. */
117 int64_t timestamp;
118};
119
126 const struct bt_mesh_model *model;
128 struct bt_mesh_model_pub pub;
130 struct bt_mesh_model_pub setup_pub;
132 struct bt_mesh_msg_ack_ctx ack_ctx;
136 struct k_work_delayable status_delay;
141 uint8_t cached_ttl;
142
155 void (*const time_update_cb)(struct bt_mesh_time_srv *srv,
156 struct bt_mesh_msg_ctx *ctx,
157 enum bt_mesh_time_update_types type);
158};
159
174 struct bt_mesh_msg_ctx *ctx);
175
194int bt_mesh_time_srv_status(struct bt_mesh_time_srv *srv, uint64_t uptime,
195 struct bt_mesh_time_status *status);
196
233int64_t bt_mesh_time_srv_mktime(struct bt_mesh_time_srv *srv, struct tm *timeptr);
234
250 int64_t uptime, struct tm *timeptr);
251
266 int64_t uptime);
267
279 int64_t uptime);
280
291void bt_mesh_time_srv_time_set(struct bt_mesh_time_srv *srv, int64_t uptime,
292 const struct bt_mesh_time_status *status);
293
304 struct bt_mesh_time_srv *srv,
305 const struct bt_mesh_time_zone_change *data);
306
317 struct bt_mesh_time_srv *srv,
318 const struct bt_mesh_time_tai_utc_change *data);
319
330 enum bt_mesh_time_role role);
331
333extern const struct bt_mesh_model_op _bt_mesh_time_srv_op[];
334extern const struct bt_mesh_model_op _bt_mesh_time_setup_srv_op[];
335extern const struct bt_mesh_model_cb _bt_mesh_time_srv_cb;
336extern const struct bt_mesh_model_cb _bt_mesh_time_setup_srv_cb;
337int _bt_mesh_time_srv_update_handler(const struct bt_mesh_model *model);
340#ifdef __cplusplus
341}
342#endif
343
344#endif /* BT_MESH_TIME_SRV_H__ */
345
int bt_mesh_time_srv_status(struct bt_mesh_time_srv *srv, uint64_t uptime, struct bt_mesh_time_status *status)
Get the time status at a given uptime.
uint64_t bt_mesh_time_srv_uncertainty_get(struct bt_mesh_time_srv *srv, int64_t uptime)
Get the device time uncertainty at a given uptime.
void bt_mesh_time_srv_time_zone_change_set(struct bt_mesh_time_srv *srv, const struct bt_mesh_time_zone_change *data)
Set the zone change parameters for the server.
int64_t bt_mesh_time_srv_mktime(struct bt_mesh_time_srv *srv, struct tm *timeptr)
Get the device uptime at a given local time.
struct tm * bt_mesh_time_srv_localtime(struct bt_mesh_time_srv *srv, int64_t uptime)
Get the device local time at a given uptime.
int bt_mesh_time_srv_time_status_send(struct bt_mesh_time_srv *srv, struct bt_mesh_msg_ctx *ctx)
Publish an unsolicited Time Status message.
void bt_mesh_time_srv_role_set(struct bt_mesh_time_srv *srv, enum bt_mesh_time_role role)
Set the role parameter for the server.
void bt_mesh_time_srv_time_set(struct bt_mesh_time_srv *srv, int64_t uptime, const struct bt_mesh_time_status *status)
Set the TAI status parameters for the server.
void bt_mesh_time_srv_tai_utc_change_set(struct bt_mesh_time_srv *srv, const struct bt_mesh_time_tai_utc_change *data)
Set the TAI UTC change parameters for the server.
struct tm * bt_mesh_time_srv_localtime_r(struct bt_mesh_time_srv *srv, int64_t uptime, struct tm *timeptr)
Get the device local time at a given uptime.
bt_mesh_time_update_types
Definition time_srv.h:90
@ BT_MESH_TIME_SRV_STATUS_UPDATE
Definition time_srv.h:92
@ BT_MESH_TIME_SRV_SET_UPDATE
Definition time_srv.h:94
@ BT_MESH_TIME_SRV_ZONE_UPDATE
Definition time_srv.h:96
@ BT_MESH_TIME_SRV_UTC_UPDATE
Definition time_srv.h:98
bt_mesh_time_role
Definition time.h:25
struct bt_mesh_time_srv_data::@167 sync
struct bt_mesh_time_tai_utc_change tai_utc_change
Definition time_srv.h:113
int64_t uptime
Definition time_srv.h:106
enum bt_mesh_time_role role
Definition time_srv.h:115
int64_t timestamp
Definition time_srv.h:117
struct bt_mesh_time_status status
Definition time_srv.h:108
struct bt_mesh_time_zone_change time_zone_change
Definition time_srv.h:111
Definition time_srv.h:102
const struct bt_mesh_model * model
Definition time_srv.h:126
bool is_unsolicited
Definition time_srv.h:138
struct bt_mesh_model_pub setup_pub
Definition time_srv.h:130
uint8_t cached_ttl
Definition time_srv.h:141
struct k_work_delayable status_delay
Definition time_srv.h:136
void(*const time_update_cb)(struct bt_mesh_time_srv *srv, struct bt_mesh_msg_ctx *ctx, enum bt_mesh_time_update_types type)
Update callback.
Definition time_srv.h:155
struct bt_mesh_msg_ack_ctx ack_ctx
Definition time_srv.h:132
struct bt_mesh_time_srv_data data
Definition time_srv.h:134
struct bt_mesh_model_pub pub
Definition time_srv.h:128
Definition time_srv.h:124
Definition time.h:45
Definition time.h:75
Definition time.h:59