[Feature][ZXW-33][GNSS]add liblynq-qser-gnss

Change-Id: I9fbd202facb969c8b05e71a0de6a9978200a7310
diff --git a/cap/zx297520v3/sources/meta-zxic-custom/conf/distro/vehicle_dc.conf b/cap/zx297520v3/sources/meta-zxic-custom/conf/distro/vehicle_dc.conf
index 35dde15..322f079 100755
--- a/cap/zx297520v3/sources/meta-zxic-custom/conf/distro/vehicle_dc.conf
+++ b/cap/zx297520v3/sources/meta-zxic-custom/conf/distro/vehicle_dc.conf
@@ -160,6 +160,7 @@
         liblynq-qser-sms \
         liblynq-qser-data \
         liblynq-qser-network \
+        liblynq-qser-gnss \
 	"
 
 zxic_lib += "${@bb.utils.contains('CONFIG_TEL_API_SUPPORT', 'RIL', 'libril libreference-ril', 'libtelsvr', d)}"
diff --git a/cap/zx297520v3/sources/meta-zxic-custom/recipes-lynq/liblynq-qser-gnss/liblynq-qser-gnss.bb b/cap/zx297520v3/sources/meta-zxic-custom/recipes-lynq/liblynq-qser-gnss/liblynq-qser-gnss.bb
new file mode 100755
index 0000000..46f2a37
--- /dev/null
+++ b/cap/zx297520v3/sources/meta-zxic-custom/recipes-lynq/liblynq-qser-gnss/liblynq-qser-gnss.bb
@@ -0,0 +1,54 @@
+#inherit externalsrc package

+

+DESCRIPTION = "liblynq-qser-gnss"

+LICENSE = "CLOSED"

+LIC_FILES_CHKSUM = "file://LICENSE;md5=3f86c7f456a6d0bbeca155e65084eee1"

+DEPENDS += "liblynq-log libxml2"

+#inherit workonsrc

+WORKONSRC = "${TOPDIR}/../src/lynq/lib/liblynq-qser-gnss/"

+FILESEXTRAPATHS_prepend :="${TOPDIR}/../src/lynq/lib/:"

+SRC_URI = " \

+          file://liblynq-qser-gnss\

+          "

+

+SRC-DIR = "${S}/../liblynq-qser-gnss"

+

+TARGET_CC_ARCH += "${LDFLAGS}"

+BB_INCLUDE_ADD = "--sysroot=${STAGING_DIR_HOST}"

+BB_LDFLAGS_ADD = "--sysroot=${STAGING_DIR_HOST} -Wl,--hash-style=gnu"

+

+EXTRA_OEMAKE = "'TARGET_PLATFORM = ${TARGET_PLATFORM}'"

+

+FILES_${PN} = "${base_libdir}/*.so "

+

+FILES_${PN}-dev = "/test \

+                   ${includedir}"

+

+FILES_${PN}-doc = "/doc"

+

+FILES_${PN}-dbg ="${base_bindir}/.debug \

+                  ${base_libdir}/.debug \

+                  ${base_sbindir}/.debug"

+

+INSANE_SKIP_${PN} += "already-stripped"

+INSANE_SKIP_${PN} += "installed-vs-shipped"

+

+

+#INHIBIT_PACKAGE_STRIP = "1"

+do_compile () {

+		oe_runmake all -C ${SRC-DIR} ROOT=${STAGING_DIR_HOST} OFLAGS="--sysroot=${STAGING_DIR_HOST} -Os -Wl,--hash-style=gnu -DTELEPHONYWARE"

+}

+

+do_install () {

+    oe_runmake install -C ${SRC-DIR} ROOT=${D}

+	

+    if [ -d "${WORKONSRC}" ] ; then

+        install -d ${D}${includedir}/

+        cp -raf ${SRC-DIR}/include/ ${D}${includedir}/

+    fi 

+}

+

+addtask bachclean

+do_bachclean () {

+    oe_runmake clean

+}

