Merge "[Feature][ZXW-203]The interface to get the time synchronization status"
diff --git a/cap/zx297520v3/sources/meta-zxic-custom/recipes-lynq/lynq-systime-demo/files/lynq_systime_demo.cpp b/cap/zx297520v3/sources/meta-zxic-custom/recipes-lynq/lynq-systime-demo/files/lynq_systime_demo.cpp
index d0fffcf..a600884 100755
--- a/cap/zx297520v3/sources/meta-zxic-custom/recipes-lynq/lynq-systime-demo/files/lynq_systime_demo.cpp
+++ b/cap/zx297520v3/sources/meta-zxic-custom/recipes-lynq/lynq-systime-demo/files/lynq_systime_demo.cpp
@@ -35,6 +35,8 @@
 int (*ntp_sync_time)(int enable);

 int (*user_set_time)(char *date, char *time);

 int (*lynq_get_time_src_status)(time_src_status_s *time_src);

+int (*get_sync_time_result)();

+

 

 int lynq_ntp_sync_demo(int argc, char *argv[])

 {

@@ -159,6 +161,22 @@
     return 0;

 }

 

+int lynq_get_sync_status_demo(int arg_c, char *arg_v[])

+{

+    get_sync_time_result = (int (*)(void))dlsym(dlHandle_systime, "get_sync_time_result");

+    int ret = 0;

+    if(NULL == get_sync_time_result)

+    {

+        printf("Failed to dlsym function get_sync_time_result: %s\n", dlerror());

+        dlclose(dlHandle_systime);

+        return -1;

+    }

+    ret = get_sync_time_result();

+    printf("get_sync_time_result = %d\n",ret);

+	dlclose(dlHandle_systime);

+    return 0;

+}

