summaryrefslogtreecommitdiff
path: root/libgpsd_core.c
diff options
context:
space:
mode:
authorEric S. Raymond <esr@thyrsus.com>2011-02-24 23:09:04 -0500
committerEric S. Raymond <esr@thyrsus.com>2011-02-24 23:09:04 -0500
commitc6db088ca0b2869eea573931f0bb73eec5222376 (patch)
treeff5ba405135581be0ba2289d157a4b06baec9e6d /libgpsd_core.c
parent8b4f69769db0f4a78ce5988338e615842bc0bdb7 (diff)
downloadgpsd-c6db088ca0b2869eea573931f0bb73eec5222376.tar.gz
Split an excessively long function. No logic changes. All regression tests pass.
Diffstat (limited to 'libgpsd_core.c')
-rw-r--r--libgpsd_core.c64
1 files changed, 64 insertions, 0 deletions
diff --git a/libgpsd_core.c b/libgpsd_core.c
index 6b1cb492..3f2323cf 100644
--- a/libgpsd_core.c
+++ b/libgpsd_core.c
@@ -722,6 +722,70 @@ void gpsd_clear(struct gps_device_t *session)
session->opentime = timestamp();
}
+int gpsd_open(struct gps_device_t *session)
+/* open a device for access to its data */
+{
+ /* special case: source may be a URI to a remote GNSS or DGPS service */
+ if (netgnss_uri_check(session->gpsdata.dev.path)) {
+ session->gpsdata.gps_fd = netgnss_uri_open(session,
+ session->gpsdata.dev.path);
+ session->sourcetype = source_tcp;
+ gpsd_report(LOG_SPIN,
+ "netgnss_uri_open(%s) returns socket on fd %d\n",
+ session->gpsdata.dev.path, session->gpsdata.gps_fd);
+ return session->gpsdata.gps_fd;
+ /* otherwise, could be an TCP data feed */
+ } else if (strncmp(session->gpsdata.dev.path, "tcp://", 6) == 0) {
+ char server[GPS_PATH_MAX], *port;
+ socket_t dsock;
+ (void)strlcpy(server, session->gpsdata.dev.path + 6, sizeof(server));
+ session->gpsdata.gps_fd = -1;
+ port = strchr(server, ':');
+ if (port == NULL) {
+ gpsd_report(LOG_ERROR, "Missing colon in TCP feed spec.\n");
+ return -1;
+ }
+ *port++ = '\0';
+ gpsd_report(LOG_INF, "opening TCP feed at %s, port %s.\n", server,
+ port);
+ if ((dsock = netlib_connectsock(AF_UNSPEC, server, port, "tcp")) < 0) {
+ gpsd_report(LOG_ERROR, "TCP device open error %s.\n",
+ netlib_errstr(dsock));
+ return -1;
+ } else
+ gpsd_report(LOG_SPIN, "TCP device opened on fd %d\n", dsock);
+ session->gpsdata.gps_fd = dsock;
+ session->sourcetype = source_tcp;
+ return session->gpsdata.gps_fd;
+ /* or could be UDP */
+ } else if (strncmp(session->gpsdata.dev.path, "udp://", 6) == 0) {
+ char server[GPS_PATH_MAX], *port;
+ socket_t dsock;
+ (void)strlcpy(server, session->gpsdata.dev.path + 6, sizeof(server));
+ session->gpsdata.gps_fd = -1;
+ port = strchr(server, ':');
+ if (port == NULL) {
+ gpsd_report(LOG_ERROR, "Missing colon in UDP feed spec.\n");
+ return -1;
+ }
+ *port++ = '\0';
+ gpsd_report(LOG_INF, "opening UDP feed at %s, port %s.\n", server,
+ port);
+ if ((dsock = netlib_connectsock(AF_UNSPEC, server, port, "udp")) < 0) {
+ gpsd_report(LOG_ERROR, "UDP device open error %s.\n",
+ netlib_errstr(dsock));
+ return -1;
+ } else
+ gpsd_report(LOG_SPIN, "UDP device opened on fd %d\n", dsock);
+ session->gpsdata.gps_fd = dsock;
+ session->sourcetype = source_udp;
+ return session->gpsdata.gps_fd;
+ }
+
+ /* fall through to plain serial open */
+ return gpsd_serial_open(session);
+}
+
/*@ -branchstate @*/
int gpsd_activate(struct gps_device_t *session)
/* acquire a connection to the GPS device */