/* / _____) _ | | ( (____ _____ ____ _| |_ _____ ____| |__ \____ \| ___ | (_ _) ___ |/ ___) _ \ _____) ) ____| | | || |_| ____( (___| | | | (______/|_____)_|_|_| \__)_____)\____)_| |_| (C)2013 Semtech-Cycleo Description: Minimum test program for the loragw_gps 'library' License: Revised BSD License, see LICENSE.TXT file include in the project Maintainer: Michael Coracin */ /* -------------------------------------------------------------------------- */ /* --- DEPENDANCIES --------------------------------------------------------- */ /* fix an issue between POSIX and C99 */ #if __STDC_VERSION__ >= 199901L #define _XOPEN_SOURCE 600 #else #define _XOPEN_SOURCE 500 #endif #include /* C99 types */ #include /* bool type */ #include /* printf */ #include /* memset */ #include /* sigaction */ #include /* exit */ #include /* read */ #include #include #include "loragw_hal.h" #include "loragw_gps.h" #include "loragw_aux.h" /* -------------------------------------------------------------------------- */ /* --- PRIVATE VARIABLES ---------------------------------------------------- */ static int exit_sig = 0; /* 1 -> application terminates cleanly (shut down hardware, close open files, etc) */ static int quit_sig = 0; /* 1 -> application terminates without shutting down the hardware */ static struct gps_data_t gpsdata; static struct fixsource_t source; struct tref ppm_ref; /* -------------------------------------------------------------------------- */ /* --- PRIVATE FUNCTIONS DECLARATION ---------------------------------------- */ static void sig_handler(int sigio); /* -------------------------------------------------------------------------- */ /* --- PRIVATE FUNCTIONS DEFINITION ----------------------------------------- */ static void sig_handler(int sigio) { if (sigio == SIGQUIT) { quit_sig = 1;; } else if ((sigio == SIGINT) || (sigio == SIGTERM)) { exit_sig = 1; } } /* -------------------------------------------------------------------------- */ /* --- MAIN FUNCTION -------------------------------------------------------- */ int main() { struct sigaction sigact; /* SIGQUIT&SIGINT&SIGTERM signal handling */ int i; /* concentrator variables */ struct lgw_conf_board_s boardconf; struct lgw_conf_rxrf_s rfconf; /* serial variables */ char serial_buff[128]; /* buffer to receive GPS data */ /* NMEA/UBX variables */ static struct tref time_reference_gps; /* time reference used for GPS <-> timestamp conversion */ /* configure signal handling */ sigemptyset(&sigact.sa_mask); sigact.sa_flags = 0; sigact.sa_handler = sig_handler; sigaction(SIGQUIT, &sigact, NULL); sigaction(SIGINT, &sigact, NULL); sigaction(SIGTERM, &sigact, NULL); /* Intro message and library information */ printf("Beginning of test for loragw_gps.c\n"); printf("*** Library version information ***\n%s\n***\n", lgw_version_info()); /* Open and configure GPS */ i = lgw_gps_enable(&gpsdata, &source); if (i != LGW_GPS_SUCCESS) { printf("ERROR: IMPOSSIBLE TO ENABLE GPS\n"); exit(EXIT_FAILURE); } /* start concentrator (default conf for IoT SK) */ /* board config */ memset(&boardconf, 0, sizeof(boardconf)); boardconf.lorawan_public = true; boardconf.clksrc = 1; lgw_board_setconf(boardconf); /* RF config */ memset(&rfconf, 0, sizeof(rfconf)); rfconf.enable = true; rfconf.freq_hz = 868000000; rfconf.rssi_offset = 0.0; rfconf.type = LGW_RADIO_TYPE_SX1257; rfconf.tx_enable = true; lgw_rxrf_setconf(0, rfconf); lgw_start(); /* initialize some variables before loop */ memset(serial_buff, 0, sizeof serial_buff); memset(&ppm_ref, 0, sizeof ppm_ref); /* loop until user action */ while ((quit_sig != 1) && (exit_sig != 1)) { wait_ms(100); int r = gps_read(&gpsdata, 0, 0); if (r!= -1 && (gpsdata.status != STATUS_NO_FIX) && (gpsdata.fix.mode == MODE_2D || gpsdata.fix.mode == MODE_3D) && !isnan(gpsdata.fix.latitude) && !isnan(gpsdata.fix.longitude)) { uint32_t trig_tstamp; /* concentrator timestamp associated with PPM pulse */ i = lgw_get_trigcnt(&trig_tstamp); lgw_gps_sync(&time_reference_gps, trig_tstamp, gpsdata.fix.time); printf("\n--- GPS ---\n"); printf("Set: %lld\n", gpsdata.set); printf("Online: %10.0f\n", gpsdata.online); printf("Status: %d\n", gpsdata.status); printf("Satellites Used: %d\n", gpsdata.satellites_used); printf("Mode: %d\n", gpsdata.fix.mode); printf("UTC time: %lld.%09ld\n", (long long)time_reference_gps.utc.tv_sec, time_reference_gps.utc.tv_nsec); printf("GPS time: %lld.%09ld\n", (long long)time_reference_gps.gps.tv_sec, time_reference_gps.gps.tv_nsec); printf("Latitude: %f\n", gpsdata.fix.latitude); printf("Longitude: %f\n", gpsdata.fix.longitude); printf("Altitude: %fm\n", gpsdata.fix.altitude); printf("Speed: %f\n", gpsdata.fix.speed); printf("Track: %f\n", gpsdata.fix.track); printf("Pdop: %f\n", gpsdata.dop.pdop); } } /* clean up before leaving */ if (exit_sig == 1) { lgw_gps_disable(&gpsdata); lgw_stop(); } printf("\nEnd of test for loragw_gps.c\n"); exit(EXIT_SUCCESS); } /* --- EOF ------------------------------------------------------------------ */