net_gnss_dispatch.c 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /* net_gnss_dispatch.c -- common interface to a number of Network GNSS services
  2. *
  3. * This file is Copyright 2010 by the GPSD project
  4. * SPDX-License-Identifier: BSD-2-clause
  5. */
  6. #include "gpsd_config.h" /* must be before all includes */
  7. #include <errno.h>
  8. #include <string.h>
  9. #include <sys/socket.h>
  10. #include <sys/stat.h>
  11. #include <sys/types.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. /* may be time to ship a usage report to the DGNSS service */
  45. void netgnss_report(struct gps_context_t *context,
  46. struct gps_device_t *gps, struct gps_device_t *dgnss)
  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 */
  56. // vim: set expandtab shiftwidth=4