lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 1 | #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 | |
| 17 | int 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.li | bdd93d5 | 2023-05-12 07:10:14 -0700 | [diff] [blame] | 37 | printf("[rtc-clock] send RTC_MSG_SET_TIME\n"); |
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 38 | AGAIN: |
| 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.li | bdd93d5 | 2023-05-12 07:10:14 -0700 | [diff] [blame] | 57 | printf("[rtc-clock] send MSG_CMD_RTC_TIME_UPDATE\n"); |
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 58 | |
| 59 | AGAIN1: |
| 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 | } |