Default open gnss pty.
Change-Id: I376ce5ec01c876f6bf3685409aed91515d915b0f
diff --git a/mbtk/mbtk_gnssd/gnss_main.c b/mbtk/mbtk_gnssd/gnss_main.c
index c0eae05..c820489 100755
--- a/mbtk/mbtk_gnssd/gnss_main.c
+++ b/mbtk/mbtk_gnssd/gnss_main.c
@@ -38,6 +38,8 @@
#define GNSS_FILE_LOG_MAX 104857600 // 100MB
#endif
+#define MBTK_GNSS_PTY_AUTO_INIT 1
+
gnss_info_t gnss_info;
#ifdef MBTK_GNSS_UBUS_ENABLE
@@ -64,6 +66,9 @@
static bool mbtk_gnss_time_set_flag = 0;
+#if MBTK_GNSS_PTY_AUTO_INIT
+static bool gnss_pty_print_enable = FALSE;
+#endif
static int gnss_pty_master_fd = -1;
static int gnss_pty_slave_fd = -1;
static int gnss_usb_at_port_fd = -1;
@@ -115,16 +120,24 @@
// TTY AT change.
if((gnss_info.print_port & GNSS_PRINT_PORT_TTY_AT) != (print_port & GNSS_PRINT_PORT_TTY_AT)) {
if(print_port & GNSS_PRINT_PORT_TTY_AT) { // Open
+#if MBTK_GNSS_PTY_AUTO_INIT
+ gnss_pty_print_enable = TRUE;
+#else
if(gnss_pty_open(&gnss_pty_master_fd, &gnss_pty_slave_fd, GNSS_PORT_PTY)) {
return GNSS_ERR_OPEN_DEV;
}
+#endif
LOGD("Open PTY port success.");
} else { // Close
+#if MBTK_GNSS_PTY_AUTO_INIT
+ gnss_pty_print_enable = FALSE;
+#else
if(gnss_pty_slave_fd > 0) {
close(gnss_pty_slave_fd);
gnss_pty_slave_fd = -1;
unlink(GNSS_PORT_PTY);
}
+#endif
LOGD("Close PTY port success.");
}
}
@@ -201,7 +214,9 @@
close(gnss_uart_at_port_fd);
gnss_uart_at_port_fd = -1;
}
-
+#if MBTK_GNSS_PTY_AUTO_INIT
+ gnss_pty_print_enable = FALSE;
+#else
if(gnss_pty_master_fd > 0) {
tcflush(gnss_pty_master_fd, TCIOFLUSH);
close(gnss_pty_master_fd);
@@ -214,7 +229,7 @@
gnss_pty_slave_fd = -1;
unlink(GNSS_PORT_PTY);
}
-
+#endif
gnss_info.print_port = 0;
return 0;
@@ -315,7 +330,13 @@
}
if(gnss_pty_master_fd > 0) {
+#if MBTK_GNSS_PTY_AUTO_INIT
+ if(gnss_pty_print_enable) {
+ ret = write(gnss_pty_master_fd, nmea, nmea_len);
+ }
+#else
ret = write(gnss_pty_master_fd, nmea, nmea_len);
+#endif
}
ind_nmea_print(nmea);
ind_location_print(nmea);
@@ -1308,6 +1329,13 @@
gnss_info.print_port = 0;
}
+#if MBTK_GNSS_PTY_AUTO_INIT
+ if(gnss_pty_open(&gnss_pty_master_fd, &gnss_pty_slave_fd, GNSS_PORT_PTY)) {
+ LOGE("gnss_pty_open() fail.");
+ return -1;
+ }
+#endif
+
// Init ubus and waitting IPC commands.
#ifdef MBTK_GNSS_UBUS_ENABLE
if(gnss_ubus_init()) {