From c6db088ca0b2869eea573931f0bb73eec5222376 Mon Sep 17 00:00:00 2001 From: "Eric S. Raymond" Date: Thu, 24 Feb 2011 23:09:04 -0500 Subject: Split an excessively long function. No logic changes. All regression tests pass. --- libgpsd_core.c | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) (limited to 'libgpsd_core.c') 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 */ -- cgit v1.2.1