--- src/host/layer23/src/common/gps.c | 26 +++++++++++++------------- 1 files changed, 13 insertions(+), 13 deletions(-)
diff --git a/src/host/layer23/src/common/gps.c b/src/host/layer23/src/common/gps.c index 38aae2c..2bdfb97 100644 --- a/src/host/layer23/src/common/gps.c +++ b/src/host/layer23/src/common/gps.c @@ -56,7 +56,7 @@ static struct osmo_fd gps_bfd;
#ifdef _HAVE_GPSD
-static struct gps_data_t* gdata; +static struct gps_data_t gdata;
int osmo_gpsd_cb(struct osmo_fd *bfd, unsigned int what) { @@ -66,25 +66,25 @@ int osmo_gpsd_cb(struct osmo_fd *bfd, unsigned int what) g.valid = 0;
/* gps is offline */ - if (gdata->online) + if (gdata.online) goto gps_not_ready;
/* gps has no data */ - if (gps_waiting(gdata)) + if (gps_waiting(&gdata, 500)) goto gps_not_ready;
/* polling returned an error */ - if (gps_poll(gdata)) + if (gps_read(&gdata)) goto gps_not_ready;
/* data are valid */ - if (gdata->set & LATLON_SET) { + if (gdata.set & LATLON_SET) { g.valid = 1; - g.gmt = gdata->fix.time; + g.gmt = gdata.fix.time; tm = localtime(&g.gmt); diff = time(NULL) - g.gmt; - g.latitude = gdata->fix.latitude; - g.longitude = gdata->fix.longitude; + g.latitude = gdata.fix.latitude; + g.longitude = gdata.fix.longitude;
LOGP(DGPS, LOGL_INFO, " time=%02d:%02d:%02d %04d-%02d-%02d, " "diff-to-host=%d, latitude=%do%.4f, longitude=%do%.4f\n", @@ -111,16 +111,15 @@ int osmo_gpsd_open(void) gps_bfd.when = BSC_FD_READ; gps_bfd.cb = osmo_gpsd_cb;
- gdata = gps_open(g.gpsd_host, g.gpsd_port); - if (gdata == NULL) { + if (gps_open(g.gpsd_host, g.gpsd_port, &gdata) == -1) { LOGP(DGPS, LOGL_ERROR, "Can't connect to gpsd\n"); return -1; } - gps_bfd.fd = gdata->gps_fd; + gps_bfd.fd = gdata.gps_fd; if (gps_bfd.fd < 0) return gps_bfd.fd;
- if (gps_stream(gdata, WATCH_ENABLE, NULL) == -1) { + if (gps_stream(&gdata, WATCH_ENABLE, NULL) == -1) { LOGP(DGPS, LOGL_ERROR, "Error in gps_stream()\n"); return -1; } @@ -139,7 +138,8 @@ void osmo_gpsd_close(void)
osmo_fd_unregister(&gps_bfd);
- gps_close(gdata); + gps_stream(&gdata, WATCH_DISABLE, NULL); + gps_close(&gdata); gps_bfd.fd = -1; /* -1 or 0 indicates: 'close' */ }
Hello.
On Tue, 2012-01-03 at 11:01, Paul Wise wrote:
src/host/layer23/src/common/gps.c | 26 +++++++++++++------------- 1 files changed, 13 insertions(+), 13 deletions(-)
diff --git a/src/host/layer23/src/common/gps.c b/src/host/layer23/src/common/gps.c index 38aae2c..2bdfb97 100644 --- a/src/host/layer23/src/common/gps.c +++ b/src/host/layer23/src/common/gps.c @@ -56,7 +56,7 @@ static struct osmo_fd gps_bfd;
#ifdef _HAVE_GPSD
-static struct gps_data_t* gdata; +static struct gps_data_t gdata;
This will break for people without the new gpsd API. At least check for the new version in configure.ac or better make it buildable with both versions.
regards Stefan Schmidt
--- src/host/layer23/src/common/gps.c | 57 +++++++++++++++++++++++++++++++++++++ 1 files changed, 57 insertions(+), 0 deletions(-)
diff --git a/src/host/layer23/src/common/gps.c b/src/host/layer23/src/common/gps.c index 38aae2c..2ab4023 100644 --- a/src/host/layer23/src/common/gps.c +++ b/src/host/layer23/src/common/gps.c @@ -56,7 +56,11 @@ static struct osmo_fd gps_bfd;
#ifdef _HAVE_GPSD
+#if GPSD_API_MAJOR_VERSION >= 5 +static struct gps_data_t gdata; +#else /* GPSD_API_MAJOR_VERSION < 5 */ static struct gps_data_t* gdata; +#endif /* GPSD_API_MAJOR_VERSION < 5 */
int osmo_gpsd_cb(struct osmo_fd *bfd, unsigned int what) { @@ -65,6 +69,38 @@ int osmo_gpsd_cb(struct osmo_fd *bfd, unsigned int what)
g.valid = 0;
+#if GPSD_API_MAJOR_VERSION >= 5 + /* gps is offline */ + if (gdata.online) + goto gps_not_ready; + + /* gps has no data */ + if (gps_waiting(&gdata, 500)) + goto gps_not_ready; + + /* polling returned an error */ + if (gps_read(&gdata)) + goto gps_not_ready; + + /* data are valid */ + if (gdata.set & LATLON_SET) { + g.valid = 1; + g.gmt = gdata.fix.time; + tm = localtime(&g.gmt); + diff = time(NULL) - g.gmt; + g.latitude = gdata.fix.latitude; + g.longitude = gdata.fix.longitude; + + LOGP(DGPS, LOGL_INFO, " time=%02d:%02d:%02d %04d-%02d-%02d, " + "diff-to-host=%d, latitude=%do%.4f, longitude=%do%.4f\n", + tm->tm_hour, tm->tm_min, tm->tm_sec, tm->tm_year + 1900, + tm->tm_mday, tm->tm_mon + 1, diff, + (int)g.latitude, + (g.latitude - ((int)g.latitude)) * 60.0, + (int)g.longitude, + (g.longitude - ((int)g.longitude)) * 60.0); + } +#else /* GPSD_API_MAJOR_VERSION < 5 */ /* gps is offline */ if (gdata->online) goto gps_not_ready; @@ -95,6 +131,7 @@ int osmo_gpsd_cb(struct osmo_fd *bfd, unsigned int what) (int)g.longitude, (g.longitude - ((int)g.longitude)) * 60.0); } +#endif /* GPSD_API_MAJOR_VERSION < 5 */
return 0;
@@ -111,6 +148,20 @@ int osmo_gpsd_open(void) gps_bfd.when = BSC_FD_READ; gps_bfd.cb = osmo_gpsd_cb;
+#if GPSD_API_MAJOR_VERSION >= 5 + if (gps_open(g.gpsd_host, g.gpsd_port, &gdata) == -1) { + LOGP(DGPS, LOGL_ERROR, "Can't connect to gpsd\n"); + return -1; + } + gps_bfd.fd = gdata.gps_fd; + if (gps_bfd.fd < 0) + return gps_bfd.fd; + + if (gps_stream(&gdata, WATCH_ENABLE, NULL) == -1) { + LOGP(DGPS, LOGL_ERROR, "Error in gps_stream()\n"); + return -1; + } +#else /* GPSD_API_MAJOR_VERSION < 5 */ gdata = gps_open(g.gpsd_host, g.gpsd_port); if (gdata == NULL) { LOGP(DGPS, LOGL_ERROR, "Can't connect to gpsd\n"); @@ -124,6 +175,7 @@ int osmo_gpsd_open(void) LOGP(DGPS, LOGL_ERROR, "Error in gps_stream()\n"); return -1; } +#endif /* GPSD_API_MAJOR_VERSION < 5 */
osmo_fd_register(&gps_bfd);
@@ -139,7 +191,12 @@ void osmo_gpsd_close(void)
osmo_fd_unregister(&gps_bfd);
+#if GPSD_API_MAJOR_VERSION >= 5 + gps_stream(&gdata, WATCH_DISABLE, NULL); + gps_close(&gdata); +#else /* GPSD_API_MAJOR_VERSION < 5 */ gps_close(gdata); +#endif /* GPSD_API_MAJOR_VERSION < 5 */ gps_bfd.fd = -1; /* -1 or 0 indicates: 'close' */ }
Wow, that just looks too awful.
Something like this should work I think and limit the changes to the essential :
at the top:
static struct gps_data_t* gdata = NULL;
#if GPSD_API_MAJOR_VERSION >= 5 static struct gps_data_t _gdata; #endif
and for the init :
#if GPSD_API_MAJOR_VERSION >= 5 gdata = gps_open(g.gpsd_host, g.gpsd_port); #else if (gps_open(g.gpsd_host, g.gpsd_port, &_gdata) == -1) gdata = NULL else gdata = &_gdata; #endif;
I don't have any setup to test here tough.
Cheers,
Sylvain
--- src/host/layer23/src/common/gps.c | 23 ++++++++++++++++++++++- 1 files changed, 22 insertions(+), 1 deletions(-)
diff --git a/src/host/layer23/src/common/gps.c b/src/host/layer23/src/common/gps.c index 38aae2c..e9aaa97 100644 --- a/src/host/layer23/src/common/gps.c +++ b/src/host/layer23/src/common/gps.c @@ -56,7 +56,12 @@ static struct osmo_fd gps_bfd;
#ifdef _HAVE_GPSD
-static struct gps_data_t* gdata; +static struct gps_data_t* gdata = NULL; + +#if GPSD_API_MAJOR_VERSION >= 5 +static struct gps_data_t _gdata; +#define gps_poll gps_read +#endif
int osmo_gpsd_cb(struct osmo_fd *bfd, unsigned int what) { @@ -69,9 +74,15 @@ int osmo_gpsd_cb(struct osmo_fd *bfd, unsigned int what) if (gdata->online) goto gps_not_ready;
+#if GPSD_API_MAJOR_VERSION >= 5 + /* gps has no data */ + if (gps_waiting(gdata, 500)) + goto gps_not_ready; +#else /* gps has no data */ if (gps_waiting(gdata)) goto gps_not_ready; +#endif
/* polling returned an error */ if (gps_poll(gdata)) @@ -111,7 +122,14 @@ int osmo_gpsd_open(void) gps_bfd.when = BSC_FD_READ; gps_bfd.cb = osmo_gpsd_cb;
+#if GPSD_API_MAJOR_VERSION >= 5 + if (gps_open(g.gpsd_host, g.gpsd_port, &_gdata) == -1) + gdata = NULL; + else + gdata = &_gdata; +#else gdata = gps_open(g.gpsd_host, g.gpsd_port); +#endif if (gdata == NULL) { LOGP(DGPS, LOGL_ERROR, "Can't connect to gpsd\n"); return -1; @@ -139,6 +157,9 @@ void osmo_gpsd_close(void)
osmo_fd_unregister(&gps_bfd);
+#if GPSD_API_MAJOR_VERSION >= 5 + gps_stream(gdata, WATCH_DISABLE, NULL); +#endif gps_close(gdata); gps_bfd.fd = -1; /* -1 or 0 indicates: 'close' */ }
On Tue, Jan 3, 2012 at 5:09 PM, Paul Wise wrote:
src/host/layer23/src/common/gps.c | 23 ++++++++++++++++++++++- 1 files changed, 22 insertions(+), 1 deletions(-)
Anything else need changing in this patch or could someone add it to master?
Hi Paul,
On Tue, Jan 17, 2012 at 12:32:22PM +0800, Paul Wise wrote:
Anything else need changing in this patch or could someone add it to master?
it's always mostly up to the original author of a given program to apply the patch. As the mobile program and specifically the gps support was written by jolly, he should review and apply it.
Regards, Harald
Paul Wise wrote:
src/host/layer23/src/common/gps.c | 23 ++++++++++++++++++++++- 1 files changed, 22 insertions(+), 1 deletions(-)
Acked-by: Peter Stuge peter@stuge.se
On Tue, 2012-01-03 at 17:09 +0800, Paul Wise wrote:
src/host/layer23/src/common/gps.c | 23 ++++++++++++++++++++++- 1 files changed, 22 insertions(+), 1 deletions(-)
Thanks to Sylvain Munaut for adding this patch to master.
baseband-devel@lists.osmocom.org