Add mbtk gnss callback.
Change-Id: I5c720e8e742648aade43f02eae1fa2274ce361ea
diff --git a/mbtk/mbtk_gnssd/gnss_main.c b/mbtk/mbtk_gnssd/gnss_main.c
index 5109126..c4f2d8d 100755
--- a/mbtk/mbtk_gnssd/gnss_main.c
+++ b/mbtk/mbtk_gnssd/gnss_main.c
@@ -30,6 +30,7 @@
#define GNSS_PORT_USB_AT "/dev/ttyGS0"
#define GNSS_PORT_USB_NMEA "/dev/ttymodem0"
#define GNSS_PORT_UART_AT "/dev/ttyS1"
+#define GNSS_CLI_IND_MAX 10
#ifdef GNSS_DEBUG
#define GNSS_NMEA_FILE_LOG "/tmp/mbtk_gnss_nmea.log"
@@ -51,6 +52,7 @@
static char data_buff[GNSS_BUFF_SIZE*4] = {0};
static uint32 nmea_buff_len = 0;
static uint32 data_buff_len = 0;
+static gnss_ind_info_t ind_info[GNSS_CLI_IND_MAX];
static bool nmea_found = FALSE;
#ifdef GNSS_DEBUG
@@ -66,6 +68,8 @@
static int gnss_uart_at_port_fd = -1;
static char *gnss_filter_info[] = {"RMC", "VTG", "GGA", "GSA", "GSV", "GLL", "ZDA", "GST", "TXT", "DHV", "DTM", NULL};
+int gnss_write(int fd, const void* buf, int buf_len);
+
static void help()
{
LOGD("mbtk_gnssd <6228/8122/5311> <gnss_dev> <0/1>");
@@ -248,6 +252,49 @@
}
#endif
+static void ind_location_print(const char *data)
+{
+ int index = 0;
+ int buff_len = 0;
+ char buff[GNSS_BUFF_SIZE] = {0};
+ buff[0] = MBTK_IND_START_FLAG;
+ buff_len++;
+ memcpy(buff + 1, MBTK_IND_LOCATION_TAG, strlen(MBTK_IND_LOCATION_TAG));
+ buff_len += strlen(MBTK_IND_LOCATION_TAG);
+ memcpy(buff + strlen(buff), data, strlen(data));
+ buff_len += strlen(data);
+ buff[strlen(buff)] = MBTK_IND_END_FLAG;
+ buff_len++;
+
+ while(index < GNSS_CLI_IND_MAX) {
+ if(ind_info[index].cli_fd > 0 && (ind_info[index].ind_flag & MBTK_GNSS_IND_LOCATION)) {
+ gnss_write(ind_info[index].cli_fd, buff, buff_len);
+ }
+ index++;
+ }
+}
+
+static void ind_nmea_print(const char *data)
+{
+ int index = 0;
+ int buff_len = 0;
+ char buff[GNSS_BUFF_SIZE] = {0};
+ buff[0] = MBTK_IND_START_FLAG;
+ buff_len++;
+ memcpy(buff + 1, MBTK_IND_NMEA_TAG, strlen(MBTK_IND_NMEA_TAG));
+ buff_len += strlen(MBTK_IND_NMEA_TAG);
+ memcpy(buff + strlen(buff), data, strlen(data));
+ buff_len += strlen(data);
+ buff[strlen(buff)] = MBTK_IND_END_FLAG;
+ buff_len++;
+ while(index < GNSS_CLI_IND_MAX) {
+ if(ind_info[index].cli_fd > 0 && (ind_info[index].ind_flag & MBTK_GNSS_IND_NMEA)) {
+ gnss_write(ind_info[index].cli_fd, buff, buff_len);
+ }
+ index++;
+ }
+}
+
static void nmea_print(const char *nmea, int nmea_len)
{
if(gnss_usb_at_port_fd > 0) {
@@ -265,6 +312,8 @@
if(gnss_pty_master_fd > 0) {
write(gnss_pty_master_fd, nmea, nmea_len);
}
+
+ ind_nmea_print(nmea);
}
static unsigned char nmea_checksum(const char *nmea)
@@ -839,6 +888,47 @@
}
}
+int gnss_ind_set(int fd, int ind_type)
+{
+ int index = 0;
+ if(ind_type) { // Add IND flag.
+ while(index < GNSS_CLI_IND_MAX) {
+ if(ind_info[index].cli_fd == fd)
+ break;
+ index++;
+ }
+
+ if(index == GNSS_CLI_IND_MAX) { // Add flag
+ index = 0;
+ while(index < GNSS_CLI_IND_MAX) {
+ if(ind_info[index].cli_fd <= 0)
+ break;
+ index++;
+ }
+ ind_info[index].cli_fd = fd;
+ ind_info[index].ind_flag = (uint32)ind_type;
+ } else { // Change flag
+ ind_info[index].cli_fd = fd;
+ ind_info[index].ind_flag = (uint32)ind_type;
+ }
+ } else { // Clear IND flag.
+ while(index < GNSS_CLI_IND_MAX) {
+ if(ind_info[index].cli_fd == fd)
+ break;
+ index++;
+ }
+
+ if(index == GNSS_CLI_IND_MAX) {
+ return GNSS_ERR_ARG;
+ }
+
+ ind_info[index].cli_fd = 0;
+ ind_info[index].ind_flag = 0;
+ }
+
+ return GNSS_ERR_OK;
+}
+
static void sig_process(int sig)
{
LOGI("I got signal %d\n", sig);