1 /* 2 * SPDX-FileCopyrightText: 2017-2021 Espressif Systems (Shanghai) CO LTD 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 */ 6 7 /** @file 8 * @brief Bluetooth Mesh Time and Scene Client Model APIs. 9 */ 10 11 #ifndef _TIME_SCENE_CLIENT_H_ 12 #define _TIME_SCENE_CLIENT_H_ 13 14 #include "client_common.h" 15 16 #ifdef __cplusplus 17 extern "C" { 18 #endif 19 20 /* Time scene client model common structure */ 21 typedef bt_mesh_client_user_data_t bt_mesh_time_scene_client_t; 22 typedef bt_mesh_client_internal_data_t time_scene_internal_data_t; 23 24 /* Time Scene Client Model Callback */ 25 extern const struct bt_mesh_model_cb bt_mesh_time_scene_client_cb; 26 27 /* Time Client Model Context */ 28 extern const struct bt_mesh_model_op bt_mesh_time_cli_op[]; 29 30 /** @def BLE_MESH_MODEL_TIME_CLI 31 * 32 * Define a new time client model. Note that this API needs to 33 * be repeated for each element which the application wants to 34 * have a time model on. 35 * @param cli_pub Pointer to a unique struct bt_mesh_model_pub. 36 * @param cli_data Pointer to a unique struct bt_mesh_time_cli. 37 * 38 * @return New time client model instance. 39 */ 40 #define BLE_MESH_MODEL_TIME_CLI(cli_pub, cli_data) \ 41 BLE_MESH_MODEL_CB(BLE_MESH_MODEL_ID_TIME_CLI, \ 42 bt_mesh_time_cli_op, cli_pub, cli_data, &bt_mesh_time_scene_client_cb) 43 44 typedef bt_mesh_client_user_data_t bt_mesh_time_client_t; 45 46 struct bt_mesh_time_status { 47 uint8_t tai_seconds[5]; /* The current TAI time in seconds */ 48 uint8_t sub_second; /* The sub-second time in units of 1/256 second */ 49 uint8_t uncertainty; /* The estimated uncertainty in 10-millisecond steps */ 50 uint16_t time_authority : 1; /* 0 = No Time Authority, 1 = Time Authority */ 51 uint16_t tai_utc_delta : 15; /* Current difference between TAI and UTC in seconds */ 52 uint8_t time_zone_offset; /* The local time zone offset in 15-minute increments */ 53 }; 54 55 struct bt_mesh_time_zone_status { 56 uint8_t time_zone_offset_curr; /* Current local time zone offset */ 57 uint8_t time_zone_offset_new; /* Upcoming local time zone offset */ 58 uint8_t tai_zone_change[5]; /* TAI Seconds time of the upcoming Time Zone Offset change */ 59 }; 60 61 struct bt_mesh_tai_utc_delta_status { 62 uint16_t tai_utc_delta_curr : 15; /* Current difference between TAI and UTC in seconds */ 63 uint16_t padding_1 : 1; /* Always 0b0. Other values are Prohibited. */ 64 uint16_t tai_utc_delta_new : 15; /* Upcoming difference between TAI and UTC in seconds */ 65 uint16_t padding_2 : 1; /* Always 0b0. Other values are Prohibited. */ 66 uint8_t tai_delta_change[5]; /* TAI Seconds time of the upcoming TAI-UTC Delta change */ 67 }; 68 69 struct bt_mesh_time_role_status { 70 uint8_t time_role; /* The Time Role for the element */ 71 }; 72 73 struct bt_mesh_time_set { 74 uint8_t tai_seconds[5]; /* The current TAI time in seconds */ 75 uint8_t sub_second; /* The sub-second time in units of 1/256 second */ 76 uint8_t uncertainty; /* The estimated uncertainty in 10-millisecond steps */ 77 uint16_t time_authority : 1; /* 0 = No Time Authority, 1 = Time Authority */ 78 uint16_t tai_utc_delta : 15; /* Current difference between TAI and UTC in seconds */ 79 uint8_t time_zone_offset; /* The local time zone offset in 15-minute increments */ 80 }; 81 82 struct bt_mesh_time_zone_set { 83 uint8_t time_zone_offset_new; /* Upcoming local time zone offset */ 84 uint8_t tai_zone_change[5]; /* TAI Seconds time of the upcoming Time Zone Offset change */ 85 }; 86 87 struct bt_mesh_tai_utc_delta_set { 88 uint16_t tai_utc_delta_new : 15; /* Upcoming difference between TAI and UTC in seconds */ 89 uint16_t padding : 1; /* Always 0b0. Other values are Prohibited. */ 90 uint8_t tai_delta_change[5]; /* TAI Seconds time of the upcoming TAI-UTC Delta change */ 91 }; 92 93 struct bt_mesh_time_role_set { 94 uint8_t time_role; /* The Time Role for the element */ 95 }; 96 97 /* Scene Client Model Context */ 98 extern const struct bt_mesh_model_op bt_mesh_scene_cli_op[]; 99 100 /** @def BLE_MESH_MODEL_SCENE_CLI 101 * 102 * Define a new scene client model. Note that this API needs to 103 * be repeated for each element which the application wants to 104 * have a scene model on. 105 * @param cli_pub Pointer to a unique struct bt_mesh_model_pub. 106 * @param cli_data Pointer to a unique struct bt_mesh_scene_cli. 107 * 108 * @return New scene client model instance. 109 */ 110 #define BLE_MESH_MODEL_SCENE_CLI(cli_pub, cli_data) \ 111 BLE_MESH_MODEL_CB(BLE_MESH_MODEL_ID_SCENE_CLI, \ 112 bt_mesh_scene_cli_op, cli_pub, cli_data, &bt_mesh_time_scene_client_cb) 113 114 typedef bt_mesh_client_user_data_t bt_mesh_scene_client_t; 115 116 struct bt_mesh_scene_status { 117 bool op_en; /* Indicate whether optional parameters included */ 118 uint8_t status_code; /* Status code for the last operation */ 119 uint16_t current_scene; /* Scene Number of a current scene */ 120 uint16_t target_scene; /* Scene Number of a target scene (optional) */ 121 uint8_t remain_time; /* Time to complete state transition (C.1) */ 122 }; 123 124 struct bt_mesh_scene_register_status { 125 uint8_t status_code; /* Status code for the previous operation */ 126 uint16_t current_scene; /* Scene Number of a current scene */ 127 struct net_buf_simple *scenes; /* A list of scenes stored within an element */ 128 }; 129 130 struct bt_mesh_scene_store { 131 uint16_t scene_number; /* The number of the scene to be stored */ 132 }; 133 134 struct bt_mesh_scene_recall { 135 bool op_en; /* Indicate whether optional parameters included */ 136 uint16_t scene_number; /* The number of the scene to be recalled */ 137 uint8_t tid; /* Transaction Identifier */ 138 uint8_t trans_time; /* Time to complete state transition (optional) */ 139 uint8_t delay; /* Indicate message execution delay (C.1) */ 140 }; 141 142 struct bt_mesh_scene_delete { 143 uint16_t scene_number; /* The number of the scene to be deleted */ 144 }; 145 146 /* Scheduler Client Model Context */ 147 extern const struct bt_mesh_model_op bt_mesh_scheduler_cli_op[]; 148 149 /** @def BLE_MESH_MODEL_SCHEDULER_CLI 150 * 151 * Define a new scheduler client model. Note that this API needs to 152 * be repeated for each element which the application wants to 153 * have a scheduler model on. 154 * @param cli_pub Pointer to a unique struct bt_mesh_model_pub. 155 * @param cli_data Pointer to a unique struct bt_mesh_scheduler_cli. 156 * 157 * @return New scheduler client model instance. 158 */ 159 #define BLE_MESH_MODEL_SCHEDULER_CLI(cli_pub, cli_data) \ 160 BLE_MESH_MODEL_CB(BLE_MESH_MODEL_ID_SCHEDULER_CLI, \ 161 bt_mesh_scheduler_cli_op, cli_pub, cli_data, &bt_mesh_time_scene_client_cb) 162 163 typedef bt_mesh_client_user_data_t bt_mesh_scheduler_client_t; 164 165 struct bt_mesh_scheduler_status { 166 uint16_t schedules; /* Bit field indicating defined Actions in the Schedule Register */ 167 }; 168 169 struct bt_mesh_scheduler_act_status { 170 uint64_t index : 4; /* Enumerates (selects) a Schedule Register entry */ 171 uint64_t year : 7; /* Scheduled year for the action */ 172 uint64_t month : 12; /* Scheduled month for the action */ 173 uint64_t day : 5; /* Scheduled day of the month for the action */ 174 uint64_t hour : 5; /* Scheduled hour for the action */ 175 uint64_t minute : 6; /* Scheduled minute for the action */ 176 uint64_t second : 6; /* Scheduled second for the action */ 177 uint64_t day_of_week : 7; /* Schedule days of the week for the action */ 178 uint64_t action : 4; /* Action to be performed at the scheduled time */ 179 uint64_t trans_time : 8; /* Transition time for this action */ 180 uint16_t scene_number; /* Transition time for this action */ 181 }; 182 183 struct bt_mesh_scheduler_act_get { 184 uint8_t index; /* Index of the Schedule Register entry to get */ 185 }; 186 187 struct bt_mesh_scheduler_act_set { 188 uint64_t index : 4; /* Index of the Schedule Register entry to set */ 189 uint64_t year : 7; /* Scheduled year for the action */ 190 uint64_t month : 12; /* Scheduled month for the action */ 191 uint64_t day : 5; /* Scheduled day of the month for the action */ 192 uint64_t hour : 5; /* Scheduled hour for the action */ 193 uint64_t minute : 6; /* Scheduled minute for the action */ 194 uint64_t second : 6; /* Scheduled second for the action */ 195 uint64_t day_of_week : 7; /* Schedule days of the week for the action */ 196 uint64_t action : 4; /* Action to be performed at the scheduled time */ 197 uint64_t trans_time : 8; /* Transition time for this action */ 198 uint16_t scene_number; /* Transition time for this action */ 199 }; 200 201 /** 202 * @brief This function is called to get scene states. 203 * 204 * @param[in] common: Message common information structure 205 * @param[in] get: Pointer of time scene get message value 206 * 207 * @return Zero-success, other-fail 208 */ 209 int bt_mesh_time_scene_client_get_state(bt_mesh_client_common_param_t *common, void *get); 210 211 /** 212 * @brief This function is called to set scene states. 213 * 214 * @param[in] common: Message common information structure 215 * @param[in] set: Pointer of time scene set message value 216 * 217 * @return Zero-success, other-fail 218 */ 219 int bt_mesh_time_scene_client_set_state(bt_mesh_client_common_param_t *common, void *set); 220 221 #ifdef __cplusplus 222 } 223 #endif 224 225 #endif /* _TIME_SCENE_CLIENT_H_ */ 226