cts.h
Go to the documentation of this file.
1
57 #ifndef __CTS_H__
58 #define __CTS_H__
59
60 #include "gr55xx_sys.h"
61 #include "custom_config.h"
62 #include "ble_prf_utils.h"
63 #include <stdint.h>
64 #include <stdbool.h>
65
70 #define CTS_CONNECTION_MAX (10 < CFG_MAX_CONNECTIONS ?\
71 10 : CFG_MAX_CONNECTIONS)
72 #define CTS_CUR_TIME_VAL_LEN 10
73 #define CTS_LOC_TIME_INFO_VAL_LEN 2
74 #define CTS_REF_TIME_INFO_VAL_LEN 4
75 #define CTS_TIME_YEAR_VALID_VAL_MIN 1582
76 #define CTS_TIME_YEAR_VALID_VAL_MAX 9999
77 #define CTS_TIME_ZONE_OFFSET_MIN -48
78 #define CTS_TIME_ZONE_OFFSET_MAX 56
79 #define CTS_TIME_ACCURACY_OUT_RANGE 254
80 #define CTS_TIME_ACCURACT_UNKNOWN 255
81 #define CTS_ERROR_FIELDS_IGNORED 0x80
88 #define CTS_CHAR_MANDATORY 0x0f
89 #define CTS_CHAR_LOC_TIME_INFO_SUP 0x30
90 #define CTS_CHAR_REF_TIME_INFO_SUP 0xc0
91 #define CTS_CHAR_FULL 0xff
99 #define CTS_AR_NO_CHANGE (0x00 << 0)
100 #define CTS_AR_MAUAL_TIME_UPDATE (0x01 << 0)
101 #define CTS_AR_EXT_REF_TIME_UPDATE (0x01 << 1)
102 #define CTS_AR_TIME_ZONE_CHANGE (0x01 << 2)
103 #define CTS_AR_DST_CHANGE (0x01 << 3)
113 typedef enum
114 {
115 CTS_WEEK_UNKNOWN_DAY,
116 CTS_WEEK_MONDAY,
117 CTS_WEEK_TUSEDAY,
118 CTS_WEEK_WEDNESDAY,
119 CTS_WEEK_THURSDAT,
120 CTS_WEEK_FRIDAY,
121 CTS_WEEK_SATURDAY,
122 CTS_WEEK_SUNDAY
123 } cts_week_day_t;
124
126 typedef enum
127 {
128 CTS_DST_OFFSET_STANDAR_TIME = 0x00,
129 CTS_DST_OFFSET_HALF_HOUR = 0x02,
130 CTS_DST_OFFSET_DAYLIGHT_TIME = 0x04,
131 CTS_DST_OFFSET_DOUB_DAYLIGHT_TIME = 0x08,
132 } cts_dst_offset_t;
133
135 typedef enum
136 {
137 CTS_REF_TIME_SRC_UNKNOWN,
138 CTS_REF_TIME_SRC_NET_TIME_PROTOCOL,
139 CTS_REF_TIME_SRC_GPS,
140 CTS_REF_TIME_SRC_RADIO_TIME_SIGNAL,
141 CTS_REF_TIME_SRC_MANUAL,
142 CTS_REF_TIME_SRC_ATOMIC_CLOCK,
143 CTS_REF_TIME_SRC_CELLUAR_NET,
144 } cts_ref_time_source_t;
145
147 typedef enum
148 {
149 CTS_EVT_INVALID = 0x00,
150 CTS_EVT_CUR_TIME_NOTIFICATION_ENABLED,
151 CTS_EVT_CUR_TIME_NOTIFICATION_DISABLED,
152 CTS_EVT_CUR_TIME_SET_BY_PEER,
153 CTS_EVT_LOC_TIME_INFO_SET_BY_PEER,
154 } cts_evt_type_t;
162 typedef struct
163 {
164 prf_date_time_t date_time;
165 uint8_t day_of_week;
166 uint8_t fractions_256;
167 } cts_exact_time_256_t;
168
170 typedef struct
171 {
172 cts_exact_time_256_t day_date_time;
173 uint8_t adjust_reason;
174 } cts_cur_time_t;
175
177 typedef struct
178 {
179 int8_t time_zone;
180 cts_dst_offset_t dst_offset;
181 } cts_loc_time_info_t;
182
184 typedef struct
185 {
186 cts_ref_time_source_t source;
187 uint8_t accuracy;
188 uint8_t days_since_update;
189 uint8_t hours_since_update;
190 } cts_ref_time_info_t;
191
193 typedef struct
194 {
195 uint8_t adjust_reason;
196 cts_exact_time_256_t day_date_time;
197 cts_loc_time_info_t loc_time_info;
198 cts_ref_time_info_t ref_time_info;
199 } cts_adj_info_t;
200
202 typedef struct
203 {
204 uint8_t conn_idx;
205 cts_evt_type_t evt_type;
206 const uint8_t *p_data;
207 uint16_t length;
208 cts_cur_time_t cur_time;
209 cts_loc_time_info_t loc_time_info;
210 } cts_evt_t;
218 typedef void (*cts_evt_handler_t)(cts_evt_t *p_evt);
226 typedef struct
227 {
228 cts_evt_handler_t evt_handler;
229 uint16_t char_mask;
230 cts_cur_time_t cur_time;
231 cts_loc_time_info_t loc_time_info;
232 cts_ref_time_info_t ref_time_info;
233 } cts_init_t;
249 sdk_err_t cts_service_init(cts_init_t *p_cts_init);
250
258 void cts_exact_time_get(cts_exact_time_256_t *p_exact_time);
259
267 void cts_exact_time_update(cts_exact_time_256_t *p_exact_time);
268
276 void cts_cur_time_adjust(cts_adj_info_t *p_adj_info);
277
288 sdk_err_t cts_cur_time_send(uint8_t conn_idx, cts_cur_time_t *p_cur_time);
291 #endif
292
cts_evt_t::evt_type
cts_evt_type_t evt_type
Definition: cts.h:205
cts_ref_time_info_t::days_since_update
uint8_t days_since_update
Definition: cts.h:188
CTS_DST_OFFSET_DOUB_DAYLIGHT_TIME
@ CTS_DST_OFFSET_DOUB_DAYLIGHT_TIME
Definition: cts.h:131
cts_adj_info_t::ref_time_info
cts_ref_time_info_t ref_time_info
Definition: cts.h:198
cts_cur_time_t
CTS Current Time value.
Definition: cts.h:171
cts_adj_info_t::loc_time_info
cts_loc_time_info_t loc_time_info
Definition: cts.h:197
CTS_EVT_CUR_TIME_SET_BY_PEER
@ CTS_EVT_CUR_TIME_SET_BY_PEER
Definition: cts.h:152
CTS_REF_TIME_SRC_MANUAL
@ CTS_REF_TIME_SRC_MANUAL
Definition: cts.h:141
cts_exact_time_256_t::day_of_week
uint8_t day_of_week
Definition: cts.h:165
cts_evt_t::length
uint16_t length
Definition: cts.h:207
CTS_WEEK_UNKNOWN_DAY
@ CTS_WEEK_UNKNOWN_DAY
Definition: cts.h:115
cts_loc_time_info_t::dst_offset
cts_dst_offset_t dst_offset
Definition: cts.h:180
CTS_EVT_LOC_TIME_INFO_SET_BY_PEER
@ CTS_EVT_LOC_TIME_INFO_SET_BY_PEER
Definition: cts.h:153
cts_init_t::evt_handler
cts_evt_handler_t evt_handler
Definition: cts.h:228
CTS_DST_OFFSET_HALF_HOUR
@ CTS_DST_OFFSET_HALF_HOUR
Definition: cts.h:129
CTS_WEEK_SUNDAY
@ CTS_WEEK_SUNDAY
Definition: cts.h:122
CTS_REF_TIME_SRC_ATOMIC_CLOCK
@ CTS_REF_TIME_SRC_ATOMIC_CLOCK
Definition: cts.h:142
CTS_DST_OFFSET_STANDAR_TIME
@ CTS_DST_OFFSET_STANDAR_TIME
Definition: cts.h:128
gr55xx_sys.h
GR55XX System API.
cts_ref_time_info_t
CTS Reference Time Information.
Definition: cts.h:185
CTS_WEEK_WEDNESDAY
@ CTS_WEEK_WEDNESDAY
Definition: cts.h:118
CTS_REF_TIME_SRC_UNKNOWN
@ CTS_REF_TIME_SRC_UNKNOWN
Definition: cts.h:137
CTS_REF_TIME_SRC_RADIO_TIME_SIGNAL
@ CTS_REF_TIME_SRC_RADIO_TIME_SIGNAL
Definition: cts.h:140
CTS_REF_TIME_SRC_CELLUAR_NET
@ CTS_REF_TIME_SRC_CELLUAR_NET
Definition: cts.h:143
CTS_EVT_CUR_TIME_NOTIFICATION_DISABLED
@ CTS_EVT_CUR_TIME_NOTIFICATION_DISABLED
Definition: cts.h:151
CTS_DST_OFFSET_DAYLIGHT_TIME
@ CTS_DST_OFFSET_DAYLIGHT_TIME
Definition: cts.h:130
cts_evt_t::conn_idx
uint8_t conn_idx
Definition: cts.h:204
cts_loc_time_info_t::time_zone
int8_t time_zone
Definition: cts.h:179
CTS_EVT_INVALID
@ CTS_EVT_INVALID
Definition: cts.h:149
cts_evt_t::p_data
const uint8_t * p_data
Definition: cts.h:206
cts_exact_time_256_t::date_time
prf_date_time_t date_time
Definition: cts.h:164
cts_exact_time_256_t
CTS Exact Time 256.
Definition: cts.h:163
cts_exact_time_256_t::fractions_256
uint8_t fractions_256
Definition: cts.h:166
cts_init_t::loc_time_info
cts_loc_time_info_t loc_time_info
Definition: cts.h:231
cts_evt_type_t
cts_evt_type_t
Current Time Service event type.
Definition: cts.h:148
cts_dst_offset_t
cts_dst_offset_t
Local time information:Daylight Saving Time Offset.
Definition: cts.h:127
CTS_REF_TIME_SRC_GPS
@ CTS_REF_TIME_SRC_GPS
Definition: cts.h:139
cts_service_init
sdk_err_t cts_service_init(cts_init_t *p_cts_init)
Initialize a Current Time Service instance and add in the DB.
cts_init_t::ref_time_info
cts_ref_time_info_t ref_time_info
Definition: cts.h:232
cts_cur_time_send
sdk_err_t cts_cur_time_send(uint8_t conn_idx, cts_cur_time_t *p_cur_time)
Send Current Time if its notification has been enabled.
cts_loc_time_info_t
CTS Local Time Information.
Definition: cts.h:178
sdk_err_t
uint16_t sdk_err_t
SDK API result type.
Definition: ble_error.h:243
CTS_REF_TIME_SRC_NET_TIME_PROTOCOL
@ CTS_REF_TIME_SRC_NET_TIME_PROTOCOL
Definition: cts.h:138
cts_exact_time_get
void cts_exact_time_get(cts_exact_time_256_t *p_exact_time)
Get exact time for user.
cts_init_t::cur_time
cts_cur_time_t cur_time
Definition: cts.h:230
prf_date_time_t
The date and time structure. The packed size is 7 bytes.
Definition: ble_prf_types.h:101
CTS_EVT_CUR_TIME_NOTIFICATION_ENABLED
@ CTS_EVT_CUR_TIME_NOTIFICATION_ENABLED
Definition: cts.h:150
cts_evt_handler_t
void(* cts_evt_handler_t)(cts_evt_t *p_evt)
Current Time Service event handler type.
Definition: cts.h:218
cts_adj_info_t::day_date_time
cts_exact_time_256_t day_date_time
Definition: cts.h:196
CTS_WEEK_TUSEDAY
@ CTS_WEEK_TUSEDAY
Definition: cts.h:117
cts_init_t
Current Time Service init structure. This contains all option and data needed for initialization of t...
Definition: cts.h:227
cts_exact_time_update
void cts_exact_time_update(cts_exact_time_256_t *p_exact_time)
Update exact time.
cts_ref_time_source_t
cts_ref_time_source_t
Reference time information:Time Source.
Definition: cts.h:136
cts_ref_time_info_t::hours_since_update
uint8_t hours_since_update
Definition: cts.h:189
cts_ref_time_info_t::source
cts_ref_time_source_t source
Definition: cts.h:186
CTS_WEEK_SATURDAY
@ CTS_WEEK_SATURDAY
Definition: cts.h:121
cts_evt_t::cur_time
cts_cur_time_t cur_time
Definition: cts.h:208
cts_cur_time_adjust
void cts_cur_time_adjust(cts_adj_info_t *p_adj_info)
Adjust current time.
CTS_WEEK_THURSDAT
@ CTS_WEEK_THURSDAT
Definition: cts.h:119
cts_week_day_t
cts_week_day_t
Current Time Day of week.
Definition: cts.h:114
cts_init_t::char_mask
uint16_t char_mask
Definition: cts.h:229
cts_ref_time_info_t::accuracy
uint8_t accuracy
Definition: cts.h:187
CTS_WEEK_FRIDAY
@ CTS_WEEK_FRIDAY
Definition: cts.h:120
ble_prf_utils.h
Profile/Service Utilities API.
cts_cur_time_t::adjust_reason
uint8_t adjust_reason
Definition: cts.h:173
cts_cur_time_t::day_date_time
cts_exact_time_256_t day_date_time
Definition: cts.h:172
cts_adj_info_t
CTS Adjust information.
Definition: cts.h:194
cts_evt_t::loc_time_info
cts_loc_time_info_t loc_time_info
Definition: cts.h:209
cts_adj_info_t::adjust_reason
uint8_t adjust_reason
Definition: cts.h:195
cts_evt_t
Current Time Service event.
Definition: cts.h:203
CTS_WEEK_MONDAY
@ CTS_WEEK_MONDAY
Definition: cts.h:116