liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 1 | /** |
| 2 | * \file gnss_test.c |
| 3 | * \brief A Documented file. |
| 4 | * |
| 5 | * Detailed description |
| 6 | * \Author: Sniper <e190@163.com> |
| 7 | * \Version: 1.0.0 |
| 8 | * \Date: 2022-03-26 |
| 9 | */ |
| 10 | #include <stdio.h> |
| 11 | #include <stdlib.h> |
| 12 | #include <string.h> |
| 13 | #include <unistd.h> |
| 14 | #include <pthread.h> |
| 15 | #include <errno.h> |
| 16 | #include <termios.h> |
| 17 | #include <unistd.h> |
| 18 | #include <fcntl.h> |
| 19 | #include <signal.h> |
| 20 | #include <sys/types.h> |
| 21 | #include <unistd.h> |
| 22 | #include <pthread.h> |
| 23 | #include <termios.h> |
| 24 | #include <sys/ioctl.h> |
| 25 | #include "mbtk_type.h" |
| 26 | #include "mbtk_gnss.h" |
| 27 | #include "lynq/lynq_gnss.h" |
| 28 | |
| 29 | static mbtk_gnss_client_handle _gnss_handle = 0; |
| 30 | |
| 31 | static lynq_gnss_rx_ind_msg_handler_t handler_ptr = NULL; |
| 32 | |
| 33 | void lynq_gnss_handler_function |
| 34 | ( |
| 35 | mbtk_gnss_client_handle h_loc, |
| 36 | int e_msg_id, |
| 37 | void *pv_data, |
| 38 | void *context_ptr |
| 39 | ) |
| 40 | { |
| 41 | if(NULL == handler_ptr) |
| 42 | return; |
| 43 | |
| 44 | if(E_LYNQ_LOC_MSG_ID_NMEA_INFO == e_msg_id) { |
| 45 | handler_ptr(h_loc, e_msg_id, pv_data, context_ptr); |
| 46 | } else { |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | //该函数用于进行GNSS初始化 |
| 51 | int lynq_gnss_init(void) |
| 52 | { |
| 53 | int ret=0; |
| 54 | |
| 55 | ret = mbtk_gnss_client_init(&_gnss_handle); |
| 56 | if(ret < 0) { |
| 57 | printf("mopen_gnss_client_init FAIL. ret:%d\n",ret); |
| 58 | return -1; |
| 59 | } |
| 60 | |
| 61 | return 0; |
| 62 | } |
| 63 | |
| 64 | //该函数用于取消GNSS初始化 |
| 65 | int lynq_gnss_deinit(void) |
| 66 | { |
| 67 | int ret; |
| 68 | if(0 == _gnss_handle) { |
| 69 | return -1; |
| 70 | } |
| 71 | |
| 72 | ret = mbtk_gnss_client_deinit(_gnss_handle); |
| 73 | if(ret < 0) { |
| 74 | printf("mopen_gnss_client_deinit FAIL. ret:%d\n",ret); |
| 75 | return -1; |
| 76 | } |
| 77 | |
| 78 | _gnss_handle = 0; |
| 79 | return 0; |
| 80 | } |
| 81 | |
| 82 | //该函数用于GNSS回调函数初始化 |
| 83 | |
| 84 | int lynq_gnss_callback_reg(lynq_gnss_rx_ind_msg_handler_t handlerPtr) |
| 85 | { |
| 86 | int ret; |
| 87 | |
| 88 | if(0 == _gnss_handle) { |
| 89 | return -1; |
| 90 | } |
| 91 | mbtk_gnss_print_version(_gnss_handle); |
| 92 | |
| 93 | ret = mbtk_gnss_add_rx_msg_handler(_gnss_handle, lynq_gnss_handler_function); |
| 94 | if(0 == ret && handlerPtr) |
| 95 | handler_ptr = handlerPtr; |
| 96 | else |
| 97 | return -1; |
| 98 | return 0; |
| 99 | } |
| 100 | |
| 101 | //该函数用于启动GNSS。 |
| 102 | int lynq_gnss_start(void) |
| 103 | { |
| 104 | if(0 == _gnss_handle) { |
| 105 | return -1; |
| 106 | } |
| 107 | |
| 108 | mbtk_gnss_set_mode(_gnss_handle, 0); |
| 109 | return mbtk_gnss_set_mode(_gnss_handle, 3); |
| 110 | } |
| 111 | |
| 112 | //该函数用于关闭GNSS。 |
| 113 | int lynq_gnss_stop(void) |
| 114 | { |
| 115 | if(0 == _gnss_handle) { |
| 116 | return -1; |
| 117 | } |
| 118 | |
| 119 | return mbtk_gnss_set_mode(_gnss_handle, 0); |
| 120 | } |
| 121 | |
| 122 | |
| 123 | int lynq_gnss_agps_dataconnopen(void) |
| 124 | { |
| 125 | int ret; |
| 126 | |
| 127 | ret = mbtk_gnss_download_tle(); |
| 128 | if(ret) |
| 129 | { |
| 130 | printf("%s: download injects failed!!\n", __FUNCTION__); |
| 131 | return -1; |
| 132 | } |
| 133 | return mbtk_gnss_injects_aidpos(_gnss_handle); |
| 134 | } |
| 135 | |
| 136 | int lynq_gnss_dev_reset(void) |
| 137 | { |
| 138 | int ret = 0; |
| 139 | if(_gnss_handle < 0) |
| 140 | { |
| 141 | return -1; |
| 142 | } |
| 143 | ret = mbtk_gnss_dev_reset(_gnss_handle, 0, 0); |
| 144 | return ret; |
| 145 | } |
| 146 | |
| 147 | int lynq_gnss_enable_glonass(void) |
| 148 | { |
| 149 | mbtk_gnss_firmware_update(); |
| 150 | return 0; |
| 151 | } |