+

 int main(int argc, char *argv[])

 {

     int ret = -1;

@@ -237,6 +255,10 @@
     {

         ret = lynq_get_time_src_status_demo(argc, argv);

     }

+    else if (strcmp(cmd,"sync_status") == 0)

+    {

+        ret = lynq_get_sync_status_demo(argc, argv);

+    }

     else

     {

         printf("command wrong !\n");

diff --git a/cap/zx297520v3/src/lynq/lib/liblynq-qser-gnss/makefile b/cap/zx297520v3/src/lynq/lib/liblynq-qser-gnss/makefile
index 0f99e4f..8ab6383 100755
--- a/cap/zx297520v3/src/lynq/lib/liblynq-qser-gnss/makefile
+++ b/cap/zx297520v3/src/lynq/lib/liblynq-qser-gnss/makefile
@@ -35,6 +35,7 @@
     -llynq-uci \

     -lsctel \

     -lbsp \

+    -lnvram \

 

 

 SOURCES = $(wildcard *.c wildcard *.h src/*.cpp)

diff --git a/cap/zx297520v3/src/lynq/lib/liblynq-qser-gnss/src/mbtk_gnss.cpp b/cap/zx297520v3/src/lynq/lib/liblynq-qser-gnss/src/mbtk_gnss.cpp
index f874f59..d508438 100755
--- a/cap/zx297520v3/src/lynq/lib/liblynq-qser-gnss/src/mbtk_gnss.cpp
+++ b/cap/zx297520v3/src/lynq/lib/liblynq-qser-gnss/src/mbtk_gnss.cpp
@@ -34,6 +34,9 @@
 extern int sc_rtc_timer_init(void);
 extern int sc_rtc_timer_uninit(void);
 extern int sc_rtc_time_set(int srcid);
+extern int sc_cfg_get(char *name, char* buf, int bufLen);
+extern int sc_cfg_set (char *name, char *value);
+
 
 static inline int update_system_time(time_t timestamp)
 {
@@ -515,6 +518,7 @@
             if (update_system_time(nmea_info.timestamp) == 0)
             {
                 g_gnss_sync_done = 1;
+                sc_cfg_set("gnss_process_result","success");
             }
         }
     }
diff --git a/cap/zx297520v3/src/lynq/lib/liblynq-systime/lynq_systime.cpp b/cap/zx297520v3/src/lynq/lib/liblynq-systime/lynq_systime.cpp
index d898f9d..67bc631 100755
--- a/cap/zx297520v3/src/lynq/lib/liblynq-systime/lynq_systime.cpp
+++ b/cap/zx297520v3/src/lynq/lib/liblynq-systime/lynq_systime.cpp
@@ -30,6 +30,8 @@
 #define LYNQ_SYNC_TIME_SECTION "lynq_sync_time"

 #define LYNQ_MODEM_TIME_KEY "lynq_modem_sync_time_enable"

 #define LYNQ_GNSS_TIME_KEY "lynq_gnss_sync_time_enable"

+#define SNTP_PROCESS_RESULT  "sntp_process_result"

+#define GNSS_PROCESS_RESULT  "gnss_process_result"

 #define BUF_LEN 258

 #define TIME_BUF 100

 #define SYNC_TIME_SUCCESS 0

@@ -38,6 +40,7 @@
 

 #define SYSTEM_FUNC_FAILED 7

 #define ERROR_PARA 8

+#define NV_SET_FAILED 9

 

 #ifdef MOBILETEK_TARGET_PLATFORM_T106

 #define NTP_RESTART_BUF "/etc/init.d/sntp restart"

@@ -59,6 +62,8 @@
 extern int sc_rtc_timer_uninit(void);

 extern int sc_rtc_time_set(int srcid);

 extern int sc_rtc_time_get(int srcid, sc_rtc_time_get_cb rtc_notify);

+extern int sc_cfg_get(char *name, char* buf, int bufLen);

+extern int sc_cfg_set (char *name, char *value);

 

 char sync_from_rtc_cb_flag = 1;

 char rtc_time_get_cb_flag = 1;

@@ -107,6 +112,106 @@
     return 0;

 }

 

+int get_sntp_process_result()

+{

+    LYLOGSET(LOG_LEVEL);

+    LYLOGEINIT(USER_LOG_TAG);

+    char sntp_process_result[10] = {0};

+    int ret = 0;

+

+    ret = sc_cfg_get(SNTP_PROCESS_RESULT,sntp_process_result,sizeof(sntp_process_result));

+

+    if(0 == ret)

+    {

+        if(strcmp(sntp_process_result,"success") != 0)

+        {

+            strcpy(sntp_process_result,"failed");

+            LYINFLOG("sntp sync result:%s\n",sntp_process_result);

+            return -1;

+        }

+

+        else

+        {

+            LYINFLOG("sntp sync result:%s\n",sntp_process_result);

+            return SYNC_TIME_SUCCESS;

+        }

+    }

+

+    else

+    {

+        LYERRLOG("read sntp_sync_result failed\n");

+        return -1;

+    }

+    

+}

+

+int get_gnss_process_result()

+{

+    LYLOGSET(LOG_LEVEL);

+    LYLOGEINIT(USER_LOG_TAG);

+    char gnss_process_result[10] = {0};

+    int ret = 0;

+

+    ret = sc_cfg_get(GNSS_PROCESS_RESULT,gnss_process_result,sizeof(gnss_process_result));

+

+    if(0 == ret)

+    {

+        if(strcmp(gnss_process_result,"success") != 0)

+        {

+            strcpy(gnss_process_result,"failed");

+            LYINFLOG("gnss sync result:%s\n",gnss_process_result);

+            return -1;

+        }

+        else

+        {

+            LYINFLOG("gnss sync result:%s\n",gnss_process_result);

+            return SYNC_TIME_SUCCESS;

+        }

+    }

+    else

+    {

+        LYERRLOG("read gnss_sync_result failed\n");

+        return -1;

+    }

+    

+}

+

+int get_sync_time_result()

+{

+    LYLOGSET(LOG_LEVEL);

+    LYLOGEINIT(USER_LOG_TAG);

+    time_src_status_s time_src = {0};

+    lynq_get_time_src_status(&time_src);

+

+    LYINFLOG("time_src -> gnss = %d,time_src -> ntp = %d, time_src -> nitz = %d\n",time_src.gnss,time_src.ntp,time_src.nitz);

+

+    if(time_src.gnss)

+    {

+        LYINFLOG("time_source is gnss\n");

+        return get_gnss_process_result();

+    }

+

+    else if(time_src.ntp)

+    {

+        LYINFLOG("time_source is ntp\n");

+        return get_sntp_process_result();

+    }

+

+    else if(time_src.nitz)

+    {

+        LYINFLOG("time_source is nitz\n");

+        return 0;

+    }

+

+    else

+    {

+        LYINFLOG("don't set any time_source\n");

+        return 0;

+    }

+

+}

+

+

 int lynq_sync_time_from_rtc(void)

 {

     LYLOGSET(LOG_LEVEL);

@@ -288,7 +393,7 @@
     int ret = system(cmd_buf);

     if (ret != 0)

     {

-        printf("Function system(\"%s\") failed.", cmd_buf);

+        printf("Function system(\"%s\") failed.\n", cmd_buf);

         return SYSTEM_FUNC_FAILED;

     }

     return 0;

@@ -299,12 +404,19 @@
     LYLOGSET(LOG_LEVEL);

     LYLOGEINIT(USER_LOG_TAG);

     LYDBGLOG("[%s][%d] enter.\n", __func__, __LINE__);

+    int ret = 0;

     if (enable != 0 && enable != 1)

     {

         LYERRLOG("Parameter error! Only 0/1 allowed.\n");

         return ERROR_PARA;

     }

-    int ret = system(PGREP_NTP_DARMON);

+    ret = sc_cfg_set(SNTP_PROCESS_RESULT,"");

+    if (0 != ret)

+    {

+        LYERRLOG("set SNTP_PROCESS_RESULT failed\n");

+        return NV_SET_FAILED;

+    }

+    ret = system(PGREP_NTP_DARMON);

     if (0 == ret)

     {

         if (enable)

@@ -374,12 +486,20 @@
     LYLOGEINIT(USER_LOG_TAG);

     LYDBGLOG("[%s][%d] enter.\n", __FUNCTION__, __LINE__);

     char buf[BUF_LEN] = "";

+    char result[10] = "";

     int ret = 0;

     if (enable != 0 && enable != 1)

     {

         LYERRLOG("Parameter error! Only 0/1 allowed.\n");

         return ERROR_PARA;

     }

+    ret = sc_cfg_set(GNSS_PROCESS_RESULT,"");

+    if (0 != ret)

+    {

+        LYERRLOG("set GNSS_PROCESS_RESULT failed\n");

+        return NV_SET_FAILED;

+    }

+    

     if (enable)

     {

         // Only one time source is allowed to run simultaneously.

diff --git a/cap/zx297520v3/src/lynq/lib/liblynq-systime/makefile b/cap/zx297520v3/src/lynq/lib/liblynq-systime/makefile
index 758315f..d0e37e8 100755
--- a/cap/zx297520v3/src/lynq/lib/liblynq-systime/makefile
+++ b/cap/zx297520v3/src/lynq/lib/liblynq-systime/makefile
@@ -37,6 +37,7 @@
     -lsctel \

     -llynq-uci \

     -llynq-log \

+    -lnvram \

 

 

 SOURCES = $(wildcard *.cpp)