blob: 21e66505a94d7e5e9a9bafd0b9cd38b89ce3d60b [file] [log] [blame]
lh9ed821d2023-04-07 01:36:19 -07001#include <sys/time.h>
2#include <sys/types.h>
3#include <string.h>
4#include <dirent.h>
5#include <stdlib.h>
6#include <signal.h>
7#include <sys/stat.h>
8#include <sys/ipc.h>
9#include <sys/msg.h>
10#include <errno.h>
11#include <linux/rtc.h>
12#include <sys/ioctl.h>
13#include <unistd.h>
14#include "rtc-service.h"
15#include <softap_api.h>
16
17int main(int argc, char **argv)
18{
19 int ret = -1;
20 time_t cur_time = time(0);
21
22 MSG_BUF stMsg = {0};
23 int rtc_id = -1;
24 int wlan_id = -1;
25
26 unsigned int msgSize = sizeof(MSG_BUF) - sizeof(long);
27
28 rtc_id = msgget(MODULE_ID_RTC_SERVICE, 0);
29 stMsg.ulMagic = MSG_MAGIC_WORD;
30 stMsg.lMsgType = MSG_TYPE_DEFAULT;
31 stMsg.src_id = MODULE_ID_WEB_CGI;
32 stMsg.dst_id = MODULE_ID_RTC_SERVICE;
33 stMsg.usMsgCmd = RTC_MSG_SET_TIME;
34 stMsg.usDataLen = sizeof(struct rtc_time);
35 memcpy(stMsg.aucDataBuf, &cur_time, sizeof(time_t));
36
xf.libdd93d52023-05-12 07:10:14 -070037 printf("[rtc-clock] send RTC_MSG_SET_TIME\n");
lh9ed821d2023-04-07 01:36:19 -070038AGAIN:
39 ret = msgsnd(rtc_id, &stMsg, msgSize, 0);
40 if (ret < 0) {
41 if (errno == EINTR) {
42 goto AGAIN;
43 }
44
45 printf("send_message failed: msgsnd error code [%ld,%d]!\n", ret, errno); //dujiajiao modified, 20151223
46 return -1;
47 }
48 //֪ͨ¶¨Ê±ÐÝÃß»½ÐÑÖØÐÂÉèÖÃ
49 wlan_id = msgget(MODULE_ID_WIFI, 0);
50 stMsg.ulMagic = MSG_MAGIC_WORD;
51 stMsg.lMsgType = MSG_TYPE_DEFAULT;
52 stMsg.src_id = MODULE_ID_WEB_CGI; // ½èÓÃÒ»ÏÂ
53 stMsg.dst_id = MODULE_ID_WIFI;
54 stMsg.usMsgCmd = MSG_CMD_RTC_TIME_UPDATE;
55 stMsg.usDataLen = 0;
56
xf.libdd93d52023-05-12 07:10:14 -070057 printf("[rtc-clock] send MSG_CMD_RTC_TIME_UPDATE\n");
lh9ed821d2023-04-07 01:36:19 -070058
59AGAIN1:
60 ret = msgsnd(wlan_id, &stMsg, msgSize, 0);
61 if (ret < 0) {
62 if (errno == EINTR) {
63 goto AGAIN1;
64 }
65
66 printf("send_message failed: msgsnd error code [%ld,%d]!\n", ret, errno); //dujiajiao modified, 20151223
67 return -1;
68 }
69 return 0;
70}