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.
 
 
 
 
 
 

77 lines
2.3 KiB

  1. /*
  2. * This file is Copyright (c) 2010-2019 by the GPSD project
  3. * SPDX-License-Identifier: BSD-2-clause
  4. */
  5. #include "gpsd_config.h" /* must be before all includes */
  6. #include "gpsd.h"
  7. #if defined(DBUS_EXPORT_ENABLE)
  8. #include <dbus/dbus.h>
  9. static DBusConnection *connection = NULL;
  10. /*
  11. * Does what is required to initialize the dbus connection
  12. * This is pretty basic at this point, as we don't receive commands via dbus.
  13. * Returns 0 when everything is OK.
  14. */
  15. int initialize_dbus_connection(void)
  16. {
  17. DBusError error;
  18. dbus_error_init(&error);
  19. connection = dbus_bus_get(DBUS_BUS_SYSTEM, &error);
  20. if (connection == NULL) {
  21. dbus_error_free(&error);
  22. /* report error */
  23. return 1;
  24. }
  25. return 0;
  26. }
  27. void send_dbus_fix(struct gps_device_t *channel)
  28. {
  29. /* sends the current fix data for this channel via dbus */
  30. struct gps_data_t *gpsdata;
  31. struct gps_fix_t *gpsfix;
  32. DBusMessage *message;
  33. /*DBusMessageIter iter; */
  34. dbus_uint32_t serial; /* collected, but not used */
  35. char *gpsd_devname;
  36. /* if the connection is non existent, return without doing anything */
  37. if (connection == NULL)
  38. return;
  39. gpsdata = &(channel->gpsdata);
  40. gpsfix = &(gpsdata->fix);
  41. gpsd_devname = gpsdata->dev.path;
  42. /* Send the named signal. */
  43. /* the dbus/locationd doc fails to specify altitude as WGS84 or MSL.
  44. * assume altMSL */
  45. message = dbus_message_new_signal("/org/gpsd", "org.gpsd", "fix");
  46. dbus_message_append_args(message,
  47. DBUS_TYPE_DOUBLE, &(gpsfix->time),
  48. DBUS_TYPE_INT32, &(gpsfix->mode),
  49. DBUS_TYPE_DOUBLE, &(gpsfix->ept),
  50. DBUS_TYPE_DOUBLE, &(gpsfix->latitude),
  51. DBUS_TYPE_DOUBLE, &(gpsfix->longitude),
  52. DBUS_TYPE_DOUBLE, &(gpsfix->eph),
  53. DBUS_TYPE_DOUBLE, &(gpsfix->altMSL),
  54. DBUS_TYPE_DOUBLE, &(gpsfix->epv),
  55. DBUS_TYPE_DOUBLE, &(gpsfix->track),
  56. DBUS_TYPE_DOUBLE, &(gpsfix->epd),
  57. DBUS_TYPE_DOUBLE, &(gpsfix->speed),
  58. DBUS_TYPE_DOUBLE, &(gpsfix->eps),
  59. DBUS_TYPE_DOUBLE, &(gpsfix->climb),
  60. DBUS_TYPE_DOUBLE, &(gpsfix->epc),
  61. DBUS_TYPE_STRING, &gpsd_devname,
  62. DBUS_TYPE_INVALID);
  63. dbus_message_set_no_reply(message, TRUE);
  64. dbus_connection_send(connection, message, &serial);
  65. dbus_message_unref(message);
  66. }
  67. #endif /* defined(DBUS_EXPORT_ENABLE) */