b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 1 | #include <stdio.h>
|
| 2 | #include <string.h>
|
| 3 | #include <strings.h>
|
| 4 | #include <stdlib.h>
|
| 5 | #include <errno.h>
|
| 6 | #include <fcntl.h>
|
| 7 | #include <signal.h>
|
| 8 | #include <sys/types.h>
|
| 9 | #include <unistd.h>
|
| 10 | #include <pthread.h>
|
| 11 | #include <termios.h>
|
| 12 | #include <time.h>
|
| 13 | #include <sys/ioctl.h>
|
| 14 | #include <dlfcn.h>
|
| 15 | #include <stdint.h>
|
| 16 | #include <stdbool.h>
|
| 17 |
|
zw.wang | 581aab1 | 2025-05-28 19:43:53 +0800 | [diff] [blame^] | 18 | #include "gsw_gnss_interface.h"
|
| 19 |
|
| 20 | #define MBTK_GNSS_IND_LOCATION (1) // 1
|
| 21 | #define MBTK_GNSS_IND_NMEA (1 << 1) // 2
|
| 22 | #define QSER_GNSS_TIMEOUT 5
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 23 |
|
| 24 | #ifndef LOG_ERR_LEVEL
|
| 25 | #define LOG_ERR_LEVEL 3 /* error conditions */
|
| 26 | #endif
|
| 27 | #ifndef LOG_WARN_LEVEL
|
| 28 | #define LOG_WARN_LEVEL 4 /* warning conditions */
|
| 29 | #endif
|
| 30 | #ifndef LOG_INFO_LEVEL
|
| 31 | #define LOG_INFO_LEVEL 6 /* informational */
|
| 32 | #endif
|
| 33 | #ifndef LOG_DEBUG_LEVEL
|
| 34 | #define LOG_DEBUG_LEVEL 7 /* debug-level messages */
|
| 35 | #endif
|
| 36 | #ifndef LOG_VERBOSE_LEVEL
|
| 37 | #define LOG_VERBOSE_LEVEL 8
|
| 38 | #endif
|
| 39 |
|
l.yang | 6a42e4d | 2025-05-28 01:04:20 -0700 | [diff] [blame] | 40 | #define GSW_GNSS "[HAL][GSW_GNSS]"
|
| 41 |
|
| 42 |
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 43 | #define LOGV(fmt, args ...) \
|
| 44 | do{ \
|
| 45 | char *file_ptr_1001 = __FILE__; \
|
| 46 | char *ptr_1001 = file_ptr_1001 + strlen(file_ptr_1001) - 1; \
|
| 47 | char line_1001[10] = {0}; \
|
| 48 | sprintf(line_1001, "%d", __LINE__); \
|
| 49 | while(ptr_1001 >= file_ptr_1001 && *ptr_1001){ \
|
| 50 | if(*ptr_1001 == '/') \
|
| 51 | break; \
|
| 52 | ptr_1001--; \
|
| 53 | } \
|
l.yang | 6a42e4d | 2025-05-28 01:04:20 -0700 | [diff] [blame] | 54 | fun_ptr_log(LOG_VERBOSE_LEVEL, "%s#%s: "GSW_GNSS"" fmt, ptr_1001 + 1, line_1001, ##args); \
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 55 | } while(0)
|
| 56 |
|
| 57 | #define LOGI(fmt, args...) \
|
| 58 | do{ \
|
| 59 | char *file_ptr_1001 = __FILE__; \
|
| 60 | char *ptr_1001 = file_ptr_1001 + strlen(file_ptr_1001) - 1; \
|
| 61 | char line_1001[10] = {0}; \
|
| 62 | sprintf(line_1001, "%d", __LINE__); \
|
| 63 | while(ptr_1001 >= file_ptr_1001 && *ptr_1001){ \
|
| 64 | if(*ptr_1001 == '/') \
|
| 65 | break; \
|
| 66 | ptr_1001--; \
|
| 67 | } \
|
l.yang | 6a42e4d | 2025-05-28 01:04:20 -0700 | [diff] [blame] | 68 | fun_ptr_log(LOG_INFO_LEVEL, "%s#%s: "GSW_GNSS"" fmt, ptr_1001 + 1, line_1001, ##args); \
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 69 | } while(0)
|
| 70 |
|
| 71 | #define LOGD(fmt, args...) \
|
| 72 | do{ \
|
| 73 | char *file_ptr_1001 = __FILE__; \
|
| 74 | char *ptr_1001 = file_ptr_1001 + strlen(file_ptr_1001) - 1; \
|
| 75 | char line_1001[10] = {0}; \
|
| 76 | sprintf(line_1001, "%d", __LINE__); \
|
| 77 | while(ptr_1001 >= file_ptr_1001 && *ptr_1001){ \
|
| 78 | if(*ptr_1001 == '/') \
|
| 79 | break; \
|
| 80 | ptr_1001--; \
|
| 81 | } \
|
l.yang | 6a42e4d | 2025-05-28 01:04:20 -0700 | [diff] [blame] | 82 | fun_ptr_log(LOG_DEBUG_LEVEL, "%s#%s: "GSW_GNSS"" fmt, ptr_1001 + 1, line_1001, ##args); \
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 83 | } while(0)
|
| 84 |
|
| 85 | #define LOGW(fmt, args...) \
|
| 86 | do{ \
|
| 87 | char *file_ptr_1001 = __FILE__; \
|
| 88 | char *ptr_1001 = file_ptr_1001 + strlen(file_ptr_1001) - 1; \
|
| 89 | char line_1001[10] = {0}; \
|
| 90 | sprintf(line_1001, "%d", __LINE__); \
|
| 91 | while(ptr_1001 >= file_ptr_1001 && *ptr_1001){ \
|
| 92 | if(*ptr_1001 == '/') \
|
| 93 | break; \
|
| 94 | ptr_1001--; \
|
| 95 | } \
|
l.yang | 6a42e4d | 2025-05-28 01:04:20 -0700 | [diff] [blame] | 96 | fun_ptr_log(LOG_WARN_LEVEL, "%s#%s: "GSW_GNSS"" fmt, ptr_1001 + 1, line_1001, ##args); \
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 97 | } while(0)
|
| 98 |
|
| 99 | #define LOGE(fmt, args...) \
|
| 100 | do{ \
|
| 101 | char *file_ptr_1001 = __FILE__; \
|
| 102 | char *ptr_1001 = file_ptr_1001 + strlen(file_ptr_1001) - 1; \
|
| 103 | char line_1001[10] = {0}; \
|
| 104 | sprintf(line_1001, "%d", __LINE__); \
|
| 105 | while(ptr_1001 >= file_ptr_1001 && *ptr_1001){ \
|
| 106 | if(*ptr_1001 == '/') \
|
| 107 | break; \
|
| 108 | ptr_1001--; \
|
| 109 | } \
|
l.yang | 6a42e4d | 2025-05-28 01:04:20 -0700 | [diff] [blame] | 110 | fun_ptr_log(LOG_ERR_LEVEL, "%s#%s: "GSW_GNSS"" fmt, ptr_1001 + 1, line_1001, ##args); \
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 111 | } while(0)
|
| 112 |
|
| 113 |
|
zw.wang | 581aab1 | 2025-05-28 19:43:53 +0800 | [diff] [blame^] | 114 | // #define GSW_HAL_SUCCESS 0
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 115 | #define GSW_HAL_FAIL -1 //表示失败(通用性)
|
| 116 | #define GSW_HAL_MEM_INVAILD -2 //表示入参地址为NULL
|
| 117 |
|
| 118 | #define MOPEN_GNSS_NMEA_MAX_LENGTH 255 /** NMEA string maximum length. */
|
| 119 | static gsw_gnss_cb *gsw_cb = NULL;
|
| 120 | static bool inited = false;
|
| 121 | static bool strated = false;
|
| 122 |
|
| 123 | typedef void (*mbtk_gnss_callback_func)(uint32_t ind_type, const void* data, uint32_t data_len);
|
| 124 | typedef void (*mbtk_log)(int level, const char *format,...);
|
| 125 | static mbtk_log fun_ptr_log = NULL;
|
| 126 |
|
| 127 | int (*mbtk_gnss_init)(mbtk_gnss_callback_func cb);
|
| 128 | int (*mbtk_gnss_deinit)();
|
| 129 |
|
| 130 | int (*mbtk_gnss_ind_set)(uint32_t ,int);
|
| 131 | int (*mbtk_gnss_open)(int, int);
|
| 132 | int (*mbtk_gnss_close)(int);
|
| 133 | int (*mbtk_gnss_setting)(const char *setting_cmd, int);
|
| 134 |
|
| 135 | int (*mbtk_gnss_eph_download)(int);
|
| 136 | int (*mbtk_gnss_eph_inject)(int);
|
| 137 |
|
| 138 | int gnss_freq = -1;
|
| 139 | GSW_GNSS_MODE_CONFIGURATION gnss_startmode = -1;
|
zw.wang | 581aab1 | 2025-05-28 19:43:53 +0800 | [diff] [blame^] | 140 | GSW_CONF_SWITCH gnss_switch_op = -1;
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 141 | void *dlHandle_gnss;
|
| 142 | char *lynqLib_gnss = "/lib/libmbtk_lib.so";
|
| 143 |
|
| 144 | typedef enum
|
| 145 | {
|
| 146 | E_MT_LOC_MSG_ID_LOCATION_INFO = 1, /**< pv_data = & mopen_location_info_t */
|
| 147 | E_MT_LOC_MSG_ID_NMEA_INFO = 3, /**< pv_data = & mopen_gnss_nmea_info_t */
|
| 148 | } e_msg_id_t;
|
| 149 |
|
| 150 | typedef struct
|
| 151 | {
|
| 152 | int64_t timestamp; /**< System Timestamp, marked for when got the nmea data */
|
| 153 | int length; /**< NMEA string length. */
|
| 154 | char nmea[MOPEN_GNSS_NMEA_MAX_LENGTH + 1]; /**< NMEA string.*/
|
| 155 | }mopen_gnss_nmea_info_t; /* Message */
|
| 156 |
|
| 157 | typedef struct
|
| 158 | {
|
| 159 | uint32_t size; /**< Set to the size of mcm_gps_location_t. */
|
| 160 | int flags; /**< Contains GPS location flags bits. */
|
| 161 | int position_source; /**< Provider indicator for HYBRID or GPS. */ //功能暂未实现,可不用添加进结构体
|
| 162 | double latitude; /**< Latitude in degrees. */
|
| 163 | double longitude; /**< Longitude in degrees. */
|
| 164 | double altitude; /**< Altitude in meters above the WGS 84 reference ellipsoid. */
|
| 165 | float speed; /**< Speed in meters per second. */
|
| 166 | float bearing; /**< Heading in degrees. */ //功能暂未实现,可不用添加进结构体
|
| 167 | float accuracy; /**< Expected accuracy in meters. */ //功能暂未实现,可不用添加进结构体
|
| 168 | int64_t timestamp; /**< Timestamp for the location fix in UTC million-second base. */
|
| 169 | int32_t is_indoor; /**< Location is indoors. */ //功能暂未实现,可不用添加进结构体
|
| 170 | float floor_number; /**< Indicates the floor number. */
|
| 171 | }mopen_location_info_t;//功能暂未实现,可不用添加进结构体
|
| 172 |
|
| 173 |
|
| 174 | typedef struct {
|
| 175 | uint32_t flags;
|
| 176 | double latitude; /**< Latitude in degrees. */
|
| 177 | double longitude; /**< Longitude in degrees. */
|
| 178 | double altitude; /**< Altitude in meters above the WGS 84 reference ellipsoid. */
|
| 179 | float speed; /**< Speed in meters per second. */
|
| 180 | float bearing; /**< Heading in degrees. */
|
| 181 | int64_t timestamp; /**< Timestamp for the location fix in UTC million-second base. */
|
| 182 | } mbtk_gnss_location_info_t;
|
| 183 |
|
zw.wang | 581aab1 | 2025-05-28 19:43:53 +0800 | [diff] [blame^] | 184 | typedef struct{
|
| 185 | GSW_GNSS_MODE_CONFIGURATION start_mode;
|
| 186 | gnss_freq_type freq;
|
| 187 | gsw_gnss_cb callback;
|
| 188 | }gsw_gnss_init_configure_t;
|
| 189 |
|
| 190 |
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 191 | typedef enum{
|
| 192 | MODE_GPS = 1, /**< GPS only */
|
| 193 | MODE_BEIDOU, /**< BEIDOU only*/
|
| 194 | MODE_GPS_BEIDOU, /**< GPS+BEIDOU */
|
| 195 | MODE_GLONASS, /**< GLONASS only */
|
| 196 | MODE_GPS_GLONASS, /**< GPS+GLONASS */
|
| 197 | MODE_GLONASS_BEIDOU, /**< GLONASS+BEIDOU */ /* The type does not support this type */
|
| 198 | MODE_GPS_GLONASS_BEIDOU, /**< GPS+GLONASS+BEIDOU */ /* The type does not support this type */
|
| 199 | MODE_GALILEO, /**< GALILEO only */
|
| 200 | MODE_GPS_GALILEO, /**< GPS+GALILEO */
|
| 201 | MODE_BEIDOU_GALILEO, /**< BEIDOU+GALILEO */
|
| 202 | MODE_GPS_BEIDOU_GALILEO, /**< GPS+BEIDOU+GALILEO */
|
| 203 | MODE_GLONASS_GALILEO, /**< GLONASS+GALILEO */
|
| 204 | MODE_GPS_GLONASS_GALILEO, /**< GPS+GLONASS+GALILEO */
|
| 205 | MODE_BEIDOU_GLONASS_GALILEO, /**< BEIDOU+GLONASS+GALILEO */ /* The type does not support this type */
|
| 206 | MODE_END = -1, /**< init value */
|
| 207 | }GSW_GNSS_MODE_CONFIGURATION_HD;
|
| 208 |
|
| 209 |
|
| 210 | GSW_GNSS_MODE_CONFIGURATION_HD map_gnss_mode(GSW_GNSS_MODE_CONFIGURATION mode)
|
| 211 | {
|
| 212 | switch (mode)
|
| 213 | {
|
| 214 | case GSW_MODE_GPS_GLONASS:
|
| 215 | return MODE_GPS_GLONASS;
|
| 216 | case GSW_MODE_GPS_BEIDOU:
|
| 217 | return MODE_GPS_BEIDOU;
|
| 218 | case GSW_MODE_GPS_GLONASS_BEIDOU:
|
| 219 | return MODE_END;
|
| 220 | case GSW_MODE_GPS:
|
| 221 | return MODE_GPS;
|
| 222 | case GSW_MODE_BEIDOU:
|
| 223 | return MODE_BEIDOU;
|
| 224 | case GSW_MODE_GLONASS:
|
| 225 | return MODE_GLONASS;
|
| 226 | case GSW_MODE_GPS_GLONASS_BEIDOU_GALILEO:
|
| 227 | return MODE_END;
|
| 228 | case GSW_MODE_GPS_GALILEO:
|
| 229 | return MODE_GPS_GALILEO;
|
| 230 | case GSW_MODE_GPS_GLONASS_GALILEO:
|
| 231 | return MODE_GPS_GLONASS_GALILEO;
|
| 232 | case GSW_MODE_GPS_GALILEO_ONLY:
|
| 233 | return MODE_GALILEO;
|
| 234 | case GSW_MODE_GPS_GLONASS_BEIDOU_GALILEO_NAVIC:
|
| 235 | return MODE_END;
|
| 236 | case GSW_MODE_GNSS_END:
|
| 237 | return MODE_END;
|
| 238 | default:
|
| 239 | return MODE_END;
|
| 240 | }
|
| 241 | }
|
| 242 |
|
| 243 | int mbtk_gnss_set_VTG()
|
| 244 | {
|
| 245 | int ret;
|
| 246 | char param_buf[32] = {0};
|
| 247 | snprintf(param_buf, 32, "$MSGCFG,2,1000");
|
| 248 | mbtk_gnss_setting=(int(*)(const char *setting_cmd, int))dlsym(dlHandle_gnss, "mbtk_gnss_setting");
|
| 249 | ret = mbtk_gnss_setting(param_buf, QSER_GNSS_TIMEOUT);
|
| 250 | if(ret != 0)
|
| 251 | {
|
| 252 | LOGE("[qser_gnss] mbtk_gnss_setting fail.ret = [%d]", ret);
|
| 253 | return GSW_HAL_FAIL;
|
| 254 | }
|
| 255 | return GSW_HAL_SUCCESS;
|
| 256 | }
|
| 257 |
|
| 258 | /**
|
| 259 | * @brief SDK interface to set gnss sampling frequency, support 1Hz、2Hz、5Hz
|
| 260 | * @param [in] freq
|
| 261 | * @retval 0: success
|
| 262 | * @retval other: fail
|
| 263 | */
|
| 264 | int gsw_gnss_set_freq(int freq)
|
| 265 | {
|
| 266 | int ret;
|
| 267 | if (!strated)
|
| 268 | {
|
| 269 | gnss_freq = freq;
|
| 270 | return GSW_HAL_SUCCESS;
|
| 271 | }
|
| 272 | char param_buf[32] = {0};
|
| 273 | snprintf(param_buf, 32, "$FREQCFG,%d", freq);
|
| 274 | mbtk_gnss_setting=(int(*)(const char *setting_cmd, int))dlsym(dlHandle_gnss, "mbtk_gnss_setting");
|
| 275 | ret = mbtk_gnss_setting(param_buf, QSER_GNSS_TIMEOUT);
|
| 276 | if(ret != 0)
|
| 277 | {
|
| 278 | LOGE("[qser_gnss] mbtk_gnss_setting fail.ret = [%d]", ret);
|
| 279 | return GSW_HAL_FAIL;
|
| 280 | }
|
| 281 | return GSW_HAL_SUCCESS;
|
| 282 | }
|
| 283 |
|
| 284 | /**
|
| 285 | * @brief SDK interface to set gnss start mode,specific mode refreence GSW_HAL_GNSS_MODE_CONFIGURATION
|
| 286 | * @param [in] start_mode
|
| 287 | * @retval 0: success
|
| 288 | * @retval other: fail
|
| 289 | */
|
| 290 | int gsw_gnss_set_start_mode(GSW_GNSS_MODE_CONFIGURATION start_mode)
|
| 291 | {
|
| 292 | int ret;
|
| 293 | if (!strated)
|
| 294 | {
|
| 295 | gnss_startmode = start_mode;
|
| 296 | return GSW_HAL_SUCCESS;
|
| 297 | }
|
| 298 | char param_buf[32] = {0};
|
| 299 | snprintf(param_buf, 32, "$SYSCFG,%d", map_gnss_mode(start_mode));
|
| 300 | if(map_gnss_mode(start_mode) == -1)
|
| 301 | {
|
| 302 | LOGE("[qser_gnss] mbtk_gnss_start_mode con't support");
|
| 303 | return GSW_HAL_FAIL;
|
| 304 | }
|
| 305 | mbtk_gnss_setting=(int(*)(const char *setting_cmd, int))dlsym(dlHandle_gnss, "mbtk_gnss_setting");
|
| 306 | ret = mbtk_gnss_setting(param_buf, QSER_GNSS_TIMEOUT);
|
| 307 | if(ret != 0)
|
| 308 | {
|
| 309 | LOGE("[qser_gnss] mbtk_gnss_setting fail.ret = [%d]", ret);
|
| 310 | return GSW_HAL_FAIL;
|
| 311 | }
|
| 312 | return GSW_HAL_SUCCESS;
|
| 313 | }
|
| 314 |
|
| 315 | /**
|
| 316 | * @brief SDK interface to set EPO switch if open or close
|
| 317 | * @param [in] switch_op
|
| 318 | * @retval 0: success
|
| 319 | * @retval other: fail
|
| 320 | */
|
zw.wang | 581aab1 | 2025-05-28 19:43:53 +0800 | [diff] [blame^] | 321 | int gsw_gnss_epo_switch(GSW_CONF_SWITCH switch_op)
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 322 | {
|
| 323 | int ret;
|
| 324 | if (!strated)
|
| 325 | {
|
| 326 | gnss_switch_op = switch_op;
|
| 327 | return GSW_HAL_SUCCESS;
|
| 328 | }
|
| 329 |
|
| 330 | if(switch_op)
|
| 331 | {
|
| 332 | mbtk_gnss_eph_download=(int(*)(int))dlsym(dlHandle_gnss, "mbtk_gnss_eph_download");
|
| 333 | ret = mbtk_gnss_eph_download(QSER_GNSS_TIMEOUT);
|
| 334 | if(ret != 0)
|
| 335 | {
|
| 336 | LOGE("[qser_gnss] mbtk_gnss_eph_download fail.ret = [%d]", ret);
|
| 337 | return GSW_HAL_FAIL;
|
| 338 | }
|
| 339 | mbtk_gnss_eph_inject=(int(*)(int))dlsym(dlHandle_gnss, "mbtk_gnss_eph_inject");
|
| 340 | ret = mbtk_gnss_eph_inject(QSER_GNSS_TIMEOUT);
|
| 341 | if(ret != 0)
|
| 342 | {
|
| 343 | LOGE("[qser_gnss] mbtk_gnss_eph_inject fail.ret = [%d]", ret);
|
| 344 | return GSW_HAL_FAIL;
|
| 345 | }
|
| 346 | }
|
| 347 | return GSW_HAL_SUCCESS;
|
| 348 | }
|
| 349 |
|
| 350 | static void gnss_callback(uint32_t ind_type, const void* data, uint32_t data_len)
|
| 351 | {
|
| 352 | if(data == NULL || data_len <= 0)
|
| 353 | {
|
| 354 | LOGE("[GSW_gnss] data is NULL.");
|
| 355 | return;
|
| 356 | }
|
| 357 |
|
| 358 | if(gsw_cb == NULL)
|
| 359 | {
|
| 360 | //LOGE("[qser_gnss] qser_gnss_callback is NULL.");
|
| 361 | return;
|
| 362 | }
|
| 363 |
|
| 364 | if(ind_type == MBTK_GNSS_IND_LOCATION) {
|
| 365 | if(data_len != sizeof(mbtk_gnss_location_info_t))
|
| 366 | {
|
| 367 | LOGE("[GSW_gnss] data size error");
|
| 368 | return;
|
| 369 | }
|
| 370 | GSW_GNSS_LOCATION_EXT_T gsw_location;
|
| 371 | GSW_GNSS_LOCATION_T gsw_location_t;
|
| 372 | mbtk_gnss_location_info_t *locl_info = (mbtk_gnss_location_info_t *)data;
|
| 373 | gsw_location_t.altitude = locl_info->altitude;
|
| 374 | gsw_location_t.latitude = locl_info->latitude;
|
| 375 | gsw_location_t.longitude = locl_info->longitude;
|
| 376 | gsw_location_t.speed = locl_info->speed;
|
| 377 | gsw_location_t.bearing = locl_info->bearing;
|
| 378 | gsw_location_t.timestamp = locl_info->timestamp;
|
| 379 | gsw_location.legacyLocation = gsw_location_t;
|
| 380 | gsw_cb->gsw_location_cb(&gsw_location);
|
| 381 | } else if(ind_type == MBTK_GNSS_IND_NMEA) {
|
| 382 | mopen_gnss_nmea_info_t qser_nmea = {0};
|
| 383 | memset(&qser_nmea, 0x0, sizeof(mopen_gnss_nmea_info_t));
|
| 384 | qser_nmea.length = data_len;
|
| 385 | memcpy(qser_nmea.nmea, (char *)data, data_len);
|
| 386 | //qser_nmea.timestamp = qser_get_gnss_time_sec(data, data_len);
|
| 387 | gsw_cb->gsw_nmea_cb(data,data_len);
|
| 388 | } else {
|
| 389 | LOGD("Unknown IND : %d\n", ind_type);
|
| 390 | }
|
| 391 | }
|
| 392 |
|
| 393 | int gsw_gnss_init(void)
|
| 394 | {
|
| 395 | int ret;
|
| 396 | if(!inited)
|
| 397 | {
|
| 398 | dlHandle_gnss = dlopen(lynqLib_gnss, RTLD_NOW);
|
| 399 | fun_ptr_log = (mbtk_log)dlsym(dlHandle_gnss, "mbtk_log");
|
| 400 | if(fun_ptr_log == NULL || dlHandle_gnss == NULL)
|
| 401 | {
|
| 402 | return GSW_HAL_FAIL;
|
| 403 | }
|
| 404 | mbtk_gnss_init=(int(*)(mbtk_gnss_callback_func))dlsym(dlHandle_gnss, "mbtk_gnss_init");
|
| 405 | ret = mbtk_gnss_init(gnss_callback);
|
| 406 | if(ret == 0)
|
| 407 | {
|
| 408 | mbtk_gnss_ind_set=(int(*)(uint32_t ,int))dlsym(dlHandle_gnss, "mbtk_gnss_ind_set");
|
| 409 | ret = mbtk_gnss_ind_set(MBTK_GNSS_IND_NMEA, QSER_GNSS_TIMEOUT);
|
| 410 | if(ret == 0)
|
| 411 | {
|
| 412 | inited = true;
|
| 413 | }
|
| 414 | else
|
| 415 | {
|
| 416 | LOGE("[GSW_gnss] init mbtk_gnss_ind_set() fail.ret = [%d]", ret);
|
| 417 | return GSW_HAL_FAIL;
|
| 418 | }
|
| 419 | }
|
| 420 | else
|
| 421 | {
|
| 422 | LOGE("[GSW_gnss] mbtk_gnss_init() fail.ret = [%d]", ret);
|
| 423 | return GSW_HAL_FAIL;
|
| 424 | }
|
| 425 | }
|
| 426 |
|
| 427 | return GSW_HAL_SUCCESS;
|
| 428 | }
|
| 429 |
|
| 430 | /**
|
| 431 | * @brief SDK interface to registered callback function
|
| 432 | * @param [in] callback
|
| 433 | * @retval 0: success
|
| 434 | * @retval other: fail
|
| 435 | */
|
| 436 | int gsw_gnss_reg_cb_group(gsw_gnss_cb callback)
|
| 437 | {
|
| 438 | if(callback.gsw_location_cb == NULL && callback.gsw_nmea_cb == NULL)
|
| 439 | {
|
| 440 | LOGE("[GSW_gnss] handler_ptr is NULL.");
|
| 441 | return GSW_HAL_FAIL;
|
| 442 | }
|
| 443 | if (gsw_cb == NULL)
|
| 444 | {
|
| 445 | gsw_cb = (gsw_gnss_cb *)malloc(sizeof(gsw_gnss_cb));
|
| 446 | if (gsw_cb == NULL)
|
| 447 | {
|
| 448 | LOGE("[GSW_gnss] Memory allocation failed.");
|
| 449 | return GSW_HAL_FAIL;
|
| 450 | }
|
| 451 | }
|
| 452 | gsw_cb->gsw_location_cb = callback.gsw_location_cb;
|
| 453 | gsw_cb->gsw_nmea_cb = callback.gsw_nmea_cb;
|
| 454 | return GSW_HAL_SUCCESS;
|
| 455 | }
|
| 456 | /**
|
| 457 | * @brief SDK interface to start gnss
|
| 458 | * @param
|
| 459 | * @retval 0: success
|
| 460 | * @retval other: fail
|
| 461 | */
|
| 462 | int gsw_gnss_start(void)
|
| 463 | {
|
| 464 | int ret;
|
| 465 | mbtk_gnss_open=(int(*)(int,int))dlsym(dlHandle_gnss, "mbtk_gnss_open");
|
| 466 | ret = mbtk_gnss_open(255, QSER_GNSS_TIMEOUT);
|
| 467 | if(ret != 0)
|
| 468 | {
|
| 469 | LOGE("[GSW_gnss] mbtk_gnss_open is error.ret = [%d]", ret);
|
| 470 | return GSW_HAL_FAIL;
|
| 471 | }
|
| 472 | strated = true;
|
| 473 | if (gnss_freq > 0)
|
| 474 | gsw_gnss_set_freq(gnss_freq);
|
| 475 | if (gnss_startmode >= 0)
|
| 476 | gsw_gnss_set_start_mode(gnss_startmode);
|
| 477 | if (gnss_switch_op > 0)
|
| 478 | gsw_gnss_epo_switch(gnss_switch_op);
|
| 479 |
|
| 480 | mbtk_gnss_set_VTG();
|
| 481 |
|
| 482 | return GSW_HAL_SUCCESS;
|
| 483 | }
|
| 484 |
|
| 485 | /**
|
| 486 | * @brief SDK interface to stop gnss
|
| 487 | * @param
|
| 488 | * @retval 0: success
|
| 489 | * @retval other: fail
|
| 490 | */
|
| 491 | int gsw_gnss_stop(void)
|
| 492 | {
|
| 493 | int ret;
|
| 494 | mbtk_gnss_close=(int(*)(int))dlsym(dlHandle_gnss, "mbtk_gnss_close");
|
| 495 | ret = mbtk_gnss_close(QSER_GNSS_TIMEOUT);
|
| 496 | if(ret != 0)
|
| 497 | {
|
| 498 | LOGE("[GSW_gnss] mbtk_gnss_close is error.ret = [%d]", ret);
|
| 499 | return GSW_HAL_FAIL;
|
| 500 | }
|
| 501 | strated = false;
|
| 502 | return GSW_HAL_SUCCESS;
|
| 503 | }
|
| 504 |
|
| 505 | /**
|
| 506 | * @brief SDK interface to de initialization gnss
|
| 507 | * @param
|
| 508 | * @retval 0: success
|
| 509 | * @retval other: fail
|
| 510 | */
|
| 511 | int gsw_gnss_deinit(void)
|
| 512 | {
|
| 513 | int ret;
|
| 514 | if(inited)
|
| 515 | {
|
| 516 | mbtk_gnss_deinit=(int(*)())dlsym(dlHandle_gnss, "mbtk_gnss_deinit");
|
| 517 | ret = mbtk_gnss_deinit();
|
| 518 | if(ret == 0)
|
| 519 | {
|
| 520 | inited = false;
|
| 521 | }
|
| 522 | else
|
| 523 | {
|
| 524 | LOGE("[GSW_gnss] mbtk_gnss_init() fail.ret = [%d]", ret);
|
| 525 | dlclose(dlHandle_gnss);
|
| 526 | dlHandle_gnss = NULL;
|
| 527 | return GSW_HAL_FAIL;
|
| 528 | }
|
| 529 | }
|
| 530 |
|
| 531 | dlclose(dlHandle_gnss);
|
| 532 | dlHandle_gnss = NULL;
|
| 533 | gnss_freq = -1;
|
| 534 | gnss_startmode = -1;
|
| 535 | gnss_switch_op = -1;
|
| 536 | return GSW_HAL_SUCCESS;
|
| 537 | }
|
| 538 |
|
| 539 |
|
| 540 | /**
|
| 541 | * @brief SDK interface to enable XTRA switch
|
| 542 | * @param [in] state
|
| 543 | * @retval 0: success
|
| 544 | * @retval other: fail
|
| 545 | */
|
| 546 | int gsw_gnss_xtra_is_enable(gsw_xtra_state_e state)
|
| 547 | {
|
| 548 | return GSW_HAL_SUCCESS;
|
| 549 | }
|
| 550 |
|
| 551 | /**
|
| 552 | * @brief SDK interface to delete aiding data,delete aiding data for cold start(1-H,2-W,3-C)
|
| 553 | * @param [in] switch_op
|
| 554 | * @retval 0: success
|
| 555 | * @retval other: fail
|
| 556 | */
|
| 557 | int gsw_gnss_delete_aiding_data(unsigned int flags) /*1-don`t delete == hot_start ; 2-delete EPH == warm start ; 3-delete all == cold start*/
|
| 558 | {
|
| 559 | int ret;
|
| 560 | char param_buf[32] = {0};
|
| 561 | snprintf(param_buf, 32, "$RESET,%u", flags);
|
| 562 | mbtk_gnss_setting=(int(*)(const char *setting_cmd, int))dlsym(dlHandle_gnss, "mbtk_gnss_setting");
|
| 563 | ret = mbtk_gnss_setting(param_buf, QSER_GNSS_TIMEOUT);
|
| 564 | if(ret != 0)
|
| 565 | {
|
| 566 | LOGE("[qser_gnss] mbtk_gnss_setting fail.ret = [%d]", ret);
|
| 567 | return GSW_HAL_FAIL;
|
| 568 | }
|
| 569 | return GSW_HAL_SUCCESS;
|
| 570 | }
|
| 571 |
|
| 572 | /**
|
| 573 | * @brief init and configure gps
|
| 574 | * @param [in] init_configure
|
| 575 | * @retval 0: success
|
| 576 | * @retval other: fail
|
| 577 | */
|
| 578 | int gsw_gnss_init_configure_gps(gsw_gnss_init_configure_t init_configure)
|
| 579 | {
|
| 580 | return GSW_HAL_SUCCESS;
|
| 581 | }
|