|
@@ -29,7 +29,7 @@ WHEN WHO WHAT, WHERE, WHY
|
|
#include "ql_api_datacall.h"
|
|
#include "ql_api_datacall.h"
|
|
#include "ql_ntp_client.h"
|
|
#include "ql_ntp_client.h"
|
|
#include "ql_api_rtc.h"
|
|
#include "ql_api_rtc.h"
|
|
-
|
|
|
|
|
|
+//#include "ntp_info_decode.h"
|
|
#define QL_NTP_LOG_LEVEL QL_LOG_LEVEL_INFO
|
|
#define QL_NTP_LOG_LEVEL QL_LOG_LEVEL_INFO
|
|
#define QL_NTP_LOG(msg, ...) QL_LOG(QL_NTP_LOG_LEVEL, "ql_NTP_DEMO", msg, ##__VA_ARGS__)
|
|
#define QL_NTP_LOG(msg, ...) QL_LOG(QL_NTP_LOG_LEVEL, "ql_NTP_DEMO", msg, ##__VA_ARGS__)
|
|
#define QL_NTP_LOG_PUSH(msg, ...) QL_LOG_PUSH("ql_NTP_DEMO", msg, ##__VA_ARGS__)
|
|
#define QL_NTP_LOG_PUSH(msg, ...) QL_LOG_PUSH("ql_NTP_DEMO", msg, ##__VA_ARGS__)
|
|
@@ -39,13 +39,15 @@ static ql_task_t ntp_task = NULL;
|
|
static ntp_client_id ntp_cli_id = 0;
|
|
static ntp_client_id ntp_cli_id = 0;
|
|
static ql_sem_t ntp_semp;
|
|
static ql_sem_t ntp_semp;
|
|
|
|
|
|
|
|
+
|
|
static void ntp_result_cb(ntp_client_id cli_id, int result, struct tm *sync_time, void *arg)
|
|
static void ntp_result_cb(ntp_client_id cli_id, int result, struct tm *sync_time, void *arg)
|
|
{
|
|
{
|
|
ql_rtc_time_t time;
|
|
ql_rtc_time_t time;
|
|
if(ntp_cli_id != cli_id)
|
|
if(ntp_cli_id != cli_id)
|
|
return;
|
|
return;
|
|
|
|
|
|
- if(result == QL_NTP_SUCCESS){
|
|
|
|
|
|
+ if(result == QL_NTP_SUCCESS)
|
|
|
|
+ {
|
|
char time_str[256] = {0};
|
|
char time_str[256] = {0};
|
|
|
|
|
|
snprintf(time_str, 256, "%04d/%02d/%02d,%02d:%02d:%02d",sync_time->tm_year + 1900, sync_time->tm_mon + 1, sync_time->tm_mday,
|
|
snprintf(time_str, 256, "%04d/%02d/%02d,%02d:%02d:%02d",sync_time->tm_year + 1900, sync_time->tm_mon + 1, sync_time->tm_mday,
|
|
@@ -62,7 +64,9 @@ static void ntp_result_cb(ntp_client_id cli_id, int result, struct tm *sync_
|
|
{
|
|
{
|
|
QL_NTP_LOG("ntp set RTC time failed");
|
|
QL_NTP_LOG("ntp set RTC time failed");
|
|
}
|
|
}
|
|
- }else{
|
|
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
QL_NTP_LOG("ntp sync failed :%d", result);
|
|
QL_NTP_LOG("ntp sync failed :%d", result);
|
|
}
|
|
}
|
|
ql_rtos_semaphore_release(ntp_semp);
|
|
ql_rtos_semaphore_release(ntp_semp);
|
|
@@ -82,7 +86,8 @@ static void ntp_app_thread(void * arg)
|
|
QL_NTP_LOG("wait for network register done");
|
|
QL_NTP_LOG("wait for network register done");
|
|
|
|
|
|
ql_rtos_semaphore_create(&ntp_semp, 0);
|
|
ql_rtos_semaphore_create(&ntp_semp, 0);
|
|
- while((ret = ql_network_register_wait(nSim, 120)) != 0 && i < 10){
|
|
|
|
|
|
+ while((ret = ql_network_register_wait(nSim, 120)) != 0 && i < 10)
|
|
|
|
+ {
|
|
i++;
|
|
i++;
|
|
ql_rtos_task_sleep_s(1);
|
|
ql_rtos_task_sleep_s(1);
|
|
}
|
|
}
|
|
@@ -136,9 +141,11 @@ static void ntp_app_thread(void * arg)
|
|
|
|
|
|
ntp_cli_id = ql_ntp_sync("ntp.aliyun.com", &sync_option, ntp_result_cb, NULL, &error_num);
|
|
ntp_cli_id = ql_ntp_sync("ntp.aliyun.com", &sync_option, ntp_result_cb, NULL, &error_num);
|
|
|
|
|
|
- if(ntp_cli_id != 0){
|
|
|
|
|
|
+ if(ntp_cli_id != 0)
|
|
|
|
+ {
|
|
ql_rtos_semaphore_wait(ntp_semp, QL_WAIT_FOREVER);
|
|
ql_rtos_semaphore_wait(ntp_semp, QL_WAIT_FOREVER);
|
|
- }else{
|
|
|
|
|
|
+ }else
|
|
|
|
+ {
|
|
QL_NTP_LOG("ntp failed");
|
|
QL_NTP_LOG("ntp failed");
|
|
}
|
|
}
|
|
QL_NTP_LOG("==============ntp_test_end[%d]================\n",run_num);
|
|
QL_NTP_LOG("==============ntp_test_end[%d]================\n",run_num);
|