#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> | |
typedef struct | |
{ | |
/**< set to sizeof(GpsLocation) */ | |
size_t size; | |
/**< Contains GpsLocationFlags bits. */ | |
unsigned short int flags; | |
/**< Represents latitude in degrees. */ | |
double latitude; | |
/**< Represents longitude in degrees. */ | |
double longitude; | |
/**< Represents altitude in meters above the WGS 84 reference ellipsoid. */ | |
double altitude; | |
/**< Represents speed in meters per second. */ | |
float speed; | |
/**< Represents heading in degrees. */ | |
float bearing; | |
/**< Represents expected accuracy in meters. */ | |
float accuracy; | |
/**< Timestamp for the location fix. */ | |
long long int timestamp; | |
}GSW_GNSS_LOCATION_T; | |
typedef struct { | |
GSW_GNSS_LOCATION_T legacyLocation; | |
float horizontalAccuracyMeters; | |
/**< Represents expected vertical position accuracy in meters | |
* (68% confidence).*/ | |
float verticalAccuracyMeters; | |
/**< Represents expected speed accuracy in meter per seconds | |
* (68% confidence).*/ | |
float speedAccuracyMetersPerSecond; | |
/**< Represents expected bearing accuracy in degrees | |
* (68% confidence).*/ | |
float bearingAccuracyDegrees; | |
}GSW_GNSS_LOCATION_EXT_T; | |
typedef enum{ | |
GSW_SWITCH_DISABLE = 0, /**< configuration switch disable :0 */ | |
GSW_SWITCH_ENABLE /**< configuration switch enable :1 */ | |
}GSW_GNSS_CONF_SWITCH; | |
typedef enum{ | |
GSW_MODE_GPS = 1, /**< GPS only */ | |
GSW_MODE_BEIDOU, /**< BEIDOU only*/ | |
GSW_MODE_GPS_BEIDOU, /**< GPS+BEIDOU */ | |
GSW_MODE_GLONASS, /**< GLONASS only */ /* The high-tech platform does not support this type */ | |
GSW_MODE_GPS_GLONASS, /**< GPS+GLONASS */ | |
GSW_MODE_GLONASS_BEIDOU, /**< GLONASS+BEIDOU */ /* The high-tech platform does not support this type */ | |
GSW_MODE_GPS_GLONASS_BEIDOU, /**< GPS+GLONASS+BEIDOU */ /* The high-tech platform does not support this type */ | |
GSW_MODE_GALILEO, /**< GALILEO only */ | |
GSW_MODE_GPS_GALILEO, /**< GPS+GALILEO */ | |
GSW_MODE_BEIDOU_GALILEO, /**< BEIDOU+GALILEO */ | |
GSW_MODE_GPS_BEIDOU_GALILEO, /**< GPS+BEIDOU+GALILEO */ | |
GSW_MODE_GLONASS_GALILEO, /**< GLONASS+GALILEO */ | |
GSW_MODE_GPS_GLONASS_GALILEO, /**< GPS+GLONASS+GALILEO */ | |
GSW_MODE_BEIDOU_GLONASS_GALILEO, /**< BEIDOU+GLONASS+GALILEO */ /* The high-tech platform does not support this type */ | |
}GSW_GNSS_MODE_CONFIGURATION; | |
typedef void (*gsw_gnss_location_callback_ext)(GSW_GNSS_LOCATION_EXT_T* location); | |
typedef void (*gsw_gnss_nmea_callback )(const char* nmea, int length); | |
typedef struct{ | |
gsw_gnss_location_callback_ext gsw_location_cb; | |
gsw_gnss_nmea_callback gsw_nmea_cb; | |
}gsw_gnss_cb; | |
typedef enum { | |
GNSS_FREQ_1HZ = 1, /**< 1Hz */ | |
GNSS_FREQ_2HZ = 2, /**< 2Hz */ | |
GNSS_FREQ_5HZ = 5, /**< 5Hz */ | |
GNSS_FREQ_10HZ = 10, /**< 10Hz */ | |
} gnss_freq_type; | |
typedef struct{ | |
GSW_GNSS_MODE_CONFIGURATION start_mode; | |
gnss_freq_type freq; | |
gsw_gnss_cb callback; | |
}gsw_gnss_init_configure_t; | |
int (*gsw_gnss_set_freq)(int freq); | |
int (*gsw_gnss_init)(void); | |
int (*gsw_gnss_start)(void); | |
int (*gsw_gnss_stop)(void); | |
int (*gsw_gnss_deinit)(void); | |
int (*gsw_gnss_add_lib)(void); | |
int (*gsw_gnss_set_start_mode)(GSW_GNSS_MODE_CONFIGURATION start_mode); | |
int (*gsw_gnss_epo_switch)(GSW_GNSS_CONF_SWITCH switch_op); | |
int (*gsw_gnss_reg_cb_group)(gsw_gnss_cb callback); | |
//int (*gsw_gnss_xtra_is_enable)(gsw_xtra_state_e state); | |
int (*gsw_gnss_delete_aiding_data)(unsigned int flags); | |
int (*gsw_gnss_init_configure_gps)(gsw_gnss_init_configure_t init_configure); | |
void *dlHandle_gnss_test; | |
char *lynqLib_gnss_test = "/lib/libgsw_lib.so"; | |
void tmp_gnss_callack(const char* nmea, int length) | |
{ | |
printf("%s",nmea); | |
} | |
void tmp_location_gnss_callack(GSW_GNSS_LOCATION_EXT_T* location) | |
{ | |
printf("Location Info:\n"); | |
printf(" Size: %zu\n", location->legacyLocation.size); | |
printf(" Flags: %hu\n", location->legacyLocation.flags); | |
printf(" Latitude: %.6lf°\n", location->legacyLocation.latitude); | |
printf(" Longitude: %.6lf°\n", location->legacyLocation.longitude); | |
printf(" Altitude: %.2lf m\n", location->legacyLocation.altitude); | |
printf(" Speed: %.2f m/s\n", location->legacyLocation.speed); | |
printf(" Bearing: %.1f°\n", location->legacyLocation.bearing); | |
printf(" Accuracy: %.2f m\n", location->legacyLocation.accuracy); | |
printf(" Timestamp: %lld\n", location->legacyLocation.timestamp); | |
printf("Extended Accuracy:\n"); | |
printf(" Horizontal: %.2f m (68%%)\n", location->horizontalAccuracyMeters); | |
printf(" Vertical: %.2f m (68%%)\n", location->verticalAccuracyMeters); | |
printf(" Speed: %.2f m/s (68%%)\n", location->speedAccuracyMetersPerSecond); | |
printf(" Bearing: %.1f° (68%%)\n", location->bearingAccuracyDegrees); | |
} | |
gsw_gnss_cb tmp_ptr = { | |
tmp_location_gnss_callack, | |
tmp_gnss_callack | |
}; | |
void user_help(void) | |
{ | |
printf("\t-1 exit\n" | |
"\t1 gnss init\n" | |
"\t2 gnss deinit \n" | |
"\t3 gnss reg_cb\n" | |
"\t6 gnss start\n" | |
"\t7 gnss stop\n" | |
"\t8 gnss Delete_Aiding_Data and reset\n" | |
"\t9 gnss epo switch\n" | |
"\t10 gnss set startmode\n" | |
"\t11 gnss set frequency\n" | |
"please input operator: >> "); | |
} | |
void delete_type(void) | |
{ | |
printf("\t1 DELETE_NOTHING\n" | |
"\t2 DELETE_EPHEMERIS\n" | |
"\t3 DELETE_ALL\n" | |
"please input operator: >> "); | |
} | |
int main(void) | |
{ | |
int ret; | |
int opt = 0; | |
dlHandle_gnss_test = dlopen(lynqLib_gnss_test, RTLD_NOW); | |
gsw_gnss_add_lib=(int(*)())dlsym(dlHandle_gnss_test, "gsw_gnss_add_lib"); | |
ret = gsw_gnss_add_lib(); | |
if(ret < 0) | |
{ | |
printf("gsw_gnss_add_lib FAIL.\n"); | |
return -1; | |
} | |
while(1) | |
{ | |
printf("=========gnss main=========\n"); | |
user_help(); | |
if (scanf("%d", &opt) != 1) | |
{ | |
printf("Input error, please check it\n"); | |
while (getchar() != '\n'); | |
continue; | |
} | |
while(getchar()!='\n'); | |
switch (opt) | |
{ | |
case -1: | |
{ | |
printf("main exit\n"); | |
return 0; | |
} | |
case 1: | |
{ | |
gsw_gnss_init=(int(*)())dlsym(dlHandle_gnss_test, "gsw_gnss_init"); | |
ret = gsw_gnss_init(); | |
if(ret < 0) | |
{ | |
printf("gsw_gnss_init FAIL.\n"); | |
return -1; | |
} | |
printf("gsw_gnss_init success.\n"); | |
break; | |
} | |
case 2: | |
{ | |
gsw_gnss_deinit=(int(*)())dlsym(dlHandle_gnss_test, "gsw_gnss_deinit"); | |
ret =gsw_gnss_deinit(); | |
if(ret < 0) | |
{ | |
printf("gsw_gnss_deinit FAIL.\n"); | |
return -1; | |
} | |
printf("gsw_gnss_deinit success \n"); | |
break; | |
} | |
case 3: | |
{ | |
gsw_gnss_reg_cb_group=(int(*)(gsw_gnss_cb))dlsym(dlHandle_gnss_test, "gsw_gnss_reg_cb_group"); | |
ret =gsw_gnss_reg_cb_group(tmp_ptr); | |
if(ret < 0) | |
{ | |
printf("gsw_gnss_reg_cb_group FAIL.\n"); | |
return -1; | |
} | |
printf("gsw_gnss_reg_cb_group success \n"); | |
break; | |
} | |
// case 4: | |
// { | |
// qser_Gnss_Deinit=(int(*)(uint32_t))dlsym(dlHandle_gnss, "qser_Gnss_Deinit"); | |
// ret =qser_Gnss_Deinit(ph_gnss); | |
// if(ret < 0) | |
// { | |
// printf("mopen_gnss_client_Deinit FAIL.\n"); | |
// return -1; | |
// } | |
// printf("mopen_gnss_client_Deinit success \n"); | |
// break; | |
// } | |
// case 5: | |
// { | |
// qser_Gnss_Deinit=(int(*)(uint32_t))dlsym(dlHandle_gnss, "qser_Gnss_Deinit"); | |
// ret =qser_Gnss_Deinit(ph_gnss); | |
// if(ret < 0) | |
// { | |
// printf("mopen_gnss_client_Deinit FAIL.\n"); | |
// return -1; | |
// } | |
// printf("mopen_gnss_client_Deinit success \n"); | |
// break; | |
// } | |
case 6: | |
{ | |
gsw_gnss_start=(int(*)())dlsym(dlHandle_gnss_test, "gsw_gnss_start"); | |
ret =gsw_gnss_start(); | |
if(ret < 0) | |
{ | |
printf("gsw_gnss_start FAIL.\n"); | |
return -1; | |
} | |
printf("gsw_gnss_start success \n"); | |
break; | |
} | |
case 7: | |
{ | |
gsw_gnss_stop=(int(*)())dlsym(dlHandle_gnss_test, "gsw_gnss_stop"); | |
ret =gsw_gnss_stop(); | |
if(ret < 0) | |
{ | |
printf("gsw_gnss_stop FAIL.\n"); | |
return -1; | |
} | |
printf("gsw_gnss_stop success \n"); | |
break; | |
} | |
case 8: | |
{ | |
int flags; // 1-dele no ; 2- dele eph ; 3 dele all | |
gsw_gnss_delete_aiding_data=(int(*)(unsigned int))dlsym(dlHandle_gnss_test, "gsw_gnss_delete_aiding_data"); | |
delete_type(); | |
if (scanf("%d", &flags) != 1) | |
printf("input error,please check it"); | |
ret =gsw_gnss_delete_aiding_data(flags); | |
if(ret < 0) | |
{ | |
printf("gsw_gnss_delete_aiding_data FAIL.\n"); | |
return -1; | |
} | |
printf("gsw_gnss_delete_aiding_data success \n"); | |
break; | |
} | |
case 9: | |
{ | |
int able; | |
gsw_gnss_epo_switch=(int(*)(GSW_GNSS_CONF_SWITCH))dlsym(dlHandle_gnss_test, "gsw_gnss_epo_switch"); | |
if (scanf("%d", &able) != 1) | |
printf("input error,please check it"); | |
ret =gsw_gnss_epo_switch(able); | |
if(ret < 0) | |
{ | |
printf("mopen_gnss_client_Deinit FAIL.\n"); | |
return -1; | |
} | |
printf("mopen_gnss_client_Deinit success \n"); | |
break; | |
} | |
case 10: | |
{ | |
int conf; | |
gsw_gnss_set_start_mode=(int(*)(uint32_t))dlsym(dlHandle_gnss_test, "gsw_gnss_set_start_mode"); | |
if (scanf("%d", &conf) != 1) | |
printf("input error,please check it"); | |
ret =gsw_gnss_set_start_mode(conf); | |
if(ret < 0) | |
{ | |
printf("gsw_gnss_set_start_mode FAIL.\n"); | |
return -1; | |
} | |
printf("gsw_gnss_set_start_mode success \n"); | |
break; | |
} | |
case 11: | |
{ | |
int frequency; | |
gsw_gnss_set_freq=(int(*)(int))dlsym(dlHandle_gnss_test, "gsw_gnss_set_freq"); | |
if (scanf("%d", &frequency) != 1) | |
printf("input error,please check it"); | |
ret =gsw_gnss_set_freq(frequency); | |
if(ret < 0) | |
{ | |
printf("gsw_gnss_set_freq FAIL.\n"); | |
return -1; | |
} | |
printf("frequency is %d\n",frequency); | |
printf("gsw_gnss_set_freq success\n"); | |
break; | |
} | |
} | |
} | |
} |