b.liu | 4e243dc | 2023-11-27 11:20:00 +0800 | [diff] [blame] | 1 | #include "lynq_systime.h" |
| 2 | #include "mbtk_type.h" |
luojin | 071b385 | 2024-01-15 15:58:34 +0800 | [diff] [blame] | 3 | #include <stdlib.h> |
| 4 | #include <sys/types.h> |
| 5 | #include <sys/socket.h> |
| 6 | #include <stdio.h> |
| 7 | #include <errno.h> |
| 8 | #include <netdb.h> |
| 9 | #include <string.h> |
| 10 | #include <unistd.h> |
| 11 | #include <time.h> |
| 12 | #include <netinet/in.h> |
| 13 | |
| 14 | #include <cutils/properties.h> |
| 15 | #include <sys/time.h> |
| 16 | |
| 17 | |
| 18 | #include "mbtk_ntp.h" |
| 19 | #include "mbtk_net_control.h" |
| 20 | #include "lynq_systime.h" |
| 21 | #include "mbtk_type.h" |
luojian | 252d7bc | 2024-09-24 16:32:38 +0800 | [diff] [blame] | 22 | #include "mbtk_log.h" |
luojin | 071b385 | 2024-01-15 15:58:34 +0800 | [diff] [blame] | 23 | |
| 24 | |
| 25 | #define MBTK_AT_NTP_LEN_MAX 128 |
| 26 | |
| 27 | |
| 28 | |
| 29 | |
| 30 | typedef enum { |
r.xiao | 8b07413 | 2024-02-22 23:57:50 -0800 | [diff] [blame] | 31 | LYNQ_TIME_TYPE_CELL = 0, //NITZ |
| 32 | LYNQ_TIME_TYPE_NTP, |
| 33 | LYNQ_TIME_TYPE_GNSS, |
| 34 | LYNQ_TIME_TYPE_USER, |
| 35 | |
| 36 | LYNQ_TIME_TYPE_UNUSE |
| 37 | } lynq_time_type_enum; |
luojin | 071b385 | 2024-01-15 15:58:34 +0800 | [diff] [blame] | 38 | |
| 39 | //enable set time from ntp |
| 40 | int ntp_sync_time(int enable); |
| 41 | //enable set time from nitz |
| 42 | int modem_time_enable(int enable); |
| 43 | //enable set time from gnss |
| 44 | int gnss_time_enable(int enable); |
| 45 | //enable set time from user |
| 46 | int user_set_time(char* date, char* time); |
| 47 | // RTC TIME set to system |
| 48 | int lynq_sync_time_from_rtc(void); |
| 49 | //check sysytem type |
| 50 | int lynq_get_time_src_status (time_src_status_s * time_src); |
| 51 | // system time set to RTC |
| 52 | int lynq_set_rtc_time(void); |
| 53 | // get RTC time |
| 54 | int lynq_get_rtc_time(unsigned long *ulsec); |
| 55 | |
luojian | 799341e | 2024-09-25 17:58:07 +0800 | [diff] [blame^] | 56 | int sync_time_flag = 0; |
luojin | 071b385 | 2024-01-15 15:58:34 +0800 | [diff] [blame] | 57 | |
luojin | 071b385 | 2024-01-15 15:58:34 +0800 | [diff] [blame] | 58 | //int req_time_set(int type, char *time, int *cme_err); |
| 59 | static int metis_strptime(char *str_time) |
| 60 | { |
luojian | 252d7bc | 2024-09-24 16:32:38 +0800 | [diff] [blame] | 61 | LOGD("%s(), str_time:%s\n", __FUNCTION__, str_time); |
luojin | 071b385 | 2024-01-15 15:58:34 +0800 | [diff] [blame] | 62 | struct tm stm; |
| 63 | char dateTime[30]; |
| 64 | struct timeval tv; |
| 65 | if(strptime(str_time, "%Y-%m-%d %H:%M:%S",&stm) != NULL) |
| 66 | { |
luojian | 88976a3 | 2024-08-14 17:40:01 +0800 | [diff] [blame] | 67 | time_t _t = (long)mktime(&stm); |
| 68 | tzset(); |
luojin | 071b385 | 2024-01-15 15:58:34 +0800 | [diff] [blame] | 69 | tv.tv_sec = _t; |
luojian | 88976a3 | 2024-08-14 17:40:01 +0800 | [diff] [blame] | 70 | tv.tv_usec = 0; |
| 71 | if(_t == -1) |
| 72 | { |
luojian | 252d7bc | 2024-09-24 16:32:38 +0800 | [diff] [blame] | 73 | LOGD("Set time :%s", str_time); |
| 74 | LOGD("timestamp:%ld", _t); |
| 75 | LOGD("mktime error, reason: %s\n", strerror(errno)); |
luojin | 071b385 | 2024-01-15 15:58:34 +0800 | [diff] [blame] | 76 | return -1; |
luojin | 071b385 | 2024-01-15 15:58:34 +0800 | [diff] [blame] | 77 | } |
luojian | 88976a3 | 2024-08-14 17:40:01 +0800 | [diff] [blame] | 78 | |
| 79 | if(settimeofday(&tv, NULL)) { |
luojian | 252d7bc | 2024-09-24 16:32:38 +0800 | [diff] [blame] | 80 | LOGD("Set time :%s", str_time); |
| 81 | LOGD("timestamp:%ld", _t); |
| 82 | LOGD("mktime error, reason: %s\n", strerror(errno)); |
luojian | 88976a3 | 2024-08-14 17:40:01 +0800 | [diff] [blame] | 83 | return -1; |
| 84 | } |
| 85 | |
luojian | 252d7bc | 2024-09-24 16:32:38 +0800 | [diff] [blame] | 86 | LOGD("Success Set time to %s.\n", str_time); |
luojian | 88976a3 | 2024-08-14 17:40:01 +0800 | [diff] [blame] | 87 | return 0; |
| 88 | |
luojin | 071b385 | 2024-01-15 15:58:34 +0800 | [diff] [blame] | 89 | } else { |
luojian | 252d7bc | 2024-09-24 16:32:38 +0800 | [diff] [blame] | 90 | LOGD("Set time fail."); |
luojin | 071b385 | 2024-01-15 15:58:34 +0800 | [diff] [blame] | 91 | return -1; |
| 92 | } |
| 93 | return 0; |
| 94 | } |
| 95 | |
| 96 | |
liuyang | bfc4d7c | 2024-05-07 10:44:28 +0800 | [diff] [blame] | 97 | static void* ntp_pthread_run(int* ntp_flag) |
luojin | 071b385 | 2024-01-15 15:58:34 +0800 | [diff] [blame] | 98 | { |
liuyang | 0a15e08 | 2024-04-19 17:28:49 +0800 | [diff] [blame] | 99 | if (mbtk_net_state_get() == MBTK_NET_STATE_OFF) |
| 100 | { |
luojian | 252d7bc | 2024-09-24 16:32:38 +0800 | [diff] [blame] | 101 | LOGD("Network is disconnected. Set time fail."); |
liuyang | bfc4d7c | 2024-05-07 10:44:28 +0800 | [diff] [blame] | 102 | if(NULL != ntp_flag) |
| 103 | { |
| 104 | *ntp_flag = -1; |
| 105 | } |
liuyang | 0a15e08 | 2024-04-19 17:28:49 +0800 | [diff] [blame] | 106 | return NULL; |
luojin | 071b385 | 2024-01-15 15:58:34 +0800 | [diff] [blame] | 107 | } |
luojian | 252d7bc | 2024-09-24 16:32:38 +0800 | [diff] [blame] | 108 | LOGD("Network is connected."); |
luojin | 071b385 | 2024-01-15 15:58:34 +0800 | [diff] [blame] | 109 | |
| 110 | char time_type[10]; |
| 111 | while(1){ |
| 112 | memset(time_type, 0, 10); |
| 113 | property_get("persist.mbtk.time_type", time_type, "0"); |
r.xiao | 8b07413 | 2024-02-22 23:57:50 -0800 | [diff] [blame] | 114 | if(atoi(time_type) == LYNQ_TIME_TYPE_NTP) // NTP time |
luojin | 071b385 | 2024-01-15 15:58:34 +0800 | [diff] [blame] | 115 | { |
| 116 | char time_str[100] = {0}; |
| 117 | time_t time = 0; |
liuyang | d0f7fdb | 2024-04-22 13:53:23 +0800 | [diff] [blame] | 118 | if((time = (time_t)mbtk_at_systime()) == 0) |
liuyang | 5458290 | 2024-04-19 18:06:25 +0800 | [diff] [blame] | 119 | { |
luojian | 252d7bc | 2024-09-24 16:32:38 +0800 | [diff] [blame] | 120 | LOGD("NTP client fail!\n"); |
liuyang | bfc4d7c | 2024-05-07 10:44:28 +0800 | [diff] [blame] | 121 | if(NULL != ntp_flag) |
| 122 | { |
| 123 | *ntp_flag = -1; |
| 124 | } |
liuyang | 5458290 | 2024-04-19 18:06:25 +0800 | [diff] [blame] | 125 | return NULL; |
luojin | 071b385 | 2024-01-15 15:58:34 +0800 | [diff] [blame] | 126 | } |
luojian | 88976a3 | 2024-08-14 17:40:01 +0800 | [diff] [blame] | 127 | #if 1 |
| 128 | struct tm CurlocalTime; |
| 129 | localtime_r(&time, &CurlocalTime); |
luojian | f7c8a6a | 2024-08-15 13:29:56 +0800 | [diff] [blame] | 130 | // CurlocalTime.tm_hour += 8; //cst |
luojian | 88976a3 | 2024-08-14 17:40:01 +0800 | [diff] [blame] | 131 | char dateTime[30]; |
| 132 | strftime(dateTime, 30, "%Y-%m-%d %H:%M:%S %A", &CurlocalTime); |
| 133 | |
luojian | f7c8a6a | 2024-08-15 13:29:56 +0800 | [diff] [blame] | 134 | // printf("dateTime:%s, %ld\n", dateTime, time+28800); //cst |
luojian | 252d7bc | 2024-09-24 16:32:38 +0800 | [diff] [blame] | 135 | LOGD("dateTime:%s, %ld\n", dateTime, time); |
luojian | 88976a3 | 2024-08-14 17:40:01 +0800 | [diff] [blame] | 136 | |
| 137 | struct timeval tv; |
| 138 | tv.tv_sec = time; |
luojian | f7c8a6a | 2024-08-15 13:29:56 +0800 | [diff] [blame] | 139 | // tv.tv_sec += 28800; //cst |
luojian | 88976a3 | 2024-08-14 17:40:01 +0800 | [diff] [blame] | 140 | tv.tv_usec = 0; |
| 141 | |
| 142 | if(settimeofday(&tv, NULL)) { |
luojian | 252d7bc | 2024-09-24 16:32:38 +0800 | [diff] [blame] | 143 | LOGD("Set time :%s", dateTime); |
| 144 | LOGD("timestamp:%ld, tv.tv_sec:%ld\n", time, tv.tv_sec); |
luojian | 88976a3 | 2024-08-14 17:40:01 +0800 | [diff] [blame] | 145 | |
| 146 | if(settimeofday(&tv, NULL)) { |
| 147 | *ntp_flag = -1; |
luojian | 252d7bc | 2024-09-24 16:32:38 +0800 | [diff] [blame] | 148 | LOGD("mktime error, reason: %s\n", strerror(errno)); |
luojian | 88976a3 | 2024-08-14 17:40:01 +0800 | [diff] [blame] | 149 | return NULL; |
| 150 | } |
| 151 | } |
luojian | 252d7bc | 2024-09-24 16:32:38 +0800 | [diff] [blame] | 152 | LOGD("Set time success\n"); |
luojian | 88976a3 | 2024-08-14 17:40:01 +0800 | [diff] [blame] | 153 | lynq_set_rtc_time(); |
| 154 | #else |
| 155 | |
luojin | 071b385 | 2024-01-15 15:58:34 +0800 | [diff] [blame] | 156 | struct tm *tm_t; |
| 157 | tm_t = localtime(&time); |
luojian | 88976a3 | 2024-08-14 17:40:01 +0800 | [diff] [blame] | 158 | tm_t->tm_hour += 8; |
luojin | 071b385 | 2024-01-15 15:58:34 +0800 | [diff] [blame] | 159 | strftime(time_str,128,"%F %T",tm_t); |
| 160 | |
| 161 | // NTP time |
luojian | 88976a3 | 2024-08-14 17:40:01 +0800 | [diff] [blame] | 162 | if(metis_strptime(time_str)) |
| 163 | { |
| 164 | *ntp_flag = -1; |
| 165 | return NULL; |
| 166 | } |
| 167 | #endif |
luojin | 071b385 | 2024-01-15 15:58:34 +0800 | [diff] [blame] | 168 | break; |
| 169 | } else { |
| 170 | break; |
| 171 | } |
| 172 | |
| 173 | sleep(64); // Sleep 64s. |
| 174 | } |
liuyang | bfc4d7c | 2024-05-07 10:44:28 +0800 | [diff] [blame] | 175 | if(NULL != ntp_flag) |
| 176 | { |
| 177 | *ntp_flag = 0; |
| 178 | } |
luojin | 071b385 | 2024-01-15 15:58:34 +0800 | [diff] [blame] | 179 | return NULL; |
| 180 | } |
| 181 | |
| 182 | int set_time_user(char* data_time_str) |
| 183 | { |
| 184 | |
| 185 | int ret = 0; |
| 186 | if(strlen(data_time_str) > 0) |
| 187 | { |
| 188 | ret = metis_strptime(data_time_str); |
| 189 | } |
| 190 | |
| 191 | return ret; |
| 192 | } |
| 193 | |
| 194 | |
| 195 | //MBTK_TIME_TYPE_CELL = 0, //NITZ |
| 196 | //MBTK_TIME_TYPE_NTP, |
| 197 | //MBTK_TIME_TYPE_GNSS, |
| 198 | //MBTK_TIME_TYPE_USER |
| 199 | void set_time_type(int mbtk_time_type) |
| 200 | { |
| 201 | char type_str[10] = {0}; |
| 202 | sprintf(type_str, "%d", mbtk_time_type); |
| 203 | property_set("persist.mbtk.time_type", type_str); |
| 204 | |
| 205 | return; |
| 206 | } |
| 207 | |
| 208 | |
| 209 | |
b.liu | 5fa9e77 | 2023-11-23 18:00:55 +0800 | [diff] [blame] | 210 | |
| 211 | int ntp_sync_time(int enable) |
| 212 | { |
liuyang | 1ce96df | 2024-05-29 19:14:34 +0800 | [diff] [blame] | 213 | if(0 != enable && 1 != enable) |
| 214 | { |
| 215 | return -1; |
| 216 | } |
b.liu | 5fa9e77 | 2023-11-23 18:00:55 +0800 | [diff] [blame] | 217 | UNUSED(enable); |
liuyang | bfc4d7c | 2024-05-07 10:44:28 +0800 | [diff] [blame] | 218 | int ntp_status = 0; |
luojian | 88976a3 | 2024-08-14 17:40:01 +0800 | [diff] [blame] | 219 | int ret = 0; |
luojian | 799341e | 2024-09-25 17:58:07 +0800 | [diff] [blame^] | 220 | sync_time_flag = 0; |
luojin | 071b385 | 2024-01-15 15:58:34 +0800 | [diff] [blame] | 221 | if(enable) |
| 222 | { |
luojian | 88976a3 | 2024-08-14 17:40:01 +0800 | [diff] [blame] | 223 | set_time_type(LYNQ_TIME_TYPE_NTP); |
liuyang | bfc4d7c | 2024-05-07 10:44:28 +0800 | [diff] [blame] | 224 | ntp_pthread_run(&ntp_status); |
| 225 | if(ntp_status == 0) |
| 226 | { |
luojian | 88976a3 | 2024-08-14 17:40:01 +0800 | [diff] [blame] | 227 | ret = 0; |
luojian | 799341e | 2024-09-25 17:58:07 +0800 | [diff] [blame^] | 228 | sync_time_flag = 0; |
liuyang | bfc4d7c | 2024-05-07 10:44:28 +0800 | [diff] [blame] | 229 | } |
| 230 | else |
| 231 | { |
luojian | 88976a3 | 2024-08-14 17:40:01 +0800 | [diff] [blame] | 232 | ret = -1; |
liuyang | bfc4d7c | 2024-05-07 10:44:28 +0800 | [diff] [blame] | 233 | set_time_type(LYNQ_TIME_TYPE_UNUSE); |
luojian | 799341e | 2024-09-25 17:58:07 +0800 | [diff] [blame^] | 234 | sync_time_flag = -1; |
liuyang | bfc4d7c | 2024-05-07 10:44:28 +0800 | [diff] [blame] | 235 | } |
luojin | 071b385 | 2024-01-15 15:58:34 +0800 | [diff] [blame] | 236 | } |
r.xiao | 8b07413 | 2024-02-22 23:57:50 -0800 | [diff] [blame] | 237 | else |
| 238 | { |
| 239 | set_time_type(LYNQ_TIME_TYPE_UNUSE); |
| 240 | } |
| 241 | |
luojian | 88976a3 | 2024-08-14 17:40:01 +0800 | [diff] [blame] | 242 | return ret; |
b.liu | 5fa9e77 | 2023-11-23 18:00:55 +0800 | [diff] [blame] | 243 | } |
| 244 | |
luojin | 071b385 | 2024-01-15 15:58:34 +0800 | [diff] [blame] | 245 | //enable set time from nitz |
b.liu | 5fa9e77 | 2023-11-23 18:00:55 +0800 | [diff] [blame] | 246 | int modem_time_enable(int enable) |
| 247 | { |
| 248 | UNUSED(enable); |
luojian | 799341e | 2024-09-25 17:58:07 +0800 | [diff] [blame^] | 249 | sync_time_flag = 0; |
b.liu | 5fa9e77 | 2023-11-23 18:00:55 +0800 | [diff] [blame] | 250 | |
luojin | 071b385 | 2024-01-15 15:58:34 +0800 | [diff] [blame] | 251 | if(enable) |
| 252 | { |
r.xiao | 8b07413 | 2024-02-22 23:57:50 -0800 | [diff] [blame] | 253 | set_time_type(LYNQ_TIME_TYPE_CELL); |
| 254 | } |
| 255 | else |
| 256 | { |
| 257 | set_time_type(LYNQ_TIME_TYPE_UNUSE); |
luojin | 071b385 | 2024-01-15 15:58:34 +0800 | [diff] [blame] | 258 | } |
b.liu | 5fa9e77 | 2023-11-23 18:00:55 +0800 | [diff] [blame] | 259 | return 0; |
| 260 | } |
| 261 | |
luojin | 071b385 | 2024-01-15 15:58:34 +0800 | [diff] [blame] | 262 | |
| 263 | //enable set time from gnss |
b.liu | 5fa9e77 | 2023-11-23 18:00:55 +0800 | [diff] [blame] | 264 | int gnss_time_enable(int enable) |
| 265 | { |
| 266 | UNUSED(enable); |
luojian | 799341e | 2024-09-25 17:58:07 +0800 | [diff] [blame^] | 267 | sync_time_flag = 0; |
luojin | 071b385 | 2024-01-15 15:58:34 +0800 | [diff] [blame] | 268 | if(enable) |
| 269 | { |
r.xiao | 8b07413 | 2024-02-22 23:57:50 -0800 | [diff] [blame] | 270 | set_time_type(LYNQ_TIME_TYPE_GNSS); |
luojin | 071b385 | 2024-01-15 15:58:34 +0800 | [diff] [blame] | 271 | } |
r.xiao | 8b07413 | 2024-02-22 23:57:50 -0800 | [diff] [blame] | 272 | else |
| 273 | { |
| 274 | set_time_type(LYNQ_TIME_TYPE_UNUSE); |
| 275 | } |
| 276 | |
b.liu | 5fa9e77 | 2023-11-23 18:00:55 +0800 | [diff] [blame] | 277 | return 0; |
| 278 | } |
| 279 | |
luojin | 071b385 | 2024-01-15 15:58:34 +0800 | [diff] [blame] | 280 | |
| 281 | //enable set time from user |
b.liu | 5fa9e77 | 2023-11-23 18:00:55 +0800 | [diff] [blame] | 282 | int user_set_time(char* date, char* time) |
| 283 | { |
| 284 | UNUSED(date); |
| 285 | UNUSED(time); |
luojin | 071b385 | 2024-01-15 15:58:34 +0800 | [diff] [blame] | 286 | if(date == NULL || time == NULL) |
| 287 | { |
| 288 | return -1; |
| 289 | } |
b.liu | 5fa9e77 | 2023-11-23 18:00:55 +0800 | [diff] [blame] | 290 | |
luojin | 071b385 | 2024-01-15 15:58:34 +0800 | [diff] [blame] | 291 | int ret = 0; |
| 292 | char time_str[128] ={0}; |
| 293 | memset(time_str, 0x0, MBTK_AT_NTP_LEN_MAX); |
| 294 | |
| 295 | char *p = time; |
| 296 | char *p1 = strstr(p, ":"); |
| 297 | char *p2 = strstr(p1+1, ":"); |
| 298 | if(p2 == NULL) |
| 299 | { |
| 300 | sprintf(time_str, "%s %s:00", date, time); //2023-11-30 11:30 |
r.xiao | 8b07413 | 2024-02-22 23:57:50 -0800 | [diff] [blame] | 301 | set_time_type(LYNQ_TIME_TYPE_USER); |
luojin | 071b385 | 2024-01-15 15:58:34 +0800 | [diff] [blame] | 302 | ret = set_time_user(time_str); |
| 303 | }else |
| 304 | { |
| 305 | sprintf(time_str, "%s %s", date, time); //2023-11-30 11:30:31 |
r.xiao | 8b07413 | 2024-02-22 23:57:50 -0800 | [diff] [blame] | 306 | set_time_type(LYNQ_TIME_TYPE_USER); |
luojin | 071b385 | 2024-01-15 15:58:34 +0800 | [diff] [blame] | 307 | ret = set_time_user(time_str); |
| 308 | } |
| 309 | |
| 310 | return ret; |
b.liu | 5fa9e77 | 2023-11-23 18:00:55 +0800 | [diff] [blame] | 311 | } |
| 312 | |
b.liu | 5fa9e77 | 2023-11-23 18:00:55 +0800 | [diff] [blame] | 313 | |
luojin | 071b385 | 2024-01-15 15:58:34 +0800 | [diff] [blame] | 314 | //check sysytem type |
b.liu | 5fa9e77 | 2023-11-23 18:00:55 +0800 | [diff] [blame] | 315 | int lynq_get_time_src_status (time_src_status_s * time_src) |
| 316 | { |
| 317 | UNUSED(time_src); |
luojin | 071b385 | 2024-01-15 15:58:34 +0800 | [diff] [blame] | 318 | int type = 0; |
| 319 | char time_type[] ={0}; |
| 320 | property_get("persist.mbtk.time_type", time_type, "0"); |
b.liu | 5fa9e77 | 2023-11-23 18:00:55 +0800 | [diff] [blame] | 321 | |
luojin | 071b385 | 2024-01-15 15:58:34 +0800 | [diff] [blame] | 322 | type = atoi(time_type); |
| 323 | printf("time_type :%d", type); |
liuyang | bfc4d7c | 2024-05-07 10:44:28 +0800 | [diff] [blame] | 324 | if(type == LYNQ_TIME_TYPE_NTP) |
| 325 | { |
luojin | 071b385 | 2024-01-15 15:58:34 +0800 | [diff] [blame] | 326 | time_src->ntp = 1; |
liuyang | bfc4d7c | 2024-05-07 10:44:28 +0800 | [diff] [blame] | 327 | time_src->nitz = 0; |
| 328 | time_src->gnss = 0; |
| 329 | } |
| 330 | else if(type == LYNQ_TIME_TYPE_CELL) |
| 331 | { |
| 332 | time_src->ntp = 0; |
luojin | 071b385 | 2024-01-15 15:58:34 +0800 | [diff] [blame] | 333 | time_src->nitz = 1; |
liuyang | bfc4d7c | 2024-05-07 10:44:28 +0800 | [diff] [blame] | 334 | time_src->gnss = 0; |
| 335 | } |
| 336 | else if(type == LYNQ_TIME_TYPE_GNSS) |
| 337 | { |
| 338 | time_src->ntp = 0; |
| 339 | time_src->nitz = 0; |
luojin | 071b385 | 2024-01-15 15:58:34 +0800 | [diff] [blame] | 340 | time_src->gnss = 1; |
liuyang | bfc4d7c | 2024-05-07 10:44:28 +0800 | [diff] [blame] | 341 | } |
| 342 | else if(type == LYNQ_TIME_TYPE_UNUSE) |
| 343 | { |
r.xiao | 8b07413 | 2024-02-22 23:57:50 -0800 | [diff] [blame] | 344 | time_src->ntp = 0; |
| 345 | time_src->nitz = 0; |
| 346 | time_src->gnss = 0; |
luojin | 071b385 | 2024-01-15 15:58:34 +0800 | [diff] [blame] | 347 | } |
liuyang | bfc4d7c | 2024-05-07 10:44:28 +0800 | [diff] [blame] | 348 | |
b.liu | 5fa9e77 | 2023-11-23 18:00:55 +0800 | [diff] [blame] | 349 | return 0; |
| 350 | } |
| 351 | |
luojin | 071b385 | 2024-01-15 15:58:34 +0800 | [diff] [blame] | 352 | // RTC TIME set to system |
| 353 | int lynq_sync_time_from_rtc(void) |
| 354 | { |
| 355 | system("hwclock --hctosys"); |
| 356 | return 0; |
| 357 | } |
| 358 | |
| 359 | // system time set to RTC |
b.liu | 5fa9e77 | 2023-11-23 18:00:55 +0800 | [diff] [blame] | 360 | int lynq_set_rtc_time(void) |
| 361 | { |
luojian | 9b9a928 | 2024-07-04 18:56:21 +0800 | [diff] [blame] | 362 | // system("hwclock --systohc"); |
| 363 | system("hwclock -w rtc0"); |
b.liu | 5fa9e77 | 2023-11-23 18:00:55 +0800 | [diff] [blame] | 364 | return 0; |
| 365 | } |
| 366 | |
| 367 | int lynq_get_rtc_time(unsigned long *ulsec) |
| 368 | { |
| 369 | UNUSED(ulsec); |
| 370 | |
| 371 | return 0; |
| 372 | } |
| 373 | |
luojian | 799341e | 2024-09-25 17:58:07 +0800 | [diff] [blame^] | 374 | int get_sync_time_result(void ) |
| 375 | { |
| 376 | |
| 377 | return sync_time_flag; |
| 378 | } |
| 379 | |
| 380 | |
| 381 | |
luojin | 071b385 | 2024-01-15 15:58:34 +0800 | [diff] [blame] | 382 | |
luojian | 252d7bc | 2024-09-24 16:32:38 +0800 | [diff] [blame] | 383 | |