[Feature][T106][task-view-1221]Add API-qser_Gnss_setting_statement_type to Control NMEA statements

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: Ic38b487f9b4a7b233a5280cbd8f82b827314e17c
diff --git a/cap/zx297520v3/src/lynq/lib/liblynq-qser-gnss/include/lynq_qser_gnss.h b/cap/zx297520v3/src/lynq/lib/liblynq-qser-gnss/include/lynq_qser_gnss.h
index a88e181..ca8f216 100755
--- a/cap/zx297520v3/src/lynq/lib/liblynq-qser-gnss/include/lynq_qser_gnss.h
+++ b/cap/zx297520v3/src/lynq/lib/liblynq-qser-gnss/include/lynq_qser_gnss.h
@@ -118,7 +118,7 @@
 int qser_Gnss_injectEphemeris(uint32_t h_gnss);
 int qser_Gnss_download_tle();
 int qser_Gnss_injectEphemeris_withpath(uint32_t h_gnss, char *path);
-
+int qser_Gnss_setting_statement_type(uint32_t h_gnss, char *statement_type,int state);
 #ifdef __cplusplus
 }
 #endif
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 172ff02..a6118de 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
@@ -318,7 +318,7 @@
 //int lynq_gnss_get_ap_data(void);
 int lynq_gnss_output_frq(int frequency);
 int lynq_gnss_start();
-
+int lynq_gnss_setting_statement_type(uint32 h_gnss, char *statement_type,int state);
 #ifdef __cplusplus
 }
 #endif
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 9e44fb0..97e0497 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
@@ -475,6 +475,23 @@
     return 0;
 }
 
+int qser_Gnss_setting_statement_type(uint32_t h_gnss, char *statement_type,int state)
+{
+    int ret;
+    if(!inited)
+    {
+        ALOGE("has not been initiated\n");
+        return -1;
+    }
+    ret = lynq_gnss_setting_statement_type(h_gnss,statement_type,state);
+    if(ret < 0)
+    {
+        return -1;
+    }
+
+    return 0;
+}
+
 void atsvc_incb_entity(char *input,int length);
 int lynq_at_cgps(int at_type,int gnss_state_type);
 int lynq_at_cgpsnmea(int at_type,int gnss_state_type);
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 c238eee..8979e97 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
@@ -341,6 +341,107 @@
     }
 }
 
+int uint16_2_byte(uint16 a, void *buff, bool big_endian)
+{
+    uint8* ptr = (uint8*)buff;
+    if(big_endian) {
+        ptr[0] = (uint8)(a >> 8);
+        ptr[1] = (uint8)a;
+    } else {
+        ptr[1] = (uint8)(a >> 8);
+        ptr[0] = (uint8)a;
+    }
+    return sizeof(uint16);
+}
+
+static uint16 fletcher16(const uint8_t* data, int data_len)
+{
+    uint32_t sum1 = 0;
+    uint32_t sum2 = 0;
+    int index;
+
+    for (index = 0; index < data_len; ++index )
+    {
+        sum1 += data[index];
+        sum2 += sum1;
+    }
+
+    return ((0xFF & sum2) << 8) | (0xFF & sum1);
+}
+
+#define HD8122_PACK_HEAD 0xD9F1
+char *nmea_param[]={
+    "GGA",
+    "GLL",
+    "GSA",
+    "GRS",
+    "GSV",
+    "RMC",
+    "VTG",
+    "ZDA",
+    "GST"
+};
+int lynq_gnss_setting_statement_type(uint32 h_gnss, char *statement_type,int state)
+{
+    int i;
+    uint8 data[3];
+    data[0] = 0xF0;
+    for (i = 0;i < sizeof(nmea_param)/sizeof(nmea_param[0]);i++)
+    {
+        if(!strncmp(statement_type,nmea_param[i],3))
+        {
+            data[1] = (uint8)i;
+            break;
+        }
+    }
+    if(i > 8)
+    {
+        if(!strncmp(statement_type,"TXT",3))
+        {
+            data[1] = 0X20;
+        }
+        else if(!strncmp(statement_type,"DTM",3))
+        {
+            data[1] = 0X0A;
+        }
+        else
+        {
+            ALOGE("statement_type error\n");
+            return -1;
+        }
+    }
+    data[2] = state;
+    uint8 buff[1024];
+    memset(buff, 0, sizeof(buff));
+    uint8 *data_ptr = buff;
+    data_ptr += uint16_2_byte(HD8122_PACK_HEAD, data_ptr, false);
+    *data_ptr++ = 0x06;
+    *data_ptr++ = 0x01;
+    data_ptr += uint16_2_byte((uint16)3, data_ptr, false);
+    
+    memcpy(data_ptr, data, 3);
+    data_ptr += 3;
+
+    data_ptr += uint16_2_byte(fletcher16(buff + 2, 4 + 3), data_ptr, false);
+    int len = data_ptr - buff;
+    int ret =0;
+    int fd = open(MBTK_GNSS_DEV, O_RDWR | O_NOCTTY | O_NDELAY);
+    if(fd < 0) {
+        ALOGE("open error\n");
+        return -1;
+    }
+    ret = write(fd, buff, len);
+    if(ret < 0)
+    {
+        ALOGE(" cmd send faild");
+        close(fd);
+        return -1;
+    }
+    usleep(1000);
+    close(fd);
+    return 0;
+}
+
 static short int from_hex(char a)
 {
     if (a >= 'A' && a <= 'F')
@@ -1376,7 +1477,6 @@
     return 0;
 }
 
-
 int lynq_gnss_client_init(uint32 *ph_gnss)
 {
     int ret;
@@ -2035,6 +2135,9 @@
     return 0;
 
 }
+
+
+
 #ifdef __cplusplus
 }
 #endif