bug 87624 87653 87536
Change-Id: I991e8210114d93fdd1264a1b9022edfc1a7ee13d
diff --git a/mbtk/liblynq_lib/src/lynq_time.c b/mbtk/liblynq_lib/src/lynq_time.c
index 22e311d..99e7d2c 100644
--- a/mbtk/liblynq_lib/src/lynq_time.c
+++ b/mbtk/liblynq_lib/src/lynq_time.c
@@ -63,16 +63,28 @@
struct timeval tv;
if(strptime(str_time, "%Y-%m-%d %H:%M:%S",&stm) != NULL)
{
- time_t _t = mktime(&stm);
+ time_t _t = (long)mktime(&stm);
+ tzset();
tv.tv_sec = _t;
- if(settimeofday(&tv, NULL)) {
- printf("Set time fail:%d");
+ tv.tv_usec = 0;
+ if(_t == -1)
+ {
+ printf("Set time :%s", str_time);
+ printf("timestamp:%ld", _t);
+ printf("mktime error, reason: %s\n", strerror(errno));
return -1;
- } else {
- lynq_set_rtc_time();
- printf("Set time to %s.", str_time);
- return 0;
}
+
+ if(settimeofday(&tv, NULL)) {
+ printf("Set time :%s", str_time);
+ printf("timestamp:%ld", _t);
+ printf("mktime error, reason: %s\n", strerror(errno));
+ return -1;
+ }
+
+ printf("Success Set time to %s.\n", str_time);
+ return 0;
+
} else {
printf("Set time fail.");
return -1;
@@ -81,7 +93,6 @@
}
-
static void* ntp_pthread_run(int* ntp_flag)
{
if (mbtk_net_state_get() == MBTK_NET_STATE_OFF)
@@ -112,12 +123,46 @@
}
return NULL;
}
+#if 1
+ struct tm CurlocalTime;
+ localtime_r(&time, &CurlocalTime);
+ CurlocalTime.tm_hour += 8;
+ char dateTime[30];
+ strftime(dateTime, 30, "%Y-%m-%d %H:%M:%S %A", &CurlocalTime);
+
+ printf("dateTime:%s, %ld\n", dateTime, time+28800);
+
+ struct timeval tv;
+ tv.tv_sec = time;
+ tv.tv_sec += 28800;
+ tv.tv_usec = 0;
+
+ if(settimeofday(&tv, NULL)) {
+ printf("Set time :%s", dateTime);
+ printf("timestamp:%ld, tv.tv_sec:%ld\n", time, tv.tv_sec);
+
+ if(settimeofday(&tv, NULL)) {
+ *ntp_flag = -1;
+ printf("mktime error, reason: %s\n", strerror(errno));
+ return NULL;
+ }
+ }
+ printf("Set time success\n");
+ lynq_set_rtc_time();
+#else
+
struct tm *tm_t;
tm_t = localtime(&time);
+ tm_t->tm_hour += 8;
strftime(time_str,128,"%F %T",tm_t);
// NTP time
- metis_strptime(time_str);
+ if(metis_strptime(time_str))
+ {
+ *ntp_flag = -1;
+ return NULL;
+ }
+#endif
break;
} else {
break;
@@ -169,15 +214,18 @@
}
UNUSED(enable);
int ntp_status = 0;
+ int ret = 0;
if(enable)
{
+ set_time_type(LYNQ_TIME_TYPE_NTP);
ntp_pthread_run(&ntp_status);
if(ntp_status == 0)
{
- set_time_type(LYNQ_TIME_TYPE_NTP);
+ ret = 0;
}
else
{
+ ret = -1;
set_time_type(LYNQ_TIME_TYPE_UNUSE);
}
}
@@ -186,7 +234,7 @@
set_time_type(LYNQ_TIME_TYPE_UNUSE);
}
- return 0;
+ return ret;
}
//enable set time from nitz