#include <stdio.h> | |
#include <string.h> | |
#include <strings.h> | |
#include <stdlib.h> | |
#include <errno.h> | |
#include <fcntl.h> | |
#include <signal.h> | |
#include <sys/types.h> | |
#include <unistd.h> | |
#include <pthread.h> | |
#include <termios.h> | |
#include <time.h> | |
#include <sys/ioctl.h> | |
#include <dlfcn.h> | |
#include <stdint.h> | |
#include <stdbool.h> | |
#include "gsw_gnss_interface.h" | |
#define MBTK_GNSS_IND_LOCATION (1) // 1 | |
#define MBTK_GNSS_IND_NMEA (1 << 1) // 2 | |
#define QSER_GNSS_TIMEOUT 5 | |
#ifndef LOG_ERR_LEVEL | |
#define LOG_ERR_LEVEL 3 /* error conditions */ | |
#endif | |
#ifndef LOG_WARN_LEVEL | |
#define LOG_WARN_LEVEL 4 /* warning conditions */ | |
#endif | |
#ifndef LOG_INFO_LEVEL | |
#define LOG_INFO_LEVEL 6 /* informational */ | |
#endif | |
#ifndef LOG_DEBUG_LEVEL | |
#define LOG_DEBUG_LEVEL 7 /* debug-level messages */ | |
#endif | |
#ifndef LOG_VERBOSE_LEVEL | |
#define LOG_VERBOSE_LEVEL 8 | |
#endif | |
#define GSW_GNSS "[HAL][GSW_GNSS]" | |
#define LOGV(fmt, args ...) \ | |
do{ \ | |
char *file_ptr_1001 = __FILE__; \ | |
char *ptr_1001 = file_ptr_1001 + strlen(file_ptr_1001) - 1; \ | |
char line_1001[10] = {0}; \ | |
sprintf(line_1001, "%d", __LINE__); \ | |
while(ptr_1001 >= file_ptr_1001 && *ptr_1001){ \ | |
if(*ptr_1001 == '/') \ | |
break; \ | |
ptr_1001--; \ | |
} \ | |
fun_ptr_log(LOG_VERBOSE_LEVEL, "%s#%s: "GSW_GNSS"" fmt, ptr_1001 + 1, line_1001, ##args); \ | |
} while(0) | |
#define LOGI(fmt, args...) \ | |
do{ \ | |
char *file_ptr_1001 = __FILE__; \ | |
char *ptr_1001 = file_ptr_1001 + strlen(file_ptr_1001) - 1; \ | |
char line_1001[10] = {0}; \ | |
sprintf(line_1001, "%d", __LINE__); \ | |
while(ptr_1001 >= file_ptr_1001 && *ptr_1001){ \ | |
if(*ptr_1001 == '/') \ | |
break; \ | |
ptr_1001--; \ | |
} \ | |
fun_ptr_log(LOG_INFO_LEVEL, "%s#%s: "GSW_GNSS"" fmt, ptr_1001 + 1, line_1001, ##args); \ | |
} while(0) | |
#define LOGD(fmt, args...) \ | |
do{ \ | |
char *file_ptr_1001 = __FILE__; \ | |
char *ptr_1001 = file_ptr_1001 + strlen(file_ptr_1001) - 1; \ | |
char line_1001[10] = {0}; \ | |
sprintf(line_1001, "%d", __LINE__); \ | |
while(ptr_1001 >= file_ptr_1001 && *ptr_1001){ \ | |
if(*ptr_1001 == '/') \ | |
break; \ | |
ptr_1001--; \ | |
} \ | |
fun_ptr_log(LOG_DEBUG_LEVEL, "%s#%s: "GSW_GNSS"" fmt, ptr_1001 + 1, line_1001, ##args); \ | |
} while(0) | |
#define LOGW(fmt, args...) \ | |
do{ \ | |
char *file_ptr_1001 = __FILE__; \ | |
char *ptr_1001 = file_ptr_1001 + strlen(file_ptr_1001) - 1; \ | |
char line_1001[10] = {0}; \ | |
sprintf(line_1001, "%d", __LINE__); \ | |
while(ptr_1001 >= file_ptr_1001 && *ptr_1001){ \ | |
if(*ptr_1001 == '/') \ | |
break; \ | |
ptr_1001--; \ | |
} \ | |
fun_ptr_log(LOG_WARN_LEVEL, "%s#%s: "GSW_GNSS"" fmt, ptr_1001 + 1, line_1001, ##args); \ | |
} while(0) | |
#define LOGE(fmt, args...) \ | |
do{ \ | |
char *file_ptr_1001 = __FILE__; \ | |
char *ptr_1001 = file_ptr_1001 + strlen(file_ptr_1001) - 1; \ | |
char line_1001[10] = {0}; \ | |
sprintf(line_1001, "%d", __LINE__); \ | |
while(ptr_1001 >= file_ptr_1001 && *ptr_1001){ \ | |
if(*ptr_1001 == '/') \ | |
break; \ | |
ptr_1001--; \ | |
} \ | |
fun_ptr_log(LOG_ERR_LEVEL, "%s#%s: "GSW_GNSS"" fmt, ptr_1001 + 1, line_1001, ##args); \ | |
} while(0) | |
#define MOPEN_GNSS_NMEA_MAX_LENGTH 255 /** NMEA string maximum length. */ | |
static gsw_gnss_cb *gsw_cb = NULL; | |
static bool inited = false; | |
static bool strated = false; | |
typedef void (*mbtk_gnss_callback_func)(uint32_t ind_type, const void* data, uint32_t data_len); | |
typedef void (*mbtk_log)(int level, const char *format,...); | |
static mbtk_log fun_ptr_log = NULL; | |
int (*mbtk_gnss_init)(mbtk_gnss_callback_func cb); | |
int (*mbtk_gnss_deinit)(); | |
int (*mbtk_gnss_ind_set)(uint32_t ,int); | |
int (*mbtk_gnss_open)(int, int); | |
int (*mbtk_gnss_close)(int); | |
int (*mbtk_gnss_setting)(const char *setting_cmd, int); | |
int (*mbtk_gnss_eph_download)(int); | |
int (*mbtk_gnss_eph_inject)(int); | |
int gnss_freq = -1; | |
GSW_GNSS_MODE_CONFIGURATION gnss_startmode = -1; | |
GSW_CONF_SWITCH gnss_switch_op = -1; | |
void *dlHandle_gnss; | |
char *lynqLib_gnss = "/lib/libmbtk_lib.so"; | |
typedef enum | |
{ | |
E_MT_LOC_MSG_ID_LOCATION_INFO = 1, /**< pv_data = & mopen_location_info_t */ | |
E_MT_LOC_MSG_ID_NMEA_INFO = 3, /**< pv_data = & mopen_gnss_nmea_info_t */ | |
} e_msg_id_t; | |
typedef struct | |
{ | |
int64_t timestamp; /**< System Timestamp, marked for when got the nmea data */ | |
int length; /**< NMEA string length. */ | |
char nmea[MOPEN_GNSS_NMEA_MAX_LENGTH + 1]; /**< NMEA string.*/ | |
}mopen_gnss_nmea_info_t; /* Message */ | |
typedef struct | |
{ | |
uint32_t size; /**< Set to the size of mcm_gps_location_t. */ | |
int flags; /**< Contains GPS location flags bits. */ | |
int position_source; /**< Provider indicator for HYBRID or GPS. */ //功能暂未实现,可不用添加进结构体 | |
double latitude; /**< Latitude in degrees. */ | |
double longitude; /**< Longitude in degrees. */ | |
double altitude; /**< Altitude in meters above the WGS 84 reference ellipsoid. */ | |
float speed; /**< Speed in meters per second. */ | |
float bearing; /**< Heading in degrees. */ //功能暂未实现,可不用添加进结构体 | |
float accuracy; /**< Expected accuracy in meters. */ //功能暂未实现,可不用添加进结构体 | |
int64_t timestamp; /**< Timestamp for the location fix in UTC million-second base. */ | |
int32_t is_indoor; /**< Location is indoors. */ //功能暂未实现,可不用添加进结构体 | |
float floor_number; /**< Indicates the floor number. */ | |
}mopen_location_info_t;//功能暂未实现,可不用添加进结构体 | |
typedef struct { | |
uint32_t flags; | |
double latitude; /**< Latitude in degrees. */ | |
double longitude; /**< Longitude in degrees. */ | |
double altitude; /**< Altitude in meters above the WGS 84 reference ellipsoid. */ | |
float speed; /**< Speed in meters per second. */ | |
float bearing; /**< Heading in degrees. */ | |
int64_t timestamp; /**< Timestamp for the location fix in UTC million-second base. */ | |
} mbtk_gnss_location_info_t; | |
typedef struct{ | |
GSW_GNSS_MODE_CONFIGURATION start_mode; | |
gnss_freq_type freq; | |
gsw_gnss_cb callback; | |
}gsw_gnss_init_configure_t; | |
typedef enum{ | |
MODE_GPS = 1, /**< GPS only */ | |
MODE_BEIDOU, /**< BEIDOU only*/ | |
MODE_GPS_BEIDOU, /**< GPS+BEIDOU */ | |
MODE_GLONASS, /**< GLONASS only */ | |
MODE_GPS_GLONASS, /**< GPS+GLONASS */ | |
MODE_GLONASS_BEIDOU, /**< GLONASS+BEIDOU */ /* The type does not support this type */ | |
MODE_GPS_GLONASS_BEIDOU, /**< GPS+GLONASS+BEIDOU */ /* The type does not support this type */ | |
MODE_GALILEO, /**< GALILEO only */ | |
MODE_GPS_GALILEO, /**< GPS+GALILEO */ | |
MODE_BEIDOU_GALILEO, /**< BEIDOU+GALILEO */ | |
MODE_GPS_BEIDOU_GALILEO, /**< GPS+BEIDOU+GALILEO */ | |
MODE_GLONASS_GALILEO, /**< GLONASS+GALILEO */ | |
MODE_GPS_GLONASS_GALILEO, /**< GPS+GLONASS+GALILEO */ | |
MODE_BEIDOU_GLONASS_GALILEO, /**< BEIDOU+GLONASS+GALILEO */ /* The type does not support this type */ | |
MODE_END = -1, /**< init value */ | |
}GSW_GNSS_MODE_CONFIGURATION_HD; | |
GSW_GNSS_MODE_CONFIGURATION_HD map_gnss_mode(GSW_GNSS_MODE_CONFIGURATION mode) | |
{ | |
switch (mode) | |
{ | |
case GSW_MODE_GPS_GLONASS: | |
return MODE_GPS_GLONASS; | |
case GSW_MODE_GPS_BEIDOU: | |
return MODE_GPS_BEIDOU; | |
case GSW_MODE_GPS_GLONASS_BEIDOU: | |
return MODE_END; | |
case GSW_MODE_GPS: | |
return MODE_GPS; | |
case GSW_MODE_BEIDOU: | |
return MODE_BEIDOU; | |
case GSW_MODE_GLONASS: | |
return MODE_GLONASS; | |
case GSW_MODE_GPS_GLONASS_BEIDOU_GALILEO: | |
return MODE_END; | |
case GSW_MODE_GPS_GALILEO: | |
return MODE_GPS_GALILEO; | |
case GSW_MODE_GPS_GLONASS_GALILEO: | |
return MODE_GPS_GLONASS_GALILEO; | |
case GSW_MODE_GPS_GALILEO_ONLY: | |
return MODE_GALILEO; | |
case GSW_MODE_GPS_GLONASS_BEIDOU_GALILEO_NAVIC: | |
return MODE_END; | |
case GSW_MODE_GNSS_END: | |
return MODE_END; | |
default: | |
return MODE_END; | |
} | |
} | |
int mbtk_gnss_set_VTG() | |
{ | |
int ret; | |
ret = system("/usr/sbin/gnss_gpio.sh VTG > /dev/null 2>&1"); | |
if(ret != 0) | |
{ | |
LOGE("[GSW_gnss] mbtk_gnss_set_VTG on fail.ret = [%d]", ret); | |
return GSW_HAL_NORMAL_FAIL; | |
} | |
return GSW_HAL_SUCCESS; | |
} | |
/** | |
* @brief SDK interface to set gnss sampling frequency, support 1Hz、2Hz、5Hz | |
* @param [in] freq | |
* @retval 0: success | |
* @retval other: fail | |
*/ | |
int gsw_gnss_set_freq(int freq) | |
{ | |
if(!inited) | |
return GSW_HAL_NORMAL_FAIL; | |
int ret; | |
if (!strated) | |
{ | |
gnss_freq = freq; | |
return GSW_HAL_SUCCESS; | |
} | |
char param_buf[32] = {0}; | |
snprintf(param_buf, 32, "$FREQCFG,%d", freq); | |
mbtk_gnss_setting=(int(*)(const char *setting_cmd, int))dlsym(dlHandle_gnss, "mbtk_gnss_setting"); | |
ret = mbtk_gnss_setting(param_buf, QSER_GNSS_TIMEOUT); | |
if(ret != 0) | |
{ | |
LOGE("[qser_gnss] mbtk_gnss_setting fail.ret = [%d]", ret); | |
return GSW_HAL_NORMAL_FAIL; | |
} | |
return GSW_HAL_SUCCESS; | |
} | |
/** | |
* @brief SDK interface to set gnss start mode,specific mode refreence GSW_HAL_GNSS_MODE_CONFIGURATION | |
* @param [in] start_mode | |
* @retval 0: success | |
* @retval other: fail | |
*/ | |
int32_t gsw_gnss_set_start_mode(GSW_GNSS_MODE_CONFIGURATION start_mode) | |
{ | |
if(!inited) | |
return GSW_HAL_NORMAL_FAIL; | |
int ret; | |
if (!strated) | |
{ | |
gnss_startmode = start_mode; | |
return GSW_HAL_SUCCESS; | |
} | |
char param_buf[32] = {0}; | |
snprintf(param_buf, 32, "$SYSCFG,%d", map_gnss_mode(start_mode)); | |
if(map_gnss_mode(start_mode) == -1) | |
{ | |
LOGE("[qser_gnss] mbtk_gnss_start_mode con't support"); | |
return GSW_HAL_NORMAL_FAIL; | |
} | |
mbtk_gnss_setting=(int(*)(const char *setting_cmd, int))dlsym(dlHandle_gnss, "mbtk_gnss_setting"); | |
ret = mbtk_gnss_setting(param_buf, QSER_GNSS_TIMEOUT); | |
if(ret != 0) | |
{ | |
LOGE("[qser_gnss] mbtk_gnss_setting fail.ret = [%d]", ret); | |
return GSW_HAL_NORMAL_FAIL; | |
} | |
return GSW_HAL_SUCCESS; | |
} | |
/** | |
* @brief SDK interface to set EPO switch if open or close | |
* @param [in] switch_op | |
* @retval 0: success | |
* @retval other: fail | |
*/ | |
int32_t gsw_gnss_epo_switch(GSW_CONF_SWITCH switch_op) | |
{ | |
if(!inited) | |
return GSW_HAL_NORMAL_FAIL; | |
int ret; | |
if (!strated) | |
{ | |
gnss_switch_op = switch_op; | |
return GSW_HAL_SUCCESS; | |
} | |
if(switch_op) | |
{ | |
mbtk_gnss_eph_download=(int(*)(int))dlsym(dlHandle_gnss, "mbtk_gnss_eph_download"); | |
ret = mbtk_gnss_eph_download(QSER_GNSS_TIMEOUT); | |
if(ret != 0) | |
{ | |
LOGE("[qser_gnss] mbtk_gnss_eph_download fail.ret = [%d]", ret); | |
return GSW_HAL_NORMAL_FAIL; | |
} | |
mbtk_gnss_eph_inject=(int(*)(int))dlsym(dlHandle_gnss, "mbtk_gnss_eph_inject"); | |
ret = mbtk_gnss_eph_inject(QSER_GNSS_TIMEOUT); | |
if(ret != 0) | |
{ | |
LOGE("[qser_gnss] mbtk_gnss_eph_inject fail.ret = [%d]", ret); | |
return GSW_HAL_NORMAL_FAIL; | |
} | |
} | |
return GSW_HAL_SUCCESS; | |
} | |
static void gnss_callback(uint32_t ind_type, const void* data, uint32_t data_len) | |
{ | |
if(data == NULL || data_len <= 0) | |
{ | |
LOGE("[GSW_gnss] data is NULL."); | |
return; | |
} | |
if(gsw_cb == NULL) | |
{ | |
//LOGE("[qser_gnss] qser_gnss_callback is NULL."); | |
return; | |
} | |
if(ind_type == MBTK_GNSS_IND_LOCATION && gsw_cb->gsw_location_cb != NULL) { | |
if(data_len != sizeof(mbtk_gnss_location_info_t)) | |
{ | |
LOGE("[GSW_gnss] data size error"); | |
return; | |
} | |
GSW_GNSS_LOCATION_EXT_T gsw_location; | |
GSW_GNSS_LOCATION_T gsw_location_t = {0}; | |
mbtk_gnss_location_info_t *locl_info = (mbtk_gnss_location_info_t *)data; | |
gsw_location_t.altitude = locl_info->altitude; | |
gsw_location_t.latitude = locl_info->latitude; | |
gsw_location_t.longitude = locl_info->longitude; | |
gsw_location_t.speed = locl_info->speed; | |
gsw_location_t.bearing = locl_info->bearing; | |
gsw_location_t.timestamp = locl_info->timestamp; | |
gsw_location_t.flags = locl_info->flags; | |
gsw_location.legacyLocation = gsw_location_t; | |
gsw_cb->gsw_location_cb(&gsw_location); | |
} else if(ind_type == MBTK_GNSS_IND_NMEA && gsw_cb->gsw_nmea_cb != NULL) { | |
mopen_gnss_nmea_info_t qser_nmea = {0}; | |
memset(&qser_nmea, 0x0, sizeof(mopen_gnss_nmea_info_t)); | |
qser_nmea.length = data_len; | |
memcpy(qser_nmea.nmea, (char *)data, data_len); | |
//qser_nmea.timestamp = qser_get_gnss_time_sec(data, data_len); | |
gsw_cb->gsw_nmea_cb(data,data_len); | |
} else { | |
LOGD("Unknown IND : %d\n", ind_type); | |
} | |
} | |
int32_t gsw_gnss_init(void) | |
{ | |
int ret; | |
if(!inited) | |
{ | |
ret = system("serial_atcmd AT*IMLCONFIG=13"); | |
if(ret != 0) | |
{ | |
LOGE("serial_atcmd fail\n"); | |
return GSW_HAL_NORMAL_FAIL; | |
} | |
if(dlHandle_gnss == NULL) | |
dlHandle_gnss = dlopen(lynqLib_gnss, RTLD_NOW); | |
if(fun_ptr_log == NULL) | |
fun_ptr_log = (mbtk_log)dlsym(dlHandle_gnss, "mbtk_log"); | |
if(fun_ptr_log == NULL || dlHandle_gnss == NULL) | |
{ | |
return GSW_HAL_NORMAL_FAIL; | |
} | |
mbtk_gnss_init=(int(*)(mbtk_gnss_callback_func))dlsym(dlHandle_gnss, "mbtk_gnss_init"); | |
ret = mbtk_gnss_init(gnss_callback); | |
if(ret == 0) | |
{ | |
mbtk_gnss_ind_set=(int(*)(uint32_t ,int))dlsym(dlHandle_gnss, "mbtk_gnss_ind_set"); | |
ret = mbtk_gnss_ind_set(MBTK_GNSS_IND_NMEA |MBTK_GNSS_IND_LOCATION, QSER_GNSS_TIMEOUT); | |
if(ret == 0) | |
{ | |
inited = true; | |
} | |
else | |
{ | |
LOGE("[GSW_gnss] init mbtk_gnss_ind_set() fail.ret = [%d]", ret); | |
return GSW_HAL_NORMAL_FAIL; | |
} | |
} | |
else | |
{ | |
LOGE("[GSW_gnss] mbtk_gnss_init() fail.ret = [%d]", ret); | |
return GSW_HAL_NORMAL_FAIL; | |
} | |
} | |
return GSW_HAL_SUCCESS; | |
} | |
/** | |
* @brief SDK interface to registered callback function | |
* @param [in] callback | |
* @retval 0: success | |
* @retval other: fail | |
*/ | |
int32_t gsw_gnss_reg_cb_group(gsw_gnss_cb callback) | |
{ | |
if(!inited) | |
return GSW_HAL_NORMAL_FAIL; | |
if(callback.gsw_location_cb == NULL && callback.gsw_nmea_cb == NULL) | |
{ | |
LOGE("[GSW_gnss] handler_ptr is NULL."); | |
return GSW_HAL_NORMAL_FAIL; | |
} | |
if (gsw_cb == NULL) | |
{ | |
gsw_cb = (gsw_gnss_cb *)malloc(sizeof(gsw_gnss_cb)); | |
if (gsw_cb == NULL) | |
{ | |
LOGE("[GSW_gnss] Memory allocation failed."); | |
return GSW_HAL_NORMAL_FAIL; | |
} | |
} | |
gsw_cb->gsw_location_cb = callback.gsw_location_cb; | |
gsw_cb->gsw_nmea_cb = callback.gsw_nmea_cb; | |
return GSW_HAL_SUCCESS; | |
} | |
/** | |
* @brief SDK interface to start gnss | |
* @param | |
* @retval 0: success | |
* @retval other: fail | |
*/ | |
int32_t gsw_gnss_start(void) | |
{ | |
int ret; | |
if(!inited) | |
return GSW_HAL_NORMAL_FAIL; | |
ret = system("/usr/sbin/gnss_gpio.sh on > /dev/null 2>&1"); | |
if(ret != 0) | |
{ | |
LOGE("[GSW_gnss] gnss_gpio.sh on fail.ret = [%d]", ret); | |
return GSW_HAL_NORMAL_FAIL; | |
} | |
// 记录mbtk_gnss_open前的时间戳 | |
struct timespec start_time; | |
if (clock_gettime(CLOCK_MONOTONIC, &start_time) != 0) { | |
LOGE("[GSW_gnss] Failed to get start time"); | |
return GSW_HAL_NORMAL_FAIL; | |
} | |
mbtk_gnss_open=(int(*)(int,int))dlsym(dlHandle_gnss, "mbtk_gnss_open"); | |
ret = mbtk_gnss_open(255, QSER_GNSS_TIMEOUT); | |
if(ret != 0) | |
{ | |
LOGE("[GSW_gnss] mbtk_gnss_open is error.ret = [%d]", ret); | |
return GSW_HAL_NORMAL_FAIL; | |
} | |
strated = true; | |
/* | |
if (gnss_freq > 0) | |
gsw_gnss_set_freq(gnss_freq); | |
if (gnss_startmode >= 0) | |
gsw_gnss_set_start_mode(gnss_startmode); | |
if (gnss_switch_op > 0) | |
gsw_gnss_epo_switch(gnss_switch_op); | |
*/ | |
// 记录mbtk_gnss_set_VTG前的时间戳并计算等待时间 | |
struct timespec end_time; | |
if (clock_gettime(CLOCK_MONOTONIC, &end_time) != 0) { | |
LOGE("[GSW_gnss] Failed to get end time"); | |
return GSW_HAL_NORMAL_FAIL; | |
} | |
long start_ms = start_time.tv_sec * 1000 + start_time.tv_nsec / 1000000; | |
long end_ms = end_time.tv_sec * 1000 + end_time.tv_nsec / 1000000; | |
long diff_ms = end_ms - start_ms; | |
if (diff_ms < 700) { | |
long wait_ms = 700 - diff_ms; | |
usleep(wait_ms * 1000); // 转换为微秒等待 | |
} | |
mbtk_gnss_set_VTG(); | |
return GSW_HAL_SUCCESS; | |
} | |
/** | |
* @brief SDK interface to stop gnss | |
* @param | |
* @retval 0: success | |
* @retval other: fail | |
*/ | |
int32_t gsw_gnss_stop(void) | |
{ | |
int ret; | |
if(!inited) | |
return GSW_HAL_NORMAL_FAIL; | |
mbtk_gnss_close=(int(*)(int))dlsym(dlHandle_gnss, "mbtk_gnss_close"); | |
ret = mbtk_gnss_close(QSER_GNSS_TIMEOUT); | |
if(ret != 0) | |
{ | |
LOGE("[GSW_gnss] mbtk_gnss_close is error.ret = [%d]", ret); | |
return GSW_HAL_NORMAL_FAIL; | |
} | |
ret = system("/usr/sbin/gnss_gpio.sh off > /dev/null 2>&1"); | |
if(ret != 0) | |
{ | |
LOGE("[GSW_gnss] gnss_gpio.sh off fail.ret = [%d]", ret); | |
return GSW_HAL_NORMAL_FAIL; | |
} | |
strated = false; | |
return GSW_HAL_SUCCESS; | |
} | |
/** | |
* @brief SDK interface to de initialization gnss | |
* @param | |
* @retval 0: success | |
* @retval other: fail | |
*/ | |
int32_t gsw_gnss_deinit(void) | |
{ | |
int ret; | |
if(!inited) | |
return GSW_HAL_NORMAL_FAIL; | |
if(inited) | |
{ | |
ret = system("serial_atcmd AT*IMLCONFIG=12"); | |
if(ret != 0) | |
{ | |
LOGE("serial_atcmd fail\n"); | |
return GSW_HAL_NORMAL_FAIL; | |
} | |
mbtk_gnss_deinit=(int(*)())dlsym(dlHandle_gnss, "mbtk_gnss_deinit"); | |
ret = mbtk_gnss_deinit(); | |
if(ret == 0) | |
{ | |
inited = false; | |
} | |
else | |
{ | |
LOGE("[GSW_gnss] mbtk_gnss_deinit() fail.ret = [%d]", ret); | |
/* | |
dlclose(dlHandle_gnss); | |
dlHandle_gnss = NULL; | |
*/ | |
return GSW_HAL_NORMAL_FAIL; | |
} | |
} | |
/* | |
dlclose(dlHandle_gnss); | |
dlHandle_gnss = NULL; | |
*/ | |
gnss_freq = -1; | |
gnss_startmode = -1; | |
gnss_switch_op = -1; | |
return GSW_HAL_SUCCESS; | |
} | |
int gsw_gnss_add_lib(void) | |
{ | |
return GSW_HAL_SUCCESS; | |
} | |
/** | |
* @brief SDK interface to enable XTRA switch | |
* @param [in] state | |
* @retval 0: success | |
* @retval other: fail | |
*/ | |
int32_t gsw_gnss_xtra_is_enable(gsw_xtra_state_e state) | |
{ | |
return GSW_HAL_SUCCESS; | |
} | |
/** | |
* @brief SDK interface to delete aiding data,delete aiding data for cold start(1-H,2-W,3-C) | |
* @param [in] switch_op | |
* @retval 0: success | |
* @retval other: fail | |
*/ | |
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*/ | |
{ | |
if(!inited) | |
return GSW_HAL_NORMAL_FAIL; | |
int ret; | |
char param_buf[32] = {0}; | |
snprintf(param_buf, 32, "$RESET,%u", flags); | |
mbtk_gnss_setting=(int(*)(const char *setting_cmd, int))dlsym(dlHandle_gnss, "mbtk_gnss_setting"); | |
ret = mbtk_gnss_setting(param_buf, QSER_GNSS_TIMEOUT); | |
if(ret != 0) | |
{ | |
LOGE("[qser_gnss] mbtk_gnss_setting fail.ret = [%d]", ret); | |
return GSW_HAL_NORMAL_FAIL; | |
} | |
return GSW_HAL_SUCCESS; | |
} | |
/** | |
* @brief init and configure gps | |
* @param [in] init_configure | |
* @retval 0: success | |
* @retval other: fail | |
*/ | |
int32_t gsw_gnss_init_configure_gps(gsw_gnss_init_configure_t init_configure) | |
{ | |
return GSW_HAL_SUCCESS; | |
} | |
int gsw_gnss_get_tail_nmea_type(char *tail_type, int len) | |
{ | |
if(NULL == tail_type){ | |
LOGE("get_tail_nmea_type fail, tail_type is NULL"); | |
return GSW_HAL_ERROR_GNSS_FAIL; | |
} | |
if(len >= 3){ | |
strcpy(tail_type, "RMC"); | |
return GSW_HAL_GNSS_SUCCESS; | |
}else{ | |
LOGE("get_tail_nmea_type fail, len[%d] is too short", len); | |
return GSW_HAL_ERROR_GNSS_FAIL; | |
} | |
} |