diff options
author | Eric S. Raymond <esr@thyrsus.com> | 2011-02-24 09:27:39 -0500 |
---|---|---|
committer | Eric S. Raymond <esr@thyrsus.com> | 2011-02-24 09:27:39 -0500 |
commit | e9f0b59325f6ea938ff8ff892cf181c6d209db9a (patch) | |
tree | 0d8e4f89e0e076ae408550a4fc5064aba6bdf026 | |
parent | 501c0f83b676eb730fab413da0bf602f8d607710 (diff) | |
download | gpsd-e9f0b59325f6ea938ff8ff892cf181c6d209db9a.tar.gz |
Move NTRIP per-connection state from global context to private driver area.
The flap over probes revealed that the NTRIP support is bolted onto the daemon
in a very awkward way that is likely to cause problems now that it's actually
being, like, *used*. This is a step towards making it behave more like a
normal driver.
-rw-r--r-- | gpsd.c | 14 | ||||
-rw-r--r-- | gpsd.h-tail | 25 | ||||
-rw-r--r-- | libgpsd_core.c | 3 | ||||
-rw-r--r-- | net_ntrip.c | 47 |
4 files changed, 45 insertions, 44 deletions
@@ -591,8 +591,6 @@ static void deactivate_device(struct gps_device_t *device) if (context.dsock == device->gpsdata.gps_fd) { context.dsock = -1; } - context.ntrip_conn_state = ntrip_conn_init; - context.ntrip_sourcetable_parse = false; gpsd_deactivate(device); } } @@ -1283,20 +1281,20 @@ static void consume_packets(struct gps_device_t *device) device->gpsdata.gps_fd); if (device->context->netgnss_service == netgnss_ntrip - && device->context->ntrip_conn_state != ntrip_conn_established) { + && device->driver.ntrip.conn_state != ntrip_conn_established) { /* the socket descriptor might change during connection */ if (device->gpsdata.gps_fd != -1) { FD_CLR(device->gpsdata.gps_fd, &all_fds); } (void)ntrip_open(device, ""); - if (device->context->ntrip_conn_state == ntrip_conn_err) { + if (device->driver.ntrip.conn_state == ntrip_conn_err) { gpsd_report(LOG_WARN, "connection to ntrip server failed\n"); - device->context->ntrip_conn_state = ntrip_conn_init; + device->driver.ntrip.conn_state = ntrip_conn_init; deactivate_device(device); } else { - if (device->context->ntrip_conn_state == ntrip_conn_established) { + if (device->driver.ntrip.conn_state == ntrip_conn_established) { device->context->dsock = device->gpsdata.gps_fd; } FD_SET(device->gpsdata.gps_fd, &all_fds); @@ -1326,8 +1324,8 @@ static void consume_packets(struct gps_device_t *device) if (device->zerokill) { /* failed timeout-and-reawake, kill it */ deactivate_device(device); - if (device->context->ntrip_works) { - device->context->ntrip_works = false; // reset so we try this once only + if (device->driver.ntrip.works) { + device->driver.ntrip.works = false; // reset so we try this once only if (gpsd_activate(device) < 0) { gpsd_report(LOG_WARN, "reconnect to ntrip server failed\n"); } else { diff --git a/gpsd.h-tail b/gpsd.h-tail index 3dcb412a..14dedf9c 100644 --- a/gpsd.h-tail +++ b/gpsd.h-tail @@ -183,15 +183,6 @@ struct gps_context_t { /* DGPSIP status */ bool sentdgps; /* have we sent a DGPS report? */ enum { netgnss_none, netgnss_dgpsip, netgnss_ntrip} netgnss_service; /* type of GNSS service */ - enum { - ntrip_conn_init, - ntrip_conn_sent_probe, - ntrip_conn_sent_get, - ntrip_conn_established, - ntrip_conn_err - } ntrip_conn_state; /* ntrip connection state for multi stage connect */ - bool ntrip_works; /* this marks a working connection, so we try to reconnect once */ - bool ntrip_sourcetable_parse; /* have we read the sourcetable header? */ int fixcnt; /* count of good fixes seen */ socket_t dsock; /* socket to DGPSIP server/Ntrip caster */ size_t rtcmbytes; /* byte count of last RTCM104 report */ @@ -518,6 +509,22 @@ struct gps_device_t { unsigned int bufindex; } isgps; #endif /* BINARY_ENABLE */ + + /* + * State of an NTRIP connection. Havoc will ensue if ntrip_conn_init + * is not 0, as this is initialized by memset(... '\0', ...). + */ + struct { + enum { + ntrip_conn_init, + ntrip_conn_sent_probe, + ntrip_conn_sent_get, + ntrip_conn_established, + ntrip_conn_err + } conn_state; /* connection state for multi stage connect */ + bool works; /* marks a working connection, so we try to reconnect once */ + bool sourcetable_parse; /* have we read the sourcetable header? */ + } ntrip; } driver; /* * Auxiliary structures for parsing data that can be interleaved with diff --git a/libgpsd_core.c b/libgpsd_core.c index 2a532eef..16008b80 100644 --- a/libgpsd_core.c +++ b/libgpsd_core.c @@ -161,9 +161,6 @@ void gps_context_init(struct gps_context_t *context) .readonly = false, .sentdgps = false, .netgnss_service = netgnss_none, - .ntrip_conn_state = ntrip_conn_init, - .ntrip_sourcetable_parse = false, - .ntrip_works = false, .fixcnt = 0, .dsock = -1, .rtcmbytes = 0, diff --git a/net_ntrip.c b/net_ntrip.c index c853f82c..27451406 100644 --- a/net_ntrip.c +++ b/net_ntrip.c @@ -186,7 +186,7 @@ static void ntrip_str_parse(char *str, size_t len, while ((s = ntrip_field_iterate(NULL, s, eol))); } -static int ntrip_sourcetable_parse(struct gps_device_t *dev) +static int ntrip_sourcetable_parse(struct gps_device_t *device) { struct ntrip_stream_t hold; ssize_t llen, len = 0; @@ -195,8 +195,7 @@ static int ntrip_sourcetable_parse(struct gps_device_t *dev) bool match = false; char buf[BUFSIZ]; size_t blen = BUFSIZ; - int fd = dev->gpsdata.gps_fd; - struct gps_context_t *context = dev->context; + int fd = device->gpsdata.gps_fd; while (1) { char *eol; @@ -229,13 +228,13 @@ static int ntrip_sourcetable_parse(struct gps_device_t *dev) gpsd_report(LOG_RAW, "Ntrip source table buffer %s\n", buf); - sourcetable = context->ntrip_sourcetable_parse; + sourcetable = device->driver.ntrip.sourcetable_parse; if (!sourcetable) { /* parse SOURCETABLE */ if (strncmp(line, NTRIP_SOURCETABLE, strlen(NTRIP_SOURCETABLE)) == 0) { sourcetable = true; - context->ntrip_sourcetable_parse = true; + device->driver.ntrip.sourcetable_parse = true; llen = (ssize_t) strlen(NTRIP_SOURCETABLE); line += llen; len -= llen; @@ -461,7 +460,7 @@ close: } /*@ -branchstate -nullpass @*/ -int ntrip_open(struct gps_device_t *dev, char *caster) +int ntrip_open(struct gps_device_t *device, char *caster) /* open a connection to a Ntrip broadcaster */ { char *amp, *colon, *slash; @@ -472,9 +471,9 @@ int ntrip_open(struct gps_device_t *dev, char *caster) int ret; char t[strlen(caster + 1)]; char *tmp = t; - struct gps_context_t *context = dev->context; + struct gps_context_t *context = device->context; - switch (context->ntrip_conn_state) { + switch (device->driver.ntrip.conn_state) { case ntrip_conn_init: ntrip_stream.set = false; (void)strlcpy(tmp, caster, strlen(caster)); @@ -490,7 +489,7 @@ int ntrip_open(struct gps_device_t *dev, char *caster) gpsd_report(LOG_ERROR, "can't extract user-ID and password from %s\n", caster); - context->ntrip_conn_state = ntrip_conn_err; + device->driver.ntrip.conn_state = ntrip_conn_err; return -1; } } @@ -502,7 +501,7 @@ int ntrip_open(struct gps_device_t *dev, char *caster) /* todo: add autoconnect like in dgpsip.c */ gpsd_report(LOG_ERROR, "can't extract Ntrip stream from %s\n", caster); - context->ntrip_conn_state = ntrip_conn_err; + device->driver.ntrip.conn_state = ntrip_conn_err; return -1; } if ((colon = strchr(tmp, ':')) != NULL) { @@ -524,42 +523,42 @@ int ntrip_open(struct gps_device_t *dev, char *caster) ret = ntrip_stream_req_probe(); if (ret == -1) { - context->ntrip_conn_state = ntrip_conn_err; + device->driver.ntrip.conn_state = ntrip_conn_err; return -1; } - dev->gpsdata.gps_fd = ret; - context->ntrip_conn_state = ntrip_conn_sent_probe; + device->gpsdata.gps_fd = ret; + device->driver.ntrip.conn_state = ntrip_conn_sent_probe; return ret; case ntrip_conn_sent_probe: - ret = ntrip_sourcetable_parse(dev); + ret = ntrip_sourcetable_parse(device); if (ret == -1) { - context->ntrip_conn_state = ntrip_conn_err; + device->driver.ntrip.conn_state = ntrip_conn_err; return -1; } if (ret == 0 && ntrip_stream.set == false) { return ret; } - (void)close(dev->gpsdata.gps_fd); + (void)close(device->gpsdata.gps_fd); if (ntrip_auth_encode(&ntrip_stream, ntrip_stream.credentials, ntrip_stream.authStr, 128) != 0) { - context->ntrip_conn_state = ntrip_conn_err; + device->driver.ntrip.conn_state = ntrip_conn_err; return -1; } ret = ntrip_stream_get_req(); if (ret == -1) { - context->ntrip_conn_state = ntrip_conn_err; + device->driver.ntrip.conn_state = ntrip_conn_err; return -1; } - dev->gpsdata.gps_fd = ret; - context->ntrip_conn_state = ntrip_conn_sent_get; + device->gpsdata.gps_fd = ret; + device->driver.ntrip.conn_state = ntrip_conn_sent_get; break; case ntrip_conn_sent_get: - ret = ntrip_stream_get_parse(dev->gpsdata.gps_fd); + ret = ntrip_stream_get_parse(device->gpsdata.gps_fd); if (ret == -1) { - context->ntrip_conn_state = ntrip_conn_err; + device->driver.ntrip.conn_state = ntrip_conn_err; return -1; } - context->ntrip_conn_state = ntrip_conn_established; - context->ntrip_works = true; // we know, this worked. + device->driver.ntrip.conn_state = ntrip_conn_established; + device->driver.ntrip.works = true; // we know, this worked. break; case ntrip_conn_established: case ntrip_conn_err: |