From df1d68a52c935053092ea3fa00e0e9d982c252cc Mon Sep 17 00:00:00 2001 From: Harsh Sharma Date: Tue, 22 Dec 2020 14:34:39 -0600 Subject: Added changes for gps thread to work with the gpsd library --- libloragw/src/loragw_gps.c | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) (limited to 'libloragw/src/loragw_gps.c') diff --git a/libloragw/src/loragw_gps.c b/libloragw/src/loragw_gps.c index 19c2f83..17bb3a1 100644 --- a/libloragw/src/loragw_gps.c +++ b/libloragw/src/loragw_gps.c @@ -252,10 +252,7 @@ int str_chop(char *s, int buff_size, char separator, int *idx_ary, int max_idx) int lgw_gps_enable(struct gps_data_t *gpsdata, struct fixsource_t *source) { - unsigned int flags; - flags = WATCH_ENABLE; - flags |= WATCH_RAW; - flags |= WATCH_NMEA; + unsigned int flags = WATCH_ENABLE| WATCH_JSON; gpsd_source_spec(NULL, source); if (gps_open(source->server, source->port, gpsdata) != 0) { @@ -282,6 +279,8 @@ int lgw_gps_enable(struct gps_data_t *gpsdata, struct fixsource_t *source) { int lgw_gps_disable(struct gps_data_t *gpsdata) { int i; + (void) gps_stream(&gps_data, WATCH_DISABLE, NULL); + /* ends the session */ i = gps_close(gpsdata); if (i != 0) { @@ -384,16 +383,15 @@ enum gps_msg lgw_parse_ubx(const char *serial_buff, size_t buff_size, size_t *ms } else { gps_time_ok = false; return INVALID; - } + } } else if ((serial_buff[2] == 0x01) && (serial_buff[3] == 0x04)) { if (serial_buff[10] == 0x0F && serial_buff[11] == 0x27 && serial_buff[10] == 0x0F && serial_buff[11] == 0x27 && serial_buff[10] == 0x0F && serial_buff[11] == 0x27 && serial_buff[10] == 0x0F && serial_buff[11] == 0x27) { - gps_time_ok = false; - gps_lock_ok = false; + gps_time_ok = false; + gps_lock_ok = false; } - return UBX_NAV_TIMEUTC; } else if ((serial_buff[2] == 0x05) && (serial_buff[3] == 0x00)) { DEBUG_MSG("NOTE: UBX ACK-NAK received\n"); @@ -580,7 +578,7 @@ int lgw_gps_get(struct timespec *utc, struct timespec *gps_time, struct coord_s /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ -int lgw_gps_sync(struct tref *ref, uint32_t count_us, struct timespec utc, struct timespec gps_time) { +int lgw_gps_sync(struct tref *ref, uint32_t count_us, struct timespec gps_time) { bool update = false; double cnt_diff; /* internal concentrator time difference (in seconds) */ double utc_diff; /* UTC time difference (in seconds) */ @@ -592,9 +590,8 @@ int lgw_gps_sync(struct tref *ref, uint32_t count_us, struct timespec utc, struc /* calculate the slope */ if (ref->systime != 0) { - cnt_diff = (double)(count_us - ref->count_us) / (double)(TS_CPS); /* uncorrected by xtal_err */ - utc_diff = (double)(utc.tv_sec - (ref->utc).tv_sec) + (1E-9 * (double)(utc.tv_nsec - (ref->utc).tv_nsec)); + utc_diff = (double)((gps_time.tv_sec - timezone) - (ref->utc).tv_sec) + (1E-9 * (double)(gps_time.tv_nsec - (ref->utc).tv_nsec)); if (cnt_diff != 0 && utc_diff != 0) { // prevent divide by zero slope = cnt_diff/utc_diff; @@ -602,7 +599,7 @@ int lgw_gps_sync(struct tref *ref, uint32_t count_us, struct timespec utc, struc slope = 0.0; } - if (gps_lock_ok && gps_time_ok && cnt_diff > 1.5) { + if (cnt_diff > 1.5) { update = true; } @@ -626,8 +623,8 @@ int lgw_gps_sync(struct tref *ref, uint32_t count_us, struct timespec utc, struc if (update || calibrating) { ref->systime = time(NULL); ref->count_us = count_us; - ref->utc.tv_sec = utc.tv_sec; - ref->utc.tv_nsec = utc.tv_nsec; + ref->utc.tv_sec = gps_time.tv_sec - timezone; + ref->utc.tv_nsec = gps_time.tv_nsec; ref->gps.tv_sec = gps_time.tv_sec; ref->gps.tv_nsec = gps_time.tv_nsec; ref->xtal_err = slope; -- cgit v1.2.3