First attempt at satellite monitor
authorEnrico Zini <enrico@enricozini.org>
Wed, 29 Jul 2009 20:28:50 +0000 (22:28 +0200)
committerEnrico Zini <enrico@enricozini.org>
Wed, 29 Jul 2009 20:28:50 +0000 (22:28 +0200)
src/app_gps.vala
src/gps.vala

index f414444eb7ce7ca795103d92d89b5c36cff4eb54..430461f7caa08938dd81eaa1bc2a6f9fa3f5ce59 100644 (file)
@@ -18,6 +18,8 @@
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
+using GLib;
+
 namespace zavai {
 namespace ui {
 namespace gps {
@@ -80,25 +82,25 @@ class GPXTracer(gtk.ToggleAction):
 
 public class Waypoint : BigButton
 {
-    public Waypoint()
-    {
-        set_label("Take waypoint");
-        zavai.gps.gpx.tracking_changed += on_gpx_tracking_changed;
-        clicked += on_clicked;
-        set_sensitive(zavai.gps.gpx.tracking);
-    }
-
-    protected void on_gpx_tracking_changed(zavai.gps.GPX gpx, bool new_state)
-    {
-stderr.printf("Toggled %d\n", (int)new_state);
-        set_sensitive(new_state);
-    }
-
-    protected void on_clicked()
-    {
-stderr.printf("Activate\n");
-        zavai.gps.gpx.waypoint();
-    }
+       public Waypoint()
+       {
+               set_label("Take waypoint");
+               zavai.gps.gpx.tracking_changed += on_gpx_tracking_changed;
+               clicked += on_clicked;
+               set_sensitive(zavai.gps.gpx.tracking);
+       }
+
+       protected void on_gpx_tracking_changed(zavai.gps.GPX gpx, bool new_state)
+       {
+               stderr.printf("Toggled %d\n", (int)new_state);
+               set_sensitive(new_state);
+       }
+
+       protected void on_clicked()
+       {
+               stderr.printf("Activate\n");
+               zavai.gps.gpx.waypoint();
+       }
 }
 
 /*
@@ -152,50 +154,50 @@ public class GPSRequestLink : Gtk.ToggleButton
        protected string service_name;
        protected string label_start;
        protected string label_stop;
-    protected Gtk.StatusIcon status_icon;
-    protected int fix_status = 0;
+       protected Gtk.StatusIcon status_icon;
+       protected int fix_status = 0;
 
        public GPSRequestLink()
        {
-        service_name = "gps";
-        label_start = "Keep GPS on";
-        label_stop = "Stop keeping GPS on";
+               service_name = "gps";
+               label_start = "Keep GPS on";
+               label_stop = "Stop keeping GPS on";
                set_size_request(0, zavai.config.min_button_height);
                toggled += on_toggled;
 
                set_label(get_active() ? label_stop : label_start);
 
-        //tooltip = "GPS status";
-        try {
-            fix_status = zavai.gps.gps.device.GetFixStatus();
-        } catch (Error e) {
-            fix_status = 0;
-        }
-        zavai.gps.gps.device.FixStatusChanged += on_fix_status_changed;
-
-        // GPS status icon
-        status_icon = new Gtk.StatusIcon();
-        status_icon.set_visible(true);
-        status_icon.activate += on_status_activate;
-        update_icon();
+               //tooltip = "GPS status";
+               try {
+                       fix_status = zavai.gps.gps.device.GetFixStatus();
+               } catch (Error e) {
+                       fix_status = 0;
+               }
+               zavai.gps.gps.device.FixStatusChanged += on_fix_status_changed;
+
+               // GPS status icon
+               status_icon = new Gtk.StatusIcon();
+               status_icon.set_visible(true);
+               status_icon.activate += on_status_activate;
+               update_icon();
        }
 
-    protected void update_icon()
-    {
-        string name;
-        if (fix_status == 2 || fix_status == 3)
-            name = zavai.config.icondir + "/" + (get_active() ? "gps_fix_on.png" : "gps_fix_off.png");
-        else
-            name = zavai.config.icondir + "/" + (get_active() ? "gps_nofix_on.png" : "gps_nofix_off.png");
-stderr.printf("load icon from %s\n", name);
-        status_icon.set_from_file(name);
-    }
-
-    private void on_fix_status_changed(dynamic DBus.Object pos, int fix_status)
-    {
-        this.fix_status = fix_status;
-        update_icon();
-    }
+       protected void update_icon()
+       {
+               string name;
+               if (fix_status == 2 || fix_status == 3)
+                       name = zavai.config.icondir + "/" + (get_active() ? "gps_fix_on.png" : "gps_fix_off.png");
+               else
+                       name = zavai.config.icondir + "/" + (get_active() ? "gps_nofix_on.png" : "gps_nofix_off.png");
+               stderr.printf("load icon from %s\n", name);
+               status_icon.set_from_file(name);
+       }
+
+       private void on_fix_status_changed(dynamic DBus.Object pos, int fix_status)
+       {
+               this.fix_status = fix_status;
+               update_icon();
+       }
 
        private void on_toggled(Gtk.Button src)
        {
@@ -205,25 +207,152 @@ stderr.printf("load icon from %s\n", name);
                else
                        s.release("servicerequestlink");
                set_label(get_active() ? label_stop : label_start);
-        update_icon();
+               update_icon();
        }
 
-    private void on_status_activate()
-    {
-        set_active(!get_active());
-    }
+       private void on_status_activate()
+       {
+               set_active(!get_active());
+       }
 }
 
+static string[] SAT_QI_NAMES;
+
+public class SatelliteMonitor : Applet
+{
+       Gtk.ListStore store;
+       Gtk.TreeView view;
+
+       public SatelliteMonitor()
+       {
+               _label = "Satellite monitor";
+
+               store = new Gtk.ListStore(11, typeof(string), typeof(string), typeof(string),
+                             typeof(string), typeof(string), typeof(string), typeof(string),
+                             typeof(string), typeof(string), typeof(string), typeof(string));
+               view = new Gtk.TreeView();
+               view.set_model(store);
+
+               var renderer = new Gtk.CellRendererText();
+               view.insert_column_with_attributes(-1, "CH", renderer, "text", 0, null);
+               view.insert_column_with_attributes(-1, "ID", renderer, "text", 1, null);
+               view.insert_column_with_attributes(-1, "SN", renderer, "text", 2, null);
+               view.insert_column_with_attributes(-1, "ELE", renderer, "text", 3, null);
+               view.insert_column_with_attributes(-1, "AZI", renderer, "text", 4, null);
+               view.insert_column_with_attributes(-1, "Used", renderer, "text", 5, null);
+               view.insert_column_with_attributes(-1, "Diff", renderer, "text", 6, null);
+               view.insert_column_with_attributes(-1, "Alm", renderer, "text", 7, null);
+               view.insert_column_with_attributes(-1, "Eph", renderer, "text", 8, null);
+               view.insert_column_with_attributes(-1, "Bad", renderer, "text", 9, null);
+               view.insert_column_with_attributes(-1, "Status", renderer, "text", 10, null);
+               pack_start(view, true, true, 0);
+       }
+
+       public override void start()
+       {
+               zavai.gps.monitor.sat_info += on_sat_info;
+               zavai.gps.monitor.request("app.satmonitor");
+       }
+
+       public override void stop()
+       {
+               zavai.gps.monitor.release("app.satmonitor");
+               zavai.gps.monitor.sat_info -= on_sat_info;
+       }
+
+       public void on_sat_info(PtrArray< HashTable<string, Value?> > data)
+       {
+               store.clear();
+               // zavai.info("CH ID SN ELE AZI Used Diff Alm Eph Bad Status")
+               for (int i = 0; i < data.len; ++i)
+               {
+                       HashTable<string, Value?> sv  = (HashTable<string, Value?>)data.pdata[i];
+
+                       Value v = sv.lookup("Flags");
+                       int flags = (int)v;
+
+                       v = sv.lookup("chn");
+                       int chn = (int)v;
+
+                       v = sv.lookup("SVID");
+                       int svid = (int)v;
+
+                       v = sv.lookup("CNO");
+                       int cno = (int)v;
+
+                       v = sv.lookup("Elev");
+                       int elev = (int)v;
+
+                       v = sv.lookup("Azim");
+                       int azim = (int)v;
+
+                       bool used = (flags & 0x01) != 0;
+                       bool diff = (flags & 0x02) != 0;
+                       bool almoreph = (flags & 0x04) != 0;
+                       bool eph = (flags & 0x08) != 0;
+                       bool bad = (flags & 0x10) != 0;
+                       v = sv.lookup("QI");
+                       string sqi = "Unknown";
+
+                       int qi = (int)v;
+                       if (qi < SAT_QI_NAMES.length)
+                               sqi = "%i: %s".printf(qi, SAT_QI_NAMES[qi]);
+
+                       Gtk.TreeIter iter;
+                       store.append(out iter);
+                       store.set(iter, "%2d".printf(chn),
+                                       "%2d".printf(svid),
+                                       "%2d".printf(cno),
+                                       "%3d".printf(elev),
+                                       "%3d".printf(azim),
+                                       used ? "used" : "",
+                                       diff ? "diff" : "",
+                                       almoreph ? "alm" : "",
+                                       eph ? "eph" : "",
+                                       bad ? "bad" : "", sqi);
+               }
+    /*
+    def on_ubxdebug_packet(self, clid, length, data):
+        # In zhone it is cbUBXDebugPacket
+        #if clid == "NAV-STATUS" and data:
+        #    i = ["%s: %d" % (k, data[0][k]) for k in sorted(data[0].keys())]
+        #    zavai.info("Status:", " ".join(i))
+        ##    if data[0]['TTFF']:
+        ##        zavai.info("TTFF: %f", data[0]['TTFF']/1000.0)
+        if clid == "NAV-SVINFO":
+            self.handle_ubx_sat_data(data[1:])
+        #else:
+        #    zavai.info("gps got ubxdebug packet", clid)
+        #    zavai.info("DATA:", data)
+    */
+
+       }
+}
+
+
 public void init()
 {
+       SAT_QI_NAMES = new string[] {
+               "idle",
+               "searching",
+               "signal acquired",
+               "signal unusable",
+               "code lock",
+               "code&carrier lock",
+               "code&carrier lock",
+               "receiving data"
+       };
+
     /*
     registry.register(GPXAudioTracer(registry))
     registry.register(GPXWaypoint(registry))
+    */
 
     // Apps
-    var useless = new Useless();
-    zavai.registry.register_applet("app.debug.useless", useless);
-    */
+    var window_list = new SatelliteMonitor();
+    zavai.registry.register_applet("ui.gps.monitor", window_list);
+    zavai.registry.getmenu("menu.main").add_applet("ui.gps.monitor");
+
     var menu_waypoint = new Waypoint();
     var menu_gpsrequest = new GPSRequestLink();
                //label_on = "Stop GPX trace";
index a405a545045cc6339fd137d02d3260ecad20c758..a55fcbae31bbd018f7d30e07030e3442e9bbb785 100644 (file)
@@ -95,6 +95,9 @@ public class Monitor : zavai.Service
 
        dynamic DBus.Object ubx;
        dynamic DBus.Object time;
+
+    public signal void sat_info(PtrArray< HashTable<string, Value?> > data);
+
        /*
        string[] filters = { "NAV-STATUS", "NAV_SVINFO" };
 
@@ -113,6 +116,7 @@ public class Monitor : zavai.Service
                        "org.freesmartphone.ogpsd",
                        "/org/freedesktop/Gypsy",
                        "org.freesmartphone.GPS.UBX");
+        /*
                time = zavai.registry.sbus.get_object(
                        "org.freesmartphone.ogpsd",
                        "/org/freedesktop/Gypsy",
@@ -121,6 +125,7 @@ public class Monitor : zavai.Service
                zavai.log.info("SETSIG1");
                time.TimeChanged += timechanged;
                zavai.log.info("SETSIG2");
+         */
 
                zavai.log.info("DEBUG1");
                ubx.DebugPacket += on_ubxdebug_packet;
@@ -135,10 +140,12 @@ public class Monitor : zavai.Service
 */
        }
 
+/*
        protected void timechanged(dynamic DBus.Object pos, int t)
        {
                zavai.log.info("TIMECHANGED");
        }
+*/
 
 /*
        protected void debug_update() throws GLib.Error
@@ -228,6 +235,7 @@ public class Monitor : zavai.Service
                */
                //message("Size: %d", data.size());
 //         self.notify("satellites", clid, length, data)
+        sat_info(prova);
        }
 
        protected override void start()