blob: 8e25f8e76ef6037228a36ec3679e785ee446ec3b [file] [log] [blame]
b.liu8f231a12024-05-31 17:55:06 +08001#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>
11
12#include "mbtk_type.h"
13#include "mbtk_log.h"
14#include "gnss_info.h"
15
16#include "gnss_6228.h"
17
18#define GNSS_DEBUG 1
19
20#define GNSS_TAG "MBTK_GNSS"
21#define GNSS_BUFF_SIZE 2048
22#define MBTK_PROP_GNSS_LOG "persist.mbtk.gnss_log_enable"
23#define GNSS_PORT_PTY "/dev/tty_gnss_nmea"
24#define GNSS_PORT_USB_AT "/dev/ttyGS0"
25#define GNSS_PORT_USB_NMEA "/dev/ttymodem0"
26#define GNSS_PORT_UART_AT "/dev/ttyS1"
27
28#ifdef GNSS_DEBUG
29#define GNSS_NMEA_FILE_LOG "/tmp/mbtk_gnss_nmea.log"
30#define GNSS_NMEA_FILE_LOG_MAX 10485760 // 10MB
31
32#define GNSS_FILE_LOG "/tmp/mbtk_gnss.log"
33#define GNSS_FILE_LOG_MAX 10485760 // 10MB
34#endif
35
36gnss_info_t gnss_info;
37
38struct ubus_context *gnss_ubus_init(void);
39int gnss_init_config(int fd);
40
41static char gnss_buff[GNSS_BUFF_SIZE*2] = {0};
42static uint32 gnss_buff_len = 0;
43static bool nmea_found = FALSE;
44#ifdef GNSS_DEBUG
45static bool nmea_log_enable = FALSE;
46static int nmea_log_fd = -1;
47static int nmea_log_fd_len = 0;
48#endif
49static int gnss_pty_master_fd = -1;
50static int gnss_pty_slave_fd = -1;
51static int gnss_usb_at_port_fd = -1;
52static int gnss_usb_nmea_port_fd = -1;
53static int gnss_uart_at_port_fd = -1;
54static char *gnss_filter_info[] = {"RMC", "VTG", "GGA", "GSA", "GSV", "GLL", "ZDA", "GST", "TXT", "DHV", "DTM", NULL};
55
56static void help()
57{
58 LOGD("mbtk_gnssd <6228/...> <gnss_dev> <0/1>");
59}
60
61static int arg_check(int argc, char *argv[])
62{
63 if(argc != 4) {
64 goto check_fail;
65 }
66
67 // Only support 6228.
68 if(strcmp(argv[1], GNSS_ID_6228)) {
69 goto check_fail;
70 }
71
72 if(access(argv[2], R_OK | W_OK)) {
73 goto check_fail;
74 }
75
76 if(strcmp(argv[3], "0") && strcmp(argv[3], "1")) {
77 goto check_fail;
78 }
79
80 return 0;
81check_fail:
82 help();
83 return -1;
84}
85
86static int gnss_ports_open(uint32 print_port)
87{
88 if(print_port & GNSS_PRINT_PORT_TTY_AT) {
89 if(gnss_pty_open(&gnss_pty_master_fd, &gnss_pty_slave_fd, GNSS_PORT_PTY)) {
90 return -1;
91 }
92 LOGD("Open PTY port success.");
93 }
94
95 if(print_port & GNSS_PRINT_PORT_USB_AT) {
96 if((gnss_usb_at_port_fd = gnss_port_open(GNSS_PORT_USB_AT, O_RDWR | O_NONBLOCK | O_NOCTTY, 115200, FALSE)) <= 0) {
97 return -1;
98 }
99 LOGD("Open USB AT port success.");
100 }
101
102 if(print_port & GNSS_PRINT_PORT_USB_NMEA) {
103 if((gnss_usb_nmea_port_fd = gnss_port_open(GNSS_PORT_USB_NMEA, O_RDWR | O_NONBLOCK | O_NOCTTY, 115200, FALSE)) <= 0) {
104 return -1;
105 }
106 LOGD("Open USB NMEA port success.");
107 }
108
109 if(print_port & GNSS_PRINT_PORT_UART1) {
110 if((gnss_uart_at_port_fd = gnss_port_open(GNSS_PORT_UART_AT, O_RDWR | O_NONBLOCK | O_NOCTTY, 115200, TRUE)) <= 0) {
111 return -1;
112 }
113 LOGD("Open UART AT port success.");
114 }
115
116 return 0;
117}
118
119static int gnss_ports_close()
120{
121 if(gnss_usb_at_port_fd > 0) {
122 close(gnss_usb_at_port_fd);
123 gnss_usb_at_port_fd = -1;
124 }
125
126 if(gnss_usb_nmea_port_fd > 0) {
127 close(gnss_usb_nmea_port_fd);
128 gnss_usb_nmea_port_fd = -1;
129 }
130
131 if(gnss_uart_at_port_fd > 0) {
132 close(gnss_uart_at_port_fd);
133 gnss_uart_at_port_fd = -1;
134 }
135
136 if(gnss_pty_master_fd > 0) {
137 close(gnss_pty_master_fd);
138 gnss_pty_master_fd = -1;
139 }
140
141 if(gnss_pty_slave_fd > 0) {
142 close(gnss_pty_slave_fd);
143 gnss_pty_slave_fd = -1;
144 unlink(GNSS_PORT_PTY);
145 }
146
147 return 0;
148}
149
150static void nmea_print(const char *nmea, int nmea_len)
151{
152#ifdef GNSS_DEBUG
153 if(nmea_log_enable){
154 if(nmea_log_fd_len > GNSS_NMEA_FILE_LOG_MAX) {
155 close(nmea_log_fd);
156 nmea_log_fd = open(GNSS_NMEA_FILE_LOG, O_WRONLY | O_CREAT | O_TRUNC, 0666);
157 if(nmea_log_fd < 0) {
158 LOGE("Open debug fd fail.");
159 }
160 nmea_log_fd_len = 0;
161 }
162
163 if(nmea_log_fd > 0) {
164 write(nmea_log_fd, nmea, nmea_len);
165 nmea_log_fd_len += nmea_len;
166 }
167 }
168#endif
169
170 if(gnss_usb_at_port_fd > 0) {
171 write(gnss_usb_at_port_fd, nmea, nmea_len);
172 }
173
174 if(gnss_usb_nmea_port_fd > 0) {
175 write(gnss_usb_nmea_port_fd, nmea, nmea_len);
176 }
177
178 if(gnss_uart_at_port_fd > 0) {
179 write(gnss_uart_at_port_fd, nmea, nmea_len);
180 }
181
182 if(gnss_pty_master_fd > 0) {
183 write(gnss_pty_master_fd, nmea, nmea_len);
184 }
185}
186
187static unsigned char nmea_checksum(const char *nmea)
188{
189 const char *p = nmea;
190 unsigned char chs = 0;
191
192 while (*p == '$') // skip '$'
193 p++;
194 while (*p != '*' && *p != 0)
195 chs ^= *p++;
196
197 return chs;
198}
199
200static bool nmea_check(const char *nmea, int nmea_len)
201{
202 char **ptr = gnss_filter_info;
203 while(*ptr) {
204 if(strstr(nmea, *ptr)) {
205 break;
206 }
207 ptr++;
208 }
209
210 if(*ptr == NULL) {
211 LOGD("Unknown NMEA[%d]:%s", nmea_len, nmea);
212 return FALSE;
213 }
214
215 char *checksum_str = strstr(nmea, "*");
216 checksum_str++; // Jump '*'
217 char checksum_buf[3] = {0};
218 snprintf(checksum_buf, 3, "%02x", nmea_checksum(nmea));
219 if(strncasecmp(checksum_buf, checksum_str, 2)) {
220 LOGD("Checksum error[%d](checksum - %s):%s", nmea_len, checksum_buf, nmea);
221 return FALSE;
222 }
223
224 return TRUE;
225}
226
227static void gnss_nmea_process(const char *data, int data_len)
228{
229 char nmea[GNSS_BUFF_SIZE] = {0};
230 memcpy(nmea, data, data_len);
231
232 if(!nmea_check(nmea, data_len)) {
233 gnss_info.gnss_set_cb(nmea, data_len);
234 return;
235 }
236
237#ifdef GNSS_DEBUG
238 if(nmea_log_enable) {
239 LOGD("NMEA[%d]:%s", data_len, nmea);
240 }
241#endif
242
243 nmea_print(nmea, data_len);
244}
245
246#if 0
247static void gnss_cmd_rsp_process(const char *data, int data_len)
248{
249 char rsp[GNSS_BUFF_SIZE] = {0};
250 memcpy(rsp, data, data_len);
251 LOGD("RSP[%d]:%s", data_len, rsp);
252}
253#endif
254
255static bool nmea_char_check(char ch)
256{
257 if(isalnum(ch) || ch == '$' || ch == '\r' || ch == '\n' || ch == '.'
258 || ch == ',' || ch == '*' || ch == '\0' || ch == '/')
259 return TRUE;
260
261 return FALSE;
262}
263
264static void gnss_data_process(const char *data, int data_len)
265{
266 if(gnss_info.state == GNSS_STATE_OPEN) {
267 LOGD("GNSS_OPEN[%d]:%s", data_len, data);
268 } else if(gnss_info.state == GNSS_STATE_DOWNLOAD) {
269 // LOGD("GNSS_DL[%d]:%s", data_len, data);
270 gnss_info.gnss_dl_read_cb(data, data_len);
271 } else if(gnss_info.state == GNSS_STATE_READY) {
272 int index = 0;
273 while(index < data_len) {
274 if(nmea_found) {
275 if(!nmea_char_check(data[index])) {
276 gnss_buff_len = 0;
277 nmea_found = FALSE;
278#if 0
279 if(isascii(data[index])) {
280 LOGD("\n\n###%c###%s\n\n", data[index], data);
281 }
282#endif
283 continue;
284 }
285
286 if(data[index] != '\0') {
287 gnss_buff[gnss_buff_len++] = data[index];
288 if(gnss_buff[gnss_buff_len - 1] == '\n') {
289
290 if(gnss_buff_len > 6 && gnss_buff[gnss_buff_len - 5] == '*') { // $XXX*YY\r\n
291 gnss_nmea_process(gnss_buff, gnss_buff_len);
292 }
293
294 gnss_buff_len = 0;
295 nmea_found = FALSE;
296 }
297 }
298 } else {
299 if(data[index] == '$') {
300 gnss_buff_len = 0;
301 nmea_found = TRUE;
302 gnss_buff[gnss_buff_len++] = data[index];
303 }
304 }
305 index++;
306 }
307 } else {
308 LOGW("Unknown state : %d", gnss_info.state);
309 }
310}
311
312void* gnss_read_pthread(void* arg)
313{
314 LOGD("gnss_read_pthread enter.");
315 char buffer[GNSS_BUFF_SIZE];
316 int len = 0;
317 int ret = 0;
318 fd_set fdr, fdw;
319 int fd_max = 0;
320
321 FD_ZERO(&fdw);
322 FD_ZERO(&fdr);
323 FD_SET(gnss_info.fd, &fdr);
324 fd_max = (gnss_info.fd > fd_max) ? gnss_info.fd : fd_max;
325 FD_SET(gnss_info.exit_fd[0], &fdr);
326 fd_max = (gnss_info.exit_fd[0] > fd_max) ? gnss_info.exit_fd[0] : fd_max;
327 memset(gnss_buff, 0, sizeof(gnss_buff));
328 gnss_buff_len = 0;
329#if GNSS_DEBUG
330 int debug_fd = -1;
331 int debug_fd_len = 0;
332 if(nmea_log_enable) {
333 debug_fd = open(GNSS_FILE_LOG, O_WRONLY | O_CREAT | O_TRUNC, 0666);
334 if(debug_fd < 0) {
335 LOGE("Open debug fd fail.");
336 }
337 nmea_log_fd = open(GNSS_NMEA_FILE_LOG, O_WRONLY | O_CREAT | O_TRUNC, 0666);
338 if(nmea_log_fd < 0) {
339 LOGE("Open nmea fd fail.");
340 }
341 nmea_log_fd_len = 0;
342 }
343#endif
344
345 while(gnss_info.state >= GNSS_STATE_OPEN) {
346 ret = select(fd_max + 1, &fdr, &fdw, 0, NULL);
347 //LOGD("select - %d", ret);
348 if (ret < 0)
349 {
350 if (errno == EINTR)
351 {
352 continue;
353 }
354 LOGE("select error, errno = %d (%s)", errno, strerror(errno));
355 break;
356 }
357 else if (ret == 0)
358 {
359 LOGE("select ret == 0");
360 break;
361 }
362
363 if (FD_ISSET(gnss_info.fd, &fdr))
364 {
365 memset(buffer, 0, GNSS_BUFF_SIZE);
366 len = read(gnss_info.fd, buffer, GNSS_BUFF_SIZE);
367 if(len > 0) {
368 //log_hex("READ", buffer, len);
369
370#if GNSS_DEBUG
371 if(nmea_log_enable){
372 if(debug_fd_len > GNSS_FILE_LOG_MAX) {
373 close(debug_fd);
374 debug_fd = open(GNSS_FILE_LOG, O_WRONLY | O_CREAT | O_TRUNC, 0666);
375 if(debug_fd < 0) {
376 LOGE("Open debug fd fail.");
377 }
378 debug_fd_len = 0;
379 }
380
381 if(debug_fd > 0) {
382 write(debug_fd, buffer, len);
383 debug_fd_len += len;
384 }
385 }
386#endif
387
388 gnss_data_process(buffer, len);
389
390 } else if(len ==0 ){
391 LOGE("Read end : len = 0");
392 break;
393 } else {
394 if(EAGAIN == errno) {
395 usleep(50000);
396 continue;
397 } else {
398 LOGD("Read ret = -1 ,errno = %d", errno);
399 break;
400 }
401 }
402 }
403 else if (FD_ISSET(gnss_info.exit_fd[0], &fdr))
404 {
405 memset(buffer, 0, GNSS_BUFF_SIZE);
406 len = read(gnss_info.fd, buffer, GNSS_BUFF_SIZE);
407 if(len > 0) {
408 if(strcmp(buffer, "exit") == 0) {
409 LOGD("Get thread exit message.");
410 break;
411 }
412 }
413 }
414 else
415 {
416 LOGW("Unknown select event.");
417 continue;
418 }
419 }
420
421#if GNSS_DEBUG
422 if(debug_fd > 0) {
423 close(debug_fd);
424 debug_fd = -1;
425 }
426 if(nmea_log_fd > 0) {
427 close(nmea_log_fd);
428 nmea_log_fd = -1;
429 }
430#endif
431
432 gnss_info.state = GNSS_STATE_CLOSE;
433 LOGD("gnss_read_pthread exit.");
434 return NULL;
435}
436
437#if 0
438int gnss_write(int fd, const void *data, int data_len)
439{
440 int count = 0;
441 int len = 0;
442 while(1)
443 {
444 len = write(fd, data + count, data_len - count);
445 if (len > 0)
446 {
447 count += len;
448 }
449 else
450 {
451 LOGE("write() fail,ret = %d,errno = %d", len, errno);
452 break;
453 }
454
455 if (count == data_len)
456 break;
457 }
458
459 return count;
460}
461#else
462int gnss_write(int fd, const void* buf, unsigned int buf_len)
463{
464 size_t size;
465 size_t size_to_wr;
466 ssize_t size_written;
467 if(GNSS_BUFF_SIZE < buf_len)
468 {
469 return -1;
470 }
471 for(size = 0; size < buf_len;)
472 {
473 size_to_wr = buf_len - size;
474 if( size_to_wr > GNSS_BUFF_SIZE)
475 size_to_wr = GNSS_BUFF_SIZE;
476
477 size_written = write(fd, &buf[size], size_to_wr);
478 if (size_written==-1)
479 {
480 return -1;
481 }
482 size += size_written;
483 if(size_written != size_to_wr)
484 {
485 return size;
486 }
487 }
488 // LOGD("SEND %d / %d", size, buf_len);
489 return size;
490}
491#endif
492
493int gnss_init(uint32 print_port)
494{
495 if(gnss_info.state != GNSS_STATE_CLOSE) {
496 LOGW("GNSS not close:%d", gnss_info.state);
497 return 0;
498 }
499
500 int ret = 0;
501
502 gnss_info.fd = gnss_info.gnss_open(gnss_info.dev_name);
503 if(gnss_info.fd <= 0) {
504 LOGE("gnss_open(%s) fail : %d", gnss_info.dev_name, gnss_info.fd);
505 gnss_info.state = GNSS_STATE_CLOSE;
506 return -1;
507 }
508 if(pipe(gnss_info.exit_fd)) {
509 LOGE("pipe() fail[%d].", errno);
510 return -1;
511 }
512 // GNSS is opened.
513 gnss_info.state = GNSS_STATE_OPEN;
514
515 #if 0
516 // Start gnss read thread.
517 pthread_attr_t thread_attr;
518 pthread_attr_init(&thread_attr);
519 if(pthread_attr_setdetachstate(&thread_attr, PTHREAD_CREATE_DETACHED))
520 {
521 LOGE("pthread_attr_setdetachstate() fail.");
522 goto main_exit;
523 }
524
525 if(pthread_create(&gnss_info.read_pid, &thread_attr, gnss_read_pthread, NULL))
526#else
527 if(pthread_create(&gnss_info.read_pid, NULL, gnss_read_pthread, NULL))
528#endif
529 {
530 LOGE("pthread_create() fail.");
531 goto exit_with_close;
532 }
533
534 ret = gnss_info.gnss_dev_open();
535 if(ret) {
536 LOGE("gnss_dev_open() fail : %d", ret);
537 goto exit_with_thread_exit;
538 }
539
540 if(gnss_info.auto_dl_fw) {
541 gnss_info.state = GNSS_STATE_DOWNLOAD;
542 ret = gnss_info.gnss_fw_dl(gnss_info.fd);
543 if(ret) {
544 LOGE("gnss_fw_dl() fail : %d", ret);
545 goto exit_with_dev_close;
546 }
547 }
548
549 // GNSS is ready, NMEA can print from uart.
550 gnss_info.state = GNSS_STATE_READY;
551 gnss_info.print_port = print_port;
552
553 LOGD("GNSS open success.");
554
555 return gnss_ports_open(gnss_info.print_port);
556
557exit_with_dev_close:
558 if(gnss_info.gnss_dev_close()) {
559 LOGE("gnss_dev_close() fail.");
560 }
561exit_with_thread_exit:
562 gnss_info.state = GNSS_STATE_CLOSING;
563 // Wait for read thread exit.
564 ret = pthread_join(gnss_info.read_pid, NULL);
565 if(ret){
566 LOGE("pthrad_join fail(%d)",ret);
567 }
568exit_with_close:
569 if(gnss_info.gnss_close(gnss_info.fd)) {
570 LOGE("gnss_close() fail.");
571 }
572 if(gnss_info.exit_fd[0] > 0) {
573 close(gnss_info.exit_fd[0]);
574 gnss_info.exit_fd[0] = -1;
575 }
576 if(gnss_info.exit_fd[1] > 0) {
577 close(gnss_info.exit_fd[1]);
578 gnss_info.exit_fd[1] = -1;
579 }
580 gnss_info.state = GNSS_STATE_CLOSE;
581 return -1;
582}
583
584int gnss_deinit()
585{
586 if(gnss_info.state == GNSS_STATE_CLOSE) {
587 LOGW("GNSS is closed.");
588 return 0;
589 } else if(gnss_info.state == GNSS_STATE_CLOSING) {
590 LOGW("GNSS is closing...");
591 return -1;
592 } else if(gnss_info.state == GNSS_STATE_DOWNLOAD) {
593 LOGW("GNSS is downloading...");
594 return -1;
595 }
596
597 // Wait for read thread exit.
598 if(gnss_info.exit_fd[1] > 0) {
599 write(gnss_info.exit_fd[1], "exit", 4);
600 }
601
602 gnss_info.state = GNSS_STATE_CLOSING;
603 int ret = pthread_join(gnss_info.read_pid, NULL);
604 if(ret){
605 LOGE("pthrad_join fail(%d)",ret);
606 return -1;
607 }
608
609 if(gnss_info.gnss_close(gnss_info.fd)) {
610 LOGE("gnss_close() fail.");
611 return -1;
612 }
613
614 if(gnss_info.gnss_dev_close()) {
615 LOGE("gnss_dev_close() fail.");
616 return -1;
617 }
618
619 if(gnss_ports_close()) {
620 LOGE("gnss_ports_close fail.");
621 return -1;
622 }
623
624 gnss_info.fd = -1;
625 if(gnss_info.exit_fd[0] > 0) {
626 close(gnss_info.exit_fd[0]);
627 gnss_info.exit_fd[0] = -1;
628 }
629 if(gnss_info.exit_fd[1] > 0) {
630 close(gnss_info.exit_fd[1]);
631 gnss_info.exit_fd[1] = -1;
632 }
633 gnss_info.state = GNSS_STATE_CLOSE;
634 LOGD("GNSS close success.");
635 return 0;
636}
637
638int gnss_set(const void* buf, unsigned int buf_len, void *cmd_rsp, int cmd_rsp_len)
639{
640 if(cmd_rsp && buf && buf_len > 0 && cmd_rsp_len > 0) {
641 memset(cmd_rsp, 0, cmd_rsp_len);
642 return gnss_info.gnss_set(gnss_info.fd, buf, cmd_rsp, cmd_rsp_len);
643 } else {
644 return -1;
645 }
646}
647
648static void sig_process(int sig)
649{
650 LOGI("I got signal %d\n", sig);
651 if(gnss_deinit()) {
652 LOGE("gnss_deinit() fail, no exist...");
653 return;
654 }
655
656 switch(sig)
657 {
658 case SIGINT: // Ctrl + C
659 {
660 LOGI("Exit by SIGINT.\n");
661 exit(0);
662 }
663 case SIGQUIT: // Ctrl + \ (ÀàËÆ SIGINT £¬µ«Òª²úÉúcoreÎļþ)
664 {
665 LOGI("Exit by SIGQUIT.\n");
666 exit(0);
667 }
668 case SIGTERM:// ĬÈÏkill (ͬ SIGKILL £¬µ« SIGKILL ²»¿É²¶»ñ)
669 {
670 LOGI("Exit by SIGTERM.\n");
671 exit(0);
672 }
673 case SIGTSTP:// Ctrl + Z (ͬ SIGSTOP £¬µ« SIGSTOP ²»¿É²¶»ñ)
674 {
675 LOGI("Exit by SIGTSTP.\n");
676 exit(0);
677 }
678 case SIGSEGV: // Èç¿ÕÖ¸Õë
679 {
680 LOGI("Exit by SIGSEGV.\n");
681 exit(0);
682 }
683 default:
684 {
685 LOGI("Unknown sig:%d\n",sig);
686 break;
687 }
688 }
689}
690
691
692// mbtk_gnssd 6228 /dev/ttyS2 baud 0/1
693int main(int argc, char *argv[])
694{
695 mbtk_log_init("radio", GNSS_TAG);
696
b.liubb590492024-06-13 16:42:08 +0800697#ifdef MBTK_DUMP_SUPPORT
698 mbtk_debug_open(NULL, TRUE);
699#endif
700
b.liu8f231a12024-05-31 17:55:06 +0800701 signal(SIGINT, sig_process);
702 signal(SIGQUIT, sig_process);
703 signal(SIGTERM, sig_process);
704
705 if(arg_check(argc, argv)) {
706 return -1;
707 }
708
709#ifdef GNSS_DEBUG
710 char buff[10];
711 memset(buff, 0, 10);
712 property_get(MBTK_PROP_GNSS_LOG, buff, "");
713 if(strlen(buff) > 0 && atoi(buff) > 0) {
714 nmea_log_enable = TRUE;
715 }
716#endif
717
718 memset(&gnss_info, 0, sizeof(gnss_info_t));
719 memcpy(gnss_info.dev_name, argv[2], strlen(argv[2]));
720 gnss_info.state = GNSS_STATE_CLOSE;
721 if(!strcmp(argv[1], GNSS_ID_6228)) {
722 gnss_info.gnss_id = GNSS_TYPE_6228;
723 gnss_info.auto_open = (bool)atoi(argv[3]);
724 gnss_info.auto_dl_fw = TRUE;
725 gnss_info.gnss_dev_open = gnss_6228_dev_open;
726 gnss_info.gnss_dev_close = gnss_6228_dev_close;
727 gnss_info.gnss_open = gnss_6228_open;
728 gnss_info.gnss_close = gnss_6228_close;
729 gnss_info.gnss_fw_dl = gnss_6228_fw_dl;
730 gnss_info.gnss_dl_read_cb = gnss_6228_dl_read_cb;
731 gnss_info.gnss_set = gnss_6228_set;
732 gnss_info.gnss_set_cb = gnss_6228_set_cb;
733 } else {
734 LOGE("No support : %s", argv[1]);
735 return -1;
736 }
737
738 LOGD("GNSS : %s, Device: %s", argv[1], gnss_info.dev_name);
739 // Auto open gnss.
740 if(gnss_info.auto_open) {
741 if(gnss_init(0)) { // No print to any port.
742 LOGE("gnss_init() fail.");
743 return -1;
744 }
745 }
746
747 // Init ubus and waitting IPC commands.
748 if(gnss_ubus_init()) {
749 LOGD("main() run...");
750 uloop_run();
751 } else {
752 LOGE("gnss_ubus_init() fail.");
753 }
754
755 LOGD("main() exit.");
756 return 0;
757}