}
+static gboolean
+gps_simulate(Gps *gps)
+{
+g_assert(gps);
+
+gps->data.lat+=g_random_double_range(-0.0002,0.0002);
+gps->data.lon+=g_random_double_range(-0.0002,0.0002);
+BOUND(gps->data.lat, -80.0, 80.0);
+BOUND(gps->data.lon, -80.0, 80.0);
+gps->data.speed=1+g_random_double_range(0.0,5.0);
+gps->data.heading+=g_random_double_range(-2.0,2.0);
+gps->data.time=time(NULL);
+gps_data_integerize(&gps->data);
+track_add(gps, FALSE);
+gps->data.lheading=gps->data.heading;
+map_refresh_mark();
+
+return TRUE;
+}
+
+/**
+ * Reset GPS read buffer
+ */
+static void
+gps_read_buffer_prepare(Gps *gps)
+{
+gps->io.curr=gps->io.buffer;
+*gps->io.curr = '\0';
+gps->io.last=gps->io.buffer+GPS_READ_BUF_SIZE-1;
+}
+
+/**
+ * Connect file descriptor to channel and add watches.
+ */
+static void
+gps_read_channel_connect(Gps *gps)
+{
+gps->io.channel=g_io_channel_unix_new(gps->io.fd);
+g_io_channel_set_encoding(gps->io.channel, NULL, NULL);
+g_io_channel_set_flags(gps->io.channel, G_IO_FLAG_NONBLOCK, NULL);
+gps->io.error_sid=g_io_add_watch_full(gps->io.channel, G_PRIORITY_HIGH_IDLE, G_IO_ERR | G_IO_HUP, gps_channel_cb_error, NULL, NULL);
+gps->io.connect_sid=g_io_add_watch_full(gps->io.channel, G_PRIORITY_HIGH_IDLE, G_IO_OUT, gps_channel_cb_connect, NULL, NULL);
+gps->io.clater_sid=0;
+}
+
/**
* Connect to the receiver.
* This method assumes that fd is -1 and _channel is NULL. If unsure, call
gps_connect_now(Gps *gps)
{
g_assert(gps);
+g_debug("GPS: Connecting GPS type %d to %s:%d\n", gps->io.type, gps->io.address, gps->io.port);
switch (gps->io.type) {
case GPS_IO_FILE:
#endif
return FALSE;
break;
+ case GPS_IO_SIMULATION:
+ /* Set a periodic cb to generate random movement */
+ gps->data.lat=64.22;
+ gps->data.lat=22.22;
+ gps->io.conn=RCVR_FIXED;
+ gps->data.fix=FIX_2D;
+ gps_data_integerize(&gps->data);
+ gps->io.input_sid=g_timeout_add(1000, (GSourceFunc)gps_simulate, gps);
+ return FALSE;
+ break;
default:
return FALSE;
break;
}
-/* Reset GPS read buffer */
-gps->io.curr=gps->io.buffer;
-*gps->io.curr = '\0';
-gps->io.last=gps->io.buffer+GPS_READ_BUF_SIZE-1;
-
-/* Create channel and add watches. */
-gps->io.channel=g_io_channel_unix_new(gps->io.fd);
-g_io_channel_set_encoding(gps->io.channel, NULL, NULL);
-g_io_channel_set_flags(gps->io.channel, G_IO_FLAG_NONBLOCK, NULL);
-gps->io.error_sid=g_io_add_watch_full(gps->io.channel, G_PRIORITY_HIGH_IDLE, G_IO_ERR | G_IO_HUP, gps_channel_cb_error, NULL, NULL);
-gps->io.connect_sid=g_io_add_watch_full(gps->io.channel, G_PRIORITY_HIGH_IDLE, G_IO_OUT, gps_channel_cb_connect, NULL, NULL);
-gps->io.clater_sid=0;
+gps_read_buffer_prepare(gps);
+gps_read_channel_connect(gps);
gps_connect(gps);
return FALSE;
}