blob: 637582022967740864f7522b5d4a093ab992a716 [file] [log] [blame]
yuezonghe824eb0c2024-06-27 02:32:26 -07001#include "parent_control_set.h"
2
3//nv
4#define DISABLE_NET_INTERVAL "disable_net_interval"
5#define ENABLE_NET_INTERVAL "enable_net_interval"
6
7#define DISABLE_NET_TIMER 61
8#define ENABLE_NET_TIMER 62
9
10//È«¾Ö±äÁ¿ÓÃÓڴ洢ÿÌìµÄÐÅÏ¢£ºÊÇ·ñÉèÖùý¡¢Ê±¼ä£¬Ï±ê0~6·Ö±ð¶ÔÓ¦ÖÜÈÕ~ÖÜÁù
11Time_Node global_disable_para[7] = {0};
12
13unsigned long val_disable = 0;
14unsigned long val_enable = 0;
15
16int disble_timer_mark = 0;
17int enable_timer_mark = 0;
18
19static void disable_net_recall();
20static void enable_net_recall();
21static int calculate_disable_interval();
22
23int get_msg_qid(int module_id)
24{
25 int msg_qid = -1;
26
27 slog(MISC_PRINT, SLOG_ERR, "[get_msg_qid] module_id = %d\n", module_id);
28
29AGAIN:
30 msg_qid = msgget(module_id, IPC_CREAT | 0600);
31 if (msg_qid == -1) {
32 slog(MISC_PRINT, SLOG_ERR, "error!cannot get the destination message id!module_id=%d, errno=%d\n", module_id, errno);
33
34 sleep(1);
35 goto AGAIN;
36 }
37
38 return msg_qid;
39}
40
41//ÏòÍøÂç·¢ËͽûÓÃÏûÏ¢
42static int send_to_net_for_disable_network()
43{
44 int iRet = -1;
45
46 slog(MISC_PRINT, SLOG_ERR, "send_to_net_for_disable_network fail\n");
47
48 iRet = ipc_send_message(MODULE_ID_PARENT_CONTROL_SET, MODULE_ID_MAIN_CTRL, MSG_CMD_NET_START_NONET, 0, NULL, 0);
49 if (iRet != 0)
50 slog(MISC_PRINT, SLOG_ERR, "send_to_net_for_disable_network fail, iRet=%d %s\n", iRet, strerror(iRet));
51 return iRet;
52}
53
54//ÏòÍøÂç·¢ËÍ¿ªÆôÏûÏ¢
55static int send_to_net_for_enable_network()
56{
57 int iRet = -1;
58
59 slog(MISC_PRINT, SLOG_ERR, "send_to_net_for_enable_network\n");
60
61 iRet = ipc_send_message(MODULE_ID_PARENT_CONTROL_SET, MODULE_ID_MAIN_CTRL, MSG_CMD_NET_STOP_NONET, 0, NULL, 0);
62 if (iRet != 0)
63 slog(MISC_PRINT, SLOG_ERR, "send_to_net_for_enable_network fail, iRet=%d %s\n", iRet, strerror(iRet));
64 return iRet;
65}
66
67//* Description: ´´½¨ÏûÏ¢¶ÓÁÐID
68//* Input: Ï̵߳ÄID±êʶ
69//* Output: ÏûÏ¢¶ÓÁÐID
70int create_msg_qid(int module_id)
71{
72 int msg_qid = -1;
73
74AGAIN:
75 msg_qid = msgget(module_id, IPC_CREAT | 0600);
76 if (msg_qid == -1) {
77 slog(MISC_PRINT, SLOG_ERR, "create msg fail, module_id=%d, errno=%d\n", module_id, errno);
78 sleep(1);
79 goto AGAIN;
80 }
81
82 return msg_qid;
83}
84
85//ɾ³ýPCS¶¨Ê±Æ÷£¬´ËÌõ¼þÏÂÔÊÐíÉÏÍø
86static void DeleteTimer_PCS()
87{
88 rtc_timer_del(DISABLE_NET_TIMER, MODULE_ID_PARENT_CONTROL_SET);
89 rtc_timer_del(ENABLE_NET_TIMER, MODULE_ID_PARENT_CONTROL_SET);
90
91 if (send_to_net_for_enable_network() < 0) {
92 slog(MISC_PRINT, SLOG_ERR, "[%s]send_to_net_for_enable_network failure\n", __FUNCTION__);
93 } else {
94 slog(MISC_PRINT, SLOG_ERR, "[%s]parent time control is closed, send_to_net_for_enable_network\n", __FUNCTION__);
95 }
96}
97
98void set_disable_time_interval(int wday, int hour)
99{
100 if (global_disable_para[wday].TimeSet[hour].flag != 1)
101 set_disable_time_interval(wday, hour - 1);
102 else {
103 global_disable_para[wday].TimeSet[hour].enable_interval += 60 * 60;
104 slog(MISC_PRINT, SLOG_ERR, "[%s]wday:%d, hour:%d, interval: %ld\n", __FUNCTION__, wday, hour, global_disable_para[wday].TimeSet[hour].enable_interval);
105 }
106}
107
108//½«Ê±¼ä´æ´¢ÓÚ¶ÔÓ¦µÄÊý×éÖÐ
109static int save_time(int wday, char *tptr)
110{
111 char time_str[64] = {0};
112 char* outer_ptr = NULL;
113 char* inner_ptr = NULL;
114 int timeNum = 0;
115 int hour = 0;
116 int last_disable_hour = -2;
117 //int last_disable_minute = 0; À©Õ¹ÓÃ
118
119 if (tptr == NULL) {
120 slog(MISC_PRINT, SLOG_ERR, "[%s]error!\n", __FUNCTION__);
121 return -1;
122 }
123 memcpy(time_str, tptr, strlen(tptr));
124 time_str[63]='\0';
125 slog(MISC_PRINT, SLOG_ERR, "[%s]time_str:%s\n", __FUNCTION__, time_str);
126
127 outer_ptr = strtok_r(time_str, ",", &inner_ptr);
128 while (outer_ptr) {
129 slog(MISC_PRINT, SLOG_ERR, "[%s]wday:%d, index:%d, time:%s\n", __FUNCTION__, wday, timeNum, outer_ptr);
130 /********************************
131 ÒÔºóÀ©Õ¹¾«È·µ½·ÖµÄʱ¼ä¿ØÖÆ
132 ÏÖÔÚĬÈÏһСʱ
133 ********************************/
134 hour = atoi(outer_ptr);
135 if(hour <= -1 || hour >=24)
136 {
137 outer_ptr = strtok_r(NULL, ",", &inner_ptr);
138 slog(MISC_PRINT, SLOG_ERR, "[%s]wday:%d, index:%d, err time:%s, hour:%d\n", __FUNCTION__, wday, timeNum, outer_ptr, hour);
139 continue;
140 }
141 //last_disable_hour == hour - 1 ˵Ã÷¿É»ØËÝ
142 if (last_disable_hour == hour - 1) {
143 set_disable_time_interval(wday, hour - 1);
144 } else {
145 global_disable_para[wday].TimeSet[hour].flag = 1;
146 //ÒÔºóÈç¹ûÖ§³Ö·ÖÖÓµÄÉèÖô˴¦À©Õ¹
147 //global_disable_para[wday].TimeSet[hour].minute[0] = 1;
148 global_disable_para[wday].TimeSet[hour].enable_interval = 60 * 60;
149 slog(MISC_PRINT, SLOG_ERR, "[%s]wday:%d, hour:%d, interval:%ld\n", __FUNCTION__, wday, hour, global_disable_para[wday].TimeSet[hour].enable_interval);
150 }
151 if (last_disable_hour == -2) {
152 global_disable_para[wday].first_hour = hour + 1;
153 }
154 last_disable_hour = hour;
155 outer_ptr = strtok_r(NULL, ",", &inner_ptr);
156 }
157 global_disable_para[wday].TimeNum = timeNum;
158 slog(MISC_PRINT, SLOG_ERR, "[%s]wday:%d, total hour num is %d\n", __FUNCTION__, wday, timeNum);
159 return 0;
160}
161
162//½«a+bµÄÊý¾Ý·Ö±ð´æ´¢
163static int save_data_to_global_para(char *ptr)
164{
165 char wtmp[2] = {0};
166 char dtmp[64] = {0};
167 int i = 0;
168 int len = 0;
169 //int sublen = 0;
170 char* tmp = NULL;
171
172 if (ptr == NULL) {
173 slog(MISC_PRINT, SLOG_ERR, "[%s]param error!\n", __FUNCTION__);
174 return -1;
175 }
176
177 len = strlen(ptr);//´«Èë²ÎÊýʵ¼Ê³¤¶È
178 slog(MISC_PRINT, SLOG_ERR, "[%s]ptr:%s, len:%d\n", __FUNCTION__, ptr, len);
179
180 //´Ë´¦°Ñ+֮ǰµÄ×Ö·ûÈ¡³ö
181 snprintf(wtmp, sizeof(wtmp), "%s", ptr);
182 slog(MISC_PRINT, SLOG_ERR, "[%s]week day is %s\n", __FUNCTION__, wtmp);
183
184 tmp = ptr + 2;
185 //sublen = len - 2;
186 //ps_log("[%s]sublen:%d,*tmp:%s\n",__FUNCTION__,sublen,tmp);
187 //´Ë´¦°Ñ+Ö®ºóµÄ×Ö·û´®Ìá³ö
188 snprintf(dtmp, sizeof(dtmp), "%s", tmp);
189 slog(MISC_PRINT, SLOG_ERR, "[%s]limited hours are %s\n", __FUNCTION__, dtmp);
190
191 for (i = 0; i < 7; i++) {
192 if (atoi(wtmp) == i) {
193 global_disable_para[i].first_hour = 1;
194 slog(MISC_PRINT, SLOG_ERR, "[%s]data to be saved:week day=%d, hours=%s\n", __FUNCTION__, i, dtmp);
195 save_time(i, dtmp);
196 break;
197 }
198 }
199
200 return 0;
201}
202
203//´ÓnvÖÐÌáÈ¡ÐÅÏ¢µ½È«¾Ö±äÁ¿ÖÐ
204//time_limited=0+0,3,4,8,10,13,14,17,21;1+1,9,12,14,19,23;3+5,9,11,12,15,20,23;
205static int get_param_from_nv(char *p_time_limited)
206{
207 char *outer_ptr = NULL;
208 char *inner_ptr = NULL;
209 char time_limited_str[PCS_NV_MAX_LEN] = {0};
210 int iRet = -1;
211
212 if (p_time_limited == NULL || *p_time_limited == '\0') {
213 slog(MISC_PRINT, SLOG_ERR, "[%s]para is invalid.\n", __FUNCTION__);
214 return -1;
215 }
216 memset(&global_disable_para, 0, 7 * sizeof(Time_Node));
217
218 memcpy(time_limited_str, p_time_limited, strlen(p_time_limited));//ÐèÒªÏÖ½«´«Èë²ÎÊý¿½±´µ½time_limited_strÊý×éÖÐ
219 time_limited_str[PCS_NV_MAX_LEN-1]='\0';
220
221 slog(MISC_PRINT, SLOG_ERR, "[%s]time_limited_str=%s\n", __FUNCTION__, time_limited_str);
222
223 outer_ptr = strtok_r(time_limited_str, ";", &inner_ptr);
224 while (outer_ptr) {
225 slog(MISC_PRINT, SLOG_ERR, "[%s]string spilt is %s\n", __FUNCTION__, outer_ptr);
226 iRet = save_data_to_global_para(outer_ptr);
227 if (iRet == -1) {
228 slog(MISC_PRINT, SLOG_ERR, "[%s]save_data_to_global_para error\n", __FUNCTION__);
229 return -1;
230 }
231 outer_ptr = strtok_r(NULL, ";", &inner_ptr);
232 }
233 return 0;
234}
235
236//»ñÈ¡µ±Ç°µÄϵͳʱ¼ä
237static int get_local_time(TM* CurrentTime)
238{
239 time_t CTime;
240
241 time(&CTime);
242 localtime_r(&CTime, CurrentTime);
243 slog(MISC_PRINT, SLOG_ERR, "[%s]CurrentTime:tm_wday=%d, tm_hour=%d, tm_min=%d, tm_sec=%d\n", __FUNCTION__, CurrentTime->tm_wday, CurrentTime->tm_hour,
244 CurrentTime->tm_min, CurrentTime->tm_sec);
245 return 0;
246}
247
248void find_the_latest_disable_hour(const int WeekDay, int *latest_disable_hour, unsigned long *interval, const int CurHour, const int min)
249{
250 //µ±Ç°×î½üÒ»´ÎÓÐЧdisableʱ¼äÔÚµ±Ç°Ê±¼äºóÃæ
251 if (*latest_disable_hour > CurHour) {
252 *interval = global_disable_para[WeekDay].TimeSet[*latest_disable_hour].enable_interval;
253 } else if (global_disable_para[WeekDay].TimeSet[*latest_disable_hour].enable_interval / 3600 + *latest_disable_hour > CurHour) {
254 //µ±Ç°´¦ÓÚdisableʱ¼ä¶Î
255 *interval = global_disable_para[WeekDay].TimeSet[*latest_disable_hour].enable_interval - (CurHour - *latest_disable_hour) * 3600 - min * 60;
256 } else if (*latest_disable_hour < 23) {
257 //ѰÕÒ×î½Ó½üµ±Ç°Ê±¼äµÄÓÐЧdisableʱ¼ä
258 *latest_disable_hour = *latest_disable_hour + global_disable_para[WeekDay].TimeSet[*latest_disable_hour].enable_interval / 3600 + 1;
259 find_the_latest_disable_hour(WeekDay, latest_disable_hour, interval, CurHour, min);
260 }
261}
262
263static int find_valid_disable_time(int WeekDay, int CurHour, int Curmin)
264{
265 int i = 0;
266 int latest_disable_hour = -2;
267 unsigned long interval = 0;
268 unsigned long dis_interval = 0;
269 char enable_time_interval[100] = {0};
270 char disable_time_interval[100] = {0};
271
272 slog(MISC_PRINT, SLOG_ERR, "[%s]enter hour %d\n", __FUNCTION__, global_disable_para[WeekDay].first_hour);
273 //ÏÈ¿´µ±Ç°ÊÇ·ñÓ¦µ±´¦ÓÚ½ûÓÃʱ¶Î£¬Ê£Óà½ûÓÃʱ³¤ÊǶàÉÙ
274 if (global_disable_para[WeekDay].first_hour - 1 >= 0) {
275 latest_disable_hour = global_disable_para[WeekDay].first_hour - 1;
276 find_the_latest_disable_hour(WeekDay, &latest_disable_hour, &interval, CurHour, Curmin);
277 if (interval > 0) {
278 if (latest_disable_hour > CurHour)
279 dis_interval = (latest_disable_hour - CurHour) * 3600 - Curmin * 60;
280 else
281 dis_interval = 1;
282 sprintf(enable_time_interval, "%ld", interval);
283 sprintf(disable_time_interval, "%ld", dis_interval);
284 cfg_set(DISABLE_NET_INTERVAL, disable_time_interval);
285 cfg_set(ENABLE_NET_INTERVAL, enable_time_interval);
286 val_enable = interval;
287 val_disable = dis_interval;
288 slog(MISC_PRINT, SLOG_ERR, "[%s] latest_disable_hour = %d, curhour = %d, curmin = %d, val_enable = %ld,val_disable = %ld\n", __FUNCTION__, latest_disable_hour, CurHour, Curmin, val_enable, val_disable);
289 return 0;
290 }
291 }
292
293 slog(MISC_PRINT, SLOG_ERR, "[%s]cur day no set or cur time has already passed\n", __FUNCTION__);
294 //Èç¹ûµ±ÌìûÓÐÉèÖûòÕßµ±Ç°Ê±¼äÒѾ­³¬¹ýÁ˵±ÌìµÄÉèÖÃʱ¼ä
295 for (i = 1; i <= 7; i++) {
296 if (global_disable_para[(WeekDay + i) % 7].first_hour - 1 >= 0) {
297 latest_disable_hour = global_disable_para[(WeekDay + i) % 7].first_hour - 1;
298
299 dis_interval = i * 60 * 60 * 24 + (latest_disable_hour - CurHour) * 60 * 60 - Curmin * 60;
300 interval = global_disable_para[(WeekDay + i) % 7].TimeSet[latest_disable_hour].enable_interval;
301
302 sprintf(enable_time_interval, "%ld", interval);
303 sprintf(disable_time_interval, "%ld", dis_interval);
304 cfg_set(DISABLE_NET_INTERVAL, disable_time_interval);
305 cfg_set(ENABLE_NET_INTERVAL, enable_time_interval);
306 val_enable = interval;
307 val_disable = dis_interval;
308 //CreateSoftTimer(DISABLE_NET_TIMER, TIMER_FLAG_ONCE, dis_interval*1000, (void*)(*disable_net_recall), NULL);
309 slog(MISC_PRINT, SLOG_ERR, "[%s] i = %d, latest_disable_hour = %d, curhour = %d, curmin = %d, val_enable = %ld,val_disable = %ld\n", __FUNCTION__, i, latest_disable_hour, CurHour, Curmin, val_enable, val_disable);
310 return 0;
311 }
312 }
313 return -1;
314}
315
316//¼ÆËãÏ´νûÖ¹ÉÏÍøºÍÔÊÐíÉÏÍøµÄ¼ä¸ôʱ¼ä
317static int calculate_disable_interval()
318{
319 int iRet = -1;
320 TM CurTime = {0};
321 int WeekDay = 0;
322 int CurHour = 0;
323 int CurMinute = 0;
324 int CurSecond = 0;
325
326 int DisableInterval = -1;
327 int EnableInterval = -1;
328
329 iRet = get_local_time(&CurTime);
330
331 WeekDay = CurTime.tm_wday;
332 CurHour = CurTime.tm_hour;
333 CurMinute = CurTime.tm_min;
334 CurSecond = CurTime.tm_sec;
335
336 slog(MISC_PRINT, SLOG_ERR, "[%s]current day is %d\n", __FUNCTION__, WeekDay);
337 iRet = find_valid_disable_time(WeekDay, CurHour, CurMinute);
338 if (iRet < 0) {
339 DeleteTimer_PCS();
340 slog(MISC_PRINT, SLOG_ERR, "[%s]find_next_disable_time error\n", __FUNCTION__);
341 }
342 return iRet;
343}
344
345//´Ë´¦´¦Àíenable
346static void enable_net_recall()
347{
348 int iRet = -1;
349
350 slog(MISC_PRINT, SLOG_ERR, "[%s]val_enable=%ld\n", __FUNCTION__, val_enable);
351
352 if (send_to_net_for_enable_network() < 0) {
353 slog(MISC_PRINT, SLOG_ERR, "[%s] send_to_net_for_enable_network failure!\n", __FUNCTION__);
354 } else {
355 slog(MISC_PRINT, SLOG_ERR, "[%s]send_to_net_for_enable_network successfully!\n", __FUNCTION__);
356 }
357
358 /* iRet = ipc_send_message(MODULE_ID_PARENT_CONTROL_SET, MODULE_ID_PARENT_CONTROL_SET, DISABLE_NET_TIMER, 0, NULL, 0);
359 if (iRet < 0){
360 slog(MISC_PRINT,SLOG_ERR,"[%s]enable_net_recall send msg failed!\n",__FUNCTION__);
361 }*/
362}
363
364static void disable_net_recall()
365{
366 int iRet = -1;
367
368 slog(MISC_PRINT, SLOG_ERR, "[%s]val_disable = %d\n", __FUNCTION__, val_disable);
369
370 if (send_to_net_for_disable_network() < 0) {
371 slog(MISC_PRINT, SLOG_ERR, "[%s]send_to_net_for_disable_network failure!\n", __FUNCTION__);
372 } else {
373 slog(MISC_PRINT, SLOG_ERR, "[%s]send_to_net_for_disable_network successfully!\n", __FUNCTION__);
374 }
375
376 /* iRet = ipc_send_message(MODULE_ID_PARENT_CONTROL_SET, MODULE_ID_PARENT_CONTROL_SET, ENABLE_NET_TIMER, 0, NULL, 0);
377 if (iRet < 0){
378 slog(MISC_PRINT,SLOG_ERR,"[%s]disable_net_recall send msg failed!\n", __FUNCTION__);
379 }*/
380}
381
382//¼Ò³¤¿ØÖÆÊ±¼ä¹ÜÀíÉèÖô¦Àí
383void handle_parent_control_setting()
384{
385 int iRet = -1;
386 char time_limited[PCS_NV_MAX_LEN] = {0};
387
388 cfg_get_item("time_limited", time_limited, sizeof(time_limited));
389
390 slog(MISC_PRINT, SLOG_ERR, "[%s]time_limited is %s\n", __FUNCTION__, time_limited);
391
392 memset(global_disable_para, 0, sizeof(Time_Node) * 7);
393
394 //ɾ³ý¶¨Ê±Æ÷
395 DeleteTimer_PCS();
396
397 val_disable = 0;
398 val_enable = 0;
399
400 if (strcmp(time_limited, "") == 0) {
401 slog(MISC_PRINT, SLOG_ERR, "[%s]no time is set,so delete two timers\n", __FUNCTION__);
402 return;
403 }
404
405 iRet = get_param_from_nv(time_limited);
406 if (iRet == -1) {
407 slog(MISC_PRINT, SLOG_ERR, "[%s] get_param_from_nv is error\n", __FUNCTION__);
408 return;
409 }
410
411 iRet = calculate_disable_interval(); //»ñµÃÁ½¸öµ¹¼ÆÊ±³¤
412 if (iRet < 0) {
413 slog(MISC_PRINT, SLOG_ERR, "[%s] error\n", __FUNCTION__);
414 return;
415 }
416 rtc_timer_add(val_disable, DISABLE_NET_TIMER, MODULE_ID_PARENT_CONTROL_SET);
417}
418
419//½âÎö½ÓÊÕµ½µÄÏûÏ¢
420int parse_recieved_msg(MSG_BUF *pstMsg)
421{
422 if (NULL == pstMsg) {
423 slog(MISC_PRINT, SLOG_ERR, "[parent control set] pstMsg is NULL\n");
424 return -1;
425 } else if (pstMsg->ulMagic != MSG_MAGIC_WORD) {
426 slog(MISC_PRINT, SLOG_ERR, "[parent control set] pstMsg magic error\n");
427 return -1;
428 } else if (pstMsg->dst_id != MODULE_ID_PARENT_CONTROL_SET) {
429 slog(MISC_PRINT, SLOG_ERR, "[parent control set] target is not wlan pstMsg->dst_id is %x\n", pstMsg->dst_id);
430 return -1;
431 }
432 slog(MISC_PRINT, SLOG_ERR, "[parent control set] src_id=%x usMsgCmd=%x\n", pstMsg->src_id, pstMsg->usMsgCmd);
433
434 //pc_wake_lock();
435 RTC_DATA_BUF *buf;
436 switch (pstMsg->src_id) {
437 case MODULE_ID_WEB_CGI:
438 if (pstMsg->usMsgCmd == MSG_CMD_PARENT_CONTROL_SET) {
439 slog(MISC_PRINT, SLOG_ERR, "[parent control set]MSG_CMD_PARENT_CONTROL_SET\n");
440 handle_parent_control_setting();
441 } else if (pstMsg->usMsgCmd == MSG_CMD_PARENT_CONTROL_CLOSE) {
442 slog(MISC_PRINT, SLOG_ERR, "[parent control set]MSG_CMD_PARENT_CONTROL_CLOSE\n");
443 DeleteTimer_PCS();
444 }
445 break;
446 case MODULE_ID_SNTP:
447 //ÊÕµ½sntpͬ²½ÏûÏ¢
448 if (pstMsg->usMsgCmd == MSG_CMD_SNTP_SUCCESS) {
449 slog(MISC_PRINT, SLOG_ERR, "[parent control set]MSG_CMD_SNTP_REPLY\n");
450 handle_parent_control_setting();
451 }
452 break;
453 /* case MODULE_ID_PARENT_CONTROL_SET:
454 //soft_timer¶¨Ê±Æ÷³¬Ê±£¬¸ø×Ô¼º·¢ÏûÏ¢
455 if (pstMsg->usMsgCmd == ENABLE_NET_TIMER)
456 {
457 slog(MISC_PRINT,SLOG_ERR, "receive msg to enable_timer\n");
458 if (enable_timer_mark == 0){
459 // CreateSoftTimer(ENABLE_NET_TIMER, TIMER_FLAG_ONCE, val_enable * 1000, (void*)(*enable_net_recall), NULL);
460 rtc_timer_add(val_enable , ENABLE_NET_TIMER, MODULE_ID_PARENT_CONTROL_SET);
461 enable_timer_mark = 1;
462 }
463 } else if (pstMsg->usMsgCmd == DISABLE_NET_TIMER){
464 slog(MISC_PRINT,SLOG_ERR, "receive msg to disable_timer\n");
465 if (calculate_disable_interval() == 0){
466 // CreateSoftTimer(DISABLE_NET_TIMER, TIMER_FLAG_ONCE, val_disable * 1000, (void*)(*disable_net_recall), NULL);
467 rtc_timer_add(val_disable, DISABLE_NET_TIMER, MODULE_ID_PARENT_CONTROL_SET);
468 disable_net_recall();
469 // disble_timer_mark = 1;
470 }
471 }
472 break;*/
473 case MODULE_ID_RTC_SERVICE:
474 buf = pstMsg->aucDataBuf;
475 slog(MISC_PRINT, SLOG_ERR, "buf.module = %d\n", buf->module);
476 if (buf->module == ENABLE_NET_TIMER) {
477 slog(MISC_PRINT, SLOG_ERR, "receive msg to enable_timer\n");
478 if (calculate_disable_interval() == 0) {
479 rtc_timer_add(val_disable, DISABLE_NET_TIMER, MODULE_ID_PARENT_CONTROL_SET);
480 enable_net_recall();
481 }
482 } else if (buf->module == DISABLE_NET_TIMER) {
483 slog(MISC_PRINT, SLOG_ERR, "receive msg to disable_timer\n");
484 rtc_timer_add(val_enable, ENABLE_NET_TIMER, MODULE_ID_PARENT_CONTROL_SET);
485 disable_net_recall();
486 }
487 default:
488 break;
489 }
490
491 //pc_wake_unlock();
492 return 0;
493}
494
495/*************************
496nv : time_limited ½ûÖ¹ÉÏÍøÊ±¼äµã,ÒÔ;Ϊ½çÇø·ÖÌì0~6(ÐÇÆÚÌì~ÐÇÆÚÁù), +ǰ±íʾÌ죬ºó±íʾ½ûÖ¹ÉÏÍøÊ±¼ä
497time_limited=0+0,3,4,8,10,13,14,17,21;1+1,9,12,14,19,23;3+5,9,11,12,15,20,23;
498*************************/
499int main(int args, char argv[])
500{
501 MSG_BUF RecvMsg = {0};
502 int iRet = -1;
503 int Ret = -1;
504 int parent_msg_qid = 0;
505 char time_limited[PCS_NV_MAX_LEN] = {0};
506
507 //³õʼ»¯´òÓ¡¼¶±ð£¬²¢×¢²á¶¯Ì¬µ÷Õû´òÓ¡¼¶±ðÐźÅÁ¿
508 loglevel_init();
509
510 parent_msg_qid = create_msg_qid(MODULE_ID_PARENT_CONTROL_SET);
511
512 slog(MISC_PRINT, SLOG_ERR, "[parent control set] main thread getpid = %d\n", getpid());
513
514 //¿ª»úÅжÏtime_limitedÕâ¸önvÊÇ·ñΪ¿Õ£¬ÈôΪ¿Õ£¬Ôò¸ønet·¢ËÍ»½ÐÑÍøÂçµÄÏûÏ¢£»Èô²»Îª¿Õ£¬ÔòÖØÐÂÉèÖá£
515 handle_parent_control_setting();
516
517 //ÏòSNTP×¢²áÏûÏ¢£¬ÒªÇóSNTP³É¹¦ºó֪ͨϱ¾Ó¦ÓÃ
518 iRet = ipc_send_message2(MODULE_ID_PARENT_CONTROL_SET, MODULE_ID_SNTP, MSG_CMD_SNTP_REGISTER, 0, NULL, 0);
519 if (iRet != 0) {
520 slog(MISC_PRINT, SLOG_ERR, "[parent control set]ipc_send_message to sntp failed\n");
521 }
522
523 while (1) {
524 memset(&RecvMsg, 0, sizeof(MSG_BUF));
525 iRet = msgrcv(parent_msg_qid, &RecvMsg, sizeof(MSG_BUF) - sizeof(LONG), 0, 0);
526 if (iRet == -1) {
527 slog(MISC_PRINT, SLOG_ERR, "[parent control set]msgrcv error errno = %d, %s\n", errno, strerror(errno));
528 continue;
529 }
530 parse_recieved_msg(&RecvMsg);
531 }
532 return 0;
533}