net_gnss_dispatch.c 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /* net_gnss_dispatch.c -- common interface to a number of Network GNSS services
  2. *
  3. * This file is Copyright (c) 2010-2018 by the GPSD project
  4. * SPDX-License-Identifier: BSD-2-clause
  5. */
  6. #include "gpsd_config.h" /* must be before all includes */
  7. #include <string.h>
  8. #include <errno.h>
  9. #include <sys/types.h>
  10. #include <sys/stat.h>
  11. #include <sys/socket.h>
  12. #include <unistd.h>
  13. #include "gpsd.h"
  14. #include "strfuncs.h"
  15. #define NETGNSS_DGPSIP "dgpsip://"
  16. #define NETGNSS_NTRIP "ntrip://"
  17. bool netgnss_uri_check(char *name)
  18. /* is given string a valid URI for GNSS/DGPS service? */
  19. {
  20. return
  21. str_starts_with(name, NETGNSS_NTRIP)
  22. || str_starts_with(name, NETGNSS_DGPSIP);
  23. }
  24. int netgnss_uri_open(struct gps_device_t *dev, char *netgnss_service)
  25. /* open a connection to a DGNSS service */
  26. {
  27. #ifdef NTRIP_ENABLE
  28. if (str_starts_with(netgnss_service, NETGNSS_NTRIP)) {
  29. dev->ntrip.conn_state = ntrip_conn_init;
  30. return ntrip_open(dev, netgnss_service + strlen(NETGNSS_NTRIP));
  31. }
  32. #endif
  33. if (str_starts_with(netgnss_service, NETGNSS_DGPSIP))
  34. return dgpsip_open(dev, netgnss_service + strlen(NETGNSS_DGPSIP));
  35. #ifndef REQUIRE_DGNSS_PROTO
  36. return dgpsip_open(dev, netgnss_service);
  37. #else
  38. GPSD_LOG(LOG_ERROR, &dev->context.errout,
  39. "Unknown or unspecified DGNSS protocol for service %s\n",
  40. netgnss_service);
  41. return -1;
  42. #endif
  43. }
  44. void netgnss_report(struct gps_context_t *context,
  45. struct gps_device_t *gps, struct gps_device_t *dgnss)
  46. /* may be time to ship a usage report to the DGNSS service */
  47. {
  48. if (dgnss->servicetype == service_dgpsip)
  49. dgpsip_report(context, gps, dgnss);
  50. #ifdef NTRIP_ENABLE
  51. else if (dgnss->servicetype == service_ntrip)
  52. ntrip_report(context, gps, dgnss);
  53. #endif
  54. }
  55. /* end */