1 /* net_gnss_dispatch.c -- common interface to a number of Network GNSS services
3 * This file is Copyright (c) 2010 by the GPSD project
4 * BSD terms apply: see the file COPYING in the distribution root for details.
8 #include "gpsd_config.h"
11 #ifdef HAVE_SYS_SOCKET_H
12 #include <sys/socket.h>
15 #endif /* S_SPLINT_S */
21 #define NETGNSS_DGPSIP "dgpsip://"
22 #define NETGNSS_NTRIP "ntrip://"
24 /* Where to find the list of DGPSIP correction servers, if there is one */
25 #define DGPSIP_SERVER_LIST "/usr/share/gpsd/dgpsip-servers"
27 bool netgnss_uri_check(char *name)
28 /* is given string a valid URI for GNSS/DGPS service? */
31 strncmp(name, NETGNSS_NTRIP, strlen(NETGNSS_NTRIP)) == 0
32 || strncmp(name, NETGNSS_DGPSIP, strlen(NETGNSS_DGPSIP)) == 0;
37 int netgnss_uri_open(struct gps_context_t *context, char *netgnss_service)
38 /* open a connection to a DGNSS service */
41 if (strncmp(netgnss_service, NETGNSS_NTRIP, strlen(NETGNSS_NTRIP)) == 0)
42 return ntrip_open(context, netgnss_service + strlen(NETGNSS_NTRIP));
45 if (strncmp(netgnss_service, NETGNSS_DGPSIP, strlen(NETGNSS_DGPSIP)) == 0)
46 return dgpsip_open(context, netgnss_service + strlen(NETGNSS_DGPSIP));
48 #ifndef REQUIRE_DGNSS_PROTO
49 return dgpsip_open(context, netgnss_service);
51 gpsd_report(LOG_ERROR,
52 "Unknown or unspecified DGNSS protocol for service %s\n",
60 int netgnss_poll(struct gps_context_t *context)
61 /* poll the DGNSS service for a correction report */
63 if (context->dsock > -1) {
65 read(context->dsock, context->rtcmbuf, sizeof(context->rtcmbuf));
66 if ((rtcmbytes == -1 && errno != EAGAIN) || (rtcmbytes == 0)) {
67 (void)shutdown(context->dsock, SHUT_RDWR);
68 (void)close(context->dsock);
69 context->rtcmbytes = 0;
72 context->rtcmbytes = (size_t) rtcmbytes;
73 context->rtcmtime = timestamp();
79 void netgnss_report(struct gps_device_t *session)
80 /* may be time to ship a usage report to the DGNSS service */
82 if (session->context->netgnss_service == netgnss_dgpsip)
83 dgpsip_report(session);
85 else if (session->context->netgnss_service == netgnss_ntrip)
86 ntrip_report(session);
90 void netgnss_autoconnect(struct gps_context_t *context, double lat,
93 if (context->netgnss_service == netgnss_dgpsip) {
94 dgpsip_autoconnect(context, lat, lon, DGPSIP_SERVER_LIST);
99 void rtcm_relay(struct gps_device_t *session)
100 /* pass a DGNSS connection report to a session */
102 if (session->gpsdata.gps_fd != -1
103 && session->context->rtcmbytes > 0
104 && session->rtcmtime < session->context->rtcmtime
105 && session->device_type->rtcm_writer != NULL) {
106 if (session->device_type->rtcm_writer(session,
107 session->context->rtcmbuf,
108 session->context->rtcmbytes) ==
110 gpsd_report(LOG_ERROR, "Write to RTCM sink failed\n");
112 session->rtcmtime = timestamp();
113 gpsd_report(LOG_IO, "<= DGPS: %zd bytes of RTCM relayed.\n",
114 session->context->rtcmbytes);