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 |
|
| 18 | typedef struct
|
| 19 | {
|
| 20 | /**< set to sizeof(GpsLocation) */
|
| 21 | size_t size;
|
| 22 | /**< Contains GpsLocationFlags bits. */
|
| 23 | unsigned short int flags;
|
| 24 | /**< Represents latitude in degrees. */
|
| 25 | double latitude;
|
| 26 | /**< Represents longitude in degrees. */
|
| 27 | double longitude;
|
| 28 | /**< Represents altitude in meters above the WGS 84 reference ellipsoid. */
|
| 29 | double altitude;
|
| 30 | /**< Represents speed in meters per second. */
|
| 31 | float speed;
|
| 32 | /**< Represents heading in degrees. */
|
| 33 | float bearing;
|
| 34 | /**< Represents expected accuracy in meters. */
|
| 35 | float accuracy;
|
| 36 | /**< Timestamp for the location fix. */
|
| 37 | long long int timestamp;
|
| 38 | }GSW_GNSS_LOCATION_T;
|
| 39 |
|
| 40 | typedef struct {
|
| 41 | GSW_GNSS_LOCATION_T legacyLocation;
|
| 42 | float horizontalAccuracyMeters;
|
| 43 | /**< Represents expected vertical position accuracy in meters
|
| 44 | * (68% confidence).*/
|
| 45 | float verticalAccuracyMeters;
|
| 46 | /**< Represents expected speed accuracy in meter per seconds
|
| 47 | * (68% confidence).*/
|
| 48 | float speedAccuracyMetersPerSecond;
|
| 49 | /**< Represents expected bearing accuracy in degrees
|
| 50 | * (68% confidence).*/
|
| 51 | float bearingAccuracyDegrees;
|
| 52 | }GSW_GNSS_LOCATION_EXT_T;
|
| 53 |
|
| 54 |
|
| 55 | typedef enum{
|
| 56 | GSW_SWITCH_DISABLE = 0, /**< configuration switch disable :0 */
|
| 57 | GSW_SWITCH_ENABLE /**< configuration switch enable :1 */
|
| 58 | }GSW_GNSS_CONF_SWITCH;
|
| 59 |
|
| 60 | typedef enum{
|
| 61 | GSW_MODE_GPS = 1, /**< GPS only */
|
| 62 | GSW_MODE_BEIDOU, /**< BEIDOU only*/
|
| 63 | GSW_MODE_GPS_BEIDOU, /**< GPS+BEIDOU */
|
| 64 | GSW_MODE_GLONASS, /**< GLONASS only */ /* The high-tech platform does not support this type */
|
| 65 | GSW_MODE_GPS_GLONASS, /**< GPS+GLONASS */
|
| 66 | GSW_MODE_GLONASS_BEIDOU, /**< GLONASS+BEIDOU */ /* The high-tech platform does not support this type */
|
| 67 | GSW_MODE_GPS_GLONASS_BEIDOU, /**< GPS+GLONASS+BEIDOU */ /* The high-tech platform does not support this type */
|
| 68 | GSW_MODE_GALILEO, /**< GALILEO only */
|
| 69 | GSW_MODE_GPS_GALILEO, /**< GPS+GALILEO */
|
| 70 | GSW_MODE_BEIDOU_GALILEO, /**< BEIDOU+GALILEO */
|
| 71 | GSW_MODE_GPS_BEIDOU_GALILEO, /**< GPS+BEIDOU+GALILEO */
|
| 72 | GSW_MODE_GLONASS_GALILEO, /**< GLONASS+GALILEO */
|
| 73 | GSW_MODE_GPS_GLONASS_GALILEO, /**< GPS+GLONASS+GALILEO */
|
| 74 | GSW_MODE_BEIDOU_GLONASS_GALILEO, /**< BEIDOU+GLONASS+GALILEO */ /* The high-tech platform does not support this type */
|
| 75 | }GSW_GNSS_MODE_CONFIGURATION;
|
| 76 |
|
| 77 | typedef void (*gsw_gnss_location_callback_ext)(GSW_GNSS_LOCATION_EXT_T* location);
|
| 78 | typedef void (*gsw_gnss_nmea_callback )(const char* nmea, int length);
|
| 79 |
|
| 80 | typedef struct{
|
| 81 | gsw_gnss_location_callback_ext gsw_location_cb;
|
| 82 | gsw_gnss_nmea_callback gsw_nmea_cb;
|
| 83 | }gsw_gnss_cb;
|
| 84 |
|
zw.wang | 581aab1 | 2025-05-28 19:43:53 +0800 | [diff] [blame] | 85 | typedef enum {
|
| 86 | GNSS_FREQ_1HZ = 1, /**< 1Hz */
|
| 87 | GNSS_FREQ_2HZ = 2, /**< 2Hz */
|
| 88 | GNSS_FREQ_5HZ = 5, /**< 5Hz */
|
| 89 | GNSS_FREQ_10HZ = 10, /**< 10Hz */
|
| 90 | } gnss_freq_type;
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 91 |
|
| 92 | typedef struct{
|
| 93 | GSW_GNSS_MODE_CONFIGURATION start_mode;
|
| 94 | gnss_freq_type freq;
|
| 95 | gsw_gnss_cb callback;
|
| 96 | }gsw_gnss_init_configure_t;
|
| 97 |
|
| 98 | int (*gsw_gnss_set_freq)(int freq);
|
| 99 | int (*gsw_gnss_init)(void);
|
| 100 | int (*gsw_gnss_start)(void);
|
| 101 | int (*gsw_gnss_stop)(void);
|
| 102 | int (*gsw_gnss_deinit)(void);
|
zw.wang | 75e98ea | 2025-05-29 17:57:38 +0800 | [diff] [blame] | 103 | int (*gsw_gnss_add_lib)(void);
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 104 | int (*gsw_gnss_set_start_mode)(GSW_GNSS_MODE_CONFIGURATION start_mode);
|
| 105 | int (*gsw_gnss_epo_switch)(GSW_GNSS_CONF_SWITCH switch_op);
|
| 106 | int (*gsw_gnss_reg_cb_group)(gsw_gnss_cb callback);
|
| 107 | //int (*gsw_gnss_xtra_is_enable)(gsw_xtra_state_e state);
|
| 108 | int (*gsw_gnss_delete_aiding_data)(unsigned int flags);
|
| 109 | int (*gsw_gnss_init_configure_gps)(gsw_gnss_init_configure_t init_configure);
|
| 110 |
|
| 111 | void *dlHandle_gnss_test;
|
| 112 | char *lynqLib_gnss_test = "/lib/libgsw_lib.so";
|
| 113 |
|
| 114 |
|
| 115 | void tmp_gnss_callack(const char* nmea, int length)
|
| 116 | {
|
| 117 | printf("%s",nmea);
|
| 118 | }
|
| 119 |
|
zw.wang | a5250d6 | 2025-06-13 16:01:34 +0800 | [diff] [blame] | 120 | void tmp_location_gnss_callack(GSW_GNSS_LOCATION_EXT_T* location)
|
| 121 | {
|
| 122 | printf("Location Info:\n");
|
| 123 | printf(" Size: %zu\n", location->legacyLocation.size);
|
| 124 | printf(" Flags: %hu\n", location->legacyLocation.flags);
|
| 125 | printf(" Latitude: %.6lf°\n", location->legacyLocation.latitude);
|
| 126 | printf(" Longitude: %.6lf°\n", location->legacyLocation.longitude);
|
| 127 | printf(" Altitude: %.2lf m\n", location->legacyLocation.altitude);
|
| 128 | printf(" Speed: %.2f m/s\n", location->legacyLocation.speed);
|
| 129 | printf(" Bearing: %.1f°\n", location->legacyLocation.bearing);
|
| 130 | printf(" Accuracy: %.2f m\n", location->legacyLocation.accuracy);
|
| 131 | printf(" Timestamp: %lld\n", location->legacyLocation.timestamp);
|
| 132 | printf("Extended Accuracy:\n");
|
| 133 | printf(" Horizontal: %.2f m (68%%)\n", location->horizontalAccuracyMeters);
|
| 134 | printf(" Vertical: %.2f m (68%%)\n", location->verticalAccuracyMeters);
|
| 135 | printf(" Speed: %.2f m/s (68%%)\n", location->speedAccuracyMetersPerSecond);
|
| 136 | printf(" Bearing: %.1f° (68%%)\n", location->bearingAccuracyDegrees);
|
| 137 | }
|
| 138 |
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 139 | gsw_gnss_cb tmp_ptr = {
|
zw.wang | a5250d6 | 2025-06-13 16:01:34 +0800 | [diff] [blame] | 140 | tmp_location_gnss_callack,
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 141 | tmp_gnss_callack
|
| 142 | };
|
| 143 |
|
| 144 | void user_help(void)
|
| 145 | {
|
| 146 | printf("\t-1 exit\n"
|
| 147 | "\t1 gnss init\n"
|
| 148 | "\t2 gnss deinit \n"
|
| 149 | "\t3 gnss reg_cb\n"
|
| 150 | "\t6 gnss start\n"
|
| 151 | "\t7 gnss stop\n"
|
| 152 | "\t8 gnss Delete_Aiding_Data and reset\n"
|
| 153 | "\t9 gnss epo switch\n"
|
| 154 | "\t10 gnss set startmode\n"
|
| 155 | "\t11 gnss set frequency\n"
|
| 156 | "please input operator: >> ");
|
| 157 | }
|
| 158 | void delete_type(void)
|
| 159 | {
|
lichengzhang | 41f65e6 | 2025-07-17 11:51:06 +0800 | [diff] [blame] | 160 | printf("\t1 DELETE_NOTHING\n"
|
| 161 | "\t2 DELETE_EPHEMERIS\n"
|
| 162 | "\t3 DELETE_ALL\n"
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 163 | "please input operator: >> ");
|
| 164 | }
|
| 165 |
|
| 166 | int main(void)
|
| 167 | {
|
| 168 | int ret;
|
| 169 | int opt = 0;
|
| 170 | dlHandle_gnss_test = dlopen(lynqLib_gnss_test, RTLD_NOW);
|
zw.wang | 75e98ea | 2025-05-29 17:57:38 +0800 | [diff] [blame] | 171 | gsw_gnss_add_lib=(int(*)())dlsym(dlHandle_gnss_test, "gsw_gnss_add_lib");
|
| 172 | ret = gsw_gnss_add_lib();
|
| 173 | if(ret < 0)
|
| 174 | {
|
| 175 | printf("gsw_gnss_add_lib FAIL.\n");
|
| 176 | return -1;
|
| 177 | }
|
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 178 | while(1)
|
| 179 | {
|
| 180 | printf("=========gnss main=========\n");
|
| 181 | user_help();
|
| 182 | if (scanf("%d", &opt) != 1)
|
| 183 | {
|
| 184 | printf("Input error, please check it\n");
|
| 185 | while (getchar() != '\n');
|
| 186 | continue;
|
| 187 | }
|
| 188 | while(getchar()!='\n');
|
| 189 | switch (opt)
|
| 190 | {
|
| 191 | case -1:
|
| 192 | {
|
| 193 | printf("main exit\n");
|
| 194 | return 0;
|
| 195 | }
|
| 196 |
|
| 197 | case 1:
|
| 198 | {
|
| 199 | gsw_gnss_init=(int(*)())dlsym(dlHandle_gnss_test, "gsw_gnss_init");
|
| 200 | ret = gsw_gnss_init();
|
| 201 | if(ret < 0)
|
| 202 | {
|
| 203 | printf("gsw_gnss_init FAIL.\n");
|
| 204 | return -1;
|
| 205 | }
|
| 206 | printf("gsw_gnss_init success.\n");
|
| 207 | break;
|
| 208 | }
|
| 209 | case 2:
|
| 210 | {
|
| 211 | gsw_gnss_deinit=(int(*)())dlsym(dlHandle_gnss_test, "gsw_gnss_deinit");
|
| 212 | ret =gsw_gnss_deinit();
|
| 213 | if(ret < 0)
|
| 214 | {
|
| 215 | printf("gsw_gnss_deinit FAIL.\n");
|
| 216 | return -1;
|
| 217 | }
|
| 218 | printf("gsw_gnss_deinit success \n");
|
| 219 | break;
|
| 220 | }
|
| 221 | case 3:
|
| 222 | {
|
| 223 | gsw_gnss_reg_cb_group=(int(*)(gsw_gnss_cb))dlsym(dlHandle_gnss_test, "gsw_gnss_reg_cb_group");
|
| 224 | ret =gsw_gnss_reg_cb_group(tmp_ptr);
|
| 225 | if(ret < 0)
|
| 226 | {
|
| 227 | printf("gsw_gnss_reg_cb_group FAIL.\n");
|
| 228 | return -1;
|
| 229 | }
|
| 230 | printf("gsw_gnss_reg_cb_group success \n");
|
| 231 | break;
|
| 232 | }
|
| 233 | // case 4:
|
| 234 | // {
|
| 235 | // qser_Gnss_Deinit=(int(*)(uint32_t))dlsym(dlHandle_gnss, "qser_Gnss_Deinit");
|
| 236 | // ret =qser_Gnss_Deinit(ph_gnss);
|
| 237 | // if(ret < 0)
|
| 238 | // {
|
| 239 | // printf("mopen_gnss_client_Deinit FAIL.\n");
|
| 240 | // return -1;
|
| 241 | // }
|
| 242 | // printf("mopen_gnss_client_Deinit success \n");
|
| 243 | // break;
|
| 244 | // }
|
| 245 | // case 5:
|
| 246 | // {
|
| 247 | // qser_Gnss_Deinit=(int(*)(uint32_t))dlsym(dlHandle_gnss, "qser_Gnss_Deinit");
|
| 248 | // ret =qser_Gnss_Deinit(ph_gnss);
|
| 249 | // if(ret < 0)
|
| 250 | // {
|
| 251 | // printf("mopen_gnss_client_Deinit FAIL.\n");
|
| 252 | // return -1;
|
| 253 | // }
|
| 254 | // printf("mopen_gnss_client_Deinit success \n");
|
| 255 | // break;
|
| 256 | // }
|
| 257 | case 6:
|
| 258 | {
|
| 259 | gsw_gnss_start=(int(*)())dlsym(dlHandle_gnss_test, "gsw_gnss_start");
|
| 260 | ret =gsw_gnss_start();
|
| 261 | if(ret < 0)
|
| 262 | {
|
| 263 | printf("gsw_gnss_start FAIL.\n");
|
| 264 | return -1;
|
| 265 | }
|
| 266 | printf("gsw_gnss_start success \n");
|
| 267 | break;
|
| 268 | }
|
| 269 | case 7:
|
| 270 | {
|
| 271 | gsw_gnss_stop=(int(*)())dlsym(dlHandle_gnss_test, "gsw_gnss_stop");
|
| 272 | ret =gsw_gnss_stop();
|
| 273 | if(ret < 0)
|
| 274 | {
|
| 275 | printf("gsw_gnss_stop FAIL.\n");
|
| 276 | return -1;
|
| 277 | }
|
| 278 | printf("gsw_gnss_stop success \n");
|
| 279 | break;
|
| 280 | }
|
| 281 | case 8:
|
| 282 | {
|
| 283 | int flags; // 1-dele no ; 2- dele eph ; 3 dele all
|
| 284 | gsw_gnss_delete_aiding_data=(int(*)(unsigned int))dlsym(dlHandle_gnss_test, "gsw_gnss_delete_aiding_data");
|
| 285 | delete_type();
|
| 286 | if (scanf("%d", &flags) != 1)
|
| 287 | printf("input error,please check it");
|
| 288 | ret =gsw_gnss_delete_aiding_data(flags);
|
| 289 | if(ret < 0)
|
| 290 | {
|
| 291 | printf("gsw_gnss_delete_aiding_data FAIL.\n");
|
| 292 | return -1;
|
| 293 | }
|
| 294 | printf("gsw_gnss_delete_aiding_data success \n");
|
| 295 | break;
|
| 296 | }
|
| 297 | case 9:
|
| 298 | {
|
| 299 | int able;
|
| 300 | gsw_gnss_epo_switch=(int(*)(GSW_GNSS_CONF_SWITCH))dlsym(dlHandle_gnss_test, "gsw_gnss_epo_switch");
|
| 301 | if (scanf("%d", &able) != 1)
|
| 302 | printf("input error,please check it");
|
| 303 | ret =gsw_gnss_epo_switch(able);
|
| 304 | if(ret < 0)
|
| 305 | {
|
| 306 | printf("mopen_gnss_client_Deinit FAIL.\n");
|
| 307 | return -1;
|
| 308 | }
|
| 309 | printf("mopen_gnss_client_Deinit success \n");
|
| 310 | break;
|
| 311 | }
|
| 312 | case 10:
|
| 313 | {
|
| 314 | int conf;
|
| 315 | gsw_gnss_set_start_mode=(int(*)(uint32_t))dlsym(dlHandle_gnss_test, "gsw_gnss_set_start_mode");
|
| 316 | if (scanf("%d", &conf) != 1)
|
| 317 | printf("input error,please check it");
|
| 318 | ret =gsw_gnss_set_start_mode(conf);
|
| 319 | if(ret < 0)
|
| 320 | {
|
| 321 | printf("gsw_gnss_set_start_mode FAIL.\n");
|
| 322 | return -1;
|
| 323 | }
|
| 324 | printf("gsw_gnss_set_start_mode success \n");
|
| 325 | break;
|
| 326 | }
|
| 327 | case 11:
|
| 328 | {
|
| 329 | int frequency;
|
| 330 | gsw_gnss_set_freq=(int(*)(int))dlsym(dlHandle_gnss_test, "gsw_gnss_set_freq");
|
| 331 | if (scanf("%d", &frequency) != 1)
|
| 332 | printf("input error,please check it");
|
| 333 | ret =gsw_gnss_set_freq(frequency);
|
| 334 | if(ret < 0)
|
| 335 | {
|
| 336 | printf("gsw_gnss_set_freq FAIL.\n");
|
| 337 | return -1;
|
| 338 | }
|
| 339 | printf("frequency is %d\n",frequency);
|
| 340 | printf("gsw_gnss_set_freq success\n");
|
| 341 | break;
|
| 342 | }
|
| 343 | }
|
| 344 | }
|
| 345 | } |