#include "latlon.h"
#include "map.h"
#include "gps-nmea-parse.h"
+#include "gps-conn.h"
#include "track.h"
+#define GPSD_NMEA "r+\r\n"
+#define GPSD_PORT (2947)
+
static gboolean gps_channel_cb_error(GIOChannel *src, GIOCondition condition, gpointer data);
static gboolean gps_channel_cb_input(GIOChannel *src, GIOCondition condition, gpointer data);
static gboolean gps_channel_cb_connect(GIOChannel * src, GIOCondition condition, gpointer data);
* Init GPS structure
*/
Gps *
-gps_new(void)
+gps_new(GpsIOSourceType type)
{
Gps *gps;
gps=g_slice_new0(Gps);
gps->data.fix=FIX_NOFIX;
gps->io.fd=-1;
+gps->io.address=NULL;
+gps->io.type=type;
gps->io.conn=RCVR_OFF;
+gps->data.lat=64.20;
+gps->data.lon=22.20;
gps_data_integerize(&gps->data);
return gps;
}
+void
+gps_set_address(Gps *gps, gchar *address, guint port)
+{
+if (gps->io.address)
+ g_free(gps->io.address);
+if (address)
+ gps->io.address=g_strdup(address);
+gps->io.port=port;
+}
+
+void
+gps_free(Gps *gps)
+{
+gps_disconnect(gps);
+if (gps->io.address)
+ g_free(gps->io.address);
+g_slice_free(Gps, gps);
+}
+
/**
* Convert the float lat/lon/speed/heading data into integer units.
* Also calculate offsets.
return FALSE;
}
+/**
+ * Helper to open a file or device node
+ */
static gboolean
gps_connect_file(Gps *gps)
{
return TRUE;
}
+/**
+ * Helper to connect to a socket file descriptor.
+ *
+ */
static gboolean
gps_connect_socket(Gps *gps)
{
return TRUE;
}
+/**
+ * Disconnect the GPS device.
+ * - Add channel callbacks are removed
+ * - Channel is close and shutdown
+ * - File descriptor is closed
+ * - Anything special for disconnecting is done
+ */
void
gps_disconnect(Gps *gps)
{
}
#endif
+#ifdef WITH_BLUEZ_DBUS_BT
+if (gps->io.type==GPS_IO_BLUEZ_DBUS && gps->io.rfcomm_req_proxy) {
+ GError *error = NULL;
+}
+#endif
+
}
/**
* gps_disconnect() first.
* Since this is an idle function, this function returns whether or not it
* should be called again, which is always FALSE.
+ *
+ * This function prepares for the connection, the gps_connect does the "connecting" if needed.
*/
gboolean
gps_connect_now(Gps *gps)
switch (gps->io.type) {
case GPS_IO_FILE:
+ if (!gps->io.address)
+ return FALSE;
if (*gps->io.address=='/')
gps->io.fd=open(gps->io.address, O_RDONLY);
else
case GPS_IO_HILDON_DBUS:
#ifdef WITH_HILDON_DBUS_BT
if (gps->io.rfcomm_req_proxy) {
- gint mybool = TRUE;
+ gboolean mybool = TRUE;
dbus_g_proxy_begin_call(_rfcomm_req_proxy,
- BTCOND_RFCOMM_CONNECT_REQ,
- (DBusGProxyCallNotify)
- rcvr_connect_response,
- NULL, NULL,
- G_TYPE_STRING,
- _rcvr_mac,
+ BTCOND_RFCOMM_CONNECT_REQ, (DBusGProxyCallNotify)gps_connect_response, NULL, NULL,
+ G_TYPE_STRING, gps->io.address,
G_TYPE_STRING, "SPP",
G_TYPE_BOOLEAN, &mybool,
G_TYPE_INVALID);
}
+#else
+ return FALSE;
#endif
break;
case GPS_IO_RFCOMM:
case GPS_IO_RFCOMM:
case GPS_IO_GPSD:
if ((getsockopt(gps->io.fd, SOL_SOCKET, SO_ERROR, &error, &size) || error)) {
- g_printf("Error connecting to receiver; retrying...\n");
+ g_printerr("Error connecting to receiver; retrying...\n");
gps_disconnect(gps);
gps_connect_later(gps);
gps->io.connect_sid=0;
+ gps->io.errors++;
return FALSE;
+ }
+ /* Set gpsd to NMEA mode */
+ if (gps->io.type==GPS_IO_GPSD) {
+ GIOStatus status;
+ gint written;
+ status=g_io_channel_write_chars(gps->io.channel, GPSD_NMEA, -1, &written, NULL);
+ if (status!=G_IO_STATUS_NORMAL || written!=sizeof(GPSD_NMEA)) {
+ g_printerr("Failed to set gpsd to NMEA mode\n");
+ gps_disconnect(gps);
+ gps_connect_later(gps);
+ gps->io.connect_sid=0;
+ gps->io.errors++;
+ return FALSE;
+ }
}
break;
case GPS_IO_FILE:
break;
default:
- return FALSE;
+ g_warning("Connection from non-connecting source\n");
break;
}
case G_IO_STATUS_EOF:
gps_disconnect(gps);
gps_connect_later(gps);
+ gps->io.errors++;
return FALSE;
break;
case G_IO_STATUS_AGAIN: