Devuan fork of gpsd
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

97 lines
1.8 KiB

  1. /*
  2. * Copyright (C) 2005 Alfredo Pironti
  3. *
  4. * SPDX-License-Identifier: BSD-2-clause
  5. */
  6. #include "gpsd_config.h" /* must be before all includes */
  7. #include <cstdlib>
  8. #include "libgpsmm.h"
  9. struct gps_data_t* gpsmm::gps_inner_open(const char *host, const char *port)
  10. {
  11. const bool err = (gps_open(host, port, gps_state()) != 0);
  12. if ( err ) {
  13. to_user = NULL;
  14. return NULL;
  15. }
  16. else { // connection successfully opened
  17. to_user= new struct gps_data_t;
  18. return backup(); //we return the backup of our internal structure
  19. }
  20. }
  21. struct gps_data_t* gpsmm::stream(int flags)
  22. {
  23. if (to_user == NULL)
  24. return NULL;
  25. else if (gps_stream(gps_state(),flags, NULL)==-1) {
  26. return NULL;
  27. }
  28. else {
  29. return backup();
  30. }
  31. }
  32. struct gps_data_t* gpsmm::send(const char *request)
  33. {
  34. if (gps_send(gps_state(),request)==-1) {
  35. return NULL;
  36. }
  37. else {
  38. return backup();
  39. }
  40. }
  41. struct gps_data_t* gpsmm::read(void)
  42. {
  43. if (gps_read(gps_state(), NULL, 0)<=0) {
  44. // we return null if there was a read() error, if no
  45. // data was ready in POLL_NOBLOCK mode, or if the
  46. // connection is closed by gpsd
  47. return NULL;
  48. }
  49. else {
  50. return backup();
  51. }
  52. }
  53. bool gpsmm::waiting(int timeout)
  54. {
  55. return gps_waiting(gps_state(), timeout);
  56. }
  57. const char *gpsmm::data(void)
  58. {
  59. return gps_data(gps_state());
  60. }
  61. // cppcheck-suppress unusedFunction
  62. void gpsmm::clear_fix(void)
  63. {
  64. gps_clear_fix(&(gps_state()->fix));
  65. }
  66. // cppcheck-suppress unusedFunction
  67. void gpsmm::enable_debug(int level, FILE *fp)
  68. {
  69. #ifdef CLIENTDEBUG_ENABLE
  70. gps_enable_debug(level, fp);
  71. #endif /* CLIENTDEBUG_ENABLE */
  72. }
  73. // cppcheck-suppress unusedFunction
  74. bool gpsmm::is_open(void)
  75. {
  76. return to_user != NULL;
  77. }
  78. gpsmm::~gpsmm()
  79. {
  80. if ( to_user != NULL ) {
  81. (void)gps_close(gps_state());
  82. delete to_user;
  83. }
  84. }