#include #include #include #include #include static void on_gps_device_changed (LocationGPSDevice *device, gpointer data) { if (!device) return; if (device->fix) { if (device->fix->fields & LOCATION_GPS_DEVICE_TIME_SET) g_print ("time = %f\n", device->fix->time); if (device->fix->fields & LOCATION_GPS_DEVICE_LATLONG_SET) g_print ("lat = %f, long = %f\n", device->fix->latitude, device->fix->longitude); if (device->fix->fields & LOCATION_GPS_DEVICE_ALTITUDE_SET) g_print ("alt = %f\n", device->fix->altitude); if (device->fix->fields & LOCATION_GPS_DEVICE_SPEED_SET) g_print ("speed = %f\n", device->fix->speed); if (device->fix->fields & LOCATION_GPS_DEVICE_TRACK_SET) g_print ("track = %f\n", device->fix->track); if (device->fix->fields & LOCATION_GPS_DEVICE_CLIMB_SET) g_print ("climb = %f\n", device->fix->climb); g_print ("Accuracy values:\n"); g_print ("\tept = %e, eph = %e, epv = %e, epd = %e, " "eps = %e, epc = %e\n", device->fix->ept, device->fix->eph, device->fix->epv, device->fix->epd, device->fix->eps, device->fix->epc); } g_print ("Satellites in view: %d\n", device->satellites_in_view); g_print ("Satellites in use: %d\n", device->satellites_in_use); if (device && device->cell_info) { if (device->cell_info->flags & LOCATION_CELL_INFO_GSM_CELL_INFO_SET) g_print ("Mobile Coutry Code GSM: %d\n", device->cell_info->gsm_cell_info.mcc); if (device->cell_info->flags & LOCATION_CELL_INFO_WCDMA_CELL_INFO_SET) g_print ("Mobile Coutry Code WCDMA: %d\n", device->cell_info->wcdma_cell_info.mcc); } } static void on_gps_error (LocationGPSDevice *device, gpointer data) { g_error ("GPS error"); } static void on_gps_stop (LocationGPSDevice *device, gpointer data) { g_warning ("GPS stopped"); } static void on_gps_start (LocationGPSDevice *device, gpointer data) { g_warning ("GPS started"); } static gboolean on_timer_start (gpointer data) { LocationGPSDControl *control = (LocationGPSDControl *) data; location_gpsd_control_start (control); return FALSE; } static gboolean on_timer_stop (gpointer data) { LocationGPSDControl *control = (LocationGPSDControl *) data; location_gpsd_control_stop (control); return FALSE; } static gboolean on_timer_quit (gpointer p) { GMainLoop *loop = (GMainLoop *) p; g_main_loop_quit (loop); return FALSE; } int main () { GMainLoop *loop; LocationGPSDControl *control; LocationGPSDevice *device; g_type_init (); loop = g_main_loop_new (NULL, FALSE); control = location_gpsd_control_get_default (); /* * Note that in real life one may want to use some other method and interval * than LOCATION_METHOD_USER_SELECTED and LOCATION_INTERVAL_DEFAULT, * respectively. For more information on possible values for these parameters * please see liblocation online documentation. */ g_object_set (G_OBJECT (control), "preferred-method", LOCATION_METHOD_USER_SELECTED, "preferred-interval", LOCATION_INTERVAL_DEFAULT, NULL); device = g_object_new (LOCATION_TYPE_GPS_DEVICE, NULL); g_signal_connect (control, "error", G_CALLBACK (on_gps_error), NULL); g_signal_connect (control, "gpsd-running", G_CALLBACK (on_gps_start), NULL); g_signal_connect (control, "gpsd-stopped", G_CALLBACK (on_gps_stop), NULL); g_signal_connect (device, "changed", G_CALLBACK (on_gps_device_changed), NULL); #define START_DELAY 1000 /* one second before starting locationing */ #define STOP_DELAY (START_DELAY + 5 * 60 * 1000) /* five minutes of running the location device */ #define QUIT_DELAY (STOP_DELAY + 1000) /* quit one second after stopping locationing */ g_timeout_add (START_DELAY, on_timer_start, control); g_timeout_add (STOP_DELAY, on_timer_stop, control); g_timeout_add (QUIT_DELAY, on_timer_quit, loop); g_main_run (loop); g_object_unref (device); g_object_unref (control); return 0; }