diff --git a/cap/zx297520v3/src/lynq/lib/liblynq-qser-gnss/LICENSE b/cap/zx297520v3/src/lynq/lib/liblynq-qser-gnss/LICENSE
new file mode 100755
index 0000000..ecc2bc1
--- /dev/null
+++ b/cap/zx297520v3/src/lynq/lib/liblynq-qser-gnss/LICENSE
@@ -0,0 +1,31 @@
+Copyright Statement:
+
+This software/firmware and related documentation ("Mobiletek Software") are
+protected under relevant copyright laws. The information contained herein is
+confidential and proprietary to Mobiletek Inc. and/or its licensors. Without
+the prior written permission of Mobiletek inc. and/or its licensors, any
+reproduction, modification, use or disclosure of Mobiletek Software, and
+information contained herein, in whole or in part, shall be strictly
+prohibited.
+
+Mobiletek Inc. (C) 2015. All rights reserved.
+
+BY OPENING THIS FILE, RECEIVER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
+THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MOBILETEK SOFTWARE")
+RECEIVED FROM MOBILETEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO RECEIVER
+ON AN "AS-IS" BASIS ONLY. MOBILETEK EXPRESSLY DISCLAIMS ANY AND ALL
+WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
+WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
+NONINFRINGEMENT. NEITHER DOES MOBILETEK PROVIDE ANY WARRANTY WHATSOEVER WITH
+RESPECT TO THE SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY,
+INCORPORATED IN, OR SUPPLIED WITH THE MOBILETEK SOFTWARE, AND RECEIVER AGREES
+TO LOOK ONLY TO SUCH THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO.
+RECEIVER EXPRESSLY ACKNOWLEDGES THAT IT IS RECEIVER'S SOLE RESPONSIBILITY TO
+OBTAIN FROM ANY THIRD PARTY ALL PROPER LICENSES CONTAINED IN MOBILETEK
+SOFTWARE. MOBILETEK SHALL ALSO NOT BE RESPONSIBLE FOR ANY MOBILETEK SOFTWARE
+RELEASES MADE TO RECEIVER'S SPECIFICATION OR TO CONFORM TO A PARTICULAR
+STANDARD OR OPEN FORUM. RECEIVER'S SOLE AND EXCLUSIVE REMEDY AND MOBILETEK'S
+ENTIRE AND CUMULATIVE LIABILITY WITH RESPECT TO THE MOBILETEK SOFTWARE
+RELEASED HEREUNDER WILL BE, AT MOBILETEK'S OPTION, TO REVISE OR REPLACE THE
+MOBILETEK SOFTWARE AT ISSUE, OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE
+CHARGE PAID BY RECEIVER TO MOBILETEK FOR SUCH MOBILETEK SOFTWARE AT ISSUE.
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
new file mode 100755
index 0000000..d761104
--- /dev/null
+++ b/cap/zx297520v3/src/lynq/lib/liblynq-qser-gnss/include/lynq_qser_gnss.h
@@ -0,0 +1,116 @@
+#ifndef __LYNQ_GNSS_H__
+#define __LYNQ_GNSS_H__
+#ifdef __cplusplus
+extern "C" {
+#endif
+struct mbtk_gnss_handle_t
+{
+    int dev_fd;
+    pthread_t  uart_pthread;
+    pthread_t  gnss_pthread;
+    gnss_handler_func_t gnss_handler_func;
+    int mode; // 0 - stop, 1 - single, 2 - periodic, 3 - start
+    pthread_mutex_t _cond_mutex;
+    int reset_state;
+    int inited;
+    ring_buffer_t ring_buffer;
+    int getap_status;
+    char *rb;
+
+#if TTFF_TEST
+    pthread_t ttff_pid;
+    int location_state;
+#endif
+    /********************
+    save handle's adr
+    phandle = &handle
+    handle  = mbtk_gnss_handle
+    *********************/
+    uint32_t *phandle; // handle's adr
+};
+
+typedef struct 
+{
+    uint32_t    size;                   /**<   Set to the size of mcm_gps_sv_info_t. */
+    int         prn;                    /**<   Pseudo-random number for the SV. */ 
+    float       snr;                    /**<   Signal-to-noise ratio. */ 
+    float       elevation;              /**<   Elevation of the SV in degrees. */ 
+    float       azimuth;                /**<   Azimuth of the SV in degrees. */ 
+}QL_LOC_SV_INFO_T;                      /* Type */
+
+#define     QL_LOC_GPS_SUPPORT_SVS_MAX   32  /**  Maximum number of satellites in view. */
+typedef struct 
+{
+    uint32_t            size;                                   /**<   Set to the size of mcm_gps_sv_status_t. */
+    int                 num_svs;                                /**<   Number of SVs currently visible. */
+    QL_LOC_SV_INFO_T    sv_list[QL_LOC_GPS_SUPPORT_SVS_MAX];    /**<   Contains an array of SV information. */
+    uint32_t            ephemeris_mask;                         /**<   Bitmask indicating which SVs have ephemeris data.  */
+    uint32_t            almanac_mask;                           /**<   Bitmask indicating which SVs have almanac data.   */
+    uint32_t            used_in_fix_mask;                       /**<   Bitmask indicating which SVs were used for computing the most recent position fix. */
+}QL_LOC_SV_STATUS_T;  /* Type */
+
+typedef enum 
+{
+    LYNQ_POS_MODE_STANDALONE        = 0, /**<  Mode for running GPS standalone (no assistance).  */
+    LYNQ_POS_MODE_MS_BASED          = 1, /**<  AGPS MS-Based mode.  */
+    LYNQ_POS_MODE_MS_ASSISTED       = 2, /**<  AGPS MS-Assisted mode.  */
+}LYNQ_POS_MODE_T;
+
+typedef enum 
+{
+    LYNQ_POS_RECURRENCE_PERIODIC    = 0, /**<  Receive GPS fixes on a recurring basis at a specified period.  */
+    LYNQ_POS_RECURRENCE_SINGLE      = 1, /**<  Request a single-shot GPS fix.  */
+}LYNQ_POS_RECURRENCE_T;
+
+struct LYNQ_POS_MODE_INFO_T
+{
+    LYNQ_POS_MODE_T       mode;               /*  Position mode.      */
+    LYNQ_POS_RECURRENCE_T recurrence;         /*  Recurrence          */
+};
+
+
+#endif
+typedef struct 
+{
+    uint32_t year; // 大于1980
+    uint32_t month; // 1-12
+    uint32_t day; // 1-31
+    uint32_t hour; // 0-23
+    uint32_t minute; // 0-59
+    uint32_t second; // 0-59
+    uint32_t millisecond; // 0-999
+}LYNQ_INJECT_TIME_INTO_T; /* Message */
+
+
+typedef enum  {
+    LOC_IND_STATUS_INFO_ON,//E_MT_LOC_MSG_ID_STATUS_INFO = 0,
+    LOC_IND_LOCATION_INFO_ON,//E_MT_LOC_MSG_ID_LOCATION_INFO,
+    LOC_IND_SV_INFO_ON,//E_MT_LOC_MSG_ID_SV_INFO,
+    LOC_IND_NMEA_INFO_ON,//E_MT_LOC_MSG_ID_NMEA_INFO,
+    LOC_IND_CAP_INFO_ON,//E_MT_LOC_MSG_ID_CAPABILITIES_INFO,
+    LOC_IND_AGPS_DATA_CONN_CMD_REQ_ON,//E_MT_LOC_MSG_ID_AGPS_STATUS,
+    LOC_IND_NI_NFY_USER_RESP_REQ_ON,//E_MT_LOC_MSG_ID_NI_NOTIFICATION,
+    LOC_IND_XTRA_DATA_REQ_ON,//E_MT_LOC_MSG_ID_XTRA_REPORT_SERVER,
+}msg_t;
+
+typedef enum {
+    DELETE_NOTHING = 0, /**< Delete nothing. */
+    DELETE_EPHEMERIS = 1, /**< Delete ephemeris data. */
+    DELETE_ALMANAC = 2, /**< Delete almanac data. */
+    DELETE_POSITION_TIME = 3, /**< Delete position and time data. */
+    DELETE_UTC = 4, /**< Delete UTC data. */
+    DELETE_ALL = 5, /**< Delete all location data. */
+}DELETE_AIDING_DATA_TYPE_T;
+
+int qser_Gnss_Init(uint32_t *h_gnss);
+int qser_Gnss_Deinit(uint32_t h_gnss);
+int qser_AddRxIndMsgHandler(gnss_handler_func_t handler_ptr,uint32_t h_gnss);
+int qser_Set_Indications(uint32_t h_gnss,e_msg_id_t type);
+int qser_Gnss_Start(uint32_t h_gnss);
+int qser_Gnss_Stop(uint32_t h_gnss);
+int qser_Gnss_Delete_Aiding_Data(uint32_t h_gnss,DELETE_AIDING_DATA_TYPE_T flags);
+int qser_Gnss_InjectTime(uint32_t h_gnss,LYNQ_INJECT_TIME_INTO_T *time_info);
+#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
new file mode 100755
index 0000000..118ebe0
--- /dev/null
+++ b/cap/zx297520v3/src/lynq/lib/liblynq-qser-gnss/include/mbtk_gnss_internal.h
@@ -0,0 +1,321 @@
+
+#include <stdint.h>
+#ifndef __MBTK_GNSS_H__
+#define __MBTK_GNSS_H__
+#include "ringbuffer.h"
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+/*
+GGA: GNSS 定位数据
+$GNGGA,,,,,,0,00,99.99,,,,,,*56
+*/
+struct gnss_gga
+{
+    char sys;
+    char time;
+    char lat;
+    char lat_dir;
+    char lon;
+    char lon_dir;
+    int local_state;
+    int sv_size;
+    float hdop;
+    float msl;
+    char m;
+    float altref;
+    char _m;
+    float diff_age;
+    float diff_station;
+    char crc;
+};
+/*
+GSV : 可见的GNSS卫星
+$GPGSV,1,1,00,0*65
+$GBGSV,1,1,00,0*77
+*/
+struct gnss_gsv
+{
+    char sys;
+    int msg_size;
+    int msg_num;
+    int sv_size;
+    int sv1_num;
+    int sv2_num;
+    int sv3_num;
+    int sv4_num;
+    int elv1;
+    int elv2;
+    int elv3;
+    int elv4;
+    int az1;
+    int az2;
+    int az3;
+    int az4;
+    int cno1;
+    int cno2;
+    int cno3;
+    int cno4;
+    char crc;
+
+};
+/*
+GSA: GNSS精度因子与有效卫星信息
+$GNGSA,A,1,,,,,,,,,,,,,99.99,99.99,99.99,4*36
+*/
+struct gnss_gsa
+{
+    char sys;
+    char s_mode;
+    char g_mode;
+    int sv1_num;
+    int sv2_num;
+    int sv3_num;
+    int sv4_num;
+    int sv5_num;
+    int sv6_num;
+    int sv7_num;
+    int sv8_num;
+    int sv9_num;
+    int sv10_num;
+    int sv11_num;
+    int sv12_num;
+    float pdop;
+    float hdop;
+    float vdop;
+    int system_id;
+    char crc;
+};
+
+/*
+VTG: 航迹向和地速
+$GNVTG,,,,,,,,,N*2E
+*/
+struct gnss_vtg
+{
+    char sys;
+    float cogt;
+    char _t;
+    float cogm;
+    char _m;
+    float sog;
+    char _n;
+    float kph;
+    char _k;
+    char mode;
+    char crc;
+};
+
+/*
+推荐的最少数据
+RMC
+$GNRMC,,V,,,,,,,,,,N,V*37
+*/
+struct gnss_rmc
+{
+    char sys;
+    char time;
+    int local_status;
+    char lat;
+    char lat_dir;
+    char lon;
+    char lon_dir;
+    float spd;
+    float cog;
+    char date;
+    float mv;
+    char mve;
+    char mode;
+    char nav_states;
+    char crc;
+};
+
+typedef uint32_t gnss_client_handle_type;
+
+typedef enum
+{
+    E_MT_LOC_MSG_ID_LOCATION_INFO,          /**<  pv_data = &QL_LOC_LOCATION_INFO_T  */
+    E_MT_LOC_MSG_ID_NMEA_INFO,              /**<  pv_data = &QL_LOC_NMEA_INFO_T  */
+}e_msg_id_t;
+
+#define     QL_LOC_MAX_SEVER_ADDR_LENGTH    255 /**  Maximum generic server address length for the host name. */
+typedef struct 
+{/** Indication Message; Indication with the reported XTRA server URLs. */
+    char server1[QL_LOC_MAX_SEVER_ADDR_LENGTH + 1];  /**<   server1.*/
+    char server2[QL_LOC_MAX_SEVER_ADDR_LENGTH + 1];  /**<   server2.*/
+    char server3[QL_LOC_MAX_SEVER_ADDR_LENGTH + 1];  /**<   server3.*/
+}QL_LOC_XTRA_REPORT_SERVER_INTO_T;
+
+typedef enum 
+{
+    E_QL_LOC_STATUS_NONE            = 0, /**<  GPS status unknown.  */
+    E_QL_LOC_STATUS_SESSION_BEGIN   = 1, /**<  GPS has begun navigating.  */
+    E_QL_LOC_STATUS_SESSION_END     = 2, /**<  GPS has stopped navigating.  */
+    E_QL_LOC_STATUS_ENGINE_ON       = 3, /**<  GPS has powered on but is not navigating.  */
+    E_QL_LOC_STATUS_ENGINE_OFF      = 4, /**<  GPS is powered off.  */
+}E_QL_LOC_STATUS_VALUE_T;
+
+typedef void (*gnss_handler_func_t)
+(
+        uint32_t    h_loc,
+        e_msg_id_t  e_msg_id,
+        void        *pv_data,
+        void        *context_ptr
+        );
+
+struct mopen_location_info_t
+{
+    uint32_t    size;                   /**<   Set to the size of mcm_gps_location_t. */
+    int flags; /**<   Contains GPS location flags bits. */
+    int position_source;  /**<   Provider indicator for HYBRID or GPS. */
+    double      latitude;               /**<   Latitude in degrees. */
+    double      longitude;              /**<   Longitude in degrees. */
+    double      altitude;               /**<   Altitude in meters above the WGS 84 reference ellipsoid. */
+    float       speed;                  /**<   Speed in meters per second. */
+    float       bearing;                /**<   Heading in degrees. */
+    float       accuracy;               /**<   Expected accuracy in meters. */
+    int64_t     timestamp;              /**<   Timestamp for the location fix in UTC million-second base.  */
+    int32_t     is_indoor;              /**<   Location is indoors. */
+    float       floor_number;           /**<   Indicates the floor number. */
+};
+
+#define MOPEN_GNSS_NMEA_MAX_LENGTH  255                 /**  NMEA string maximum length. */
+typedef struct
+{
+    int64_t     timestamp;                          /**<   System Timestamp, marked for when got the nmea data */
+    int         length;                             /**<   NMEA string length. */
+    char        nmea[MOPEN_GNSS_NMEA_MAX_LENGTH + 1];   /**<   NMEA string.*/
+}mopen_gnss_nmea_info_t;  /* Message */
+
+struct mopen_gnss_device_info_t
+{
+    int      device_info_valid;
+    int      usrt_bandrate;
+    char     product_name[10];
+    char     dev_config[6];
+    char     hw_ver[6];
+    char     fw_ver[32];
+    char     pn[16];
+    char     sn[16];
+    char     nmea_ver[4];
+};
+
+#ifdef DEBUG
+#define gnss_log(...)                    printf(__VA_ARGS__)
+#else
+#define gnss_log(...)
+#endif
+#endif
+#define LOGE printf
+#define LOGI printf
+
+// 默认为 9600,打开为 115200,但是 AT+MGPSCMD 会重启。
+#define BAUDRATE_115200  0
+
+#define TTFF_TEST   0
+
+#define MBTK_GNSS_DEV  "/dev/ttyS2"
+
+#define MBTK_UART_RECV_BUFFER_SIZE 1024
+#define MBTK_UART_SEND_BUFFER_MAX 128
+
+#define TRUE 1
+#define uint32 uint32_t
+
+
+// 获取当前时间
+#define GET_TIME()  { gettimeofday(&time_m, NULL); \
+    time_m.tv_sec += TIMEOUT_SEC;\
+}
+// 设置从循环中退出的时间
+#define SET_TIME_OUT(x)  { gettimeofday(&time_m, NULL); \
+    time_m.tv_sec += x;\
+}
+// 检测时间是否超时,超时则退出当前函数
+#define CHK_TIME()  { gettimeofday(&time_n, NULL); \
+    if(time_n.tv_sec > time_m.tv_sec) { \
+    printf("\ntimeout!!!\n\n");\
+    close(fd); \
+    return ret; \
+} \
+}
+// 检测时间是否超时,超时则退出当前循环
+#define CHK_TIME_BREAK()  { gettimeofday(&time_n, NULL); \
+    if(time_n.tv_sec > time_m.tv_sec) { \
+    printf("\ntimeout!!!\n\n");\
+    break; \
+} \
+}
+// 检测延时是否到达,到达则退出当前循环
+#define DELAY_TIME_BREAK()  { gettimeofday(&time_n, NULL); \
+    if(time_n.tv_sec > time_m.tv_sec) { \
+    break; \
+} \
+}
+
+typedef void (*gnss_msg_func_t)
+(
+        int index,
+        char *in_data,
+        void *out_ptr
+        );
+
+struct mbtk_gnss_cmd_msg_t
+{
+    int index; // 序号
+    char *cmd_str; // 匹配字符
+    gnss_msg_func_t gnss_msg_func; // 回调函数
+    int is_continue; // 是否随NEMA数据一起输出
+};
+
+
+
+static struct mopen_gnss_device_info_t mopen_gnss_device_info;
+static struct mbtk_gnss_handle_t *mbtk_gnss_handle = NULL;
+static int firmware_extren_state = 0;
+
+static char g_no_sv = 0;// 参与定位的卫星数量
+
+int mopen_gnss_get_nmea_config(uint32 h_gnss);
+int mopen_gnss_get_ant_state_info(uint32 h_gnss);
+
+static void get_gnss_time_info(int cmd, char *str, void *data);
+static void get_gnss_agnss_state(int cmd, char *str, void *data);
+static void get_gnss_device_info(int type, char *str, void *usr_ptr);
+static void gnss_uart_info(int cmd, char *str, void *data);
+static void gnss_gsa_info(int cmd, char *str, void *data);
+static int mopen_uart_change(int fd, int check);
+
+static int select_read( int fd, int timeout );
+ssize_t deal_read(int fd, void *buf, size_t count);
+
+
+
+int mopen_gnss_print_version(uint32 h_gnss);
+int lynq_gnss_client_init(uint32 *ph_gnss);
+int lynq_gnss_client_deinit(uint32 h_gnss);
+int mopen_gnss_add_rx_msg_handler(uint32 h_gnss, gnss_handler_func_t handler_ptr);
+int mopen_gnss_set_mode(uint32 h_gnss, int mode);
+int mopen_gnss_set_system_config(uint32 h_gnss, int mode);
+int mopen_gnss_set_nema_config(uint32 h_gnss, int mode);
+int mopen_gnss_download_tle(void);
+int mopen_gnss_injects_aidpos(uint32 h_gnss);
+int mopen_gnss_firmware_update(void);
+int mbtk_at_gnss_start_ttff(int type, int timeout_sec, int count);
+int lynq_gnss_send_cmd(uint32 h_gnss, const char *cmd, int cmd_len);
+int mopen_gnss_write(int fd, const char* buf, unsigned int buf_len);
+int set_baudrate(int fd, int baudrate);
+int mopen_gnss_dev_reset(uint32 h_gnss, int type, int mode);
+int lynq_open_gps(int state);
+int lynq_gnss_Injection_ephemeris(uint32 h_gnss);
+int exec_cmd(const char *cmd, char *result);
+int lynq_gnss_get_aidinfo(uint32 h_gnss);
+int lynq_gnss_get_device_info(uint32 h_gnss);
+int lynq_gnss_get_uart(uint32 h_gnss);
+int lynq_gnss_get_ap_data(void);
+
+#ifdef __cplusplus
+}
+#endif
diff --git a/cap/zx297520v3/src/lynq/lib/liblynq-qser-gnss/include/ringbuffer.h b/cap/zx297520v3/src/lynq/lib/liblynq-qser-gnss/include/ringbuffer.h
new file mode 100755
index 0000000..d2d5c91
--- /dev/null
+++ b/cap/zx297520v3/src/lynq/lib/liblynq-qser-gnss/include/ringbuffer.h
@@ -0,0 +1,50 @@
+#include <inttypes.h>
+#include <stddef.h>
+#include <assert.h>
+/**
+ * Prototypes and structures for the ring buffer module.
+ */
+
+#ifndef RINGBUFFER_H
+#define RINGBUFFER_H
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#define RING_BUFFER_ASSERT(x) assert(x)
+
+
+#define RING_BUFFER_IS_POWER_OF_TWO(buffer_size) ((buffer_size & (buffer_size - 1)) == 0)
+
+typedef size_t ring_buffer_size_t;
+#define RING_BUFFER_MASK(rb) (rb->buffer_mask)
+typedef struct ring_buffer_t ring_buffer_t;
+struct ring_buffer_t {
+    /** Buffer memory. */
+    char *buffer;
+    /** Buffer mask. */
+    ring_buffer_size_t buffer_mask;
+    /** Index of tail. */
+    ring_buffer_size_t tail_index;
+    /** Index of head. */
+    ring_buffer_size_t head_index;
+};
+
+void ring_buffer_init(ring_buffer_t *buffer, char *buf, size_t buf_size);
+void ring_buffer_queue(ring_buffer_t *buffer, char data);
+void ring_buffer_queue_arr(ring_buffer_t *buffer, const char *data, ring_buffer_size_t size);
+uint8_t ring_buffer_dequeue(ring_buffer_t *buffer, char *data);
+ring_buffer_size_t ring_buffer_dequeue_arr(ring_buffer_t *buffer, char *data, ring_buffer_size_t len);
+uint8_t ring_buffer_peek(ring_buffer_t *buffer, char *data, ring_buffer_size_t index);
+uint8_t ring_buffer_is_empty(ring_buffer_t *buffer);
+uint8_t ring_buffer_is_full(ring_buffer_t *buffer);
+ring_buffer_size_t ring_buffer_num_items(ring_buffer_t *buffer);
+void ring_buffer_clean(ring_buffer_t *buffer);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* RINGBUFFER_H */
diff --git a/cap/zx297520v3/src/lynq/lib/liblynq-qser-gnss/makefile b/cap/zx297520v3/src/lynq/lib/liblynq-qser-gnss/makefile
new file mode 100755
index 0000000..bdd8518
--- /dev/null
+++ b/cap/zx297520v3/src/lynq/lib/liblynq-qser-gnss/makefile
@@ -0,0 +1,67 @@
+SHELL = /bin/sh

