gnss: update gnss code
Change-Id: Id906b93eb619bcbebc11469338647a3fdc47076f
diff --git a/mbtk/mbtk_gnssd/gnss_hd8122.c b/mbtk/mbtk_gnssd/gnss_hd8122.c
index b34b4a4..ec7b515 100755
--- a/mbtk/mbtk_gnssd/gnss_hd8122.c
+++ b/mbtk/mbtk_gnssd/gnss_hd8122.c
@@ -512,6 +512,7 @@
if(memcmp(cmd, "$RESET", 6) == 0) // $RESET,<mode>
{
gnss_reset_type_enum mode = (gnss_reset_type_enum)atoi(cmd + 7);
+ LOGD("set reset: %d", mode);
if(mode == GNSS_RESET_TYPE_HOT)
{
gnss_set_result = gnss_8122_reset(fd, 3);
@@ -576,6 +577,7 @@
int rate;
if(2 == sscanf(cmd, "$MSGCFG,%d,%d", &mode, &rate))
{
+ LOGD("set msgcfg: %d, %d", mode, rate);
int time = rate / 1000; // s
if(time < 0)
{
@@ -587,13 +589,14 @@
| GNSS_SET_MSGCFG_GRS | GNSS_SET_MSGCFG_GSV | GNSS_SET_MSGCFG_GLL | GNSS_SET_MSGCFG_ZDA
| GNSS_SET_MSGCFG_GST | GNSS_SET_MSGCFG_TXT) & mode) != mode)
{
+ LOGD("msgcfg not support mode");
gnss_set_result = GNSS_ERR_ARG;
goto set_fail;
}
if(mode & GNSS_SET_MSGCFG_RMC)
{
- gnss_set_result = gnss_8122_msgcfg(fd, 0xF8, 0x05, time);
+ gnss_set_result = gnss_8122_msgcfg(fd, 0xF0, 0x05, time);
if(gnss_set_result != GNSS_ERR_OK)
{
goto set_fail;
diff --git a/mbtk/mbtk_gnssd/gnss_info.h b/mbtk/mbtk_gnssd/gnss_info.h
index 2b91523..6338c92 100755
--- a/mbtk/mbtk_gnssd/gnss_info.h
+++ b/mbtk/mbtk_gnssd/gnss_info.h
@@ -86,6 +86,11 @@
} gnss_ind_info_t;
typedef struct {
+ int nmea_cb_num;
+ int locl_cb_num;
+} gnss_ind_type_num_t;
+
+typedef struct {
gnss_id_enum gnss_id;
char dev_name[32];
bool auto_open; // Should auto open gnss?
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;