Initial commit
authorDr. Johann Pfefferl <pfefferl@nghape.jpnet>
Fri, 7 May 2010 18:56:25 +0000 (20:56 +0200)
committerDr. Johann Pfefferl <pfefferl@nghape.jpnet>
Fri, 7 May 2010 18:56:25 +0000 (20:56 +0200)
Makefile [new file with mode: 0644]
gps-tracker.c [new file with mode: 0644]

diff --git a/Makefile b/Makefile
new file mode 100644 (file)
index 0000000..9f9fb87
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,32 @@
+# define a list of pkg-config packages we want to use
+pkg_packages := gtk+-2.0 hildon-1 liblocation
+
+# get the necessary flags for compiling
+PKG_CFLAGS := $(shell pkg-config --cflags $(pkg_packages))
+# get the necessary flags for linking
+PKG_LDFLAGS := $(shell pkg-config --libs $(pkg_packages))
+
+# additional flags
+# -Wall: warnings
+# -g: debugging
+ADD_CFLAGS := -Wall -g
+
+# combine the flags (so that CFLAGS/LDFLAGS from the command line
+# still work).
+CFLAGS  := $(PKG_CFLAGS) $(ADD_CFLAGS) $(CFLAGS)
+LDFLAGS := $(PKG_LDFLAGS) $(LDFLAGS)
+
+targets = gps-tracker
+
+.PHONY: all
+all: $(targets)
+
+gps-tracker: gps-tracker.o
+       $(CC) $^ -o $@ $(LDFLAGS)
+
+.PHONY: clean
+clean:
+       $(RM) $(targets) *.o
+
+run: $(targets)
+       run-standalone.sh `pwd`/gps-tracker
diff --git a/gps-tracker.c b/gps-tracker.c
new file mode 100644 (file)
index 0000000..3499a8e
--- /dev/null
@@ -0,0 +1,166 @@
+#include <glib.h>
+
+#include <hildon/hildon.h>
+#include <location/location-gpsd-control.h>
+#include <location/location-gps-device.h>
+#include <location/location-misc.h>
+#include <location/location-distance-utils.h>
+
+static void
+on_gps_device_changed (LocationGPSDevice *device, gpointer data)
+{
+  GtkLabel *info = (GtkLabel*)data;
+  GString *msg;
+       if (!device)
+               return;
+
+  msg = g_string_new("");
+       if (device->fix) {
+               if (device->fix->fields & LOCATION_GPS_DEVICE_TIME_SET) {
+                       g_print ("time = %f\n", device->fix->time);
+      g_string_append_printf(msg, "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);
+                       g_string_append_printf (msg, "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);
+                       g_string_append_printf (msg, "alt = %f\n", device->fix->altitude);
+    }
+
+               if (device->fix->fields & LOCATION_GPS_DEVICE_SPEED_SET) {
+                       g_print ("speed = %f\n", device->fix->speed);
+                       g_string_append_printf (msg, "speed = %f\n", device->fix->speed);
+    }
+
+               if (device->fix->fields & LOCATION_GPS_DEVICE_TRACK_SET) {
+                       g_print ("track = %f\n", device->fix->track);
+                       g_string_append_printf (msg, "track = %f\n", device->fix->track);
+    }
+
+               if (device->fix->fields & LOCATION_GPS_DEVICE_CLIMB_SET) {
+                       g_print ("climb = %f\n", device->fix->climb);
+                       g_string_append_printf (msg, "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);
+       g_print ("GPS status: %d\n", device->status);
+
+       if (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);
+       }
+
+  gtk_label_set_text(info, msg->str);
+  //gtk_widget_show(GTK_WIDGET(info));
+  g_string_free(msg, TRUE);
+}
+
+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");
+}
+
+int main (int argc, char **argv)
+{
+       HildonProgram *program = NULL;
+       GtkWidget *window = NULL;
+       GtkWidget *picker_button = NULL;
+  GtkVBox *vbox;
+  GtkWidget *status_label;
+
+       hildon_gtk_init (&argc, &argv);
+       LocationGPSDControl *control;
+       LocationGPSDevice *device;
+
+       program = hildon_program_get_instance ();
+       g_set_application_name("GPS tracker");
+
+       window = hildon_stackable_window_new ();
+       hildon_program_add_window (program, HILDON_WINDOW (window));
+
+  vbox = (void*)gtk_vbox_new(TRUE, 8);
+
+       /* Create a picker button */
+       picker_button = hildon_date_button_new (HILDON_SIZE_AUTO,
+                       HILDON_BUTTON_ARRANGEMENT_VERTICAL);
+
+       /* Set a title to the button*/
+       hildon_button_set_title (HILDON_BUTTON (picker_button), "Pick a date");
+
+  gtk_box_pack_start(GTK_BOX(vbox), picker_button, FALSE, FALSE, 0);
+  status_label = gtk_label_new("Hier kommt der Status hin\nUnd hier ist die 2. Zeile");
+  gtk_box_pack_start_defaults(GTK_BOX(vbox), status_label);
+       /* Add vbox to main window */
+       gtk_container_add (GTK_CONTAINER (window), GTK_WIDGET(vbox));
+
+       g_signal_connect (G_OBJECT (window), "destroy",
+                       G_CALLBACK (gtk_main_quit), NULL);
+
+       control = location_gpsd_control_get_default ();
+       location_gpsd_control_start (control);
+
+       /*
+        * 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),     status_label);
+
+       gtk_widget_show_all (GTK_WIDGET (window));
+
+       gtk_main ();
+
+       location_gpsd_control_stop (control);
+
+       g_object_unref (device);
+       g_object_unref (control);
+
+       return 0;
+}