+RM = rm -f

+

+LOCAL_CFLAGS := -Wall \

+                -std=gnu++14 \

+                -g -Os \

+                -flto \

+                -fPIC \

+                -fpermissive \

+

+ifeq ($(strip $(TARGET_PLATFORM)), T106)

+LOCAL_CFLAGS += -DBINDER_IPC_32BIT=1 -DHAVE_ENDIAN_H -DHAVE_PTHREADS -DHAVE_SYS_UIO_H -DHAVE_POSIX_FILEMAP -DHAVE_STRLCPY -DHAVE_PRCTL -DHAVE_MEMSET16 -DHAVE_MEMSET32 -DANDROID_SMP=0

+endif

+

+$(warning ################# lynq qser sms demo ROOT: $(ROOT),includedir:$(includedir))

+LOCAL_PATH   = .

+

+LOCAL_C_INCLUDES = \

+  -I. \

+  -I$(LOCAL_PATH)/include/ \

+  -I$(ROOT)$(includedir)/logger \

+  -I$(ROOT)$(includedir)/liblog \

+  -I$(ROOT)$(includedir)/libxml2 \

+

+

+LOCAL_LIBS := \

+    -L. \

+    -lstdc++ \

+    -lcutils \

+    -lutils \

+    -lpthread \

+    -llynq-log \

+    -lxml2 \

+

+

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

+

+EXECUTABLE = liblynq-qser-gnss.so

+

+OBJECTS=$(SOURCES:.cpp=.o)

+

+

+.PHONY: build clean install pack_rootfs 

+all: build

+$(EXECUTABLE): $(OBJECTS)

+	$(CXX) -shared -Wl,--no-undefined $(OBJECTS) $(LOCAL_LIBS) $(LOCAL_CFLAGS) $(LOCAL_C_INCLUDES) -o $@

+

+%.o : %.cpp

+	$(CXX) $(LOCAL_C_INCLUDES) $(LOCAL_CFLAGS) $(LOCAL_LIBS) -o $@ -c $<

+

+build:  $(EXECUTABLE)

+	$(warning ########## build $(EXECUTABLE)  ##########)

+install:

+	mkdir -p $(ROOT)$(base_libdir)/

+	install $(EXECUTABLE) $(ROOT)$(base_libdir)/

+	mkdir -p $(ROOT)$(includedir)/$(NAME)/sdk

+pack_rootfs:

+	mkdir -p $(PACK_INITRAMFS_TO)$(base_libdir)/

+	cp -af $(EXECUTABLE) $(PACK_INITRAMFS_TO)$(base_libdir)/

+	$(CROSS)strip $(PACK_INITRAMFS_TO)$(base_libdir)/$(EXECUTABLE)

+	mkdir -p $(PACK_TO)$(base_libdir)/

+	cp -af $(EXECUTABLE) $(PACK_TO)$(base_libdir)/

+	$(CROSS)strip $(PACK_TO)$(base_libdir)/$(EXECUTABLE)

+.PHONY: clean

+clean:

+	$(RM) $(OBJECTS) $(EXECUTABLE)

+	-find . -name "*.o" -delete

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
new file mode 100755
index 0000000..66046b7
--- /dev/null
+++ b/cap/zx297520v3/src/lynq/lib/liblynq-qser-gnss/src/lynq_qser_gnss.cpp
@@ -0,0 +1,227 @@
+/*============================================================================= 
+#     FileName: lynq_gnss.c
+#     Desc: about GNSS
+#     Author: cz.li
+#     Version: V1.0
+#     LastChange: 2023-06-13 
+#     History: 
+=============================================================================*/
+
+#include <stdio.h>
+#include <string.h>
+#include <strings.h>
+#include <stdlib.h>
+#include <errno.h>
+#include <termios.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <signal.h>
+#include <sys/types.h>
+#include <unistd.h>
+#include <pthread.h>
+#include <termios.h>
+#include <time.h>
+#include <sys/timeb.h>
+#include <sys/socket.h>
+#include <netdb.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <sys/ioctl.h>
+#include <dlfcn.h>
+#include <stdint.h>
+#include "mbtk_gnss_internal.h"
+#include "ringbuffer.h"
+#include "lynq_qser_gnss.h"
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+int ret;
+LYNQ_INJECT_TIME_INTO_T time_test;
+
+int qser_Gnss_Init(uint32_t *h_gnss)
+{
+    ret = lynq_gnss_client_init(h_gnss);
+    if(ret)
+    {
+        printf("Init faild\n");
+    }
+    return 0;
+}
+
+int qser_Gnss_Deinit(uint32_t h_gnss)
+{
+    ret = lynq_gnss_client_deinit(h_gnss);
+    if(ret)
+    {
+        printf("Deinit faild\n");
+    }
+    return 0;
+}
+
+int qser_AddRxIndMsgHandler(gnss_handler_func_t handler_ptr,uint32_t h_gnss)
+{
+    struct mbtk_gnss_handle_t *gnss_handle = (struct mbtk_gnss_handle_t *)h_gnss;
+    if(0 == h_gnss && NULL == handler_ptr)
+    {
+        printf("%s handler invalid.\n", __func__);
+        return -1;
+    }
+    gnss_handle->gnss_handler_func = handler_ptr;
+    return 0;
+}
+
+int qser_Set_Indications(uint32_t h_gnss,e_msg_id_t type)
+{
+    struct mbtk_gnss_handle_t *gnss_handle = (struct mbtk_gnss_handle_t *)h_gnss;
+    printf("type in\n");
+    switch(type)
+    {
+
+    case 1:
+    {
+        gnss_handle->mode = 1;
+        break;
+    }
+
+    case 3:
+    {
+        gnss_handle->mode = 3;
+        break;
+    }
+    default:
+        break;
+
+    }
+    return 0;
+}
+
+
+/*need  set system time in advance*/
+int qser_Gnss_InjectTime(uint32_t h_gnss,LYNQ_INJECT_TIME_INTO_T *time_info)
+{
+    time_t tNOW =time(NULL);
+    struct timeb tmNOW;
+    struct tm *ptm = {0};
+    ptm = gmtime(&tNOW);
+    printf("gmtime\n");
+    ftime(&tmNOW);
+    printf("fuzhi start\n");
+    time_info->year = (ptm->tm_year+1900);
+    time_info->month = (ptm->tm_mon+1);
+    time_info->day = ptm->tm_mday;
+    time_info->hour = ptm->tm_hour;
+    time_info->minute = ptm->tm_min;
+    time_info->second = ptm->tm_sec;
+    time_info->millisecond = tmNOW.millitm;
+    printf("fuzhi complate\n");
+    char send_buf[128] = {0};
+    printf("%d\n,%d\n,%d\n,%d\n,%d\n,%d\n,%d\r\n",time_info->year,time_info->month,time_info->day,\
+           time_info->hour,time_info->minute,time_info->second,time_info->millisecond);
+    snprintf(send_buf, sizeof(send_buf), "$AIDTIME,%d,%d,%d,%d,%d,%d,%d\r\n", time_info->year,time_info->month,time_info->day,\
+             time_info->hour,time_info->minute,time_info->second,time_info->millisecond);
+    ret = lynq_gnss_send_cmd(h_gnss, send_buf, sizeof(send_buf));
+    if(ret < 0)
+    {
+        printf("send fail\n");
+        return -1;
+    }
+
+    return 0;
+}
+
+int qser_Gnss_Start(uint32_t h_gnss)
+{
+    struct mbtk_gnss_handle_t *gnss_handle = (struct mbtk_gnss_handle_t *)h_gnss;
+    lynq_open_gps(1);
+    ret = set_baudrate(gnss_handle->dev_fd, B9600);
+    if(-1 == ret)
+    {
+        return  -2;
+    }
+    return 0;
+}
+
+int qser_Gnss_Stop(uint32_t h_gnss)
+{
+    lynq_open_gps(0);
+    return 0;
+}
+
+
+
+/*清除辅助数据
+bit0 - 清除星历
+bit1 - reserve0
+bit2 - 清除接收机位置和接收机时间
+bit3 - reserve1
+bit4 - 清除电离层修正参数和 UTC 参数
+bit5 - reserve2
+bit6 - reserve3
+bit7 - 清除历书
+*/
+
+int qser_Gnss_Delete_Aiding_Data(uint32_t h_gnss,DELETE_AIDING_DATA_TYPE_T flags)
+{
+    char send_buf[60] = {0};
+    struct mbtk_gnss_handle_t *gnss_handle = (struct mbtk_gnss_handle_t *)h_gnss;
+    switch(flags)
+    {
+    case 0:
+    {
+        snprintf(send_buf, sizeof(send_buf), "$RESET,0,h00\r\n");
+
+        break;
+    }
+    case 1:
+    {
+        snprintf(send_buf, sizeof(send_buf), "$RESET,0,h01\r\n");
+
+        break;
+    }
+    case 2:
+    {
+        snprintf(send_buf, sizeof(send_buf), "$RESET,0,h04\r\n");
+        break;
+    }
+    case 3:
+    {
+        snprintf(send_buf, sizeof(send_buf), "$RESET,0,h10\r\n");
+        break;
+    }
+    case 4:
+    {
+        snprintf(send_buf, sizeof(send_buf), "$RESET,0,h80\r\n");
+        break;
+    }
+    case 5:
+    {
+        snprintf(send_buf, sizeof(send_buf), "$RESET,0,hFF\r\n");//冷启动
+        break;
+    }
+    }
+    ring_buffer_clean(&gnss_handle->ring_buffer);
+    gnss_log("%s : %s\n", __FUNCTION__, send_buf);
+    pthread_mutex_lock(&gnss_handle->_cond_mutex);
+    gnss_handle->reset_state = 1;
+    pthread_mutex_unlock(&gnss_handle->_cond_mutex);
+    ret = lynq_gnss_send_cmd(h_gnss, send_buf, strlen(send_buf));
+    if(ret < 0)
+    {
+        printf("send faild");
+        return -1;
+    }
+    printf("reset OK!!!!!\n");
+
+    ret = set_baudrate(gnss_handle->dev_fd, B9600);
+    if(-1 == ret)
+    {
+        return  -2;
+    }
+
+    return 0;
+}
+
+#ifdef __cplusplus
+}
+#endif
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
new file mode 100755
index 0000000..97744ac
--- /dev/null
+++ b/cap/zx297520v3/src/lynq/lib/liblynq-qser-gnss/src/mbtk_gnss.cpp
@@ -0,0 +1,1411 @@
+
+#include <stdio.h>
+#include <string.h>
+#include <strings.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <errno.h>
+#include <termios.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <signal.h>
+#include <sys/types.h>
+#include <pthread.h>
+#include <termios.h>
+#include <time.h>
+#include <sys/ioctl.h>
+#include <malloc.h>
+#include <sys/time.h>
+#include "mbtk_gnss_internal.h"
+#include "ringbuffer.h"
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+struct mbtk_gnss_handle_t
+{
+    int dev_fd;
+    pthread_t  uart_pthread;
+    pthread_t  gnss_pthread;
+    gnss_handler_func_t gnss_handler_func;
+    int mode; // 0 - stop, 1 - single, 2 - periodic, 3 - start
+    pthread_mutex_t _cond_mutex;
+    int reset_state;
+    int inited;
+    ring_buffer_t ring_buffer;
+    int getap_status;
+    char *rb;
+    e_msg_id_t e_msg_id;
+    
+#if TTFF_TEST
+    pthread_t ttff_pid;
+    int location_state;
+#endif
+    /********************
+    存储handle的地址指针
+    phandle = &handle
+    handle  = mbtk_gnss_handle
+    *********************/
+    uint32_t *phandle; // handle的地址指针
+};
+#if TTFF_TEST
+struct mbtk_gnss_ttff_t
+{
+    int type;
+    int timeout_sec;
+    int test_count;
+    int average_loc_time;
+};
+// ttff 测试 flag
+static int location_test = 0;
+static pthread_mutex_t loc_cond_mutex_r = PTHREAD_MUTEX_INITIALIZER;
+static pthread_cond_t loc_sync_cond = PTHREAD_COND_INITIALIZER;
+#endif
+
+static struct mbtk_gnss_cmd_msg_t mbtk_gnss_cmd_msg_map[] = {
+{ 1,     "$OK",         NULL,                 0},
+{ 2,     "$Fail",       NULL,                 0},
+{ 3,     "RMC",         get_gnss_time_info,   1},
+{ 4,     "GGA",         get_gnss_time_info,   1},
+{ 5,     "$PDTINFO",    get_gnss_device_info, 0},
+{ 6,     "$CFGNMEA",    get_gnss_device_info, 0},
+{ 7,     "$CFGPRT",     gnss_uart_info,       0},
+{ 8,     "$CFGAID",     get_gnss_agnss_state, 0},
+{ 9,     "$ANTSTAT",    NULL,                 0},
+#if TTFF_TEST
+{10,     "GSA",         gnss_gsa_info,        1},
+#endif
+};
+
+
+/**
+ *  \brief strstr_n
+ *
+ *  find string return number
+ *
+ *  \param param
+ *  \return return type
+ */
+int strstr_n(const char *s1, const char *s2)
+{
+    int n;
+    int strlen = 0;
+
+    if(*s2)
+    {
+        while(*s1)
+        {
+            for(n = 0; *(s1+n) == *(s2 + n); n++)
+            {
+                if(!*(s2 + n + 1))
+                {
+                    strlen++;
+                    return strlen;
+                }
+            }
+            s1++;
+            strlen++;
+        }
+        return 0;
+    }
+    else
+        return 0;
+}
+
+/**
+ * @brief      gnss_get_para_from_nmea
+ *
+ * @details    从buf里面得到第num个逗号所在的位置
+ *
+ * @param      param
+ *
+ * @return     0~0xfe,代表逗号所在位置的偏移.
+ *             0xff,代表不存在第cx个逗号
+ */
+static int gnss_get_para_from_nmea(const char *data, char *out_data, int num)
+{
+    int i = 0;
+    int n[2] = {0};
+    int tmp;
+
+    // 找到第num个",",结果放到 n[0]
+    for (i = 0; i < num; ++i) {
+        tmp = strstr_n(&data[n[0]], ",");
+        if(0 == tmp) {
+            gnss_log("%s %d : error\n", __func__, __LINE__);
+            gnss_log("error: [%d] %s\n", num, data);
+            return -1;
+        }
+        n[0] += tmp;
+    }
+    if ((n[1] = strstr_n(&data[n[0]], ",")) ||
+            (n[1] = strstr_n(&data[n[0]], "*")) &&
+            (n[1] > 1)) {
+        memcpy(out_data, &data[n[0]], n[1] - 1);
+        printf("%s\n",out_data);
+    } else {
+        gnss_log("%s %d : error [%d]\n" , __func__, __LINE__, n[1]);
+        gnss_log("error: [%d] %s\n", num, data);
+        return -1;
+    }
+
+    return 0;
+}
+/**
+* @brief      get_timestamp
+*
+* @details    
+*
+* @param      param
+*
+* @return     return type
+*/
+static time_t get_timestamp(char *time)
+{
+    char tmp_char[4] = {0};
+    struct tm* tmp_time = (struct tm*)malloc(sizeof(struct tm));
+
+    memset(tmp_time, 0, sizeof(struct tm));
+    memset(tmp_char, 0, sizeof(tmp_char));
+    memcpy(tmp_char, &time[4], 2);
+    tmp_time->tm_sec = atoi(tmp_char);
+    memcpy(tmp_char, &time[2], 2);
+    tmp_time->tm_min = atoi(tmp_char);
+    memcpy(tmp_char, &time[0], 2);
+    tmp_time->tm_hour = atoi(tmp_char);
+    memcpy(tmp_char, &time[6], 2);
+    tmp_time->tm_mday = atoi(tmp_char);
+    memcpy(tmp_char, &time[8], 2);
+    tmp_time->tm_mon = atoi(tmp_char);
+    memcpy(tmp_char, &time[10], 2);
+    tmp_time->tm_year = 100 + atoi(tmp_char);
+
+    time_t _t = mktime(tmp_time);//按当地时区解析tmp_time
+    // gnss_log("timestamp: %ld\n",_t);
+    free(tmp_time);
+
+    return _t;
+}
+/**
+ * @brief      get_gnss_device_info
+ *
+ * @details    获取设备信息
+ *
+ * @param      type: 5-从$PDTINFO获取
+ *                   6-从$CFGNMEA获取
+ *
+ * @return     return type
+ */
+static void get_gnss_device_info(int type, char *str, void *usr_ptr)
+{
+    char tmp_str[32] = {0};
+    int i, ret;
+
+    if(5 == type) // define  mbtk_gnss_cmd_msg_map
+    {
+        // $PDTINFO get product info
+        char *tmp_ptr[6] = {mopen_gnss_device_info.product_name,
+                            mopen_gnss_device_info.dev_config,
+                            mopen_gnss_device_info.hw_ver,
+                            mopen_gnss_device_info.fw_ver,
+                            mopen_gnss_device_info.pn,
+                            mopen_gnss_device_info.sn
+                           };
+        for (i = 0; i < 6; ++i) {
+            memset(tmp_str, 0, sizeof(tmp_str));
+            // get product name
+            ret = gnss_get_para_from_nmea(str, tmp_str, i + 1);
+            if(ret)
+                continue;
+            memcpy(tmp_ptr[i], tmp_str, strlen(tmp_str));
+        }
+        gnss_log("*************************\n");
+        gnss_log("-Pn: %s\n dc: %s\n hv: %s\n fw: %s\n pn: %s\n sn: %s\n ",
+                 mopen_gnss_device_info.product_name,
+                 mopen_gnss_device_info.dev_config,
+                 mopen_gnss_device_info.hw_ver,
+                 mopen_gnss_device_info.fw_ver,
+                 mopen_gnss_device_info.pn,
+                 mopen_gnss_device_info.sn);
+    }
+    if(6 == type) // define  mbtk_gnss_cmd_msg_map
+    {
+        // $CFGNMEA get nmea version
+        memset(tmp_str, 0, sizeof(tmp_str));
+        ret = gnss_get_para_from_nmea(str, tmp_str, 1);
+        if(ret)
+            return;
+        memcpy(mopen_gnss_device_info.nmea_ver, tmp_str, strlen(tmp_str));
+        mopen_gnss_device_info.device_info_valid = TRUE;
+    }
+}
+
+static short int from_hex(char a)
+{
+    if (a >= 'A' && a <= 'F')
+        return a - 'A' + 10;
+    else if (a >= 'a' && a <= 'f')
+        return a - 'a' + 10;
+    else
+        return a - '0';
+}
+
+static int str_to_hex(char *str)
+{
+    unsigned char str_len = strlen(str);
+    int i;
+    int ret = 0;
+
+    for (i = 0; i < str_len; ++i) {
+        ret = ret * 16 + from_hex(str[i]);
+    }
+    return ret;
+}
+
+static void get_gnss_agnss_state(int cmd, char *str, void *data)
+{
+
+    int ret;
+    char tmp_str[10] = {0};
+    int agps;
+    static int count = 0;
+
+    ret = gnss_get_para_from_nmea(str, tmp_str, 2);
+    if(ret) {
+        printf("\n%s[%d] error!\n" , __FUNCTION__, __LINE__);
+    }
+    agps = str_to_hex(tmp_str);
+    gnss_log("\n%s[%d] agnss: %s[%x]\n" , __FUNCTION__, __LINE__, tmp_str, agps);
+    if(0 == agps && count < 5) {
+        lynq_gnss_get_aidinfo((uint32)mbtk_gnss_handle);
+        count++;
+    } else {
+        printf("\nagnss: %s\n", str);
+        count = 0;
+    }
+}
+// 1节=1海里/小时=1.852公里/小时
+/**
+ * @brief      function description
+ *
+ * @details    获取位置信息
+ *
+ * @param      type: 1-从$RMC获取
+ *                   2-从$GGA获取
+ * @return     return type
+ */
+static void get_gnss_loc_info(int type, char *str,
+                              struct mopen_location_info_t *_mopen_location_info)
+
+{
+    char tmp_str[32] = {0};
+    int ret;
+
+    if(1 == type)
+    {
+        // $xxRMC get product info
+        memset(tmp_str, 0, sizeof(tmp_str));
+        // get product name
+        ret = gnss_get_para_from_nmea(str, tmp_str, 7);
+        if(ret)
+            return;
+        _mopen_location_info->speed = atof(tmp_str);
+        memset(tmp_str, 0, sizeof(tmp_str));
+        // get product name
+        ret = gnss_get_para_from_nmea(str, tmp_str, 8);
+        if(ret)
+            return;
+        _mopen_location_info->bearing = atof(tmp_str);
+    }
+    else if(2 == type)
+    {
+        // $XXGGA get product info
+        memset(tmp_str, 0, sizeof(tmp_str));
+        // get product name
+        ret = gnss_get_para_from_nmea(str, tmp_str, 2);
+        if(ret)
+            return;
+        _mopen_location_info->latitude = atof(tmp_str);
+        memset(tmp_str, 0, sizeof(tmp_str));
+        // get product name
+        ret = gnss_get_para_from_nmea(str, tmp_str, 4);
+        if(ret)
+            return;
+        _mopen_location_info->longitude = atof(tmp_str);
+        memset(tmp_str, 0, sizeof(tmp_str));
+        // get product name
+        ret = gnss_get_para_from_nmea(str, tmp_str, 9);
+        if(ret)
+            return;
+        _mopen_location_info->altitude = atof(tmp_str);
+    }
+}
+
+static void get_gnss_time_info(int cmd, char *str, void *data)
+{
+    int ret;
+    char param[36] = {0};
+    struct mopen_location_info_t *mopen_location_info_ptr = (struct mopen_location_info_t *)data;
+
+    if (3 == cmd) {
+        memset(param, 0, sizeof(param));
+        // get time
+        ret = gnss_get_para_from_nmea(str, param, 1);
+        if(ret)
+            return;
+        // get date
+        ret = gnss_get_para_from_nmea(str, &param[6], 9);
+        if(ret)
+            return;
+
+        mopen_location_info_ptr->timestamp = get_timestamp(param);
+        get_gnss_loc_info(1, str, mopen_location_info_ptr);
+    } else if(4 == cmd) /* GGA */{
+        get_gnss_loc_info(2, str, mopen_location_info_ptr);
+        ret = gnss_get_para_from_nmea(str, param, 7);
+        if(ret)
+            return;
+        char no_sv = (char)atoi(param);
+        gnss_log("SV number: %d, %d\n", g_no_sv, no_sv);
+        /*
+          只能在临时固件下,才能获取APdata星历数据
+          在6颗卫星保存文件,每增加2颗保存一次。
+         */
+        if (1 == firmware_extren_state &&
+                g_no_sv < (no_sv - 1) && no_sv > 5) {
+
+            g_no_sv = no_sv;
+            lynq_gnss_get_ap_data();
+        }
+    }
+}
+
+static void gnss_uart_info(int cmd, char *str, void *data)
+{
+    int ret;
+    char tmp_str[12] = {0};
+
+    // $CFGPRT,1,h0,9600,129,3*57
+    ret = gnss_get_para_from_nmea(str, tmp_str, 3);
+    if(ret)
+        return;
+    mopen_gnss_device_info.usrt_bandrate = atoi(tmp_str);
+    gnss_log("CFGPRT: %s\n", str);
+    gnss_log("Uart bandrate: %d\n" , mopen_gnss_device_info.usrt_bandrate);
+    gnss_log("*************************\n");
+}
+/**
+ *  \brief function description
+ *
+ *  Detailed 处理gnss数据
+ *
+ *  \param param
+ *  \return return type
+ */
+static void process_gnss_callback(struct mbtk_gnss_handle_t *handle, char *data, int data_len)
+{
+    int ret = 0;
+    int i = 0;
+    static struct mopen_location_info_t mopen_location_info;
+    static int64_t tmp_time = 0;
+    mopen_gnss_nmea_info_t nmea_info;
+
+    memset(&nmea_info, 0, sizeof(nmea_info));
+    if(0 == tmp_time)
+        memset(&mopen_location_info, 0, sizeof(mopen_location_info));
+
+    for (i = 0;
+         i < (sizeof(mbtk_gnss_cmd_msg_map) / sizeof(struct mbtk_gnss_cmd_msg_t));
+         ++i) {
+        if(strstr_n(data, mbtk_gnss_cmd_msg_map[i].cmd_str)) {
+            if(mbtk_gnss_cmd_msg_map[i].gnss_msg_func)
+                mbtk_gnss_cmd_msg_map[i].gnss_msg_func(mbtk_gnss_cmd_msg_map[i].index,
+                                                       data, &mopen_location_info);
+            break;
+        }
+    }
+    if(0 == mbtk_gnss_cmd_msg_map[i].is_continue)
+        return;
+
+    tmp_time = mopen_location_info.timestamp;
+    nmea_info.timestamp = mopen_location_info.timestamp;
+    nmea_info.length = data_len;
+    memcpy(nmea_info.nmea, data, data_len);
+    //gnss_log("nmea:[%d] %s", data_len, data);
+    if( handle->mode == 3 && nmea_info.timestamp &&handle->gnss_handler_func)
+    {
+        handle->gnss_handler_func((uint32)handle, E_MT_LOC_MSG_ID_NMEA_INFO, &nmea_info, NULL);
+    }
+    if(handle->gnss_handler_func && handle->mode == 1 &&
+            mopen_location_info.latitude &&
+            mopen_location_info.longitude &&
+            mopen_location_info.altitude &&
+            mopen_location_info.timestamp &&
+            mopen_location_info.speed)
+    {
+        
+        handle->gnss_handler_func((uint32)handle, E_MT_LOC_MSG_ID_LOCATION_INFO, &mopen_location_info, NULL);
+        memset(&mopen_location_info, 0, sizeof(mopen_location_info));
+    }
+
+    return;
+}
+
+/**
+ *  \brief get_gnss_from_str
+ *
+ *  Detailed 从串口数据解析出每条消息
+ *
+ *  \param param
+ *  \return return type
+ */
+static int get_gnss_from_str(struct mbtk_gnss_handle_t *handle, char *data, int data_len)
+{
+    char *tail = NULL;
+    static int seek = 0;
+    // 等待 OK, 如果20条结果没有等到,就异常
+    static int reset_count = 0;
+    int i = 0, ret = -1;
+
+    if (handle->reset_state)
+    {
+        // 等待 reset 回复的 OK
+        if(0 != memcmp(data, "$OK", 3) && reset_count < 20) {
+            printf("gnss reset invalid: [%s]\n", data);
+            reset_count++;
+            return -1;
+        }
+        if (reset_count > 19) {
+            printf("%s: device reset timeout!!!\n", __FUNCTION__);
+            LOGI("%s: device reset timeout!!!\n", __FUNCTION__);
+        }
+        reset_count = 0;
+        gnss_log("reset ok: %s\n", data);
+#if BAUDRATE_115200
+        ret = mopen_uart_change(handle->dev_fd, 0);
+        if(ret) {
+            printf("reset Uart set 115200 error\n");
+        }
+#endif
+        pthread_mutex_lock(&handle->_cond_mutex);
+        handle->reset_state = 0;
+        pthread_mutex_unlock(&handle->_cond_mutex);
+    }
+
+    if((data[0] == '$' || data[0] == '#') &&
+            data[data_len - 1] == '\n' &&
+            data_len < 128) {
+        process_gnss_callback(handle, data, data_len);
+    } else {
+        gnss_log("nmea error: %s\n", data);
+    }
+
+    return 1;
+}
+
+void mopen_gnss_NonBlock(int fd, int cmd)
+{
+    int flags;
+
+    flags = fcntl(fd, F_GETFL, 0);
+    if(cmd)
+        flags |= O_NONBLOCK;
+    else
+        flags &= ~O_NONBLOCK;
+
+    fcntl(fd, F_SETFL, flags);
+}
+
+int set_baudrate(int fd, int baudrate)
+{
+    struct termios options, oldtio;
+
+    if(fcntl(fd, F_SETFL, 0) < 0) {
+        printf("fcntl failed!\n");
+        return -1;
+    }
+
+    if(tcgetattr(fd, &oldtio) != 0) {
+        printf("setup serial error!\n");
+        return -1;
+    }
+
+    /* Get the current options for the port... */
+    tcgetattr(fd, &options);
+
+    /* Set the baud rates to baudrate... */
+    cfsetispeed(&options, baudrate);
+    cfsetospeed(&options, baudrate);
+    tcsetattr(fd, TCSANOW, &options);
+
+    if (0 != tcgetattr(fd, &options))
+    {
+        printf("get options error!\n");
+        return -1;
+    }
+
+    /*
+     * 8bit Data,no partity,1 stop bit...
+     */
+    options.c_cflag &= ~PARENB;//无奇偶校验
+    options.c_cflag &= ~CSTOPB;//停止位,1位
+    options.c_cflag &= ~CSIZE; //数据位的位掩码
+    options.c_cflag |= CS8;    //数据位,8位
+
+    cfmakeraw(&options);
+
+    /*
+     * Set the new options for the port...
+     */
+    if (tcsetattr(fd, TCSANOW, &options) != 0)
+    {
+        printf("setup serial error!\n");
+        return -1 ;
+    }
+    return 0 ;
+}
+/*
+  自适应波特率设置
+ */
+static int auto_set_uart_baudrate(int fd)
+{
+    char rbuf[512];
+    int rByte = 0;
+    int b[3] = {B115200, B9600, 0};
+    int ret = B9600;
+    struct timeval time_m, time_n;
+    // 时间超时标志
+    int timeout_sign = 0;
+    // 先测试默认的9600波特率
+    SET_TIME_OUT(3);
+    do {
+        gettimeofday(&time_n, NULL);
+        if(time_n.tv_sec > time_m.tv_sec) {
+            //printf("Baudrate--test-9600--- timeout!\n");
+            if(timeout_sign)
+                break;
+            set_baudrate(fd, B115200);
+            ret = B115200;
+            timeout_sign = 1;
+            SET_TIME_OUT(3);
+            continue;
+        }
+
+        if(select_read(fd, 1) > 0)
+            usleep(50000);
+        else
+            continue;
+
+        rByte = deal_read(fd,&rbuf,sizeof(rbuf));
+        if(rByte > 0) {
+            gnss_log("Auto Baudrate[%d]%s\n", rByte, rbuf);
+            if(strstr(rbuf, "$"))
+                return ret;
+            memset(rbuf, 0, sizeof(rbuf));
+        } else {
+            printf("*** read error\n");
+        }
+    }while(1);
+
+    return 0;
+}
+
+int mopen_gnss_open(char *dev, int baudrate)
+{
+    int ret;
+    int fd = 0;
+
+    fd = open(dev, O_RDWR | O_NOCTTY | O_NDELAY);
+    if(fd < 0) {
+        printf("open error\n");
+        return -1;
+    }
+    gnss_log("curent dev: %s, fd: %d \n", dev, fd);
+    printf("curent dev: %s, fd: %d \n", dev, fd);
+    if(baudrate) {
+        gnss_log("set baudrate: %d \n", baudrate);
+        ret = set_baudrate(fd, baudrate);
+        if(-1 == ret) {
+            close(fd);
+            return -1;
+        }
+    } else {
+        set_baudrate(fd, B9600);
+        printf("baudrate ok\n");
+    }
+
+    return fd;
+}
+
+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);
+    return read(fd, buf, buf_len);
+}
+
+int mopen_gnss_write(int fd, const char* buf, unsigned int buf_len)
+{
+    size_t size;
+    size_t size_to_wr;
+    ssize_t size_written;
+    if(MBTK_UART_SEND_BUFFER_MAX < buf_len)
+    {
+        return -1;
+    }
+    for(size = 0; size < buf_len;)
+    {
+        size_to_wr = buf_len - size;
+        if( size_to_wr > MBTK_UART_SEND_BUFFER_MAX)
+            size_to_wr = MBTK_UART_SEND_BUFFER_MAX;
+        printf("write 0\n");
+        size_written = write(fd, &buf[size], size_to_wr);
+        printf("write 1\n");
+        if (size_written==-1)
+        {
+            return -1;
+        }
+        printf("send cmd: %s\n", &buf[size]);
+        printf("%d\n",fd);
+        size += size_written;
+        if(size_written != size_to_wr)
+        {
+            return size;
+        }
+    }
+    return size;
+}
+
+int mopen_gnss_close(int fd)
+{
+    return close(fd);
+}
+
+static void gnss_info_pthread(void* hdl)
+{
+    struct mbtk_gnss_handle_t *gnss_handle = (struct mbtk_gnss_handle_t *)hdl;
+    int ret = 0, i;
+    char tmp;
+    char tmp_arr[128] = {0};
+
+    pthread_detach(pthread_self());
+
+    memset(tmp_arr, 0, sizeof(tmp_arr));
+    while(mbtk_gnss_handle->inited)
+    {
+        for (i = 0; i < 256; ++i) {
+            if (0 == mbtk_gnss_handle->inited)
+                goto exit;
+            ret = ring_buffer_peek(&gnss_handle->ring_buffer, &tmp, i);
+            if (0 == ret) {
+                usleep(300000);
+                gnss_log("ring_buffer_peek ringbuffer read error\n");
+                i--;
+                continue;
+            }
+            if (tmp == '\n') {
+                break;
+            }
+        }
+
+        if (i > (256 - 2))
+            continue;
+
+        ret = ring_buffer_dequeue_arr(&gnss_handle->ring_buffer, tmp_arr, i + 1);
+
+        if(ret > 0 && 0 == mbtk_gnss_handle->getap_status) {
+            // gnss_log("NEMA:[%d] %s", ret, tmp_arr);
+            get_gnss_from_str(gnss_handle, tmp_arr, ret);
+            memset(tmp_arr, 0, sizeof(tmp_arr));
+        } else {
+            gnss_log("ringbuffer read error\n");
+        }
+        usleep(5000);
+    }
+exit:
+    pthread_exit(NULL);
+}
+
+static void gnss_uart_pthread(void* hdl)
+{
+    struct mbtk_gnss_handle_t *gnss_handle = (struct mbtk_gnss_handle_t *)hdl;
+    int ret = 0;
+    char buf[MBTK_UART_RECV_BUFFER_SIZE] = {0};
+
+    pthread_detach(pthread_self());
+
+    memset(buf, 0, sizeof(buf));
+    mbtk_gnss_handle->getap_status = 0;
+    while(mbtk_gnss_handle->inited)
+    {
+        while(mbtk_gnss_handle->getap_status){
+            // 在读AP_DATA星历时,不能输出NMEA
+            printf("g");
+            usleep(100000);
+        }
+        ret = mopen_gnss_read(gnss_handle->dev_fd, buf, MBTK_UART_RECV_BUFFER_SIZE);
+        if(ret > 0) {
+            printf("read: [%d] %s\n", ret, buf);
+            ring_buffer_queue_arr(&gnss_handle->ring_buffer, buf, ret);
+            memset(buf, 0, sizeof(buf));
+        } else {
+            gnss_log("read error\n");
+        }
+        usleep(100000);
+    }
+
+    pthread_exit(NULL);
+}
+
+ssize_t deal_read(int fd, void *buf, size_t count)
+{
+    int ret = 0;
+
+#if 0
+    ret = read(fd, buf, count);
+    return ret;
+#else
+    while (1)
+    {
+        ret = read(fd, buf, count);
+        if (ret == 0) {
+            printf("read serial return 0, please check serial device.\n");
+            exit(-5);
+        }
+        if(ret < 0) {
+            if ((errno == EAGAIN) || (errno == EINTR)) {
+                printf("read serial return -1, errno = %d, retry.\n", errno);
+                continue;
+            } else {
+                printf("read serial return -1, errno = %d, please check serial device.\n", errno);
+                exit(-5);
+            }
+        }
+        return ret;
+    }
+#endif
+}
+
+static int select_read( int fd, int timeout ) //1ms
+{
+    fd_set set;
+    struct timeval t;
+    int ret;
+    int i = timeout;
+
+    do {
+        FD_ZERO(&set);
+        FD_SET(fd, &set);
+        t.tv_sec = 0;
+        t.tv_usec = 100;
+
+        ret = select(FD_SETSIZE, &set, NULL, NULL, &t );
+        if(ret == 0) continue;
+        if(ret < 0 && errno == EINTR)continue;
+        else return ret;
+    } while(i--);
+
+    return ret;
+}
+
+// check: 是否需要校验
+static int mopen_uart_change(int fd, int check)
+{
+    int rByte = 0, i = 20;
+    char name[32];
+    char rbuf[1024];
+
+    sprintf(name,"$CFGPRT,1,h0,115200,129,3\r\n");
+    rByte = write( fd, name, strlen(name));
+    tcdrain(fd);//阻塞直到发送完成
+
+    set_baudrate(fd, B115200);
+    usleep(200000);
+    tcflush(fd, TCIFLUSH);//清空缓存区数据
+
+    if (0 == check)
+        return 0;
+    do{
+        rByte = 0;
+        memset(rbuf, 0, sizeof(rbuf));
+        if(select_read(fd, 1) > 0) {
+            rByte = deal_read(fd, &rbuf, sizeof(rbuf) - 1);
+            rbuf[rByte] = 0;
+            gnss_log("%s: %s", __FUNCTION__, rbuf);
+        }
+        if(strstr(rbuf, "$")) {
+            return 0;
+        } else {
+            gnss_log("%d rByte = %d, [%s]\n", 20 - i, rByte, rbuf);
+        }
+        usleep(5000 * 100);
+    }while(i--);
+
+    return -1;
+}
+
+#define GPS_DEV "/sys/devices/soc.0/d4000000.apb/mbtk-dev-op/gps_power"
+
+int lynq_open_gps(int state)
+{
+    char cmd[128] = "echo '86' > /sys/class/gpio/export && cd /sys/class/gpio/gpio86";
+    int ret;
+
+    if(0 == state)
+    {
+        ret = exec_cmd(cmd,NULL);
+        if(0 != ret)
+        {
+            printf("stop fail %x\n", ret);
+        }
+        char cmd2[128] = "echo '0' > /sys/class/gpio/gpio86/value && echo '86' > /sys/class/gpio/unexport";
+        ret = exec_cmd(cmd2,NULL);
+        if(0 != ret)
+        {
+            printf("stop fail %x\n", ret);
+        }
+    }
+
+    if(1 == state)
+    {
+        ret = exec_cmd(cmd,NULL);
+        if(0 != ret)
+        {
+            printf("start fail %x\n", ret);
+            return -1;
+        }
+        char cmd3[128] = "echo '1' > /sys/class/gpio/gpio86/value && echo '86' > /sys/class/gpio/unexport";
+        ret = exec_cmd(cmd3,NULL);
+        if(0 != ret)
+        {
+            printf("start fail %x\n", ret);
+            return -1;
+        }
+    }
+    return 0;
+}
+
+int lynq_gnss_client_init(uint32 *ph_gnss)
+{
+    int ret;
+    if(ph_gnss == NULL) {
+        printf("ARG error or has inited.");
+        return -1;
+    }
+
+    if (mbtk_gnss_handle) {
+        printf("GNSS has inited.");
+        *ph_gnss = (uint32)mbtk_gnss_handle;
+        return 0;
+    }
+    mbtk_gnss_handle = (mbtk_gnss_handle_t*)malloc(sizeof(struct mbtk_gnss_handle_t));
+    if(NULL == mbtk_gnss_handle)
+    {
+        printf("malloc memory error\n");
+        return -3;
+    }
+    memset(mbtk_gnss_handle, 0, sizeof(struct mbtk_gnss_handle_t));
+    memset(&mopen_gnss_device_info, 0, sizeof(mopen_gnss_device_info));
+    sleep(1);
+    lynq_open_gps(0);
+
+    mbtk_gnss_handle->dev_fd = mopen_gnss_open(MBTK_GNSS_DEV, 0);
+    ret = auto_set_uart_baudrate(mbtk_gnss_handle->dev_fd);
+    if(-1 == ret) {
+        ret = -2;
+        goto err;
+    } else if (B9600 == ret) {
+        ret = mopen_uart_change(mbtk_gnss_handle->dev_fd, 1);
+        printf("1\n");
+        if(ret)
+        {
+            printf("GNSS Uart set B115200 error\n");
+            mopen_gnss_close(mbtk_gnss_handle->dev_fd);
+            return -1;
+        }
+    }
+    
+    printf("Gnss Config Uart Baudrate Successful.\n");
+    
+    mbtk_gnss_handle->rb = (char*)malloc(MBTK_UART_RECV_BUFFER_SIZE);
+    if(NULL == mbtk_gnss_handle->rb)
+    {
+        printf("malloc memory error\n");
+        return -1;
+    }
+
+    ring_buffer_init(&mbtk_gnss_handle->ring_buffer,
+                     mbtk_gnss_handle->rb,
+                     MBTK_UART_RECV_BUFFER_SIZE);
+    mbtk_gnss_handle->inited = 1;
+    pthread_mutex_init(&mbtk_gnss_handle->_cond_mutex, NULL);
+    pthread_create(&mbtk_gnss_handle->uart_pthread, NULL, (void* (*)(void*))gnss_uart_pthread, (void *)mbtk_gnss_handle);
+    pthread_create(&mbtk_gnss_handle->gnss_pthread, NULL, (void* (*)(void*))gnss_info_pthread, (void *)mbtk_gnss_handle);
+    mopen_gnss_get_ant_state_info((uint32)mbtk_gnss_handle);
+    lynq_gnss_get_device_info((uint32)mbtk_gnss_handle);
+    mopen_gnss_get_nmea_config((uint32)mbtk_gnss_handle);
+    lynq_gnss_get_uart((uint32)mbtk_gnss_handle);
+    lynq_gnss_get_aidinfo((uint32)mbtk_gnss_handle);
+    *ph_gnss = (uint32)mbtk_gnss_handle;
+    mbtk_gnss_handle->phandle = ph_gnss;
+
+    return 0;
+err:
+    mopen_gnss_close(mbtk_gnss_handle->dev_fd);
+    lynq_open_gps(0);
+    firmware_extren_state = 0;
+    if (mbtk_gnss_handle) free(mbtk_gnss_handle);
+    mbtk_gnss_handle = NULL;
+
+    return ret;
+}
+static int _kill_pthread(pthread_t pid, int kill)
+{
+    int ret;
+
+    if (kill) {
+        ret = pthread_cancel(pid);
+        pthread_join(pid, NULL);
+    }
+    do{
+        ret = pthread_kill(pid, 0);
+        if(ret == ESRCH)
+            gnss_log("The specified thread does not exist or has terminated\n");
+        else if(ret == EINVAL)
+            gnss_log("Useless signal\n");
+        else
+            gnss_log("The thread exists\n");
+        usleep(100000);
+    }while(0 == ret);
+
+    return 0;
+}
+int lynq_gnss_client_deinit(uint32 h_gnss)
+{
+    int ret;
+    struct mbtk_gnss_handle_t *gnss_handle = (struct mbtk_gnss_handle_t *)h_gnss;
+
+    if(h_gnss == NULL)
+    {
+        gnss_log("ARG error or not inited.");
+        printf("ARG error or not inited.\n");
+        return -1;
+    }
+    gnss_handle->inited = 0;
+#if TTFF_TEST
+    // ttff测试线程在运行,而且不是临时固件模式
+    if (gnss_handle->ttff_pid &&
+            0 == firmware_extren_state &&
+            0 == location_test) {
+        gnss_log("kill thread ttff.\n");
+        _kill_pthread(gnss_handle->ttff_pid, 1);
+    }
+#endif
+    gnss_log("kill thread info 0.\n");
+    _kill_pthread(gnss_handle->gnss_pthread, 0);
+    gnss_log("kill thread uart.\n");
+    _kill_pthread(gnss_handle->uart_pthread, 0);
+    mopen_gnss_close(gnss_handle->dev_fd);
+    ret = lynq_open_gps(0);
+    if(ret)
+    {
+        printf("GNSS close init error\n");
+        return -1;
+    }
+
+    firmware_extren_state = 0;
+    if (gnss_handle->rb) free(gnss_handle->rb);
+    free((void *)h_gnss);
+    return 0;
+}
+
+int lynq_gnss_send_cmd(uint32 h_gnss, const char *cmd, int cmd_len)
+{
+    struct mbtk_gnss_handle_t *gnss_handle = (struct mbtk_gnss_handle_t *)h_gnss;
+    return  mopen_gnss_write(gnss_handle->dev_fd, cmd, cmd_len);
+}
+
+
+int lynq_gnss_get_device_info(uint32 h_gnss)
+{
+    int ret;
+    char *send_buf = "$PDTINFO\r\n";
+    if(0 == h_gnss)
+    {
+        printf("%s handler invalid.\n", __func__);
+        return -1;
+    }
+
+    ret = lynq_gnss_send_cmd(h_gnss, send_buf, strlen(send_buf));
+    if(ret < 0)
+    {
+        printf("lynq_gnss_client_init FAIL.	ret:%d\n",ret);
+        return -1;
+    }
+
+    return 0;
+}
+
+
+/**
+ * @brief      lynq_gnss_get_aidinfo
+ *
+ * @details    查询辅助数据状态
+ *             $CFGAID,0,D7FBFBDF,00000000,08*47
+ * @param      param
+ *
+ * @return     return type
+ */
+int lynq_gnss_get_aidinfo(uint32 h_gnss)
+{
+    int ret;
+    // char *send_buf = "$AIDINFO\r\n";
+    char *send_buf = "$CFGAID,0\r\n";
+    if(0 == h_gnss)
+    {
+        printf("%s handler invalid.\n", __func__);
+        return -1;
+    }
+
+    ret = lynq_gnss_send_cmd(h_gnss, send_buf, strlen(send_buf));
+    printf("%s \n",h_gnss);
+    if(ret < 0)
+    {
+        printf("%s FAIL. ret:%d\n", __FUNCTION__, ret);
+        return -1;
+    }
+    return 0;
+}
+/**
+ * @brief      lynq_gnss_get_uart
+ *
+ * @details    get uart config info.
+ *             $CFGPRT,1,h0,9600,129,3*57
+ *
+ * @param      param
+ *
+ * @return     return type
+ */
+int lynq_gnss_get_uart(uint32 h_gnss)
+{
+    int ret;
+    char *send_buf = "$CFGPRT,1\r\n";
+    // char *send_buf = "$CFGPRT,2\r\n";
+    if(0 == h_gnss)
+    {
+        printf("%s handler invalid.\n", __func__);
+        return -1;
+    }
+
+    ret = lynq_gnss_send_cmd(h_gnss, send_buf, strlen(send_buf));
+    if(ret < 0)
+    {
+        printf("lynq_gnss_client_init FAIL.	ret:%d\n",ret);
+        return -1;
+    }
+    return 0;
+}
+
+int mopen_gnss_set_uart(uint32 h_gnss, int baudrate)
+{
+    int ret;
+    char send_buf[28] = {0};
+    // char *send_buf = "$CFGPRT,1,h0,9600,1,3\r\n";
+
+    if(0 == h_gnss)
+    {
+        printf("%s handler invalid.\n", __func__);
+        return -1;
+    }
+    sprintf(send_buf, "$CFGPRT,1,h0,%d,1,3\r\n", baudrate);
+    gnss_log("%s %s", __FUNCTION__, send_buf);
+    ret = lynq_gnss_send_cmd(h_gnss, send_buf, strlen(send_buf));
+    if(ret < 0)
+    {
+        printf("lynq_gnss_client_init FAIL.	ret:%d\n",ret);
+        return -1;
+    }
+    return 0;
+}
+
+
+int mopen_gnss_get_ant_state_info(uint32 h_gnss)
+{
+    int ret;
+    char *cmd1_buf = "$ANTSTAT,1\r\n";
+    char *cmd2_buf = "$ANTSTAT1\r\n";
+
+    if(0 == h_gnss)
+    {
+        printf("%s handler invalid.\n", __func__);
+        return -1;
+    }
+    printf("ant 0\n");
+    ret = lynq_gnss_send_cmd(h_gnss, cmd1_buf, strlen(cmd1_buf));
+    printf("ant 1\n");
+    if(ret < 0)
+    {
+        gnss_log("%s FAIL. ret:%d\n", __func__, ret);
+        return -1;
+    }
+    ret = lynq_gnss_send_cmd(h_gnss, cmd2_buf, strlen(cmd2_buf));
+    printf("ant 2\n");
+    if(ret < 0)
+    {
+        gnss_log("%s FAIL. ret:%d\n", __func__, ret);
+        return -1;
+    }
+    return 0;
+}
+
+int mopen_gnss_get_nmea_config(uint32 h_gnss)
+{
+    int ret;
+    char *send_buf = "$CFGNMEA\r\n";
+
+    if(0 == h_gnss)
+    {
+        printf("%s handler invalid.\n", __func__);
+        return -1;
+    }
+    ret = lynq_gnss_send_cmd(h_gnss, send_buf, strlen(send_buf));
+    if(ret < 0)
+    {
+        gnss_log("%s FAIL. ret:%d\n", __func__, ret);
+        return -1;
+    }
+    return 0;
+}
+
+int mopen_gnss_add_rx_msg_handler(uint32 h_gnss, gnss_handler_func_t handler_ptr)
+{
+    struct mbtk_gnss_handle_t *gnss_handle = (struct mbtk_gnss_handle_t *)h_gnss;
+    if(0 == h_gnss && NULL == handler_ptr)
+    {
+        printf("%s handler invalid.\n", __func__);
+        return -1;
+    }
+    gnss_handle->gnss_handler_func = handler_ptr;
+    printf("okok\n");
+    return 0;
+}
+
+#define AGNSS_TLE_FILE  "/tmp/agnss_tle"
+
+
+
+
+#define AGNSS_CONFIG_FILE  "/etc/mbtk/gps.conf"
+
+
+/**
+ * @brief
+ *
+ * @details    detailed description
+ *
+ * @param      mode
+ *                  0 : stop
+ *                  1 : 输出一次坐标
+ *                  2 : periodic
+ *                  3 : 输出nmea数据到回调函数
+ *    0 - stop, 1 - single, 2 - periodic, 3 - start
+ *
+ * @return     return type
+ */
+int mopen_gnss_set_mode(uint32 h_gnss, int mode)
+{
+    struct mbtk_gnss_handle_t *gnss_handle = (struct mbtk_gnss_handle_t *)h_gnss;
+    if(0 == h_gnss)
+    {
+        printf("%s handler invalid.\n", __func__);
+        return -1;
+    }
+    gnss_handle->mode = mode;
+
+    return 0;
+}
+
+int mopen_gnss_print_version(uint32 h_gnss)
+{
+    printf("*************************\n");
+    printf("-Pn: %s\n dc: %s\n hv: %s\n fw: %s\n pn: %s\n sn: %s\n ",
+           mopen_gnss_device_info.product_name,
+           mopen_gnss_device_info.dev_config,
+           mopen_gnss_device_info.hw_ver,
+           mopen_gnss_device_info.fw_ver,
+           mopen_gnss_device_info.pn,
+           mopen_gnss_device_info.sn);
+    printf("Uart bandrate: %d\n" , mopen_gnss_device_info.usrt_bandrate);
+    printf("*************************\n");
+
+    return 0;
+}
+
+/**
+* @brief 使用popen调用终端并获取执行结果
+*
+* @param[in] cmd 命令内容
+* @param[out] result 保存结果的地址
+* @return 0或1 执行状态,成功或失败
+*/
+int exec_cmd(const char *cmd, char *result)
+{
+    FILE *pipe = popen(cmd, "r");
+    if(!pipe)
+        return -1;
+
+    char buffer[256] = {0};
+    while(!feof(pipe))
+    {
+        if(fgets(buffer, 256, pipe))
+        {
+            printf("%s", buffer);
+            memset(buffer, 0, sizeof(buffer));
+        }
+    }
+    pclose(pipe);
+    return 0;
+}
+
+#define GNSS_AP_DATA_FILE  "/etc/mbtk/rtm.bin"
+
+int lynq_gnss_get_ap_data(void)
+{
+    int state = 0;
+    uint32 *ph_gnss = NULL;
+    gnss_handler_func_t cb;
+    int current_mode;
+    const char* cmd = "mbtk_gnss_update getap -d /dev/ttyS2 -b 115200 -a /etc/mbtk/rtm.bin";
+
+    if(access(GNSS_AP_DATA_FILE, F_OK) != -1) {
+        unlink(GNSS_AP_DATA_FILE);
+    }
+    mbtk_gnss_handle->getap_status = 1;
+    sleep(1);
+    printf("Mopen Gnss Get Ap Data -> \n");
+    int ret = exec_cmd(cmd, NULL);
+
+    usleep(100000);
+    mbtk_gnss_handle->getap_status = 0;
+    if(0 != ret) {
+        printf("Gnss getap result: %x\n", ret);
+        return -1;
+    }
+    LOGI("%s %d: %d.\n", __FUNCTION__, __LINE__, ret);
+    return ret;
+}
+/*
+  sync : 1
+ */
+int mopen_gnss_firmware_update(void)
+{
+    int state = 0;
+    uint32 *ph_gnss = NULL;
+    gnss_handler_func_t cb;
+    int current_mode;
+    const char* cmd_1 = "mbtk_gnss_update downbl -d /dev/ttyS2 \
+            -l /mnt/userdata/bootloader_r3.0.0_build6773_uartboot_921600.pkg";
+
+            const char* cmd_2 = "mbtk_gnss_update sendap -d /dev/ttyS2 -b 921600 -a /etc/mbtk/rtm.bin";
+
+    const char* cmd_3 = "mbtk_gnss_update downfw -d /dev/ttyS2 -b 921600\
+            -f /mnt/userdata/UC6228CI-R3.2.10.100Build8019_mfg.pkg";
+            // /etc/mbtk/UC6228CI-R3.4.0.0Build7258_mfg.pkg
+
+            if (mbtk_gnss_handle) {
+            printf("%s gnss thread runing!!!\n", __func__);
+            if (mbtk_gnss_handle->gnss_handler_func)
+            cb = mbtk_gnss_handle->gnss_handler_func;
+
+            ph_gnss = mbtk_gnss_handle->phandle;
+            current_mode = mbtk_gnss_handle->mode;
+            // 主线程是否在运行
+            if (mbtk_gnss_handle->gnss_pthread)
+            state = 1;
+            lynq_gnss_client_deinit((uint32)mbtk_gnss_handle);
+}
+            printf("Mopen Gnss Bootloader Update -> \n");
+    int ret = exec_cmd(cmd_1, NULL);
+    if(0 != ret) {
+        printf("Gnss update result: %x\n", ret);
+        return -1;
+    }
+
+    /*if(access(GNSS_AP_DATA_FILE, F_OK) != -1)
+    {
+        printf("Mopen Gnss Send AP Data  -> \n");
+        ret = exec_cmd(cmd_2, NULL);
+        if(0 != ret) {
+            printf("Gnss update result: %x\n", ret);
+        }
+    }*/
+
+    printf("Mopen Gnss Firmware Update -> \n");
+    ret = exec_cmd(cmd_3, NULL);
+    if(0 != ret) {
+        printf("Gnss update result: %x\n", ret);
+        return -2;
+    }
+
+    if (0 == firmware_extren_state)
+        firmware_extren_state = 1;
+    if (state && ph_gnss) {
+        ret = lynq_gnss_client_init(ph_gnss);
+        if (cb) {
+            mbtk_gnss_handle->gnss_handler_func = cb;
+            mbtk_gnss_handle->mode = current_mode;
+        }
+    }
+
+    LOGI("%s %d: %d.\n", __FUNCTION__, __LINE__, ret);
+    return ret;
+}
+
+/*update ephemeris from network*/
+#define AGNSS_TLE_FILE "/mnt/userdata/agnss_tle" //deposit ephemeris
+
+/*Injection ephemeris AGNSS_TLE_FILE*/
+int lynq_gnss_Injection_ephemeris(uint32 h_gnss)
+{
+    int ret;
+    int agnss_fd = 0;
+    int size = 0;
+
+    if(0 == h_gnss)
+    {
+        printf("%s handler invalid.\n", __func__);
+        return -1;
+    }
+
+    agnss_fd = open(AGNSS_TLE_FILE, O_RDWR);
+    if (agnss_fd <= 0)
+    {
+        printf("%s open file FAIL. errno:%d\n", __FUNCTION__, errno);
+        return -1;
+    }
+    char* databuf = (char*)malloc(128);
+    if(databuf == NULL)
+    {
+        gnss_log("%s malloc() fail.", __FUNCTION__);
+        return -1;
+    }
+    memset(databuf, 0, 128);
+    while(0 < (size = read(agnss_fd, databuf, 128)))
+    {
+        gnss_log("%s Write[%d]\r\n", __FUNCTION__, size);
+        ret = lynq_gnss_send_cmd(h_gnss, databuf, size);
+        if(ret < 0)
+        {
+            printf("send cmd FAIL. ret:%d\n",  ret);
+            break;
+        }
+        memset(databuf, 0, 128);
+    }
+    close(agnss_fd);
+    free(databuf);
+    return 0;
+
+}
+#ifdef __cplusplus
+}
+#endif
diff --git a/cap/zx297520v3/src/lynq/lib/liblynq-qser-gnss/src/ringbuffer.cpp b/cap/zx297520v3/src/lynq/lib/liblynq-qser-gnss/src/ringbuffer.cpp
new file mode 100755
index 0000000..7bbd0fc
--- /dev/null
+++ b/cap/zx297520v3/src/lynq/lib/liblynq-qser-gnss/src/ringbuffer.cpp
@@ -0,0 +1,84 @@
+#include "ringbuffer.h"
+
+/**
+ * Implementation of ring buffer functions.
+ */
+
+void ring_buffer_init(ring_buffer_t *buffer, char *buf, size_t buf_size) {
+    assert(RING_BUFFER_IS_POWER_OF_TWO(buf_size) == 1);
+    buffer->buffer = buf;
+    buffer->buffer_mask = buf_size - 1;
+    buffer->tail_index = 0;
+    buffer->head_index = 0;
+}
+
+void ring_buffer_queue(ring_buffer_t *buffer, char data) {
+    if(ring_buffer_is_full(buffer)) {
+        buffer->tail_index = ((buffer->tail_index + 1) & RING_BUFFER_MASK(buffer));
+    }
+
+
+    buffer->buffer[buffer->head_index] = data;
+    buffer->head_index = ((buffer->head_index + 1) & RING_BUFFER_MASK(buffer));
+}
+
+void ring_buffer_queue_arr(ring_buffer_t *buffer, const char *data, ring_buffer_size_t size) {
+
+    ring_buffer_size_t i;
+    for(i = 0; i < size; i++) {
+        ring_buffer_queue(buffer, data[i]);
+    }
+}
+
+uint8_t ring_buffer_dequeue(ring_buffer_t *buffer, char *data) {
+    if(ring_buffer_is_empty(buffer)) {
+        return 0;
+    }
+
+    *data = buffer->buffer[buffer->tail_index];
+    buffer->tail_index = ((buffer->tail_index + 1) & RING_BUFFER_MASK(buffer));
+    return 1;
+}
+
+ring_buffer_size_t ring_buffer_dequeue_arr(ring_buffer_t *buffer, char *data, ring_buffer_size_t len) {
+    if(ring_buffer_is_empty(buffer)) {
+        return 0;
+    }
+
+    char *data_ptr = data;
+    ring_buffer_size_t cnt = 0;
+    while((cnt < len) && ring_buffer_dequeue(buffer, data_ptr)) {
+        cnt++;
+        data_ptr++;
+    }
+    return cnt;
+}
+
+uint8_t ring_buffer_peek(ring_buffer_t *buffer, char *data, ring_buffer_size_t index) {
+    if(index >= ring_buffer_num_items(buffer)) {
+        /* No items at index */
+        return 0;
+    }
+
+    /* Add index to pointer */
+    ring_buffer_size_t data_index = ((buffer->tail_index + index) & RING_BUFFER_MASK(buffer));
+    *data = buffer->buffer[data_index];
+    return 1;
+}
+
+uint8_t ring_buffer_is_empty(ring_buffer_t *buffer) {
+    return (buffer->head_index == buffer->tail_index);
+}
+
+uint8_t ring_buffer_is_full(ring_buffer_t *buffer) {
+    return ((buffer->head_index - buffer->tail_index) & RING_BUFFER_MASK(buffer)) == RING_BUFFER_MASK(buffer);
+}
+
+ring_buffer_size_t ring_buffer_num_items(ring_buffer_t *buffer) {
+    return ((buffer->head_index - buffer->tail_index) & RING_BUFFER_MASK(buffer));
+}
+
+void ring_buffer_clean(ring_buffer_t *buffer) {
+    buffer->tail_index = 0;
+    buffer->head_index = 0;
+}