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)
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 112 |
|
| 113 | #define MOPEN_GNSS_NMEA_MAX_LENGTH 255 /** NMEA string maximum length. */
|
| 114 | static gsw_gnss_cb *gsw_cb = NULL;
|
| 115 | static bool inited = false;
|
| 116 | static bool strated = false;
|
| 117 |
|
| 118 | typedef void (*mbtk_gnss_callback_func)(uint32_t ind_type, const void* data, uint32_t data_len);
|
| 119 | typedef void (*mbtk_log)(int level, const char *format,...);
|
| 120 | static mbtk_log fun_ptr_log = NULL;
|
| 121 |
|
| 122 | int (*mbtk_gnss_init)(mbtk_gnss_callback_func cb);
|
| 123 | int (*mbtk_gnss_deinit)();
|
| 124 |
|
| 125 | int (*mbtk_gnss_ind_set)(uint32_t ,int);
|
| 126 | int (*mbtk_gnss_open)(int, int);
|
| 127 | int (*mbtk_gnss_close)(int);
|
| 128 | int (*mbtk_gnss_setting)(const char *setting_cmd, int);
|
| 129 |
|
| 130 | int (*mbtk_gnss_eph_download)(int);
|
| 131 | int (*mbtk_gnss_eph_inject)(int);
|
| 132 |
|
| 133 | int gnss_freq = -1;
|
| 134 | GSW_GNSS_MODE_CONFIGURATION gnss_startmode = -1;
|
zw.wang | 581aab1 | 2025-05-28 19:43:53 +0800 | [diff] [blame] | 135 | GSW_CONF_SWITCH gnss_switch_op = -1;
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 136 | void *dlHandle_gnss;
|
| 137 | char *lynqLib_gnss = "/lib/libmbtk_lib.so";
|
| 138 |
|
| 139 | typedef enum
|
| 140 | {
|
| 141 | E_MT_LOC_MSG_ID_LOCATION_INFO = 1, /**< pv_data = & mopen_location_info_t */
|
| 142 | E_MT_LOC_MSG_ID_NMEA_INFO = 3, /**< pv_data = & mopen_gnss_nmea_info_t */
|
| 143 | } e_msg_id_t;
|
| 144 |
|
| 145 | typedef struct
|
| 146 | {
|
| 147 | int64_t timestamp; /**< System Timestamp, marked for when got the nmea data */
|
| 148 | int length; /**< NMEA string length. */
|
| 149 | char nmea[MOPEN_GNSS_NMEA_MAX_LENGTH + 1]; /**< NMEA string.*/
|
| 150 | }mopen_gnss_nmea_info_t; /* Message */
|
| 151 |
|
| 152 | typedef struct
|
| 153 | {
|
| 154 | uint32_t size; /**< Set to the size of mcm_gps_location_t. */
|
| 155 | int flags; /**< Contains GPS location flags bits. */
|
| 156 | int position_source; /**< Provider indicator for HYBRID or GPS. */ //功能暂未实现,可不用添加进结构体
|
| 157 | double latitude; /**< Latitude in degrees. */
|
| 158 | double longitude; /**< Longitude in degrees. */
|
| 159 | double altitude; /**< Altitude in meters above the WGS 84 reference ellipsoid. */
|
| 160 | float speed; /**< Speed in meters per second. */
|
| 161 | float bearing; /**< Heading in degrees. */ //功能暂未实现,可不用添加进结构体
|
| 162 | float accuracy; /**< Expected accuracy in meters. */ //功能暂未实现,可不用添加进结构体
|
| 163 | int64_t timestamp; /**< Timestamp for the location fix in UTC million-second base. */
|
| 164 | int32_t is_indoor; /**< Location is indoors. */ //功能暂未实现,可不用添加进结构体
|
| 165 | float floor_number; /**< Indicates the floor number. */
|
| 166 | }mopen_location_info_t;//功能暂未实现,可不用添加进结构体
|
| 167 |
|
| 168 |
|
| 169 | typedef struct {
|
| 170 | uint32_t flags;
|
| 171 | double latitude; /**< Latitude in degrees. */
|
| 172 | double longitude; /**< Longitude in degrees. */
|
| 173 | double altitude; /**< Altitude in meters above the WGS 84 reference ellipsoid. */
|
| 174 | float speed; /**< Speed in meters per second. */
|
| 175 | float bearing; /**< Heading in degrees. */
|
| 176 | int64_t timestamp; /**< Timestamp for the location fix in UTC million-second base. */
|
| 177 | } mbtk_gnss_location_info_t;
|
| 178 |
|
zw.wang | 581aab1 | 2025-05-28 19:43:53 +0800 | [diff] [blame] | 179 | typedef struct{
|
| 180 | GSW_GNSS_MODE_CONFIGURATION start_mode;
|
| 181 | gnss_freq_type freq;
|
| 182 | gsw_gnss_cb callback;
|
| 183 | }gsw_gnss_init_configure_t;
|
| 184 |
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 185 | typedef enum{
|
| 186 | MODE_GPS = 1, /**< GPS only */
|
| 187 | MODE_BEIDOU, /**< BEIDOU only*/
|
| 188 | MODE_GPS_BEIDOU, /**< GPS+BEIDOU */
|
| 189 | MODE_GLONASS, /**< GLONASS only */
|
| 190 | MODE_GPS_GLONASS, /**< GPS+GLONASS */
|
| 191 | MODE_GLONASS_BEIDOU, /**< GLONASS+BEIDOU */ /* The type does not support this type */
|
| 192 | MODE_GPS_GLONASS_BEIDOU, /**< GPS+GLONASS+BEIDOU */ /* The type does not support this type */
|
| 193 | MODE_GALILEO, /**< GALILEO only */
|
| 194 | MODE_GPS_GALILEO, /**< GPS+GALILEO */
|
| 195 | MODE_BEIDOU_GALILEO, /**< BEIDOU+GALILEO */
|
| 196 | MODE_GPS_BEIDOU_GALILEO, /**< GPS+BEIDOU+GALILEO */
|
| 197 | MODE_GLONASS_GALILEO, /**< GLONASS+GALILEO */
|
| 198 | MODE_GPS_GLONASS_GALILEO, /**< GPS+GLONASS+GALILEO */
|
| 199 | MODE_BEIDOU_GLONASS_GALILEO, /**< BEIDOU+GLONASS+GALILEO */ /* The type does not support this type */
|
| 200 | MODE_END = -1, /**< init value */
|
| 201 | }GSW_GNSS_MODE_CONFIGURATION_HD;
|
| 202 |
|
| 203 |
|
| 204 | GSW_GNSS_MODE_CONFIGURATION_HD map_gnss_mode(GSW_GNSS_MODE_CONFIGURATION mode)
|
| 205 | {
|
| 206 | switch (mode)
|
| 207 | {
|
| 208 | case GSW_MODE_GPS_GLONASS:
|
| 209 | return MODE_GPS_GLONASS;
|
| 210 | case GSW_MODE_GPS_BEIDOU:
|
| 211 | return MODE_GPS_BEIDOU;
|
| 212 | case GSW_MODE_GPS_GLONASS_BEIDOU:
|
| 213 | return MODE_END;
|
| 214 | case GSW_MODE_GPS:
|
| 215 | return MODE_GPS;
|
| 216 | case GSW_MODE_BEIDOU:
|
| 217 | return MODE_BEIDOU;
|
| 218 | case GSW_MODE_GLONASS:
|
| 219 | return MODE_GLONASS;
|
| 220 | case GSW_MODE_GPS_GLONASS_BEIDOU_GALILEO:
|
| 221 | return MODE_END;
|
| 222 | case GSW_MODE_GPS_GALILEO:
|
| 223 | return MODE_GPS_GALILEO;
|
| 224 | case GSW_MODE_GPS_GLONASS_GALILEO:
|
| 225 | return MODE_GPS_GLONASS_GALILEO;
|
| 226 | case GSW_MODE_GPS_GALILEO_ONLY:
|
| 227 | return MODE_GALILEO;
|
| 228 | case GSW_MODE_GPS_GLONASS_BEIDOU_GALILEO_NAVIC:
|
| 229 | return MODE_END;
|
| 230 | case GSW_MODE_GNSS_END:
|
| 231 | return MODE_END;
|
| 232 | default:
|
| 233 | return MODE_END;
|
| 234 | }
|
| 235 | }
|
| 236 |
|
| 237 | int mbtk_gnss_set_VTG()
|
| 238 | {
|
| 239 | int ret;
|
| 240 | char param_buf[32] = {0};
|
| 241 | snprintf(param_buf, 32, "$MSGCFG,2,1000");
|
| 242 | mbtk_gnss_setting=(int(*)(const char *setting_cmd, int))dlsym(dlHandle_gnss, "mbtk_gnss_setting");
|
| 243 | ret = mbtk_gnss_setting(param_buf, QSER_GNSS_TIMEOUT);
|
| 244 | if(ret != 0)
|
| 245 | {
|
| 246 | LOGE("[qser_gnss] mbtk_gnss_setting fail.ret = [%d]", ret);
|
hong.liu | d241707 | 2025-06-27 07:10:37 -0700 | [diff] [blame] | 247 | return GSW_HAL_NORMAL_FAIL;
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 248 | }
|
| 249 | return GSW_HAL_SUCCESS;
|
| 250 | }
|
| 251 |
|
| 252 | /**
|
| 253 | * @brief SDK interface to set gnss sampling frequency, support 1Hz、2Hz、5Hz
|
| 254 | * @param [in] freq
|
| 255 | * @retval 0: success
|
| 256 | * @retval other: fail
|
| 257 | */
|
| 258 | int gsw_gnss_set_freq(int freq)
|
| 259 | {
|
zw.wang | bc534c0 | 2025-06-26 09:31:44 +0800 | [diff] [blame] | 260 | if(!inited)
|
hong.liu | d241707 | 2025-06-27 07:10:37 -0700 | [diff] [blame] | 261 | return GSW_HAL_NORMAL_FAIL;
|
zw.wang | bc534c0 | 2025-06-26 09:31:44 +0800 | [diff] [blame] | 262 |
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 263 | int ret;
|
| 264 | if (!strated)
|
| 265 | {
|
| 266 | gnss_freq = freq;
|
| 267 | return GSW_HAL_SUCCESS;
|
| 268 | }
|
| 269 | char param_buf[32] = {0};
|
| 270 | snprintf(param_buf, 32, "$FREQCFG,%d", freq);
|
| 271 | mbtk_gnss_setting=(int(*)(const char *setting_cmd, int))dlsym(dlHandle_gnss, "mbtk_gnss_setting");
|
| 272 | ret = mbtk_gnss_setting(param_buf, QSER_GNSS_TIMEOUT);
|
| 273 | if(ret != 0)
|
| 274 | {
|
| 275 | LOGE("[qser_gnss] mbtk_gnss_setting fail.ret = [%d]", ret);
|
hong.liu | d241707 | 2025-06-27 07:10:37 -0700 | [diff] [blame] | 276 | return GSW_HAL_NORMAL_FAIL;
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 277 | }
|
| 278 | return GSW_HAL_SUCCESS;
|
| 279 | }
|
| 280 |
|
| 281 | /**
|
| 282 | * @brief SDK interface to set gnss start mode,specific mode refreence GSW_HAL_GNSS_MODE_CONFIGURATION
|
| 283 | * @param [in] start_mode
|
| 284 | * @retval 0: success
|
| 285 | * @retval other: fail
|
| 286 | */
|
hong.liu | d241707 | 2025-06-27 07:10:37 -0700 | [diff] [blame] | 287 | int32_t gsw_gnss_set_start_mode(GSW_GNSS_MODE_CONFIGURATION start_mode)
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 288 | {
|
zw.wang | bc534c0 | 2025-06-26 09:31:44 +0800 | [diff] [blame] | 289 | if(!inited)
|
hong.liu | d241707 | 2025-06-27 07:10:37 -0700 | [diff] [blame] | 290 | return GSW_HAL_NORMAL_FAIL;
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 291 | int ret;
|
| 292 | if (!strated)
|
| 293 | {
|
| 294 | gnss_startmode = start_mode;
|
| 295 | return GSW_HAL_SUCCESS;
|
| 296 | }
|
| 297 | char param_buf[32] = {0};
|
| 298 | snprintf(param_buf, 32, "$SYSCFG,%d", map_gnss_mode(start_mode));
|
| 299 | if(map_gnss_mode(start_mode) == -1)
|
| 300 | {
|
| 301 | LOGE("[qser_gnss] mbtk_gnss_start_mode con't support");
|
hong.liu | d241707 | 2025-06-27 07:10:37 -0700 | [diff] [blame] | 302 | return GSW_HAL_NORMAL_FAIL;
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 303 | }
|
| 304 | mbtk_gnss_setting=(int(*)(const char *setting_cmd, int))dlsym(dlHandle_gnss, "mbtk_gnss_setting");
|
| 305 | ret = mbtk_gnss_setting(param_buf, QSER_GNSS_TIMEOUT);
|
| 306 | if(ret != 0)
|
| 307 | {
|
| 308 | LOGE("[qser_gnss] mbtk_gnss_setting fail.ret = [%d]", ret);
|
hong.liu | d241707 | 2025-06-27 07:10:37 -0700 | [diff] [blame] | 309 | return GSW_HAL_NORMAL_FAIL;
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 310 | }
|
| 311 | return GSW_HAL_SUCCESS;
|
| 312 | }
|
| 313 |
|
| 314 | /**
|
| 315 | * @brief SDK interface to set EPO switch if open or close
|
| 316 | * @param [in] switch_op
|
| 317 | * @retval 0: success
|
| 318 | * @retval other: fail
|
| 319 | */
|
hong.liu | d241707 | 2025-06-27 07:10:37 -0700 | [diff] [blame] | 320 | int32_t gsw_gnss_epo_switch(GSW_CONF_SWITCH switch_op)
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 321 | {
|
zw.wang | bc534c0 | 2025-06-26 09:31:44 +0800 | [diff] [blame] | 322 | if(!inited)
|
hong.liu | d241707 | 2025-06-27 07:10:37 -0700 | [diff] [blame] | 323 | return GSW_HAL_NORMAL_FAIL;
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 324 | int ret;
|
| 325 | if (!strated)
|
| 326 | {
|
| 327 | gnss_switch_op = switch_op;
|
| 328 | return GSW_HAL_SUCCESS;
|
| 329 | }
|
| 330 |
|
| 331 | if(switch_op)
|
| 332 | {
|
| 333 | mbtk_gnss_eph_download=(int(*)(int))dlsym(dlHandle_gnss, "mbtk_gnss_eph_download");
|
| 334 | ret = mbtk_gnss_eph_download(QSER_GNSS_TIMEOUT);
|
| 335 | if(ret != 0)
|
| 336 | {
|
| 337 | LOGE("[qser_gnss] mbtk_gnss_eph_download fail.ret = [%d]", ret);
|
hong.liu | d241707 | 2025-06-27 07:10:37 -0700 | [diff] [blame] | 338 | return GSW_HAL_NORMAL_FAIL;
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 339 | }
|
| 340 | mbtk_gnss_eph_inject=(int(*)(int))dlsym(dlHandle_gnss, "mbtk_gnss_eph_inject");
|
| 341 | ret = mbtk_gnss_eph_inject(QSER_GNSS_TIMEOUT);
|
| 342 | if(ret != 0)
|
| 343 | {
|
| 344 | LOGE("[qser_gnss] mbtk_gnss_eph_inject fail.ret = [%d]", ret);
|
hong.liu | d241707 | 2025-06-27 07:10:37 -0700 | [diff] [blame] | 345 | return GSW_HAL_NORMAL_FAIL;
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 346 | }
|
| 347 | }
|
| 348 | return GSW_HAL_SUCCESS;
|
| 349 | }
|
| 350 |
|
| 351 | static void gnss_callback(uint32_t ind_type, const void* data, uint32_t data_len)
|
| 352 | {
|
| 353 | if(data == NULL || data_len <= 0)
|
| 354 | {
|
| 355 | LOGE("[GSW_gnss] data is NULL.");
|
| 356 | return;
|
| 357 | }
|
| 358 |
|
| 359 | if(gsw_cb == NULL)
|
| 360 | {
|
| 361 | //LOGE("[qser_gnss] qser_gnss_callback is NULL.");
|
| 362 | return;
|
| 363 | }
|
| 364 |
|
zw.wang | a5250d6 | 2025-06-13 16:01:34 +0800 | [diff] [blame] | 365 | if(ind_type == MBTK_GNSS_IND_LOCATION && gsw_cb->gsw_location_cb != NULL) {
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 366 | if(data_len != sizeof(mbtk_gnss_location_info_t))
|
| 367 | {
|
| 368 | LOGE("[GSW_gnss] data size error");
|
| 369 | return;
|
| 370 | }
|
| 371 | GSW_GNSS_LOCATION_EXT_T gsw_location;
|
hong.liu | d241707 | 2025-06-27 07:10:37 -0700 | [diff] [blame] | 372 | GSW_GNSS_LOCATION_T gsw_location_t = {0};
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 373 | mbtk_gnss_location_info_t *locl_info = (mbtk_gnss_location_info_t *)data;
|
| 374 | gsw_location_t.altitude = locl_info->altitude;
|
| 375 | gsw_location_t.latitude = locl_info->latitude;
|
| 376 | gsw_location_t.longitude = locl_info->longitude;
|
| 377 | gsw_location_t.speed = locl_info->speed;
|
| 378 | gsw_location_t.bearing = locl_info->bearing;
|
| 379 | gsw_location_t.timestamp = locl_info->timestamp;
|
zw.wang | a5250d6 | 2025-06-13 16:01:34 +0800 | [diff] [blame] | 380 | gsw_location_t.flags = locl_info->flags;
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 381 | gsw_location.legacyLocation = gsw_location_t;
|
| 382 | gsw_cb->gsw_location_cb(&gsw_location);
|
zw.wang | a5250d6 | 2025-06-13 16:01:34 +0800 | [diff] [blame] | 383 | } else if(ind_type == MBTK_GNSS_IND_NMEA && gsw_cb->gsw_nmea_cb != NULL) {
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 384 | mopen_gnss_nmea_info_t qser_nmea = {0};
|
| 385 | memset(&qser_nmea, 0x0, sizeof(mopen_gnss_nmea_info_t));
|
| 386 | qser_nmea.length = data_len;
|
| 387 | memcpy(qser_nmea.nmea, (char *)data, data_len);
|
| 388 | //qser_nmea.timestamp = qser_get_gnss_time_sec(data, data_len);
|
| 389 | gsw_cb->gsw_nmea_cb(data,data_len);
|
| 390 | } else {
|
| 391 | LOGD("Unknown IND : %d\n", ind_type);
|
| 392 | }
|
| 393 | }
|
| 394 |
|
hong.liu | d241707 | 2025-06-27 07:10:37 -0700 | [diff] [blame] | 395 | int32_t gsw_gnss_init(void)
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 396 | {
|
lichengzhang | a708917 | 2025-07-01 20:41:46 +0800 | [diff] [blame] | 397 | int ret;
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 398 | if(!inited)
|
| 399 | {
|
lichengzhang | a708917 | 2025-07-01 20:41:46 +0800 | [diff] [blame] | 400 | ret = system("serial_atcmd AT*IMLCONFIG=13");
|
| 401 | if(ret != 0)
|
| 402 | {
|
| 403 | LOGE("serial_atcmd fail\n");
|
| 404 | return GSW_HAL_NORMAL_FAIL;
|
| 405 | }
|
zw.wang | 1907e8f | 2025-07-01 16:26:39 +0800 | [diff] [blame] | 406 | if(dlHandle_gnss == NULL)
|
| 407 | dlHandle_gnss = dlopen(lynqLib_gnss, RTLD_NOW);
|
| 408 | if(fun_ptr_log == NULL)
|
| 409 | fun_ptr_log = (mbtk_log)dlsym(dlHandle_gnss, "mbtk_log");
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 410 | if(fun_ptr_log == NULL || dlHandle_gnss == NULL)
|
| 411 | {
|
hong.liu | d241707 | 2025-06-27 07:10:37 -0700 | [diff] [blame] | 412 | return GSW_HAL_NORMAL_FAIL;
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 413 | }
|
| 414 | mbtk_gnss_init=(int(*)(mbtk_gnss_callback_func))dlsym(dlHandle_gnss, "mbtk_gnss_init");
|
| 415 | ret = mbtk_gnss_init(gnss_callback);
|
| 416 | if(ret == 0)
|
| 417 | {
|
| 418 | mbtk_gnss_ind_set=(int(*)(uint32_t ,int))dlsym(dlHandle_gnss, "mbtk_gnss_ind_set");
|
zw.wang | a5250d6 | 2025-06-13 16:01:34 +0800 | [diff] [blame] | 419 | ret = mbtk_gnss_ind_set(MBTK_GNSS_IND_NMEA |MBTK_GNSS_IND_LOCATION, QSER_GNSS_TIMEOUT);
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 420 | if(ret == 0)
|
| 421 | {
|
| 422 | inited = true;
|
| 423 | }
|
| 424 | else
|
| 425 | {
|
| 426 | LOGE("[GSW_gnss] init mbtk_gnss_ind_set() fail.ret = [%d]", ret);
|
hong.liu | d241707 | 2025-06-27 07:10:37 -0700 | [diff] [blame] | 427 | return GSW_HAL_NORMAL_FAIL;
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 428 | }
|
| 429 | }
|
| 430 | else
|
| 431 | {
|
| 432 | LOGE("[GSW_gnss] mbtk_gnss_init() fail.ret = [%d]", ret);
|
hong.liu | d241707 | 2025-06-27 07:10:37 -0700 | [diff] [blame] | 433 | return GSW_HAL_NORMAL_FAIL;
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 434 | }
|
| 435 | }
|
| 436 |
|
| 437 | return GSW_HAL_SUCCESS;
|
| 438 | }
|
| 439 |
|
| 440 | /**
|
| 441 | * @brief SDK interface to registered callback function
|
| 442 | * @param [in] callback
|
| 443 | * @retval 0: success
|
| 444 | * @retval other: fail
|
| 445 | */
|
hong.liu | d241707 | 2025-06-27 07:10:37 -0700 | [diff] [blame] | 446 | int32_t gsw_gnss_reg_cb_group(gsw_gnss_cb callback)
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 447 | {
|
zw.wang | bc534c0 | 2025-06-26 09:31:44 +0800 | [diff] [blame] | 448 | if(!inited)
|
hong.liu | d241707 | 2025-06-27 07:10:37 -0700 | [diff] [blame] | 449 | return GSW_HAL_NORMAL_FAIL;
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 450 | if(callback.gsw_location_cb == NULL && callback.gsw_nmea_cb == NULL)
|
| 451 | {
|
| 452 | LOGE("[GSW_gnss] handler_ptr is NULL.");
|
hong.liu | d241707 | 2025-06-27 07:10:37 -0700 | [diff] [blame] | 453 | return GSW_HAL_NORMAL_FAIL;
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 454 | }
|
| 455 | if (gsw_cb == NULL)
|
| 456 | {
|
| 457 | gsw_cb = (gsw_gnss_cb *)malloc(sizeof(gsw_gnss_cb));
|
| 458 | if (gsw_cb == NULL)
|
| 459 | {
|
| 460 | LOGE("[GSW_gnss] Memory allocation failed.");
|
hong.liu | d241707 | 2025-06-27 07:10:37 -0700 | [diff] [blame] | 461 | return GSW_HAL_NORMAL_FAIL;
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 462 | }
|
| 463 | }
|
| 464 | gsw_cb->gsw_location_cb = callback.gsw_location_cb;
|
| 465 | gsw_cb->gsw_nmea_cb = callback.gsw_nmea_cb;
|
| 466 | return GSW_HAL_SUCCESS;
|
| 467 | }
|
| 468 | /**
|
| 469 | * @brief SDK interface to start gnss
|
| 470 | * @param
|
| 471 | * @retval 0: success
|
| 472 | * @retval other: fail
|
| 473 | */
|
hong.liu | d241707 | 2025-06-27 07:10:37 -0700 | [diff] [blame] | 474 | int32_t gsw_gnss_start(void)
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 475 | {
|
| 476 | int ret;
|
zw.wang | bc534c0 | 2025-06-26 09:31:44 +0800 | [diff] [blame] | 477 | if(!inited)
|
hong.liu | d241707 | 2025-06-27 07:10:37 -0700 | [diff] [blame] | 478 | return GSW_HAL_NORMAL_FAIL;
|
zw.wang | bc534c0 | 2025-06-26 09:31:44 +0800 | [diff] [blame] | 479 | ret = system("/usr/sbin/gnss_gpio.sh on > /dev/null 2>&1");
|
| 480 | if(ret != 0)
|
| 481 | {
|
| 482 | LOGE("[GSW_gnss] gnss_gpio.sh on fail.ret = [%d]", ret);
|
hong.liu | d241707 | 2025-06-27 07:10:37 -0700 | [diff] [blame] | 483 | return GSW_HAL_NORMAL_FAIL;
|
zw.wang | bc534c0 | 2025-06-26 09:31:44 +0800 | [diff] [blame] | 484 | }
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 485 | mbtk_gnss_open=(int(*)(int,int))dlsym(dlHandle_gnss, "mbtk_gnss_open");
|
| 486 | ret = mbtk_gnss_open(255, QSER_GNSS_TIMEOUT);
|
| 487 | if(ret != 0)
|
| 488 | {
|
| 489 | LOGE("[GSW_gnss] mbtk_gnss_open is error.ret = [%d]", ret);
|
hong.liu | d241707 | 2025-06-27 07:10:37 -0700 | [diff] [blame] | 490 | return GSW_HAL_NORMAL_FAIL;
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 491 | }
|
zw.wang | 89c1824 | 2025-06-24 19:07:10 +0800 | [diff] [blame] | 492 |
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 493 | strated = true;
|
zw.wang | 7aa3406 | 2025-06-27 17:54:55 +0800 | [diff] [blame] | 494 | /*
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 495 | if (gnss_freq > 0)
|
| 496 | gsw_gnss_set_freq(gnss_freq);
|
| 497 | if (gnss_startmode >= 0)
|
| 498 | gsw_gnss_set_start_mode(gnss_startmode);
|
| 499 | if (gnss_switch_op > 0)
|
| 500 | gsw_gnss_epo_switch(gnss_switch_op);
|
zw.wang | 7aa3406 | 2025-06-27 17:54:55 +0800 | [diff] [blame] | 501 | */
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 502 | mbtk_gnss_set_VTG();
|
| 503 |
|
| 504 | return GSW_HAL_SUCCESS;
|
| 505 | }
|
| 506 |
|
| 507 | /**
|
| 508 | * @brief SDK interface to stop gnss
|
| 509 | * @param
|
| 510 | * @retval 0: success
|
| 511 | * @retval other: fail
|
| 512 | */
|
hong.liu | d241707 | 2025-06-27 07:10:37 -0700 | [diff] [blame] | 513 | int32_t gsw_gnss_stop(void)
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 514 | {
|
| 515 | int ret;
|
zw.wang | bc534c0 | 2025-06-26 09:31:44 +0800 | [diff] [blame] | 516 | if(!inited)
|
hong.liu | d241707 | 2025-06-27 07:10:37 -0700 | [diff] [blame] | 517 | return GSW_HAL_NORMAL_FAIL;
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 518 | mbtk_gnss_close=(int(*)(int))dlsym(dlHandle_gnss, "mbtk_gnss_close");
|
| 519 | ret = mbtk_gnss_close(QSER_GNSS_TIMEOUT);
|
| 520 | if(ret != 0)
|
| 521 | {
|
| 522 | LOGE("[GSW_gnss] mbtk_gnss_close is error.ret = [%d]", ret);
|
hong.liu | d241707 | 2025-06-27 07:10:37 -0700 | [diff] [blame] | 523 | return GSW_HAL_NORMAL_FAIL;
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 524 | }
|
zw.wang | bc534c0 | 2025-06-26 09:31:44 +0800 | [diff] [blame] | 525 | ret = system("/usr/sbin/gnss_gpio.sh off > /dev/null 2>&1");
|
| 526 | if(ret != 0)
|
| 527 | {
|
| 528 | LOGE("[GSW_gnss] gnss_gpio.sh off fail.ret = [%d]", ret);
|
hong.liu | d241707 | 2025-06-27 07:10:37 -0700 | [diff] [blame] | 529 | return GSW_HAL_NORMAL_FAIL;
|
zw.wang | bc534c0 | 2025-06-26 09:31:44 +0800 | [diff] [blame] | 530 | }
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 531 | strated = false;
|
| 532 | return GSW_HAL_SUCCESS;
|
| 533 | }
|
| 534 |
|
| 535 | /**
|
| 536 | * @brief SDK interface to de initialization gnss
|
| 537 | * @param
|
| 538 | * @retval 0: success
|
| 539 | * @retval other: fail
|
| 540 | */
|
hong.liu | d241707 | 2025-06-27 07:10:37 -0700 | [diff] [blame] | 541 | int32_t gsw_gnss_deinit(void)
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 542 | {
|
| 543 | int ret;
|
zw.wang | bc534c0 | 2025-06-26 09:31:44 +0800 | [diff] [blame] | 544 | if(!inited)
|
hong.liu | d241707 | 2025-06-27 07:10:37 -0700 | [diff] [blame] | 545 | return GSW_HAL_NORMAL_FAIL;
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 546 | if(inited)
|
| 547 | {
|
lichengzhang | a708917 | 2025-07-01 20:41:46 +0800 | [diff] [blame] | 548 | ret = system("serial_atcmd AT*IMLCONFIG=12");
|
| 549 | if(ret != 0)
|
| 550 | {
|
| 551 | LOGE("serial_atcmd fail\n");
|
| 552 | return GSW_HAL_NORMAL_FAIL;
|
| 553 | }
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 554 | mbtk_gnss_deinit=(int(*)())dlsym(dlHandle_gnss, "mbtk_gnss_deinit");
|
| 555 | ret = mbtk_gnss_deinit();
|
| 556 | if(ret == 0)
|
| 557 | {
|
| 558 | inited = false;
|
| 559 | }
|
| 560 | else
|
| 561 | {
|
zw.wang | 1907e8f | 2025-07-01 16:26:39 +0800 | [diff] [blame] | 562 | LOGE("[GSW_gnss] mbtk_gnss_deinit() fail.ret = [%d]", ret);
|
| 563 | /*
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 564 | dlclose(dlHandle_gnss);
|
| 565 | dlHandle_gnss = NULL;
|
zw.wang | 1907e8f | 2025-07-01 16:26:39 +0800 | [diff] [blame] | 566 | */
|
hong.liu | d241707 | 2025-06-27 07:10:37 -0700 | [diff] [blame] | 567 | return GSW_HAL_NORMAL_FAIL;
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 568 | }
|
| 569 | }
|
| 570 |
|
zw.wang | 1907e8f | 2025-07-01 16:26:39 +0800 | [diff] [blame] | 571 | /*
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 572 | dlclose(dlHandle_gnss);
|
| 573 | dlHandle_gnss = NULL;
|
zw.wang | 1907e8f | 2025-07-01 16:26:39 +0800 | [diff] [blame] | 574 | */
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 575 | gnss_freq = -1;
|
| 576 | gnss_startmode = -1;
|
| 577 | gnss_switch_op = -1;
|
| 578 | return GSW_HAL_SUCCESS;
|
| 579 | }
|
| 580 |
|
zw.wang | 75e98ea | 2025-05-29 17:57:38 +0800 | [diff] [blame] | 581 | int gsw_gnss_add_lib(void)
|
| 582 | {
|
| 583 | return GSW_HAL_SUCCESS;
|
| 584 | }
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 585 |
|
| 586 | /**
|
| 587 | * @brief SDK interface to enable XTRA switch
|
| 588 | * @param [in] state
|
| 589 | * @retval 0: success
|
| 590 | * @retval other: fail
|
| 591 | */
|
hong.liu | d241707 | 2025-06-27 07:10:37 -0700 | [diff] [blame] | 592 | int32_t gsw_gnss_xtra_is_enable(gsw_xtra_state_e state)
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 593 | {
|
| 594 | return GSW_HAL_SUCCESS;
|
| 595 | }
|
| 596 |
|
| 597 | /**
|
| 598 | * @brief SDK interface to delete aiding data,delete aiding data for cold start(1-H,2-W,3-C)
|
| 599 | * @param [in] switch_op
|
| 600 | * @retval 0: success
|
| 601 | * @retval other: fail
|
| 602 | */
|
hong.liu | d241707 | 2025-06-27 07:10:37 -0700 | [diff] [blame] | 603 | int32_t gsw_gnss_delete_aiding_data(unsigned int flags) /*1-don`t delete == hot_start ; 2-delete EPH == warm start ; 3-delete all == cold start*/
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 604 | {
|
zw.wang | bc534c0 | 2025-06-26 09:31:44 +0800 | [diff] [blame] | 605 | if(!inited)
|
hong.liu | d241707 | 2025-06-27 07:10:37 -0700 | [diff] [blame] | 606 | return GSW_HAL_NORMAL_FAIL;
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 607 | int ret;
|
| 608 | char param_buf[32] = {0};
|
| 609 | snprintf(param_buf, 32, "$RESET,%u", flags);
|
| 610 | mbtk_gnss_setting=(int(*)(const char *setting_cmd, int))dlsym(dlHandle_gnss, "mbtk_gnss_setting");
|
| 611 | ret = mbtk_gnss_setting(param_buf, QSER_GNSS_TIMEOUT);
|
| 612 | if(ret != 0)
|
| 613 | {
|
| 614 | LOGE("[qser_gnss] mbtk_gnss_setting fail.ret = [%d]", ret);
|
hong.liu | d241707 | 2025-06-27 07:10:37 -0700 | [diff] [blame] | 615 | return GSW_HAL_NORMAL_FAIL;
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 616 | }
|
| 617 | return GSW_HAL_SUCCESS;
|
| 618 | }
|
| 619 |
|
| 620 | /**
|
| 621 | * @brief init and configure gps
|
| 622 | * @param [in] init_configure
|
| 623 | * @retval 0: success
|
| 624 | * @retval other: fail
|
| 625 | */
|
hong.liu | d241707 | 2025-06-27 07:10:37 -0700 | [diff] [blame] | 626 | int32_t gsw_gnss_init_configure_gps(gsw_gnss_init_configure_t init_configure)
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 627 | {
|
| 628 | return GSW_HAL_SUCCESS;
|
| 629 | }
|
hong.liu | d241707 | 2025-06-27 07:10:37 -0700 | [diff] [blame] | 630 |
|
| 631 | int gsw_gnss_get_tail_nmea_type(char *tail_type, int len)
|
| 632 | {
|
| 633 | if(NULL == tail_type){
|
| 634 | LOGE("get_tail_nmea_type fail, tail_type is NULL");
|
| 635 | return GSW_HAL_ERROR_GNSS_FAIL;
|
| 636 | }
|
| 637 |
|
| 638 | if(len >= 3){
|
| 639 | strcpy(tail_type, "RMC");
|
| 640 | return GSW_HAL_GNSS_SUCCESS;
|
| 641 | }else{
|
| 642 | LOGE("get_tail_nmea_type fail, len[%d] is too short", len);
|
| 643 | return GSW_HAL_ERROR_GNSS_FAIL;
|
| 644 | }
|
| 645 | }
|