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