From ec2f140ac5eb32aace40f4e6f0c3f7b3bed88e71 Mon Sep 17 00:00:00 2001 From: Enrico Zini Date: Mon, 8 Mar 2010 22:47:58 +0100 Subject: [PATCH] Initial libgps-based gps monitor support --- README | 5 ++ src/CMakeLists.txt | 2 +- src/app_gps.vala | 14 +++- src/gps.vala | 198 +++++++++++++++++++-------------------------- 4 files changed, 98 insertions(+), 121 deletions(-) diff --git a/README b/README index fdf9ace..0a7fcbe 100644 --- a/README +++ b/README @@ -162,6 +162,11 @@ TODO list / wish list + set to keep the GPS on during suspend - use the gpsd protocol to know if there is a fix or not - suspend/resume hooks to put the GPS into low power mode + - log + - timestamp, coordinates + - message (structured) (json?) + - instant or period (start, end). Period have timestamp and coordinates at + start and end. And GPX track of trip. - alarm - log unacked alarms - play sound at alarm trigger diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 62dbc54..9e03dfd 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -3,7 +3,7 @@ include(../vala.cmake) set(zavai_version 0.1) -set(packages gtk+-2.0 dbus-glib-1>=0.80 libwnck-1.0>=2.26.0 lua5.1 libomhacks x11 gdk-x11-2.0) +set(packages gtk+-2.0 dbus-glib-1>=0.80 libwnck-1.0>=2.26.0 lua5.1 libomhacks x11 gdk-x11-2.0 libgps) add_packages(ZAVAI ${packages}) set(VALA_PACKAGES ${packages} posix linux-input dbus-extra gtkfisheyelist) diff --git a/src/app_gps.vala b/src/app_gps.vala index 7ad705b..a82429c 100644 --- a/src/app_gps.vala +++ b/src/app_gps.vala @@ -24,6 +24,7 @@ namespace zavai { namespace ui { namespace gps { +#if 0 public class Waypoint : BigButton { public Waypoint() @@ -92,6 +93,7 @@ class GPXAudioTracer(gtk.ToggleAction): else: self.recorder.stop() */ +#endif public class GPSRequestLink : Gtk.ToggleButton { @@ -110,12 +112,14 @@ public class GPSRequestLink : Gtk.ToggleButton set_label(get_active() ? label_stop : label_start); //tooltip = "GPS status"; +#if 0 try { fix_status = zavai.gps.gps.device.GetFixStatus(); } catch (Error e) { fix_status = 0; } zavai.gps.gps.device.FixStatusChanged += on_fix_status_changed; +#endif // GPS status icon status_icon = new zavai.StatusIcon(); @@ -143,6 +147,7 @@ public class GPSRequestLink : Gtk.ToggleButton private void on_toggled(Gtk.Button src) { +stderr.printf("TOGGOLED\n"); if (get_active()) zavai.gps.gps.request("servicerequestlink"); else @@ -157,6 +162,7 @@ public class GPSRequestLink : Gtk.ToggleButton } } +#if 0 public class GPSStuck : Gtk.Button { protected bool happened; @@ -179,7 +185,7 @@ public class GPSStuck : Gtk.Button label = "The GPS is stuck"; } } - +#endif public void init() { /* @@ -187,15 +193,15 @@ public void init() */ // Apps - var menu_waypoint = new Waypoint(); + // var menu_waypoint = new Waypoint(); var menu_gpsrequest = new GPSRequestLink(); // Menus zavai.menu_gps.add_service_toggle(zavai.gps.gpx, "Start GPX trace", "Stop GPX trace"); //zavai.menu_gps.add_applet("ui.gps.monitor"); - zavai.menu_gps.add_widget(menu_waypoint); + //zavai.menu_gps.add_widget(menu_waypoint); zavai.menu_gps.add_widget(menu_gpsrequest); - zavai.menu_gps.add_widget(new GPSStuck()); + //zavai.menu_gps.add_widget(new GPSStuck()); } } diff --git a/src/gps.vala b/src/gps.vala index 434f7f2..85e7997 100644 --- a/src/gps.vala +++ b/src/gps.vala @@ -1,7 +1,7 @@ /* * gps - gps resource for zavai * - * Copyright (C) 2009 Enrico Zini + * Copyright (C) 2009--2010 Enrico Zini * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -26,125 +26,90 @@ namespace gps { // For a list of dbus services, look in /etc/dbus-1/system.d/ public class GPS: zavai.Service { - public dynamic DBus.Object usage; - public dynamic DBus.Object device; + protected libgps.data_t data; + protected IOChannel gpsfd = null; + protected uint gpsfd_watch = 0; - public GPS() - { - Object(name: "gps"); - - // see mdbus -s org.freesmartphone.ousaged /org/freesmartphone/Usage - usage = zavai.registry.sbus.get_object( - "org.freesmartphone.ousaged", - "/org/freesmartphone/Usage", - "org.freesmartphone.Usage"); + public GPS() + { + Object(name: "gps"); + data = libgps.data_t(); + } - device = zavai.registry.sbus.get_object( - "org.freesmartphone.ogpsd", - "/org/freedesktop/Gypsy", - "org.freedesktop.Gypsy.Device"); - } + protected bool on_input_data(IOChannel source, IOCondition condition) + { + while (libgps.waiting(ref data)) + { + int res = libgps.poll(ref data); + if (res != 0) + zavai.log.error(libgps.errstr(res)); + stderr.printf("GPSMSG %d %d\n", (int)data.set, data.status); + } + return true; + } - public void power_cycle(bool aggressive) + /// Request GPS resource + public override void start() { - // "Have you tried turning it off and on again?" - try { - usage.SetResourcePolicy("GPS", "disabled"); - } catch (GLib.Error e) { - zavai.log.error(e.message); - } - Thread.usleep(500000); - if (aggressive) - // Sometimes the GPS crashes because its state contains something - // that makes it crash, so we need to remove the saved state or it - // crashes again quite soon - FileUtils.unlink("/var/lib/freesmartphone/ogpsd.pickle"); - try { - usage.SetResourcePolicy("GPS", "auto"); - } catch (GLib.Error e) { - zavai.log.error(e.message); - } + if (started) return; + + try { + // Then run our own script + zavai.app.run_script(zavai.config.homedir + "/gps start"); + } catch (Error e) { + zavai.log.error("Running " + zavai.config.homedir + "/gps start: " + e.message); + return; + } + + int res = libgps.open_r("ciapino", "gpsd", ref data); + if (res != 0) + { + zavai.log.error(libgps.errstr(res)); + return; + } + + res = libgps.stream(ref data, libgps.WATCH_ENABLE, null); + if (res != 0) + { + zavai.log.error(libgps.errstr(res)); + return; + } + + //res = libgps.send(ref data, "?SKY;"); + //res = libgps.send(ref data, "?WATCH;"); + //if (res != 0) zavai.log.error(libgps.errstr(res)); + + gpsfd = new IOChannel.unix_new(data.gps_fd); + try { + gpsfd.set_encoding(null); + } catch (Error e) { + zavai.log.error("Setting encoding to null on gpsd io channel: " + e.message); + } + //gpsfd.set_buffered(false); + gpsfd_watch = gpsfd.add_watch(IOCondition.IN, on_input_data); + + zavai.log.info("GPS turned on"); + base.start(); } - /// Request GPS resource - public override void start() - { - if (started) return; - bool done = false; -/* - try { - // First try with FSO - usage.RequestResource("GPS"); - done = true; - } catch (GLib.Error e) { - zavai.log.error("Requesting resource GPS: " + e.message); - } - if (!done) - { - try { - // Then make it work for fil - // TODO: switch fil to om - zavai.app.run_script("om-device start gps"); - done = true; - } catch (Error e) { - zavai.log.error("Running om-device start gps: " + e.message); - } - } -*/ - if (!done) - { - try { - // Then run our own script - zavai.app.run_script(zavai.config.homedir + "/gps start"); - done = true; - } catch (Error e) { - zavai.log.error("Running " + zavai.config.homedir + "/gps on: " + e.message); - } - } - if (done) - zavai.log.info("GPS turned on"); - else - zavai.log.error("Could not turn on GPS"); - base.start(); - } + // Release usage of GPS + public override void stop() + { + if (!started) return; - // Release usage of GPS - public override void stop() - { - if (!started) return; - bool done = false; -/* - try { - usage.ReleaseResource("GPS"); - done = true; - } catch (GLib.Error e) { - zavai.log.error("Releasing resource GPS: " + e.message); - } - if (!done) - { - try { - zavai.app.run_script("om-device stop gps"); - done = true; - } catch (Error e) { - zavai.log.error("Running device stop gps: " + e.message); - } - } -*/ - if (!done) - { - try { - zavai.app.run_script(zavai.config.homedir + "/gps stop"); - done = true; - } catch (Error e) { - zavai.log.error("Running device stop gps: " + e.message); - } - } - if (done) - zavai.log.info("GPS turned off"); - else - zavai.log.error("Could not turn off GPS"); - base.stop(); - } + Source.remove(gpsfd_watch); + + int res = libgps.close(ref data); + if (res != 0) + zavai.log.error(libgps.errstr(res)); + + try { + zavai.app.run_script(zavai.config.homedir + "/gps stop"); + } catch (Error e) { + zavai.log.error("Running device stop gps: " + e.message); + } + base.stop(); + } } public class Position : zavai.Service @@ -396,9 +361,10 @@ public zavai.gps.GPX gpx = null; public void init() { - gps = new GPS(); - position = new Position(); - gpx = new GPX(); + gps = new GPS(); + position = new Position(); + gpx = new GPX(); + } } -- 2.39.5