summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHarsh Sharma <harsh.sharma@multitech.com>2020-12-23 16:46:55 -0600
committerHarsh Sharma <harsh.sharma@multitech.com>2020-12-23 16:46:55 -0600
commit103726df50df9feb8b1bc18e63f653f6161cab98 (patch)
tree791ceba53622c99b9a4e78bbf1684a7d61d2bf7b
parentea028e8048d55367a52365087f9e3928746c55a5 (diff)
parentdf1d68a52c935053092ea3fa00e0e9d982c252cc (diff)
downloadlora_gateway_mtac_full-103726df50df9feb8b1bc18e63f653f6161cab98.tar.gz
lora_gateway_mtac_full-103726df50df9feb8b1bc18e63f653f6161cab98.tar.bz2
lora_gateway_mtac_full-103726df50df9feb8b1bc18e63f653f6161cab98.zip
Merge branch 'add-new-gpsd' into 'master'
Added changes for gps thread to work with the gpsd library See merge request !1
-rw-r--r--libloragw/inc/loragw_gps.h2
-rw-r--r--libloragw/src/loragw_gps.c25
2 files changed, 12 insertions, 15 deletions
diff --git a/libloragw/inc/loragw_gps.h b/libloragw/inc/loragw_gps.h
index 59b2d37..94d1d2a 100644
--- a/libloragw/inc/loragw_gps.h
+++ b/libloragw/inc/loragw_gps.h
@@ -173,7 +173,7 @@ int lgw_gps_get(struct timespec *utc, struct timespec *gps_time, struct coord_s
Set systime to 0 in ref to trigger initial synchronization.
*/
-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);
/**
@brief Convert concentrator timestamp counter value to UTC time
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;