cts_c.h
Go to the documentation of this file.
1
59 #ifndef __CTS_C_H__
60 #define __CTS_C_H__
61
62 #include "gr55xx_sys.h"
63 #include "custom_config.h"
64 #include "ble_prf_utils.h"
65 #include <stdint.h>
66 #include <stdbool.h>
67
72 #define CTS_C_CONNECTION_MAX (10 < CFG_MAX_CONNECTIONS ?\
73 10 : CFG_MAX_CONNECTIONS)
75 #define CTS_C_CUR_TIME_VAL_LEN 10
76 #define CTS_C_LOC_TIME_INFO_VAL_LEN 2
77 #define CTS_C_TIME_Y_M_D_UNKNOWN 0
78 #define CTS_C_TIME_YEAR_VALID_VAL_MIN 1582
79 #define CTS_C_TIME_YEAR_VALID_VAL_MAX 9999
80 #define CTS_C_TIME_ZONE_OFFSET_MIN -48
81 #define CTS_C_TIME_ZONE_OFFSET_MAX 56
82 #define CTS_C_TIME_ACCURACY_OUT_RANGE 254
83 #define CTS_C_TIME_ACCURACT_UNKNOWN 255
84 #define CTS_C_ERROR_FIELDS_IGNORED 0x80
91 #define CTS_C_AR_NO_CHANGE (0x00 << 0)
92 #define CTS_C_AR_MAUAL_TIME_UPDATE (0x01 << 0)
93 #define CTS_C_AR_EXT_REF_TIME_UPDATE (0x01 << 1)
94 #define CTS_C_AR_TIME_ZONE_CHANGE (0x01 << 2)
95 #define CTS_C_AR_DST_CHANGE (0x01 << 3)
104 typedef enum
105 {
106 CTS_C_WEEK_UNKNOWN_DAY,
107 CTS_C_WEEK_MONDAY,
108 CTS_C_WEEK_TUSEDAY,
109 CTS_C_WEEK_WEDNESDAY,
110 CTS_C_WEEK_THURSDAT,
111 CTS_C_WEEK_FRIDAY,
112 CTS_C_WEEK_SATURDAY,
113 CTS_C_WEEK_SUNDAY
114 } cts_c_week_day_t;
115
117 typedef enum
118 {
119 CTS_C_DST_OFFSET_STANDAR_TIME = 0x00,
120 CTS_C_DST_OFFSET_HALF_HOUR = 0x02,
121 CTS_C_DST_OFFSET_DAYLIGHT_TIME = 0x04,
122 CTS_C_DST_OFFSET_DOUB_DAYLIGHT_TIME = 0x08,
123 } cts_c_dst_offset_t;
124
126 typedef enum
127 {
128 CTS_C_REF_TIME_SRC_UNKNOWN,
129 CTS_C_REF_TIME_SRC_NET_TIME_PROTOCOL,
130 CTS_C_REF_TIME_SRC_GPS,
131 CTS_C_REF_TIME_SRC_RADIO_TIME_SIGNAL,
132 CTS_C_REF_TIME_SRC_MANUAL,
133 CTS_C_REF_TIME_SRC_ATOMIC_CLOCK,
134 CTS_C_REF_TIME_SRC_CELLUAR_NET,
135 } cts_c_ref_time_source_t;
136
138 typedef enum
139 {
140 CTS_C_EVT_INVALID,
141 CTS_C_EVT_DISCOVERY_COMPLETE,
142 CTS_C_EVT_DISCOVERY_FAIL,
143 CTS_C_EVT_CUR_TIME_NTF_SET_SUCCESS,
144 CTS_C_EVT_VALID_CUR_TIME_REC,
145 CTS_C_EVT_INVALID_CUR_TIME_REC,
146 CTS_C_EVT_VALID_LOC_TIME_INFO_REC,
147 CTS_C_EVT_INVALID_LOC_TIME_INFO_REC,
148 CTS_C_EVT_VALID_REF_TIME_INFO_REC,
149 CTS_C_EVT_INVALID_REF_TIME_INFO_REC,
150 CTS_C_EVT_CUR_TIME_SET_SUCCESS,
151 CTS_C_EVT_LOC_TIME_INFO_SET_SUCCESS,
152 CTS_C_EVT_WRITE_OP_ERR,
153 } cts_c_evt_type_t;
161 typedef struct
162 {
163 uint16_t cts_srvc_start_handle;
164 uint16_t cts_srvc_end_handle;
165 uint16_t cts_cur_time_handle;
166 uint16_t cts_cur_time_cccd_handle;
167 uint16_t cts_loc_time_info_handle;
168 uint16_t cts_ref_time_info_handle;
169 } cts_c_handles_t;
170
172 typedef struct
173 {
174 prf_date_time_t date_time;
175 uint8_t day_of_week;
176 uint8_t fractions_256;
177 } cts_c_exact_time_256_t;
178
180 typedef struct
181 {
182 cts_c_exact_time_256_t day_date_time;
183 uint8_t adjust_reason;
184 } cts_c_cur_time_t;
185
187 typedef struct
188 {
189 int8_t time_zone;
190 cts_c_dst_offset_t dst_offset;
191 } cts_c_loc_time_info_t;
192
194 typedef struct
195 {
196 cts_c_ref_time_source_t source;
197 uint8_t accuracy;
198 uint8_t days_since_update;
199 uint8_t hours_since_update;
200 } cts_c_ref_time_info_t;
201
203 typedef struct
204 {
205 uint8_t conn_idx;
206 cts_c_evt_type_t evt_type;
207 union
208 {
209 cts_c_cur_time_t cur_time;
210 cts_c_loc_time_info_t loc_time_info;
211 cts_c_ref_time_info_t ref_time_info;
212 } value;
213 } cts_c_evt_t;
221 typedef void (*cts_c_evt_handler_t)(cts_c_evt_t *p_evt);
237 sdk_err_t cts_client_init(cts_c_evt_handler_t evt_handler);
238
248 sdk_err_t cts_c_disc_srvc_start(uint8_t conn_idx);
249
260 sdk_err_t cts_c_cur_time_notify_set(uint8_t conn_idx, bool is_enable);
261
271 sdk_err_t cts_c_cur_time_read(uint8_t conn_idx);
272
282 sdk_err_t cts_c_loc_time_info_read(uint8_t conn_idx);
283
293 sdk_err_t cts_c_ref_time_info_read(uint8_t conn_idx);
294
305 sdk_err_t cts_c_cur_time_set(uint8_t conn_idx, cts_c_cur_time_t *p_cur_time);
306
317 sdk_err_t cts_c_loc_time_info_set(uint8_t conn_idx, cts_c_loc_time_info_t *p_loc_time_info);
320 #endif
321
CTS_C_REF_TIME_SRC_NET_TIME_PROTOCOL
@ CTS_C_REF_TIME_SRC_NET_TIME_PROTOCOL
Definition: cts_c.h:129
cts_c_loc_time_info_t
Local Time Information.
Definition: cts_c.h:188
cts_c_ref_time_info_t::hours_since_update
uint8_t hours_since_update
Definition: cts_c.h:199
CTS_C_WEEK_THURSDAT
@ CTS_C_WEEK_THURSDAT
Definition: cts_c.h:110
cts_c_handles_t::cts_cur_time_handle
uint16_t cts_cur_time_handle
Definition: cts_c.h:165
CTS_C_EVT_INVALID_CUR_TIME_REC
@ CTS_C_EVT_INVALID_CUR_TIME_REC
Definition: cts_c.h:145
CTS_C_EVT_CUR_TIME_SET_SUCCESS
@ CTS_C_EVT_CUR_TIME_SET_SUCCESS
Definition: cts_c.h:150
cts_c_ref_time_source_t
cts_c_ref_time_source_t
Reference time information:Time Source.
Definition: cts_c.h:127
CTS_C_WEEK_UNKNOWN_DAY
@ CTS_C_WEEK_UNKNOWN_DAY
Definition: cts_c.h:106
CTS_C_REF_TIME_SRC_UNKNOWN
@ CTS_C_REF_TIME_SRC_UNKNOWN
Definition: cts_c.h:128
cts_c_evt_t::cur_time
cts_c_cur_time_t cur_time
Definition: cts_c.h:209
CTS_C_EVT_VALID_REF_TIME_INFO_REC
@ CTS_C_EVT_VALID_REF_TIME_INFO_REC
Definition: cts_c.h:148
cts_c_ref_time_info_t::source
cts_c_ref_time_source_t source
Definition: cts_c.h:196
cts_c_cur_time_t::day_date_time
cts_c_exact_time_256_t day_date_time
Definition: cts_c.h:182
cts_c_loc_time_info_read
sdk_err_t cts_c_loc_time_info_read(uint8_t conn_idx)
Read Local Time Information characteristic value.
cts_c_exact_time_256_t::date_time
prf_date_time_t date_time
Definition: cts_c.h:174
cts_c_ref_time_info_t::accuracy
uint8_t accuracy
Definition: cts_c.h:197
CTS_C_EVT_INVALID_LOC_TIME_INFO_REC
@ CTS_C_EVT_INVALID_LOC_TIME_INFO_REC
Definition: cts_c.h:147
cts_c_exact_time_256_t
Exact Time 256.
Definition: cts_c.h:173
CTS_C_WEEK_WEDNESDAY
@ CTS_C_WEEK_WEDNESDAY
Definition: cts_c.h:109
CTS_C_DST_OFFSET_HALF_HOUR
@ CTS_C_DST_OFFSET_HALF_HOUR
Definition: cts_c.h:120
cts_c_loc_time_info_t::time_zone
int8_t time_zone
Definition: cts_c.h:189
CTS_C_EVT_INVALID_REF_TIME_INFO_REC
@ CTS_C_EVT_INVALID_REF_TIME_INFO_REC
Definition: cts_c.h:149
CTS_C_EVT_INVALID
@ CTS_C_EVT_INVALID
Definition: cts_c.h:140
gr55xx_sys.h
GR55XX System API.
cts_c_handles_t::cts_cur_time_cccd_handle
uint16_t cts_cur_time_cccd_handle
Definition: cts_c.h:166
cts_c_handles_t::cts_ref_time_info_handle
uint16_t cts_ref_time_info_handle
Definition: cts_c.h:168
CTS_C_EVT_VALID_LOC_TIME_INFO_REC
@ CTS_C_EVT_VALID_LOC_TIME_INFO_REC
Definition: cts_c.h:146
CTS_C_REF_TIME_SRC_RADIO_TIME_SIGNAL
@ CTS_C_REF_TIME_SRC_RADIO_TIME_SIGNAL
Definition: cts_c.h:131
cts_c_handles_t
Handles on the connected peer device needed to interact with it.
Definition: cts_c.h:162
CTS_C_DST_OFFSET_DOUB_DAYLIGHT_TIME
@ CTS_C_DST_OFFSET_DOUB_DAYLIGHT_TIME
Definition: cts_c.h:122
cts_c_handles_t::cts_loc_time_info_handle
uint16_t cts_loc_time_info_handle
Definition: cts_c.h:167
cts_c_evt_t
Current Time Service Client event.
Definition: cts_c.h:204
cts_c_disc_srvc_start
sdk_err_t cts_c_disc_srvc_start(uint8_t conn_idx)
Discovery Current Time Service on peer.
CTS_C_EVT_CUR_TIME_NTF_SET_SUCCESS
@ CTS_C_EVT_CUR_TIME_NTF_SET_SUCCESS
Definition: cts_c.h:143
cts_c_cur_time_t::adjust_reason
uint8_t adjust_reason
Definition: cts_c.h:183
cts_c_dst_offset_t
cts_c_dst_offset_t
Local time information:Daylight Saving Time Offset.
Definition: cts_c.h:118
CTS_C_REF_TIME_SRC_MANUAL
@ CTS_C_REF_TIME_SRC_MANUAL
Definition: cts_c.h:132
cts_c_ref_time_info_t
Reference Time Information.
Definition: cts_c.h:195
cts_c_evt_t::loc_time_info
cts_c_loc_time_info_t loc_time_info
Definition: cts_c.h:210
cts_c_handles_t::cts_srvc_end_handle
uint16_t cts_srvc_end_handle
Definition: cts_c.h:164
cts_c_evt_t::ref_time_info
cts_c_ref_time_info_t ref_time_info
Definition: cts_c.h:211
cts_c_cur_time_set
sdk_err_t cts_c_cur_time_set(uint8_t conn_idx, cts_c_cur_time_t *p_cur_time)
Set Current Time characteristic value.
CTS_C_REF_TIME_SRC_ATOMIC_CLOCK
@ CTS_C_REF_TIME_SRC_ATOMIC_CLOCK
Definition: cts_c.h:133
cts_c_loc_time_info_set
sdk_err_t cts_c_loc_time_info_set(uint8_t conn_idx, cts_c_loc_time_info_t *p_loc_time_info)
Set Local Time Information characteristic value.
sdk_err_t
uint16_t sdk_err_t
SDK API result type.
Definition: ble_error.h:243
CTS_C_WEEK_MONDAY
@ CTS_C_WEEK_MONDAY
Definition: cts_c.h:107
prf_date_time_t
The date and time structure. The packed size is 7 bytes.
Definition: ble_prf_types.h:101
cts_client_init
sdk_err_t cts_client_init(cts_c_evt_handler_t evt_handler)
Register CTS Client event handler.
cts_c_ref_time_info_read
sdk_err_t cts_c_ref_time_info_read(uint8_t conn_idx)
Read Reference Time Information characteristic value.
CTS_C_DST_OFFSET_STANDAR_TIME
@ CTS_C_DST_OFFSET_STANDAR_TIME
Definition: cts_c.h:119
cts_c_exact_time_256_t::fractions_256
uint8_t fractions_256
Definition: cts_c.h:176
cts_c_evt_type_t
cts_c_evt_type_t
Current Time Service Client event type.
Definition: cts_c.h:139
cts_c_handles_t::cts_srvc_start_handle
uint16_t cts_srvc_start_handle
Definition: cts_c.h:163
cts_c_loc_time_info_t::dst_offset
cts_c_dst_offset_t dst_offset
Definition: cts_c.h:190
cts_c_cur_time_read
sdk_err_t cts_c_cur_time_read(uint8_t conn_idx)
Read Current Time characteristic value.
CTS_C_REF_TIME_SRC_GPS
@ CTS_C_REF_TIME_SRC_GPS
Definition: cts_c.h:130
CTS_C_WEEK_FRIDAY
@ CTS_C_WEEK_FRIDAY
Definition: cts_c.h:111
cts_c_exact_time_256_t::day_of_week
uint8_t day_of_week
Definition: cts_c.h:175
cts_c_evt_t::evt_type
cts_c_evt_type_t evt_type
Definition: cts_c.h:206
CTS_C_EVT_DISCOVERY_FAIL
@ CTS_C_EVT_DISCOVERY_FAIL
Definition: cts_c.h:142
CTS_C_EVT_LOC_TIME_INFO_SET_SUCCESS
@ CTS_C_EVT_LOC_TIME_INFO_SET_SUCCESS
Definition: cts_c.h:151
cts_c_cur_time_t
Current Time value.
Definition: cts_c.h:181
cts_c_evt_t::conn_idx
uint8_t conn_idx
Definition: cts_c.h:205
CTS_C_WEEK_TUSEDAY
@ CTS_C_WEEK_TUSEDAY
Definition: cts_c.h:108
cts_c_evt_handler_t
void(* cts_c_evt_handler_t)(cts_c_evt_t *p_evt)
Current Time Service Client event handler type.
Definition: cts_c.h:221
ble_prf_utils.h
Profile/Service Utilities API.
CTS_C_WEEK_SATURDAY
@ CTS_C_WEEK_SATURDAY
Definition: cts_c.h:112
cts_c_week_day_t
cts_c_week_day_t
Current Time Day of week.
Definition: cts_c.h:105
CTS_C_WEEK_SUNDAY
@ CTS_C_WEEK_SUNDAY
Definition: cts_c.h:113
CTS_C_DST_OFFSET_DAYLIGHT_TIME
@ CTS_C_DST_OFFSET_DAYLIGHT_TIME
Definition: cts_c.h:121
CTS_C_EVT_DISCOVERY_COMPLETE
@ CTS_C_EVT_DISCOVERY_COMPLETE
Definition: cts_c.h:141
CTS_C_EVT_WRITE_OP_ERR
@ CTS_C_EVT_WRITE_OP_ERR
Definition: cts_c.h:152
CTS_C_EVT_VALID_CUR_TIME_REC
@ CTS_C_EVT_VALID_CUR_TIME_REC
Definition: cts_c.h:144
CTS_C_REF_TIME_SRC_CELLUAR_NET
@ CTS_C_REF_TIME_SRC_CELLUAR_NET
Definition: cts_c.h:134
cts_c_cur_time_notify_set
sdk_err_t cts_c_cur_time_notify_set(uint8_t conn_idx, bool is_enable)
Enable or disable peer Current Time characteristic notify.
cts_c_ref_time_info_t::days_since_update
uint8_t days_since_update
Definition: cts_c.h:198