b.liu | 8f231a1 | 2024-05-31 17:55:06 +0800 | [diff] [blame] | 1 | #include <stdio.h> |
| 2 | #include <stdlib.h> |
| 3 | #include <unistd.h> |
| 4 | #include <errno.h> |
| 5 | #include <pthread.h> |
| 6 | #include <fcntl.h> |
| 7 | #include <libubox/ustream.h> |
| 8 | #include <libubus.h> |
| 9 | #include <signal.h> |
| 10 | #include <cutils/properties.h> |
b.liu | 778645e | 2024-06-21 16:47:42 +0800 | [diff] [blame] | 11 | #include <ctype.h> |
b.liu | 978f543 | 2024-07-01 18:04:18 +0800 | [diff] [blame] | 12 | #include <termios.h> |
b.liu | 8f231a1 | 2024-05-31 17:55:06 +0800 | [diff] [blame] | 13 | |
| 14 | #include "mbtk_type.h" |
| 15 | #include "mbtk_log.h" |
| 16 | #include "gnss_info.h" |
b.liu | 778645e | 2024-06-21 16:47:42 +0800 | [diff] [blame] | 17 | #include "gnss_utils.h" |
b.liu | 8f231a1 | 2024-05-31 17:55:06 +0800 | [diff] [blame] | 18 | #include "gnss_6228.h" |
b.liu | f9fbfa1 | 2024-06-14 15:53:59 +0800 | [diff] [blame] | 19 | #include "gnss_hd8122.h" |
b.liu | 99c645d | 2024-06-20 10:52:15 +0800 | [diff] [blame] | 20 | #include "gnss_asr5311.h" |
b.liu | 42f558e | 2024-07-18 14:06:49 +0800 | [diff] [blame^] | 21 | #include "gnss_n50db.h" |
b.liu | 8f231a1 | 2024-05-31 17:55:06 +0800 | [diff] [blame] | 22 | |
| 23 | #define GNSS_DEBUG 1 |
b.liu | d0ba715 | 2024-06-19 14:47:21 +0800 | [diff] [blame] | 24 | #define GNSS_UBUS_ENABLE 1 |
b.liu | 8f231a1 | 2024-05-31 17:55:06 +0800 | [diff] [blame] | 25 | |
| 26 | #define GNSS_TAG "MBTK_GNSS" |
| 27 | #define GNSS_BUFF_SIZE 2048 |
| 28 | #define MBTK_PROP_GNSS_LOG "persist.mbtk.gnss_log_enable" |
| 29 | #define GNSS_PORT_PTY "/dev/tty_gnss_nmea" |
| 30 | #define GNSS_PORT_USB_AT "/dev/ttyGS0" |
| 31 | #define GNSS_PORT_USB_NMEA "/dev/ttymodem0" |
| 32 | #define GNSS_PORT_UART_AT "/dev/ttyS1" |
b.liu | e77ac3a | 2024-07-17 17:36:57 +0800 | [diff] [blame] | 33 | #define GNSS_CLI_IND_MAX 10 |
b.liu | 8f231a1 | 2024-05-31 17:55:06 +0800 | [diff] [blame] | 34 | |
| 35 | #ifdef GNSS_DEBUG |
| 36 | #define GNSS_NMEA_FILE_LOG "/tmp/mbtk_gnss_nmea.log" |
b.liu | 8f231a1 | 2024-05-31 17:55:06 +0800 | [diff] [blame] | 37 | #define GNSS_FILE_LOG "/tmp/mbtk_gnss.log" |
b.liu | 99c645d | 2024-06-20 10:52:15 +0800 | [diff] [blame] | 38 | #define GNSS_FILE_LOG_MAX 104857600 // 100MB |
b.liu | 8f231a1 | 2024-05-31 17:55:06 +0800 | [diff] [blame] | 39 | #endif |
| 40 | |
| 41 | gnss_info_t gnss_info; |
| 42 | |
b.liu | d0ba715 | 2024-06-19 14:47:21 +0800 | [diff] [blame] | 43 | #ifdef MBTK_GNSS_UBUS_ENABLE |
b.liu | 8f231a1 | 2024-05-31 17:55:06 +0800 | [diff] [blame] | 44 | struct ubus_context *gnss_ubus_init(void); |
b.liu | 5f950c5 | 2024-06-15 20:13:12 +0800 | [diff] [blame] | 45 | #else |
| 46 | int gnss_ipc_service_start(); |
| 47 | #endif |
| 48 | |
b.liu | 8f231a1 | 2024-05-31 17:55:06 +0800 | [diff] [blame] | 49 | int gnss_init_config(int fd); |
| 50 | |
wangyouqiang | fa897f8 | 2024-06-27 09:44:55 +0800 | [diff] [blame] | 51 | static char nmea_buff[GNSS_BUFF_SIZE*4] = {0}; |
| 52 | static char data_buff[GNSS_BUFF_SIZE*4] = {0}; |
b.liu | d0ba715 | 2024-06-19 14:47:21 +0800 | [diff] [blame] | 53 | static uint32 nmea_buff_len = 0; |
| 54 | static uint32 data_buff_len = 0; |
b.liu | e77ac3a | 2024-07-17 17:36:57 +0800 | [diff] [blame] | 55 | static gnss_ind_info_t ind_info[GNSS_CLI_IND_MAX]; |
b.liu | d0ba715 | 2024-06-19 14:47:21 +0800 | [diff] [blame] | 56 | |
b.liu | 8f231a1 | 2024-05-31 17:55:06 +0800 | [diff] [blame] | 57 | static bool nmea_found = FALSE; |
| 58 | #ifdef GNSS_DEBUG |
| 59 | static bool nmea_log_enable = FALSE; |
| 60 | static int nmea_log_fd = -1; |
b.liu | 99c645d | 2024-06-20 10:52:15 +0800 | [diff] [blame] | 61 | static int debug_fd = -1; |
| 62 | static int debug_fd_len = 0; |
b.liu | 8f231a1 | 2024-05-31 17:55:06 +0800 | [diff] [blame] | 63 | #endif |
| 64 | static int gnss_pty_master_fd = -1; |
| 65 | static int gnss_pty_slave_fd = -1; |
| 66 | static int gnss_usb_at_port_fd = -1; |
| 67 | static int gnss_usb_nmea_port_fd = -1; |
| 68 | static int gnss_uart_at_port_fd = -1; |
| 69 | static char *gnss_filter_info[] = {"RMC", "VTG", "GGA", "GSA", "GSV", "GLL", "ZDA", "GST", "TXT", "DHV", "DTM", NULL}; |
| 70 | |
b.liu | e77ac3a | 2024-07-17 17:36:57 +0800 | [diff] [blame] | 71 | int gnss_write(int fd, const void* buf, int buf_len); |
| 72 | |
b.liu | 8f231a1 | 2024-05-31 17:55:06 +0800 | [diff] [blame] | 73 | static void help() |
| 74 | { |
b.liu | 42f558e | 2024-07-18 14:06:49 +0800 | [diff] [blame^] | 75 | LOGD("mbtk_gnssd <6228/8122/5311/N50DB> <gnss_dev> <0/1>"); |
b.liu | 8f231a1 | 2024-05-31 17:55:06 +0800 | [diff] [blame] | 76 | } |
| 77 | |
| 78 | static int arg_check(int argc, char *argv[]) |
| 79 | { |
| 80 | if(argc != 4) { |
b.liu | 4ae4118 | 2024-06-28 16:30:15 +0800 | [diff] [blame] | 81 | LOGE("argc = %d", argc); |
b.liu | 8f231a1 | 2024-05-31 17:55:06 +0800 | [diff] [blame] | 82 | goto check_fail; |
| 83 | } |
| 84 | |
b.liu | 99c645d | 2024-06-20 10:52:15 +0800 | [diff] [blame] | 85 | // Only support 6228/8122/5311. |
b.liu | 42f558e | 2024-07-18 14:06:49 +0800 | [diff] [blame^] | 86 | if(strcmp(argv[1], GNSS_ID_6228) && strcmp(argv[1], GNSS_ID_8122) && strcmp(argv[1], GNSS_ID_5311) |
| 87 | && strcmp(argv[1], GNSS_ID_N50DB)) { |
b.liu | 4ae4118 | 2024-06-28 16:30:15 +0800 | [diff] [blame] | 88 | LOGE("argv[1] = %s", argv[1]); |
b.liu | 8f231a1 | 2024-05-31 17:55:06 +0800 | [diff] [blame] | 89 | goto check_fail; |
| 90 | } |
| 91 | |
| 92 | if(access(argv[2], R_OK | W_OK)) { |
b.liu | 4ae4118 | 2024-06-28 16:30:15 +0800 | [diff] [blame] | 93 | LOGE("access(%s) rw fail. ", argv[2]); |
b.liu | 8f231a1 | 2024-05-31 17:55:06 +0800 | [diff] [blame] | 94 | goto check_fail; |
| 95 | } |
| 96 | |
b.liu | ced8dd0 | 2024-06-28 13:28:29 +0800 | [diff] [blame] | 97 | #if 0 |
| 98 | int init_mode = atoi(argv[3]); |
| 99 | if(((GNSS_PRINT_PORT_UART1 | GNSS_PRINT_PORT_USB_NMEA | GNSS_PRINT_PORT_USB_AT | GNSS_PRINT_PORT_TTY_AT) & init_mode) != init_mode) { |
b.liu | 8f231a1 | 2024-05-31 17:55:06 +0800 | [diff] [blame] | 100 | goto check_fail; |
| 101 | } |
b.liu | ced8dd0 | 2024-06-28 13:28:29 +0800 | [diff] [blame] | 102 | #endif |
b.liu | 8f231a1 | 2024-05-31 17:55:06 +0800 | [diff] [blame] | 103 | |
| 104 | return 0; |
| 105 | check_fail: |
| 106 | help(); |
| 107 | return -1; |
| 108 | } |
| 109 | |
| 110 | static int gnss_ports_open(uint32 print_port) |
| 111 | { |
b.liu | ced8dd0 | 2024-06-28 13:28:29 +0800 | [diff] [blame] | 112 | // TTY AT change. |
| 113 | if((gnss_info.print_port & GNSS_PRINT_PORT_TTY_AT) != (print_port & GNSS_PRINT_PORT_TTY_AT)) { |
| 114 | if(print_port & GNSS_PRINT_PORT_TTY_AT) { // Open |
| 115 | if(gnss_pty_open(&gnss_pty_master_fd, &gnss_pty_slave_fd, GNSS_PORT_PTY)) { |
| 116 | return GNSS_ERR_OPEN_DEV; |
| 117 | } |
| 118 | LOGD("Open PTY port success."); |
| 119 | } else { // Close |
| 120 | if(gnss_pty_slave_fd > 0) { |
| 121 | close(gnss_pty_slave_fd); |
| 122 | gnss_pty_slave_fd = -1; |
| 123 | unlink(GNSS_PORT_PTY); |
| 124 | } |
| 125 | LOGD("Close PTY port success."); |
b.liu | 8f231a1 | 2024-05-31 17:55:06 +0800 | [diff] [blame] | 126 | } |
b.liu | 8f231a1 | 2024-05-31 17:55:06 +0800 | [diff] [blame] | 127 | } |
| 128 | |
b.liu | ced8dd0 | 2024-06-28 13:28:29 +0800 | [diff] [blame] | 129 | // USB AT change. |
| 130 | if((gnss_info.print_port & GNSS_PRINT_PORT_USB_AT) != (print_port & GNSS_PRINT_PORT_USB_AT)) { |
| 131 | if(print_port & GNSS_PRINT_PORT_USB_AT) { // Open |
b.liu | 978f543 | 2024-07-01 18:04:18 +0800 | [diff] [blame] | 132 | if((gnss_usb_at_port_fd = gnss_port_open(GNSS_PORT_USB_AT, O_RDWR | O_NONBLOCK | O_NOCTTY, 115200, TRUE)) <= 0) { |
b.liu | ced8dd0 | 2024-06-28 13:28:29 +0800 | [diff] [blame] | 133 | return GNSS_ERR_OPEN_DEV; |
| 134 | } |
| 135 | LOGD("Open USB AT port success."); |
| 136 | } else { // Close |
| 137 | if(gnss_usb_at_port_fd > 0) { |
| 138 | close(gnss_usb_at_port_fd); |
| 139 | gnss_usb_at_port_fd = -1; |
| 140 | } |
| 141 | LOGD("Close USB AT port success."); |
b.liu | 8f231a1 | 2024-05-31 17:55:06 +0800 | [diff] [blame] | 142 | } |
b.liu | 8f231a1 | 2024-05-31 17:55:06 +0800 | [diff] [blame] | 143 | } |
| 144 | |
b.liu | ced8dd0 | 2024-06-28 13:28:29 +0800 | [diff] [blame] | 145 | // USB NMEA change. |
| 146 | if((gnss_info.print_port & GNSS_PRINT_PORT_USB_NMEA) != (print_port & GNSS_PRINT_PORT_USB_NMEA)) { |
| 147 | if(print_port & GNSS_PRINT_PORT_USB_NMEA) { // Open |
b.liu | 978f543 | 2024-07-01 18:04:18 +0800 | [diff] [blame] | 148 | if((gnss_usb_nmea_port_fd = gnss_port_open(GNSS_PORT_USB_NMEA, O_RDWR | O_NONBLOCK | O_NOCTTY, 115200, TRUE)) <= 0) { |
b.liu | ced8dd0 | 2024-06-28 13:28:29 +0800 | [diff] [blame] | 149 | return GNSS_ERR_OPEN_DEV; |
| 150 | } |
| 151 | LOGD("Open USB NMEA port success."); |
| 152 | } else { // Close |
| 153 | if(gnss_usb_nmea_port_fd > 0) { |
| 154 | close(gnss_usb_nmea_port_fd); |
| 155 | gnss_usb_nmea_port_fd = -1; |
| 156 | } |
| 157 | LOGD("Close USB NMEA port success."); |
b.liu | 8f231a1 | 2024-05-31 17:55:06 +0800 | [diff] [blame] | 158 | } |
b.liu | 8f231a1 | 2024-05-31 17:55:06 +0800 | [diff] [blame] | 159 | } |
| 160 | |
b.liu | ced8dd0 | 2024-06-28 13:28:29 +0800 | [diff] [blame] | 161 | // Uart AT change. |
| 162 | if((gnss_info.print_port & GNSS_PRINT_PORT_UART1) != (print_port & GNSS_PRINT_PORT_UART1)) { |
| 163 | if(print_port & GNSS_PRINT_PORT_UART1) { // Open |
| 164 | if((gnss_uart_at_port_fd = gnss_port_open(GNSS_PORT_UART_AT, O_RDWR | O_NONBLOCK | O_NOCTTY, 115200, TRUE)) <= 0) { |
| 165 | return GNSS_ERR_OPEN_DEV; |
| 166 | } |
| 167 | LOGD("Open UART AT port success."); |
| 168 | } else { // Close |
| 169 | if(gnss_uart_at_port_fd > 0) { |
| 170 | close(gnss_uart_at_port_fd); |
| 171 | gnss_uart_at_port_fd = -1; |
| 172 | } |
| 173 | LOGD("Close UART AT port success."); |
b.liu | 8f231a1 | 2024-05-31 17:55:06 +0800 | [diff] [blame] | 174 | } |
b.liu | 8f231a1 | 2024-05-31 17:55:06 +0800 | [diff] [blame] | 175 | } |
| 176 | |
b.liu | ced8dd0 | 2024-06-28 13:28:29 +0800 | [diff] [blame] | 177 | gnss_info.print_port = print_port; |
| 178 | |
b.liu | dbc3f4b | 2024-06-25 18:22:24 +0800 | [diff] [blame] | 179 | return GNSS_ERR_OK; |
b.liu | 8f231a1 | 2024-05-31 17:55:06 +0800 | [diff] [blame] | 180 | } |
| 181 | |
| 182 | static int gnss_ports_close() |
| 183 | { |
| 184 | if(gnss_usb_at_port_fd > 0) { |
b.liu | 978f543 | 2024-07-01 18:04:18 +0800 | [diff] [blame] | 185 | tcflush(gnss_usb_at_port_fd, TCIOFLUSH); |
b.liu | 8f231a1 | 2024-05-31 17:55:06 +0800 | [diff] [blame] | 186 | close(gnss_usb_at_port_fd); |
| 187 | gnss_usb_at_port_fd = -1; |
| 188 | } |
| 189 | |
| 190 | if(gnss_usb_nmea_port_fd > 0) { |
b.liu | 978f543 | 2024-07-01 18:04:18 +0800 | [diff] [blame] | 191 | tcflush(gnss_usb_nmea_port_fd, TCIOFLUSH); |
b.liu | 8f231a1 | 2024-05-31 17:55:06 +0800 | [diff] [blame] | 192 | close(gnss_usb_nmea_port_fd); |
| 193 | gnss_usb_nmea_port_fd = -1; |
| 194 | } |
| 195 | |
| 196 | if(gnss_uart_at_port_fd > 0) { |
b.liu | 978f543 | 2024-07-01 18:04:18 +0800 | [diff] [blame] | 197 | tcflush(gnss_uart_at_port_fd, TCIOFLUSH); |
b.liu | 8f231a1 | 2024-05-31 17:55:06 +0800 | [diff] [blame] | 198 | close(gnss_uart_at_port_fd); |
| 199 | gnss_uart_at_port_fd = -1; |
| 200 | } |
| 201 | |
| 202 | if(gnss_pty_master_fd > 0) { |
b.liu | 978f543 | 2024-07-01 18:04:18 +0800 | [diff] [blame] | 203 | tcflush(gnss_pty_master_fd, TCIOFLUSH); |
b.liu | 8f231a1 | 2024-05-31 17:55:06 +0800 | [diff] [blame] | 204 | close(gnss_pty_master_fd); |
| 205 | gnss_pty_master_fd = -1; |
| 206 | } |
| 207 | |
| 208 | if(gnss_pty_slave_fd > 0) { |
b.liu | 978f543 | 2024-07-01 18:04:18 +0800 | [diff] [blame] | 209 | tcflush(gnss_pty_slave_fd, TCIOFLUSH); |
b.liu | 8f231a1 | 2024-05-31 17:55:06 +0800 | [diff] [blame] | 210 | close(gnss_pty_slave_fd); |
| 211 | gnss_pty_slave_fd = -1; |
| 212 | unlink(GNSS_PORT_PTY); |
| 213 | } |
| 214 | |
b.liu | ced8dd0 | 2024-06-28 13:28:29 +0800 | [diff] [blame] | 215 | gnss_info.print_port = 0; |
| 216 | |
b.liu | 8f231a1 | 2024-05-31 17:55:06 +0800 | [diff] [blame] | 217 | return 0; |
| 218 | } |
| 219 | |
b.liu | 8f231a1 | 2024-05-31 17:55:06 +0800 | [diff] [blame] | 220 | #ifdef GNSS_DEBUG |
b.liu | 99c645d | 2024-06-20 10:52:15 +0800 | [diff] [blame] | 221 | static void log_save(int fd, const char *data, int data_len) |
| 222 | { |
b.liu | 8f231a1 | 2024-05-31 17:55:06 +0800 | [diff] [blame] | 223 | if(nmea_log_enable){ |
b.liu | 99c645d | 2024-06-20 10:52:15 +0800 | [diff] [blame] | 224 | if(0 /* debug_fd_len > GNSS_FILE_LOG_MAX */) { |
| 225 | LOGD("Reopen file:%s(len = %d)", GNSS_FILE_LOG, debug_fd_len); |
| 226 | close(debug_fd); |
| 227 | debug_fd = open(GNSS_FILE_LOG, O_WRONLY | O_CREAT | O_TRUNC, 0666); |
| 228 | if(debug_fd < 0) { |
| 229 | LOGE("Open debug fd fail."); |
| 230 | } |
| 231 | debug_fd_len = 0; |
| 232 | |
| 233 | LOGD("Reopen file:%s", GNSS_NMEA_FILE_LOG); |
b.liu | 8f231a1 | 2024-05-31 17:55:06 +0800 | [diff] [blame] | 234 | close(nmea_log_fd); |
| 235 | nmea_log_fd = open(GNSS_NMEA_FILE_LOG, O_WRONLY | O_CREAT | O_TRUNC, 0666); |
| 236 | if(nmea_log_fd < 0) { |
| 237 | LOGE("Open debug fd fail."); |
| 238 | } |
b.liu | 8f231a1 | 2024-05-31 17:55:06 +0800 | [diff] [blame] | 239 | } |
| 240 | |
b.liu | 99c645d | 2024-06-20 10:52:15 +0800 | [diff] [blame] | 241 | if(fd == nmea_log_fd) { |
| 242 | if(nmea_log_fd > 0) { |
| 243 | write(nmea_log_fd, data, data_len); |
| 244 | debug_fd_len += data_len; |
| 245 | } |
| 246 | } else if(fd == debug_fd) { |
| 247 | if(debug_fd > 0) { |
| 248 | write(debug_fd, data, data_len); |
| 249 | debug_fd_len += data_len; |
| 250 | } |
b.liu | 8f231a1 | 2024-05-31 17:55:06 +0800 | [diff] [blame] | 251 | } |
| 252 | } |
b.liu | 99c645d | 2024-06-20 10:52:15 +0800 | [diff] [blame] | 253 | } |
b.liu | 8f231a1 | 2024-05-31 17:55:06 +0800 | [diff] [blame] | 254 | #endif |
| 255 | |
b.liu | e77ac3a | 2024-07-17 17:36:57 +0800 | [diff] [blame] | 256 | static void ind_location_print(const char *data) |
| 257 | { |
| 258 | int index = 0; |
| 259 | int buff_len = 0; |
| 260 | char buff[GNSS_BUFF_SIZE] = {0}; |
| 261 | buff[0] = MBTK_IND_START_FLAG; |
| 262 | buff_len++; |
| 263 | memcpy(buff + 1, MBTK_IND_LOCATION_TAG, strlen(MBTK_IND_LOCATION_TAG)); |
| 264 | buff_len += strlen(MBTK_IND_LOCATION_TAG); |
| 265 | memcpy(buff + strlen(buff), data, strlen(data)); |
| 266 | buff_len += strlen(data); |
| 267 | buff[strlen(buff)] = MBTK_IND_END_FLAG; |
| 268 | buff_len++; |
| 269 | |
| 270 | while(index < GNSS_CLI_IND_MAX) { |
| 271 | if(ind_info[index].cli_fd > 0 && (ind_info[index].ind_flag & MBTK_GNSS_IND_LOCATION)) { |
| 272 | gnss_write(ind_info[index].cli_fd, buff, buff_len); |
| 273 | } |
| 274 | index++; |
| 275 | } |
| 276 | } |
| 277 | |
| 278 | static void ind_nmea_print(const char *data) |
| 279 | { |
| 280 | int index = 0; |
| 281 | int buff_len = 0; |
| 282 | char buff[GNSS_BUFF_SIZE] = {0}; |
| 283 | buff[0] = MBTK_IND_START_FLAG; |
| 284 | buff_len++; |
| 285 | memcpy(buff + 1, MBTK_IND_NMEA_TAG, strlen(MBTK_IND_NMEA_TAG)); |
| 286 | buff_len += strlen(MBTK_IND_NMEA_TAG); |
| 287 | memcpy(buff + strlen(buff), data, strlen(data)); |
| 288 | buff_len += strlen(data); |
| 289 | buff[strlen(buff)] = MBTK_IND_END_FLAG; |
| 290 | buff_len++; |
| 291 | while(index < GNSS_CLI_IND_MAX) { |
| 292 | if(ind_info[index].cli_fd > 0 && (ind_info[index].ind_flag & MBTK_GNSS_IND_NMEA)) { |
| 293 | gnss_write(ind_info[index].cli_fd, buff, buff_len); |
| 294 | } |
| 295 | index++; |
| 296 | } |
| 297 | } |
| 298 | |
b.liu | 99c645d | 2024-06-20 10:52:15 +0800 | [diff] [blame] | 299 | static void nmea_print(const char *nmea, int nmea_len) |
| 300 | { |
b.liu | 8f231a1 | 2024-05-31 17:55:06 +0800 | [diff] [blame] | 301 | if(gnss_usb_at_port_fd > 0) { |
| 302 | write(gnss_usb_at_port_fd, nmea, nmea_len); |
| 303 | } |
| 304 | |
| 305 | if(gnss_usb_nmea_port_fd > 0) { |
| 306 | write(gnss_usb_nmea_port_fd, nmea, nmea_len); |
| 307 | } |
| 308 | |
| 309 | if(gnss_uart_at_port_fd > 0) { |
| 310 | write(gnss_uart_at_port_fd, nmea, nmea_len); |
| 311 | } |
| 312 | |
| 313 | if(gnss_pty_master_fd > 0) { |
| 314 | write(gnss_pty_master_fd, nmea, nmea_len); |
| 315 | } |
b.liu | e77ac3a | 2024-07-17 17:36:57 +0800 | [diff] [blame] | 316 | |
| 317 | ind_nmea_print(nmea); |
b.liu | 8f231a1 | 2024-05-31 17:55:06 +0800 | [diff] [blame] | 318 | } |
| 319 | |
| 320 | static unsigned char nmea_checksum(const char *nmea) |
| 321 | { |
| 322 | const char *p = nmea; |
| 323 | unsigned char chs = 0; |
| 324 | |
| 325 | while (*p == '$') // skip '$' |
| 326 | p++; |
| 327 | while (*p != '*' && *p != 0) |
| 328 | chs ^= *p++; |
| 329 | |
| 330 | return chs; |
| 331 | } |
| 332 | |
| 333 | static bool nmea_check(const char *nmea, int nmea_len) |
| 334 | { |
| 335 | char **ptr = gnss_filter_info; |
| 336 | while(*ptr) { |
| 337 | if(strstr(nmea, *ptr)) { |
| 338 | break; |
| 339 | } |
| 340 | ptr++; |
| 341 | } |
| 342 | |
| 343 | if(*ptr == NULL) { |
| 344 | LOGD("Unknown NMEA[%d]:%s", nmea_len, nmea); |
| 345 | return FALSE; |
| 346 | } |
| 347 | |
| 348 | char *checksum_str = strstr(nmea, "*"); |
| 349 | checksum_str++; // Jump '*' |
| 350 | char checksum_buf[3] = {0}; |
| 351 | snprintf(checksum_buf, 3, "%02x", nmea_checksum(nmea)); |
| 352 | if(strncasecmp(checksum_buf, checksum_str, 2)) { |
| 353 | LOGD("Checksum error[%d](checksum - %s):%s", nmea_len, checksum_buf, nmea); |
| 354 | return FALSE; |
| 355 | } |
| 356 | |
| 357 | return TRUE; |
| 358 | } |
| 359 | |
| 360 | static void gnss_nmea_process(const char *data, int data_len) |
| 361 | { |
b.liu | 99c645d | 2024-06-20 10:52:15 +0800 | [diff] [blame] | 362 | // LOGD("gnss_nmea_process() : data_len - %d", data_len); |
| 363 | #if 0 |
b.liu | 8f231a1 | 2024-05-31 17:55:06 +0800 | [diff] [blame] | 364 | char nmea[GNSS_BUFF_SIZE] = {0}; |
| 365 | memcpy(nmea, data, data_len); |
b.liu | 99c645d | 2024-06-20 10:52:15 +0800 | [diff] [blame] | 366 | #else |
| 367 | const char *nmea = data; |
| 368 | #endif |
b.liu | 8f231a1 | 2024-05-31 17:55:06 +0800 | [diff] [blame] | 369 | |
| 370 | if(!nmea_check(nmea, data_len)) { |
b.liu | 42f558e | 2024-07-18 14:06:49 +0800 | [diff] [blame^] | 371 | // No print "$HOSTSLEEP". |
| 372 | if(memcmp(nmea, "$HOSTSLEEP", strlen("$HOSTSLEEP"))) { |
| 373 | LOGD("NO-NMEA:%s", nmea); |
| 374 | } |
b.liu | 99c645d | 2024-06-20 10:52:15 +0800 | [diff] [blame] | 375 | #if GNSS_DEBUG |
| 376 | log_save(nmea_log_fd, "/**/", 4); |
| 377 | log_save(nmea_log_fd, nmea, data_len); |
| 378 | #endif |
| 379 | if(gnss_info.gnss_set_cb) |
| 380 | gnss_info.gnss_set_cb(nmea, data_len); |
b.liu | 8f231a1 | 2024-05-31 17:55:06 +0800 | [diff] [blame] | 381 | return; |
| 382 | } |
| 383 | |
| 384 | #ifdef GNSS_DEBUG |
| 385 | if(nmea_log_enable) { |
| 386 | LOGD("NMEA[%d]:%s", data_len, nmea); |
| 387 | } |
b.liu | 99c645d | 2024-06-20 10:52:15 +0800 | [diff] [blame] | 388 | |
| 389 | log_save(nmea_log_fd, nmea, data_len); |
b.liu | 8f231a1 | 2024-05-31 17:55:06 +0800 | [diff] [blame] | 390 | #endif |
| 391 | |
| 392 | nmea_print(nmea, data_len); |
| 393 | } |
| 394 | |
| 395 | #if 0 |
| 396 | static void gnss_cmd_rsp_process(const char *data, int data_len) |
| 397 | { |
| 398 | char rsp[GNSS_BUFF_SIZE] = {0}; |
| 399 | memcpy(rsp, data, data_len); |
| 400 | LOGD("RSP[%d]:%s", data_len, rsp); |
| 401 | } |
| 402 | #endif |
| 403 | |
| 404 | static bool nmea_char_check(char ch) |
| 405 | { |
| 406 | if(isalnum(ch) || ch == '$' || ch == '\r' || ch == '\n' || ch == '.' |
b.liu | 99c645d | 2024-06-20 10:52:15 +0800 | [diff] [blame] | 407 | || ch == ',' || ch == '*' || ch == '\0' || ch == '/' || ch == '_' || ch == '=') |
b.liu | 8f231a1 | 2024-05-31 17:55:06 +0800 | [diff] [blame] | 408 | return TRUE; |
| 409 | |
| 410 | return FALSE; |
| 411 | } |
| 412 | |
| 413 | static void gnss_data_process(const char *data, int data_len) |
| 414 | { |
| 415 | if(gnss_info.state == GNSS_STATE_OPEN) { |
| 416 | LOGD("GNSS_OPEN[%d]:%s", data_len, data); |
| 417 | } else if(gnss_info.state == GNSS_STATE_DOWNLOAD) { |
| 418 | // LOGD("GNSS_DL[%d]:%s", data_len, data); |
b.liu | 99c645d | 2024-06-20 10:52:15 +0800 | [diff] [blame] | 419 | if(gnss_info.gnss_dl_read_cb) { |
| 420 | gnss_info.gnss_dl_read_cb(data, data_len); |
| 421 | } |
b.liu | 8f231a1 | 2024-05-31 17:55:06 +0800 | [diff] [blame] | 422 | } else if(gnss_info.state == GNSS_STATE_READY) { |
| 423 | int index = 0; |
| 424 | while(index < data_len) { |
| 425 | if(nmea_found) { |
| 426 | if(!nmea_char_check(data[index])) { |
b.liu | d0ba715 | 2024-06-19 14:47:21 +0800 | [diff] [blame] | 427 | // Copy nmea_buff to data_buff |
| 428 | // Start with '$', but not nmea data, so copy to data_buff. |
| 429 | memcpy(data_buff + data_buff_len, nmea_buff, nmea_buff_len); |
| 430 | data_buff_len += nmea_buff_len; |
| 431 | data_buff[data_buff_len++] = data[index]; |
| 432 | |
| 433 | nmea_buff_len = 0; |
b.liu | 8f231a1 | 2024-05-31 17:55:06 +0800 | [diff] [blame] | 434 | nmea_found = FALSE; |
b.liu | 8f231a1 | 2024-05-31 17:55:06 +0800 | [diff] [blame] | 435 | continue; |
| 436 | } |
| 437 | |
| 438 | if(data[index] != '\0') { |
b.liu | d0ba715 | 2024-06-19 14:47:21 +0800 | [diff] [blame] | 439 | nmea_buff[nmea_buff_len++] = data[index]; |
| 440 | if(nmea_buff[nmea_buff_len - 1] == '\n') { |
| 441 | if(data_buff_len > 0) { |
b.liu | 99c645d | 2024-06-20 10:52:15 +0800 | [diff] [blame] | 442 | #if GNSS_DEBUG |
| 443 | log_save(nmea_log_fd, "/**/", 4); |
| 444 | log_save(nmea_log_fd, data_buff, data_buff_len); |
| 445 | #endif |
| 446 | if(gnss_info.gnss_set_cb) { |
| 447 | gnss_info.gnss_set_cb(data_buff, data_buff_len); |
| 448 | } |
b.liu | d0ba715 | 2024-06-19 14:47:21 +0800 | [diff] [blame] | 449 | data_buff_len = 0; |
b.liu | 8f231a1 | 2024-05-31 17:55:06 +0800 | [diff] [blame] | 450 | } |
| 451 | |
b.liu | d0ba715 | 2024-06-19 14:47:21 +0800 | [diff] [blame] | 452 | if(nmea_buff_len > 6 && nmea_buff[nmea_buff_len - 5] == '*') { // $XXX*YY\r\n |
b.liu | 99c645d | 2024-06-20 10:52:15 +0800 | [diff] [blame] | 453 | nmea_buff[nmea_buff_len] = '\0'; |
b.liu | d0ba715 | 2024-06-19 14:47:21 +0800 | [diff] [blame] | 454 | gnss_nmea_process(nmea_buff, nmea_buff_len); |
b.liu | 99c645d | 2024-06-20 10:52:15 +0800 | [diff] [blame] | 455 | } else if(nmea_buff_len > 0) { |
| 456 | nmea_buff[nmea_buff_len] = '\0'; |
b.liu | 42f558e | 2024-07-18 14:06:49 +0800 | [diff] [blame^] | 457 | if(memcmp(nmea_buff, "$HOSTSLEEP", strlen("$HOSTSLEEP"))) { |
| 458 | LOGD("NO-NMEA:%s", nmea_buff); |
| 459 | } |
b.liu | 99c645d | 2024-06-20 10:52:15 +0800 | [diff] [blame] | 460 | #if GNSS_DEBUG |
| 461 | log_save(nmea_log_fd, "/**/", 4); |
| 462 | log_save(nmea_log_fd, nmea_buff, nmea_buff_len); |
| 463 | #endif |
b.liu | d0ba715 | 2024-06-19 14:47:21 +0800 | [diff] [blame] | 464 | } |
| 465 | |
| 466 | nmea_buff_len = 0; |
b.liu | 8f231a1 | 2024-05-31 17:55:06 +0800 | [diff] [blame] | 467 | nmea_found = FALSE; |
| 468 | } |
| 469 | } |
| 470 | } else { |
| 471 | if(data[index] == '$') { |
b.liu | d0ba715 | 2024-06-19 14:47:21 +0800 | [diff] [blame] | 472 | nmea_buff_len = 0; |
b.liu | 8f231a1 | 2024-05-31 17:55:06 +0800 | [diff] [blame] | 473 | nmea_found = TRUE; |
b.liu | d0ba715 | 2024-06-19 14:47:21 +0800 | [diff] [blame] | 474 | nmea_buff[nmea_buff_len++] = data[index]; |
| 475 | } else { |
| 476 | data_buff[data_buff_len++] = data[index]; |
b.liu | 8f231a1 | 2024-05-31 17:55:06 +0800 | [diff] [blame] | 477 | } |
| 478 | } |
| 479 | index++; |
| 480 | } |
| 481 | } else { |
| 482 | LOGW("Unknown state : %d", gnss_info.state); |
| 483 | } |
| 484 | } |
| 485 | |
| 486 | void* gnss_read_pthread(void* arg) |
| 487 | { |
| 488 | LOGD("gnss_read_pthread enter."); |
| 489 | char buffer[GNSS_BUFF_SIZE]; |
| 490 | int len = 0; |
| 491 | int ret = 0; |
| 492 | fd_set fdr, fdw; |
| 493 | int fd_max = 0; |
| 494 | |
b.liu | 8f231a1 | 2024-05-31 17:55:06 +0800 | [diff] [blame] | 495 | fd_max = (gnss_info.fd > fd_max) ? gnss_info.fd : fd_max; |
b.liu | 8f231a1 | 2024-05-31 17:55:06 +0800 | [diff] [blame] | 496 | fd_max = (gnss_info.exit_fd[0] > fd_max) ? gnss_info.exit_fd[0] : fd_max; |
b.liu | d0ba715 | 2024-06-19 14:47:21 +0800 | [diff] [blame] | 497 | memset(nmea_buff, 0, sizeof(nmea_buff)); |
| 498 | memset(data_buff, 0, sizeof(data_buff)); |
| 499 | nmea_buff_len = 0; |
| 500 | data_buff_len = 0; |
b.liu | 8f231a1 | 2024-05-31 17:55:06 +0800 | [diff] [blame] | 501 | #if GNSS_DEBUG |
b.liu | 8f231a1 | 2024-05-31 17:55:06 +0800 | [diff] [blame] | 502 | if(nmea_log_enable) { |
| 503 | debug_fd = open(GNSS_FILE_LOG, O_WRONLY | O_CREAT | O_TRUNC, 0666); |
| 504 | if(debug_fd < 0) { |
| 505 | LOGE("Open debug fd fail."); |
| 506 | } |
| 507 | nmea_log_fd = open(GNSS_NMEA_FILE_LOG, O_WRONLY | O_CREAT | O_TRUNC, 0666); |
| 508 | if(nmea_log_fd < 0) { |
| 509 | LOGE("Open nmea fd fail."); |
| 510 | } |
b.liu | 99c645d | 2024-06-20 10:52:15 +0800 | [diff] [blame] | 511 | debug_fd_len = 0; |
b.liu | 8f231a1 | 2024-05-31 17:55:06 +0800 | [diff] [blame] | 512 | } |
| 513 | #endif |
| 514 | |
b.liu | dbc3f4b | 2024-06-25 18:22:24 +0800 | [diff] [blame] | 515 | LOGD("uart_fd - %d, exit_fd - %d", gnss_info.fd, gnss_info.exit_fd[0]); |
| 516 | |
b.liu | 8f231a1 | 2024-05-31 17:55:06 +0800 | [diff] [blame] | 517 | while(gnss_info.state >= GNSS_STATE_OPEN) { |
wangyouqiang | 55d36bf | 2024-06-27 09:35:52 +0800 | [diff] [blame] | 518 | FD_ZERO(&fdw); |
| 519 | FD_ZERO(&fdr); |
| 520 | FD_SET(gnss_info.fd, &fdr); |
| 521 | FD_SET(gnss_info.exit_fd[0], &fdr); |
b.liu | 8f231a1 | 2024-05-31 17:55:06 +0800 | [diff] [blame] | 522 | ret = select(fd_max + 1, &fdr, &fdw, 0, NULL); |
| 523 | //LOGD("select - %d", ret); |
b.liu | ece0db0 | 2024-06-25 18:39:09 +0800 | [diff] [blame] | 524 | if(gnss_info.state < GNSS_STATE_OPEN) { |
| 525 | LOGD("State = %d, ret = %d", gnss_info.state, ret); |
| 526 | if(ret > 0) { |
| 527 | if (FD_ISSET(gnss_info.fd, &fdr)) { |
| 528 | LOGD("gnss_fd can read."); |
| 529 | } else if (FD_ISSET(gnss_info.exit_fd[0], &fdr)) { |
| 530 | LOGD("exit_fd can read."); |
| 531 | } else { |
| 532 | LOGW("Unknown select event."); |
| 533 | } |
| 534 | } |
| 535 | break; |
| 536 | } |
| 537 | |
b.liu | 8f231a1 | 2024-05-31 17:55:06 +0800 | [diff] [blame] | 538 | if (ret < 0) |
| 539 | { |
| 540 | if (errno == EINTR) |
| 541 | { |
| 542 | continue; |
| 543 | } |
| 544 | LOGE("select error, errno = %d (%s)", errno, strerror(errno)); |
| 545 | break; |
| 546 | } |
| 547 | else if (ret == 0) |
| 548 | { |
| 549 | LOGE("select ret == 0"); |
| 550 | break; |
| 551 | } |
| 552 | |
| 553 | if (FD_ISSET(gnss_info.fd, &fdr)) |
| 554 | { |
| 555 | memset(buffer, 0, GNSS_BUFF_SIZE); |
b.liu | 99c645d | 2024-06-20 10:52:15 +0800 | [diff] [blame] | 556 | len = read(gnss_info.fd, buffer, GNSS_BUFF_SIZE - 1); |
b.liu | 8f231a1 | 2024-05-31 17:55:06 +0800 | [diff] [blame] | 557 | if(len > 0) { |
| 558 | //log_hex("READ", buffer, len); |
| 559 | |
| 560 | #if GNSS_DEBUG |
b.liu | 99c645d | 2024-06-20 10:52:15 +0800 | [diff] [blame] | 561 | //LOGD("read data_len = %d", len); |
| 562 | log_save(debug_fd, buffer, len); |
b.liu | 8f231a1 | 2024-05-31 17:55:06 +0800 | [diff] [blame] | 563 | #endif |
| 564 | |
| 565 | gnss_data_process(buffer, len); |
| 566 | |
| 567 | } else if(len ==0 ){ |
| 568 | LOGE("Read end : len = 0"); |
| 569 | break; |
| 570 | } else { |
| 571 | if(EAGAIN == errno) { |
| 572 | usleep(50000); |
| 573 | continue; |
| 574 | } else { |
| 575 | LOGD("Read ret = -1 ,errno = %d", errno); |
| 576 | break; |
| 577 | } |
| 578 | } |
| 579 | } |
| 580 | else if (FD_ISSET(gnss_info.exit_fd[0], &fdr)) |
| 581 | { |
b.liu | ece0db0 | 2024-06-25 18:39:09 +0800 | [diff] [blame] | 582 | LOGD("exit_fd select event."); |
b.liu | 8f231a1 | 2024-05-31 17:55:06 +0800 | [diff] [blame] | 583 | memset(buffer, 0, GNSS_BUFF_SIZE); |
b.liu | dbc3f4b | 2024-06-25 18:22:24 +0800 | [diff] [blame] | 584 | len = read(gnss_info.exit_fd[0], buffer, GNSS_BUFF_SIZE); |
b.liu | 8f231a1 | 2024-05-31 17:55:06 +0800 | [diff] [blame] | 585 | if(len > 0) { |
| 586 | if(strcmp(buffer, "exit") == 0) { |
| 587 | LOGD("Get thread exit message."); |
| 588 | break; |
| 589 | } |
| 590 | } |
| 591 | } |
| 592 | else |
| 593 | { |
| 594 | LOGW("Unknown select event."); |
| 595 | continue; |
| 596 | } |
| 597 | } |
| 598 | |
| 599 | #if GNSS_DEBUG |
| 600 | if(debug_fd > 0) { |
| 601 | close(debug_fd); |
| 602 | debug_fd = -1; |
| 603 | } |
| 604 | if(nmea_log_fd > 0) { |
| 605 | close(nmea_log_fd); |
| 606 | nmea_log_fd = -1; |
| 607 | } |
| 608 | #endif |
| 609 | |
| 610 | gnss_info.state = GNSS_STATE_CLOSE; |
| 611 | LOGD("gnss_read_pthread exit."); |
| 612 | return NULL; |
| 613 | } |
| 614 | |
| 615 | #if 0 |
| 616 | int gnss_write(int fd, const void *data, int data_len) |
| 617 | { |
| 618 | int count = 0; |
| 619 | int len = 0; |
| 620 | while(1) |
| 621 | { |
| 622 | len = write(fd, data + count, data_len - count); |
| 623 | if (len > 0) |
| 624 | { |
| 625 | count += len; |
| 626 | } |
| 627 | else |
| 628 | { |
| 629 | LOGE("write() fail,ret = %d,errno = %d", len, errno); |
| 630 | break; |
| 631 | } |
| 632 | |
| 633 | if (count == data_len) |
| 634 | break; |
| 635 | } |
| 636 | |
| 637 | return count; |
| 638 | } |
| 639 | #else |
b.liu | 778645e | 2024-06-21 16:47:42 +0800 | [diff] [blame] | 640 | int gnss_write(int fd, const void* buf, int buf_len) |
b.liu | 8f231a1 | 2024-05-31 17:55:06 +0800 | [diff] [blame] | 641 | { |
b.liu | 778645e | 2024-06-21 16:47:42 +0800 | [diff] [blame] | 642 | ssize_t size; |
| 643 | ssize_t size_to_wr; |
b.liu | 8f231a1 | 2024-05-31 17:55:06 +0800 | [diff] [blame] | 644 | ssize_t size_written; |
| 645 | if(GNSS_BUFF_SIZE < buf_len) |
| 646 | { |
| 647 | return -1; |
| 648 | } |
| 649 | for(size = 0; size < buf_len;) |
| 650 | { |
| 651 | size_to_wr = buf_len - size; |
| 652 | if( size_to_wr > GNSS_BUFF_SIZE) |
| 653 | size_to_wr = GNSS_BUFF_SIZE; |
| 654 | |
b.liu | 778645e | 2024-06-21 16:47:42 +0800 | [diff] [blame] | 655 | size_written = write(fd, (const uint8*)buf + size, size_to_wr); |
b.liu | 8f231a1 | 2024-05-31 17:55:06 +0800 | [diff] [blame] | 656 | if (size_written==-1) |
| 657 | { |
| 658 | return -1; |
| 659 | } |
| 660 | size += size_written; |
| 661 | if(size_written != size_to_wr) |
| 662 | { |
| 663 | return size; |
| 664 | } |
| 665 | } |
| 666 | // LOGD("SEND %d / %d", size, buf_len); |
| 667 | return size; |
| 668 | } |
| 669 | #endif |
| 670 | |
| 671 | int gnss_init(uint32 print_port) |
| 672 | { |
| 673 | if(gnss_info.state != GNSS_STATE_CLOSE) { |
| 674 | LOGW("GNSS not close:%d", gnss_info.state); |
b.liu | ced8dd0 | 2024-06-28 13:28:29 +0800 | [diff] [blame] | 675 | if(gnss_info.state == GNSS_STATE_READY) { |
| 676 | LOGD("Reset print port : %d -> %d", gnss_info.print_port, print_port); |
| 677 | if(gnss_info.print_port != print_port) { |
| 678 | return gnss_ports_open(print_port); |
| 679 | } else { |
| 680 | return GNSS_ERR_OK; |
| 681 | } |
| 682 | } else { |
| 683 | return GNSS_ERR_OK; |
| 684 | } |
b.liu | 8f231a1 | 2024-05-31 17:55:06 +0800 | [diff] [blame] | 685 | } |
| 686 | |
| 687 | int ret = 0; |
b.liu | 99c645d | 2024-06-20 10:52:15 +0800 | [diff] [blame] | 688 | if(gnss_info.dl_befor_open) { |
| 689 | //if(gnss_info.auto_dl_fw) { |
| 690 | gnss_info.state = GNSS_STATE_DOWNLOAD; |
b.liu | dbc3f4b | 2024-06-25 18:22:24 +0800 | [diff] [blame] | 691 | ret = gnss_info.gnss_fw_dl(gnss_info.fd, NULL, gnss_info.dev_name); |
b.liu | 99c645d | 2024-06-20 10:52:15 +0800 | [diff] [blame] | 692 | if(ret) { |
| 693 | LOGE("gnss_fw_dl() fail : %d", ret); |
| 694 | gnss_info.state = GNSS_STATE_CLOSE; |
b.liu | dbc3f4b | 2024-06-25 18:22:24 +0800 | [diff] [blame] | 695 | return GNSS_ERR_DL_FW; |
b.liu | 99c645d | 2024-06-20 10:52:15 +0800 | [diff] [blame] | 696 | } |
b.liu | 8f231a1 | 2024-05-31 17:55:06 +0800 | [diff] [blame] | 697 | |
b.liu | 99c645d | 2024-06-20 10:52:15 +0800 | [diff] [blame] | 698 | gnss_info.fd = gnss_info.gnss_open(gnss_info.dev_name); |
| 699 | if(gnss_info.fd <= 0) { |
| 700 | LOGE("gnss_open(%s) fail : %d", gnss_info.dev_name, gnss_info.fd); |
| 701 | gnss_info.state = GNSS_STATE_CLOSE; |
b.liu | dbc3f4b | 2024-06-25 18:22:24 +0800 | [diff] [blame] | 702 | return GNSS_ERR_OPEN_DEV; |
b.liu | 99c645d | 2024-06-20 10:52:15 +0800 | [diff] [blame] | 703 | } |
| 704 | if(pipe(gnss_info.exit_fd)) { |
| 705 | LOGE("pipe() fail[%d].", errno); |
b.liu | dbc3f4b | 2024-06-25 18:22:24 +0800 | [diff] [blame] | 706 | return GNSS_ERR_UNKNOWN; |
b.liu | 99c645d | 2024-06-20 10:52:15 +0800 | [diff] [blame] | 707 | } |
| 708 | // GNSS is opened. |
| 709 | gnss_info.state = GNSS_STATE_OPEN; |
b.liu | 8f231a1 | 2024-05-31 17:55:06 +0800 | [diff] [blame] | 710 | |
b.liu | 99c645d | 2024-06-20 10:52:15 +0800 | [diff] [blame] | 711 | #if 0 |
| 712 | // Start gnss read thread. |
| 713 | pthread_attr_t thread_attr; |
| 714 | pthread_attr_init(&thread_attr); |
| 715 | if(pthread_attr_setdetachstate(&thread_attr, PTHREAD_CREATE_DETACHED)) |
| 716 | { |
| 717 | LOGE("pthread_attr_setdetachstate() fail."); |
| 718 | goto main_exit; |
| 719 | } |
b.liu | 8f231a1 | 2024-05-31 17:55:06 +0800 | [diff] [blame] | 720 | |
b.liu | 99c645d | 2024-06-20 10:52:15 +0800 | [diff] [blame] | 721 | if(pthread_create(&gnss_info.read_pid, &thread_attr, gnss_read_pthread, NULL)) |
b.liu | 8f231a1 | 2024-05-31 17:55:06 +0800 | [diff] [blame] | 722 | #else |
b.liu | 99c645d | 2024-06-20 10:52:15 +0800 | [diff] [blame] | 723 | if(pthread_create(&gnss_info.read_pid, NULL, gnss_read_pthread, NULL)) |
b.liu | 8f231a1 | 2024-05-31 17:55:06 +0800 | [diff] [blame] | 724 | #endif |
b.liu | 99c645d | 2024-06-20 10:52:15 +0800 | [diff] [blame] | 725 | { |
| 726 | LOGE("pthread_create() fail."); |
| 727 | goto exit_with_close; |
| 728 | } |
b.liu | 8f231a1 | 2024-05-31 17:55:06 +0800 | [diff] [blame] | 729 | |
b.liu | 99c645d | 2024-06-20 10:52:15 +0800 | [diff] [blame] | 730 | ret = gnss_info.gnss_dev_open(); |
| 731 | if(ret) { |
| 732 | LOGE("gnss_dev_open() fail : %d", ret); |
| 733 | goto exit_with_thread_exit; |
| 734 | } |
| 735 | //} |
| 736 | } else { |
| 737 | gnss_info.fd = gnss_info.gnss_open(gnss_info.dev_name); |
| 738 | if(gnss_info.fd <= 0) { |
| 739 | LOGE("gnss_open(%s) fail : %d", gnss_info.dev_name, gnss_info.fd); |
| 740 | gnss_info.state = GNSS_STATE_CLOSE; |
b.liu | dbc3f4b | 2024-06-25 18:22:24 +0800 | [diff] [blame] | 741 | return GNSS_ERR_OPEN_DEV; |
b.liu | 99c645d | 2024-06-20 10:52:15 +0800 | [diff] [blame] | 742 | } |
| 743 | if(pipe(gnss_info.exit_fd)) { |
| 744 | LOGE("pipe() fail[%d].", errno); |
b.liu | dbc3f4b | 2024-06-25 18:22:24 +0800 | [diff] [blame] | 745 | return GNSS_ERR_UNKNOWN; |
b.liu | 99c645d | 2024-06-20 10:52:15 +0800 | [diff] [blame] | 746 | } |
| 747 | // GNSS is opened. |
| 748 | gnss_info.state = GNSS_STATE_OPEN; |
b.liu | 8f231a1 | 2024-05-31 17:55:06 +0800 | [diff] [blame] | 749 | |
b.liu | 99c645d | 2024-06-20 10:52:15 +0800 | [diff] [blame] | 750 | #if 0 |
| 751 | // Start gnss read thread. |
| 752 | pthread_attr_t thread_attr; |
| 753 | pthread_attr_init(&thread_attr); |
| 754 | if(pthread_attr_setdetachstate(&thread_attr, PTHREAD_CREATE_DETACHED)) |
| 755 | { |
| 756 | LOGE("pthread_attr_setdetachstate() fail."); |
| 757 | goto main_exit; |
| 758 | } |
| 759 | |
| 760 | if(pthread_create(&gnss_info.read_pid, &thread_attr, gnss_read_pthread, NULL)) |
| 761 | #else |
| 762 | if(pthread_create(&gnss_info.read_pid, NULL, gnss_read_pthread, NULL)) |
| 763 | #endif |
| 764 | { |
| 765 | LOGE("pthread_create() fail."); |
| 766 | goto exit_with_close; |
| 767 | } |
| 768 | |
| 769 | ret = gnss_info.gnss_dev_open(); |
b.liu | 8f231a1 | 2024-05-31 17:55:06 +0800 | [diff] [blame] | 770 | if(ret) { |
b.liu | 99c645d | 2024-06-20 10:52:15 +0800 | [diff] [blame] | 771 | LOGE("gnss_dev_open() fail : %d", ret); |
| 772 | goto exit_with_thread_exit; |
| 773 | } |
b.liu | 8f231a1 | 2024-05-31 17:55:06 +0800 | [diff] [blame] | 774 | } |
| 775 | |
| 776 | // GNSS is ready, NMEA can print from uart. |
| 777 | gnss_info.state = GNSS_STATE_READY; |
b.liu | 8f231a1 | 2024-05-31 17:55:06 +0800 | [diff] [blame] | 778 | |
| 779 | LOGD("GNSS open success."); |
| 780 | |
b.liu | ced8dd0 | 2024-06-28 13:28:29 +0800 | [diff] [blame] | 781 | return gnss_ports_open(print_port); |
b.liu | 8f231a1 | 2024-05-31 17:55:06 +0800 | [diff] [blame] | 782 | |
b.liu | 8f231a1 | 2024-05-31 17:55:06 +0800 | [diff] [blame] | 783 | exit_with_thread_exit: |
| 784 | gnss_info.state = GNSS_STATE_CLOSING; |
| 785 | // Wait for read thread exit. |
| 786 | ret = pthread_join(gnss_info.read_pid, NULL); |
| 787 | if(ret){ |
| 788 | LOGE("pthrad_join fail(%d)",ret); |
| 789 | } |
| 790 | exit_with_close: |
| 791 | if(gnss_info.gnss_close(gnss_info.fd)) { |
| 792 | LOGE("gnss_close() fail."); |
| 793 | } |
| 794 | if(gnss_info.exit_fd[0] > 0) { |
| 795 | close(gnss_info.exit_fd[0]); |
| 796 | gnss_info.exit_fd[0] = -1; |
| 797 | } |
| 798 | if(gnss_info.exit_fd[1] > 0) { |
| 799 | close(gnss_info.exit_fd[1]); |
| 800 | gnss_info.exit_fd[1] = -1; |
| 801 | } |
| 802 | gnss_info.state = GNSS_STATE_CLOSE; |
b.liu | dbc3f4b | 2024-06-25 18:22:24 +0800 | [diff] [blame] | 803 | return GNSS_ERR_UNKNOWN; |
b.liu | 8f231a1 | 2024-05-31 17:55:06 +0800 | [diff] [blame] | 804 | } |
| 805 | |
| 806 | int gnss_deinit() |
| 807 | { |
| 808 | if(gnss_info.state == GNSS_STATE_CLOSE) { |
| 809 | LOGW("GNSS is closed."); |
b.liu | dbc3f4b | 2024-06-25 18:22:24 +0800 | [diff] [blame] | 810 | return GNSS_ERR_OK; |
b.liu | 8f231a1 | 2024-05-31 17:55:06 +0800 | [diff] [blame] | 811 | } else if(gnss_info.state == GNSS_STATE_CLOSING) { |
| 812 | LOGW("GNSS is closing..."); |
b.liu | dbc3f4b | 2024-06-25 18:22:24 +0800 | [diff] [blame] | 813 | return GNSS_ERR_UNKNOWN; |
b.liu | 8f231a1 | 2024-05-31 17:55:06 +0800 | [diff] [blame] | 814 | } else if(gnss_info.state == GNSS_STATE_DOWNLOAD) { |
| 815 | LOGW("GNSS is downloading..."); |
b.liu | dbc3f4b | 2024-06-25 18:22:24 +0800 | [diff] [blame] | 816 | return GNSS_ERR_UNKNOWN; |
b.liu | 8f231a1 | 2024-05-31 17:55:06 +0800 | [diff] [blame] | 817 | } |
| 818 | |
b.liu | 978f543 | 2024-07-01 18:04:18 +0800 | [diff] [blame] | 819 | if(gnss_info.gnss_dev_close(gnss_info.fd)) { |
| 820 | LOGE("gnss_dev_close() fail."); |
| 821 | return GNSS_ERR_UNKNOWN; |
| 822 | } |
| 823 | |
b.liu | 8f231a1 | 2024-05-31 17:55:06 +0800 | [diff] [blame] | 824 | // Wait for read thread exit. |
| 825 | if(gnss_info.exit_fd[1] > 0) { |
| 826 | write(gnss_info.exit_fd[1], "exit", 4); |
| 827 | } |
| 828 | |
| 829 | gnss_info.state = GNSS_STATE_CLOSING; |
| 830 | int ret = pthread_join(gnss_info.read_pid, NULL); |
| 831 | if(ret){ |
| 832 | LOGE("pthrad_join fail(%d)",ret); |
b.liu | dbc3f4b | 2024-06-25 18:22:24 +0800 | [diff] [blame] | 833 | return GNSS_ERR_UNKNOWN; |
b.liu | 8f231a1 | 2024-05-31 17:55:06 +0800 | [diff] [blame] | 834 | } |
| 835 | |
| 836 | if(gnss_info.gnss_close(gnss_info.fd)) { |
| 837 | LOGE("gnss_close() fail."); |
b.liu | dbc3f4b | 2024-06-25 18:22:24 +0800 | [diff] [blame] | 838 | return GNSS_ERR_UNKNOWN; |
b.liu | 8f231a1 | 2024-05-31 17:55:06 +0800 | [diff] [blame] | 839 | } |
| 840 | |
b.liu | 8f231a1 | 2024-05-31 17:55:06 +0800 | [diff] [blame] | 841 | if(gnss_ports_close()) { |
| 842 | LOGE("gnss_ports_close fail."); |
b.liu | dbc3f4b | 2024-06-25 18:22:24 +0800 | [diff] [blame] | 843 | return GNSS_ERR_UNKNOWN; |
b.liu | 8f231a1 | 2024-05-31 17:55:06 +0800 | [diff] [blame] | 844 | } |
| 845 | |
b.liu | d0ba715 | 2024-06-19 14:47:21 +0800 | [diff] [blame] | 846 | LOGD("gnss_ports_close() complete."); |
| 847 | |
b.liu | 8f231a1 | 2024-05-31 17:55:06 +0800 | [diff] [blame] | 848 | gnss_info.fd = -1; |
| 849 | if(gnss_info.exit_fd[0] > 0) { |
| 850 | close(gnss_info.exit_fd[0]); |
| 851 | gnss_info.exit_fd[0] = -1; |
| 852 | } |
| 853 | if(gnss_info.exit_fd[1] > 0) { |
| 854 | close(gnss_info.exit_fd[1]); |
| 855 | gnss_info.exit_fd[1] = -1; |
| 856 | } |
| 857 | gnss_info.state = GNSS_STATE_CLOSE; |
| 858 | LOGD("GNSS close success."); |
b.liu | dbc3f4b | 2024-06-25 18:22:24 +0800 | [diff] [blame] | 859 | return GNSS_ERR_OK; |
b.liu | 8f231a1 | 2024-05-31 17:55:06 +0800 | [diff] [blame] | 860 | } |
| 861 | |
| 862 | int gnss_set(const void* buf, unsigned int buf_len, void *cmd_rsp, int cmd_rsp_len) |
| 863 | { |
b.liu | d0ba715 | 2024-06-19 14:47:21 +0800 | [diff] [blame] | 864 | if(buf && buf_len > 0) { |
| 865 | if(cmd_rsp && cmd_rsp_len > 0) { |
| 866 | memset(cmd_rsp, 0, cmd_rsp_len); |
| 867 | } |
b.liu | 8f231a1 | 2024-05-31 17:55:06 +0800 | [diff] [blame] | 868 | return gnss_info.gnss_set(gnss_info.fd, buf, cmd_rsp, cmd_rsp_len); |
| 869 | } else { |
b.liu | dbc3f4b | 2024-06-25 18:22:24 +0800 | [diff] [blame] | 870 | return GNSS_ERR_UNKNOWN; |
| 871 | } |
| 872 | } |
| 873 | |
| 874 | int gnss_dl_fw(const char* fw_name, void *rsp, int rsp_len) |
| 875 | { |
b.liu | 42f558e | 2024-07-18 14:06:49 +0800 | [diff] [blame^] | 876 | // Only 8122 support download fw. |
b.liu | dbc3f4b | 2024-06-25 18:22:24 +0800 | [diff] [blame] | 877 | if(gnss_info.gnss_id != GNSS_TYPE_8122) { |
| 878 | return GNSS_ERR_UNSUPPORT; |
| 879 | } |
| 880 | |
| 881 | if(rsp && rsp_len > 0) { |
| 882 | memset(rsp, 0, rsp_len); |
| 883 | } |
| 884 | |
| 885 | if(gnss_info.gnss_fw_dl) { |
| 886 | if(GNSS_ERR_OK != gnss_deinit()) { |
| 887 | LOGE("Close gnss fail."); |
| 888 | return GNSS_ERR_UNKNOWN; |
| 889 | } else { |
| 890 | LOGD("Start gnss fw dl."); |
| 891 | return gnss_info.gnss_fw_dl(gnss_info.fd, fw_name, gnss_info.dev_name); |
| 892 | } |
| 893 | } else { |
b.liu | 42f558e | 2024-07-18 14:06:49 +0800 | [diff] [blame^] | 894 | return GNSS_ERR_UNSUPPORT; |
b.liu | 8f231a1 | 2024-05-31 17:55:06 +0800 | [diff] [blame] | 895 | } |
| 896 | } |
| 897 | |
b.liu | e77ac3a | 2024-07-17 17:36:57 +0800 | [diff] [blame] | 898 | int gnss_ind_set(int fd, int ind_type) |
| 899 | { |
| 900 | int index = 0; |
| 901 | if(ind_type) { // Add IND flag. |
| 902 | while(index < GNSS_CLI_IND_MAX) { |
| 903 | if(ind_info[index].cli_fd == fd) |
| 904 | break; |
| 905 | index++; |
| 906 | } |
| 907 | |
| 908 | if(index == GNSS_CLI_IND_MAX) { // Add flag |
| 909 | index = 0; |
| 910 | while(index < GNSS_CLI_IND_MAX) { |
| 911 | if(ind_info[index].cli_fd <= 0) |
| 912 | break; |
| 913 | index++; |
| 914 | } |
| 915 | ind_info[index].cli_fd = fd; |
| 916 | ind_info[index].ind_flag = (uint32)ind_type; |
| 917 | } else { // Change flag |
| 918 | ind_info[index].cli_fd = fd; |
| 919 | ind_info[index].ind_flag = (uint32)ind_type; |
| 920 | } |
| 921 | } else { // Clear IND flag. |
| 922 | while(index < GNSS_CLI_IND_MAX) { |
| 923 | if(ind_info[index].cli_fd == fd) |
| 924 | break; |
| 925 | index++; |
| 926 | } |
| 927 | |
| 928 | if(index == GNSS_CLI_IND_MAX) { |
| 929 | return GNSS_ERR_ARG; |
| 930 | } |
| 931 | |
| 932 | ind_info[index].cli_fd = 0; |
| 933 | ind_info[index].ind_flag = 0; |
| 934 | } |
| 935 | |
| 936 | return GNSS_ERR_OK; |
| 937 | } |
| 938 | |
b.liu | 8f231a1 | 2024-05-31 17:55:06 +0800 | [diff] [blame] | 939 | static void sig_process(int sig) |
| 940 | { |
| 941 | LOGI("I got signal %d\n", sig); |
| 942 | if(gnss_deinit()) { |
| 943 | LOGE("gnss_deinit() fail, no exist..."); |
| 944 | return; |
| 945 | } |
| 946 | |
| 947 | switch(sig) |
| 948 | { |
| 949 | case SIGINT: // Ctrl + C |
| 950 | { |
| 951 | LOGI("Exit by SIGINT.\n"); |
| 952 | exit(0); |
| 953 | } |
| 954 | case SIGQUIT: // Ctrl + \ (ÀàËÆ SIGINT £¬µ«Òª²úÉúcoreÎļþ) |
| 955 | { |
| 956 | LOGI("Exit by SIGQUIT.\n"); |
| 957 | exit(0); |
| 958 | } |
| 959 | case SIGTERM:// ĬÈÏkill (ͬ SIGKILL £¬µ« SIGKILL ²»¿É²¶»ñ) |
| 960 | { |
| 961 | LOGI("Exit by SIGTERM.\n"); |
| 962 | exit(0); |
| 963 | } |
| 964 | case SIGTSTP:// Ctrl + Z (ͬ SIGSTOP £¬µ« SIGSTOP ²»¿É²¶»ñ) |
| 965 | { |
| 966 | LOGI("Exit by SIGTSTP.\n"); |
| 967 | exit(0); |
| 968 | } |
| 969 | case SIGSEGV: // Èç¿ÕÖ¸Õë |
| 970 | { |
| 971 | LOGI("Exit by SIGSEGV.\n"); |
| 972 | exit(0); |
| 973 | } |
| 974 | default: |
| 975 | { |
| 976 | LOGI("Unknown sig:%d\n",sig); |
| 977 | break; |
| 978 | } |
| 979 | } |
| 980 | } |
| 981 | |
| 982 | |
b.liu | ced8dd0 | 2024-06-28 13:28:29 +0800 | [diff] [blame] | 983 | // mbtk_gnssd 6228 /dev/ttyS2 baud 0/1 <port_type> |
b.liu | 8f231a1 | 2024-05-31 17:55:06 +0800 | [diff] [blame] | 984 | int main(int argc, char *argv[]) |
| 985 | { |
| 986 | mbtk_log_init("radio", GNSS_TAG); |
| 987 | |
b.liu | bb59049 | 2024-06-13 16:42:08 +0800 | [diff] [blame] | 988 | #ifdef MBTK_DUMP_SUPPORT |
| 989 | mbtk_debug_open(NULL, TRUE); |
| 990 | #endif |
| 991 | |
b.liu | 8f231a1 | 2024-05-31 17:55:06 +0800 | [diff] [blame] | 992 | signal(SIGINT, sig_process); |
| 993 | signal(SIGQUIT, sig_process); |
| 994 | signal(SIGTERM, sig_process); |
| 995 | |
| 996 | if(arg_check(argc, argv)) { |
| 997 | return -1; |
| 998 | } |
| 999 | |
| 1000 | #ifdef GNSS_DEBUG |
| 1001 | char buff[10]; |
| 1002 | memset(buff, 0, 10); |
| 1003 | property_get(MBTK_PROP_GNSS_LOG, buff, ""); |
| 1004 | if(strlen(buff) > 0 && atoi(buff) > 0) { |
| 1005 | nmea_log_enable = TRUE; |
| 1006 | } |
| 1007 | #endif |
| 1008 | |
| 1009 | memset(&gnss_info, 0, sizeof(gnss_info_t)); |
| 1010 | memcpy(gnss_info.dev_name, argv[2], strlen(argv[2])); |
| 1011 | gnss_info.state = GNSS_STATE_CLOSE; |
| 1012 | if(!strcmp(argv[1], GNSS_ID_6228)) { |
| 1013 | gnss_info.gnss_id = GNSS_TYPE_6228; |
| 1014 | gnss_info.auto_open = (bool)atoi(argv[3]); |
| 1015 | gnss_info.auto_dl_fw = TRUE; |
b.liu | 99c645d | 2024-06-20 10:52:15 +0800 | [diff] [blame] | 1016 | gnss_info.dl_befor_open = FALSE; |
b.liu | 8f231a1 | 2024-05-31 17:55:06 +0800 | [diff] [blame] | 1017 | gnss_info.gnss_dev_open = gnss_6228_dev_open; |
| 1018 | gnss_info.gnss_dev_close = gnss_6228_dev_close; |
| 1019 | gnss_info.gnss_open = gnss_6228_open; |
| 1020 | gnss_info.gnss_close = gnss_6228_close; |
| 1021 | gnss_info.gnss_fw_dl = gnss_6228_fw_dl; |
| 1022 | gnss_info.gnss_dl_read_cb = gnss_6228_dl_read_cb; |
| 1023 | gnss_info.gnss_set = gnss_6228_set; |
| 1024 | gnss_info.gnss_set_cb = gnss_6228_set_cb; |
b.liu | f9fbfa1 | 2024-06-14 15:53:59 +0800 | [diff] [blame] | 1025 | } else if(!strcmp(argv[1], GNSS_ID_8122)) { |
| 1026 | gnss_info.gnss_id = GNSS_TYPE_8122; |
| 1027 | gnss_info.auto_open = (bool)atoi(argv[3]); |
| 1028 | gnss_info.auto_dl_fw = FALSE; |
b.liu | 99c645d | 2024-06-20 10:52:15 +0800 | [diff] [blame] | 1029 | gnss_info.dl_befor_open = FALSE; |
b.liu | f9fbfa1 | 2024-06-14 15:53:59 +0800 | [diff] [blame] | 1030 | gnss_info.gnss_dev_open = gnss_8122_dev_open; |
| 1031 | gnss_info.gnss_dev_close = gnss_8122_dev_close; |
| 1032 | gnss_info.gnss_open = gnss_8122_open; |
| 1033 | gnss_info.gnss_close = gnss_8122_close; |
| 1034 | gnss_info.gnss_fw_dl = gnss_8122_fw_dl; |
| 1035 | gnss_info.gnss_dl_read_cb = NULL; |
| 1036 | gnss_info.gnss_set = gnss_8122_set; |
b.liu | 5f950c5 | 2024-06-15 20:13:12 +0800 | [diff] [blame] | 1037 | gnss_info.gnss_set_cb = gnss_8122_set_cb; |
b.liu | 99c645d | 2024-06-20 10:52:15 +0800 | [diff] [blame] | 1038 | } else if(!strcmp(argv[1], GNSS_ID_5311)) { |
| 1039 | gnss_info.gnss_id = GNSS_TYPE_5311; |
| 1040 | gnss_info.auto_open = (bool)atoi(argv[3]); |
| 1041 | gnss_info.auto_dl_fw = TRUE; |
| 1042 | gnss_info.dl_befor_open = TRUE; |
| 1043 | gnss_info.gnss_dev_open = gnss_5311_dev_open; |
| 1044 | gnss_info.gnss_dev_close = gnss_5311_dev_close; |
| 1045 | gnss_info.gnss_open = gnss_5311_open; |
| 1046 | gnss_info.gnss_close = gnss_5311_close; |
| 1047 | gnss_info.gnss_fw_dl = gnss_5311_fw_dl; |
| 1048 | gnss_info.gnss_dl_read_cb = NULL; |
| 1049 | gnss_info.gnss_set = gnss_5311_set; |
| 1050 | gnss_info.gnss_set_cb = gnss_5311_set_cb; |
b.liu | 42f558e | 2024-07-18 14:06:49 +0800 | [diff] [blame^] | 1051 | } else if(!strcmp(argv[1], GNSS_ID_N50DB)) { |
| 1052 | gnss_info.gnss_id = GNSS_TYPE_N50DB; |
| 1053 | gnss_info.auto_open = (bool)atoi(argv[3]); |
| 1054 | gnss_info.auto_dl_fw = FALSE; |
| 1055 | gnss_info.dl_befor_open = FALSE; |
| 1056 | gnss_info.gnss_dev_open = gnss_n50db_dev_open; |
| 1057 | gnss_info.gnss_dev_close = gnss_n50db_dev_close; |
| 1058 | gnss_info.gnss_open = gnss_n50db_open; |
| 1059 | gnss_info.gnss_close = gnss_n50db_close; |
| 1060 | gnss_info.gnss_fw_dl = gnss_n50db_fw_dl; |
| 1061 | gnss_info.gnss_dl_read_cb = NULL; |
| 1062 | gnss_info.gnss_set = gnss_n50db_set; |
| 1063 | gnss_info.gnss_set_cb = gnss_n50db_set_cb; |
b.liu | 8f231a1 | 2024-05-31 17:55:06 +0800 | [diff] [blame] | 1064 | } else { |
| 1065 | LOGE("No support : %s", argv[1]); |
| 1066 | return -1; |
| 1067 | } |
| 1068 | |
| 1069 | LOGD("GNSS : %s, Device: %s", argv[1], gnss_info.dev_name); |
| 1070 | // Auto open gnss. |
| 1071 | if(gnss_info.auto_open) { |
b.liu | ced8dd0 | 2024-06-28 13:28:29 +0800 | [diff] [blame] | 1072 | int init_mode = atoi(argv[3]); |
| 1073 | if(((GNSS_PRINT_PORT_UART1 | GNSS_PRINT_PORT_USB_NMEA | GNSS_PRINT_PORT_USB_AT | GNSS_PRINT_PORT_TTY_AT) & init_mode) != init_mode) { |
| 1074 | init_mode = 0; |
b.liu | 8f231a1 | 2024-05-31 17:55:06 +0800 | [diff] [blame] | 1075 | } |
b.liu | ced8dd0 | 2024-06-28 13:28:29 +0800 | [diff] [blame] | 1076 | if(gnss_init((uint32)init_mode)) { |
| 1077 | LOGE("gnss_init() fail."); |
| 1078 | // return -1; |
| 1079 | } |
| 1080 | } else { |
| 1081 | gnss_info.print_port = 0; |
b.liu | 8f231a1 | 2024-05-31 17:55:06 +0800 | [diff] [blame] | 1082 | } |
| 1083 | |
| 1084 | // Init ubus and waitting IPC commands. |
b.liu | d0ba715 | 2024-06-19 14:47:21 +0800 | [diff] [blame] | 1085 | #ifdef MBTK_GNSS_UBUS_ENABLE |
b.liu | 8f231a1 | 2024-05-31 17:55:06 +0800 | [diff] [blame] | 1086 | if(gnss_ubus_init()) { |
| 1087 | LOGD("main() run..."); |
| 1088 | uloop_run(); |
| 1089 | } else { |
| 1090 | LOGE("gnss_ubus_init() fail."); |
| 1091 | } |
b.liu | 5f950c5 | 2024-06-15 20:13:12 +0800 | [diff] [blame] | 1092 | #else |
| 1093 | if(!gnss_ipc_service_start()) { |
| 1094 | LOGD("main() run..."); |
| 1095 | while(1) { |
| 1096 | sleep(24 * 60 * 60); |
| 1097 | } |
| 1098 | } else { |
| 1099 | LOGE("gnss_ipc_service_start() fail."); |
| 1100 | } |
| 1101 | #endif |
b.liu | 8f231a1 | 2024-05-31 17:55:06 +0800 | [diff] [blame] | 1102 | |
| 1103 | LOGD("main() exit."); |
| 1104 | return 0; |
| 1105 | } |