[Bugfix][T106][bug-view-568]Add a reset mechanism when there is no data output from the GPS during startup and fix Power on timing issue

Only Configure :No
Affected branch:master
Affected module:gnss
Is it affected on both ZXIC and MTK:only ZXIC
Self-test: Yes
Doc Update: No

Change-Id: Ic9c6527d34a53a87a9a68dff1d8c3864150a65e1
(cherry picked from commit 9f6432085b75520a242cde90a25d890c39870035)
diff --git a/cap/zx297520v3/src/lynq/lib/liblynq-qser-gnss/include/mbtk_gnss_internal.h b/cap/zx297520v3/src/lynq/lib/liblynq-qser-gnss/include/mbtk_gnss_internal.h
index 5602ffe..338f3c1 100755
--- a/cap/zx297520v3/src/lynq/lib/liblynq-qser-gnss/include/mbtk_gnss_internal.h
+++ b/cap/zx297520v3/src/lynq/lib/liblynq-qser-gnss/include/mbtk_gnss_internal.h
@@ -347,6 +347,7 @@
 int lynq_gnss_get_uart(uint32 h_gnss);
 int lynq_gnss_get_ap_data(void);
 int lynq_gnss_output_frq(int frequency);
+int lynq_gnss_start();
 
 #ifdef __cplusplus
 }
diff --git a/cap/zx297520v3/src/lynq/lib/liblynq-qser-gnss/src/lynq_qser_gnss.cpp b/cap/zx297520v3/src/lynq/lib/liblynq-qser-gnss/src/lynq_qser_gnss.cpp
index 7df703e..f17111e 100755
--- a/cap/zx297520v3/src/lynq/lib/liblynq-qser-gnss/src/lynq_qser_gnss.cpp
+++ b/cap/zx297520v3/src/lynq/lib/liblynq-qser-gnss/src/lynq_qser_gnss.cpp
@@ -48,7 +48,6 @@
 int inited = 0;
 int event = 0;
 int lock_fd = 0;
-
 int qser_Gnss_Init(uint32_t *h_gnss)
 {
     ret = lynq_gnss_client_init(h_gnss);
@@ -229,7 +228,8 @@
     g_gnss_sync_enable_flag = atoi(gnss_sync_enable);
     g_gnss_sync_done = 0;
 
-    lynq_open_gps(1);
+    if (lynq_gnss_start() == -1)
+        return -1;
 #if defined(HD_GNSS)
         ret = set_baudrate(gnss_handle->dev_fd, B115200);
         if(-1 == ret)
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 360011b..3b699f5 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
@@ -18,6 +18,7 @@
 #include <malloc.h>
 #include <sys/time.h>
 #include <liblog/lynq_deflog.h>
+#include <include/lynq_uci.h>
 #include "mbtk_gnss_internal.h"
 #include "mbtk_http.h"
 #include "mbtk_type.h"
@@ -170,7 +171,6 @@
 #endif
 };
 
-
 /**
  *  \brief strstr_n
  *
@@ -864,6 +864,49 @@
     return fd;
 }
 
+int gnss_reset()
+{
+    void* reset_handle= sc_gpio_init(126,1,0,0);
+    if (reset_handle == NULL)
+        return -1;
+    sc_gpio_value_set(reset_handle,1);
+    usleep(500000);//500ms
+    sc_gpio_value_set(reset_handle,0);
+    sc_gpio_uninit(reset_handle);
+    return 0;
+}
+
+int check_status()
+{
+    int count = 10;
+    int fd = open(MBTK_GNSS_DEV, O_RDWR | O_NOCTTY | O_NDELAY);
+    fd_set readfds;
+    struct timeval timeout;
+    do {
+        FD_ZERO(&readfds);
+        FD_SET(fd, &readfds);
+        timeout.tv_sec = count == 10 ? 10 : 1;  // 设置超时时间为 10 秒
+        int retval = select(fd + 1, &readfds, NULL, NULL, &timeout);
+        if (retval == -1)
+        {
+            ALOGE("FD ERROR\n");
+            continue;
+        }
+        else if (retval == 0)
+        {
+            gnss_reset();
+            continue;
+        }
+        else
+        {
+            close(fd);
+            return 0;
+        }
+    } while(count--);
+    close(fd);
+    return -1; 
+}
+
 static int mopen_gnss_read(int fd, char* buf, unsigned int buf_len)
 {
     buf_len=(buf_len > MBTK_UART_RECV_BUFFER_SIZE ? MBTK_UART_RECV_BUFFER_SIZE : buf_len);
@@ -944,6 +987,7 @@
 exit:
     pthread_exit(NULL);
 }
+
 int flag = 1;
 static void gnss_uart_pthread(void* hdl)
 {
@@ -969,9 +1013,9 @@
             }
             if(ret > 0) {
                 ring_buffer_queue_arr(&gnss_handle->ring_buffer, buf, ret);
-                memset(buf, 0, sizeof(buf));
+                memset(buf, 0, sizeof(buf)); 
             } else {
-                gnss_log("read error\n");
+                ALOGE("read error\n");
             }
         }
         usleep(5000);
@@ -979,6 +1023,7 @@
     pthread_exit(NULL);
 }
 
+
 ssize_t deal_read(int fd, void *buf, size_t count)
 {
     int ret = 0;
@@ -1103,15 +1148,28 @@
 
     else if(1 == state)
     {
-        nmea_state = 1;
+        
     #if defined(HD_GNSS)
             test_gpio_handle[84] = sc_gpio_init(84,1,0,0);
             test_gpio_handle[15] = sc_gpio_init(15,0,0,0);
+            test_gpio_handle[126] = sc_gpio_init(126,1,0,0);
+            ret = sc_gpio_value_set(test_gpio_handle[126],1);
+            if(ret)
+            {
+                ALOGE("gpio126 set value 1 error\n");
+            }
+            usleep(30000);
             ret = sc_gpio_value_set(test_gpio_handle[84],1);
             if(ret)
             {
                 ALOGE("gpio84 set value 1 error\n");
             }
+            usleep(15000);
+            ret = sc_gpio_value_set(test_gpio_handle[126],0);
+            if(ret)
+            {
+                ALOGE("gpio126 set value 1 error\n");
+            }
     #elif defined(HX_GNSS)
             test_gpio_handle[86] = sc_gpio_init(86,1,0,0);
             ret = sc_gpio_value_set(test_gpio_handle[86],1);
@@ -1125,8 +1183,10 @@
     #if defined(HD_GNSS)
         sc_gpio_uninit(test_gpio_handle[15]);
         sc_gpio_uninit(test_gpio_handle[84]);
+        sc_gpio_uninit(test_gpio_handle[126]);
         test_gpio_handle[15] = NULL;
         test_gpio_handle[84] = NULL;
+        test_gpio_handle[126] = NULL;
     #elif defined(HX_GNSS)
         sc_gpio_uninit(test_gpio_handle[86]);
         test_gpio_handle[86] = NULL;
@@ -1134,6 +1194,15 @@
     return 0;
 }
 
+int lynq_gnss_start()
+{
+    int ret;
+    lynq_open_gps(1);
+    if (check_status())
+        return -1;
+    nmea_state = 1;
+    return 0;
+}
 
 
 int lynq_gnss_client_init(uint32 *ph_gnss)