gnss: update gnss code
Change-Id: Id906b93eb619bcbebc11469338647a3fdc47076f
diff --git a/mbtk/mbtk_gnssd/gnss_main.c b/mbtk/mbtk_gnssd/gnss_main.c
index 7c6191b..4d3a8dc 100755
--- a/mbtk/mbtk_gnssd/gnss_main.c
+++ b/mbtk/mbtk_gnssd/gnss_main.c
@@ -38,7 +38,7 @@
#define GNSS_FILE_LOG_MAX 104857600 // 100MB
#endif
-gnss_info_t gnss_info;
+gnss_info_t gnss_info;
#ifdef MBTK_GNSS_UBUS_ENABLE
struct ubus_context *gnss_ubus_init(void);
@@ -53,6 +53,7 @@
static uint32 nmea_buff_len = 0;
static uint32 data_buff_len = 0;
static gnss_ind_info_t ind_info[GNSS_CLI_IND_MAX];
+static gnss_ind_type_num_t ind_num;
static bool nmea_found = FALSE;
#ifdef GNSS_DEBUG
@@ -298,23 +299,32 @@
static void nmea_print(const char *nmea, int nmea_len)
{
+ int ret = -1;
if(gnss_usb_at_port_fd > 0) {
- write(gnss_usb_at_port_fd, nmea, nmea_len);
+ ret = write(gnss_usb_at_port_fd, nmea, nmea_len);
}
if(gnss_usb_nmea_port_fd > 0) {
- write(gnss_usb_nmea_port_fd, nmea, nmea_len);
+ ret = write(gnss_usb_nmea_port_fd, nmea, nmea_len);
}
if(gnss_uart_at_port_fd > 0) {
- write(gnss_uart_at_port_fd, nmea, nmea_len);
+ ret = write(gnss_uart_at_port_fd, nmea, nmea_len);
}
if(gnss_pty_master_fd > 0) {
- write(gnss_pty_master_fd, nmea, nmea_len);
+ ret = write(gnss_pty_master_fd, nmea, nmea_len);
}
- ind_nmea_print(nmea);
+ if(ind_num.nmea_cb_num > 0)
+ {
+ ind_nmea_print(nmea);
+ }
+
+ if(ind_num.locl_cb_num > 0)
+ {
+ ind_location_print(nmea);
+ }
}
static unsigned char nmea_checksum(const char *nmea)
@@ -404,7 +414,7 @@
static bool nmea_char_check(char ch)
{
if(isalnum(ch) || ch == '$' || ch == '\r' || ch == '\n' || ch == '.'
- || ch == ',' || ch == '*' || ch == '\0' || ch == '/' || ch == '_' || ch == '=')
+ || ch == ',' || ch == '*' || ch == '\0' || ch == '/' || ch == '_' || ch == '=' || ch == '-')
return TRUE;
return FALSE;
@@ -912,12 +922,35 @@
break;
index++;
}
+ if(index == GNSS_CLI_IND_MAX)
+ {
+ LOGE("ind flag is full.");
+ return GNSS_ERR_CLI_FULL;
+ }
ind_info[index].cli_fd = fd;
ind_info[index].ind_flag = (uint32)ind_type;
} else { // Change flag
+ if(ind_info[index].ind_flag == MBTK_GNSS_IND_LOCATION)
+ {
+ ind_num.locl_cb_num--;
+ }
+ else if(ind_info[index].ind_flag == MBTK_GNSS_IND_NMEA)
+ {
+ ind_num.nmea_cb_num--;
+ }
+
ind_info[index].cli_fd = fd;
ind_info[index].ind_flag = (uint32)ind_type;
}
+
+ if(ind_type == MBTK_GNSS_IND_LOCATION)
+ {
+ ind_num.locl_cb_num++;
+ }
+ else if(ind_type == MBTK_GNSS_IND_NMEA)
+ {
+ ind_num.nmea_cb_num++;
+ }
} else { // Clear IND flag.
while(index < GNSS_CLI_IND_MAX) {
if(ind_info[index].cli_fd == fd)
@@ -929,6 +962,15 @@
return GNSS_ERR_ARG;
}
+ if(ind_info[index].ind_flag == MBTK_GNSS_IND_LOCATION)
+ {
+ ind_num.locl_cb_num--;
+ }
+ else if(ind_info[index].ind_flag == MBTK_GNSS_IND_NMEA)
+ {
+ ind_num.nmea_cb_num--;
+ }
+
ind_info[index].cli_fd = 0;
ind_info[index].ind_flag = 0;
}
@@ -1006,6 +1048,7 @@
}
#endif
+ memset(&ind_num, 0x0, sizeof(gnss_ind_type_num_t));
memset(&gnss_info, 0, sizeof(gnss_info_t));
memcpy(gnss_info.dev_name, argv[2], strlen(argv[2]));
gnss_info.state = GNSS_STATE_CLOSE;