Started satellite monitor
authorEnrico Zini <enrico@enricozini.org>
Sun, 14 Jun 2009 05:05:45 +0000 (13:05 +0800)
committerEnrico Zini <enrico@enricozini.org>
Sun, 14 Jun 2009 05:05:45 +0000 (13:05 +0800)
plugins/sat_monitor.py [new file with mode: 0644]
zavai/gps.py

diff --git a/plugins/sat_monitor.py b/plugins/sat_monitor.py
new file mode 100644 (file)
index 0000000..af8a24c
--- /dev/null
@@ -0,0 +1,122 @@
+# sat_monitor - zavai satellite monitor
+#
+# Copyright (C) 2009  Enrico Zini <enrico@enricozini.org>
+#
+# 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
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+
+import gtk
+import sys
+import gettext
+_ = gettext.gettext
+import zavai
+
+SAT_QI_NAMES = {
+    0: _("idle"),
+    1: _("searching"),
+    2: _("signal acquired"),
+    3: _("signal unusable"),
+    4: _("code lock"),
+    5: _("code&carrier lock"),
+    6: _("code&carrier lock"),
+    7: _("receiving data")
+}
+
+class SatelliteMonitor(gtk.VBox, zavai.Resource):
+    def __init__(self, registry, name, **kw):
+        super(SatelliteMonitor, self).__init__()
+
+        self.gps = registry.resource("gps")
+
+        self.store = gtk.ListStore(str, str, str, str, str, str, str, str, str, str, str)
+        self.view = gtk.TreeView(self.store)
+
+        renderer = gtk.CellRendererText()
+        for idx, name in enumerate((_("CH"), _("ID"), _("SN"), _("ELE"), _("AZI"),
+                     _("Used"), _("Diff"), _("Alm"), _("Eph"),
+                     _("Bad"), _("Status"))):
+            col = gtk.TreeViewColumn(name)
+            col.pack-start(renderer, False)
+            col.add_attribute(rendrer, "text", idx)
+            self.view.append_column(col)
+
+        self.back = registry.menu_link("gps", _("Back"))
+        self.back.connect("clicked", self.stop)
+
+        self.pack_start(self.view, True, True)
+        self.pack_start(self.back, False, False)
+
+    def shutdown(self):
+        self.stop()
+
+    def start(self, args):
+        self.gps.monitor.connect(self.on_ubxdebug_packet)
+
+    def stop(self, args):
+        self.gps.monitor.disconnect(self.on_ubxdebug_packet)
+
+    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)
+
+    def handle_ubx_sat_data(self, ubxinfo):
+        #zavai.info("CH ID SN ELE AZI Used Diff Alm Eph Bad Status")
+        self.store.clear()
+        for sv in ubxinfo:
+            if sv["CNO"] == 0: continue
+            svid = sv["SVID"]
+            used = sv["Flags"] & 0x01
+            diff = sv["Flags"] & 0x02
+            almoreph = sv["Flags"] & 0x04
+            eph = sv["Flags"] & 0x08
+            bad = sv["Flags"] & 0x10
+            qi = ("%i: " % sv["QI"]) + SAT_QI_NAMES.get(sv["QI"], _("Unknown"))
+            self.store.append([
+                "%2d" % sv["chn"],
+                "%2d" % sv["SVID"],
+                "%2d" % sv["CNO"],
+                "%3d" % sv["Elev"],
+                "%3d" % sv["Azim"],
+                used and "used" or "",
+                diff and "diff" or "",
+                almoreph and "alm" or "",
+                eph and "eph" or "",
+                bad and "bad" or "",
+                qi])
+
+def start_monitor(registry):
+    monitor = registry.resource("app.satellite_monitor")
+    registry.resource("app").show_widget(monitor)
+    monitor.start()
+
+def init(conf = None, registry = None, **kw):
+    registry.register("app.satellite_monitor", SatelliteMonitor)
+    menu_gps = registry.menu("main.gps")
+
+    monitor = gtk.Button(_("Monitor"))
+    monitor.connect("clicked", lambda *args: start_monitor(registry))
+    menu_gps.add_child(monitor)
+
+    # TODO: automate this in registry
+    registry.menu("main").add_child(registry.menu_link("main.gps", _("GPS")))
+
index 22e3a6dc86f030c8ea71c6f6193ad18eb56bff2a..1c5930ef0e8ee7b4b7defd08bcdff15b307eb7f2 100755 (executable)
@@ -109,56 +109,6 @@ class GPSMonitor():
         if not self.callbacks:
             self._stop_listening()
 
-#        # 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.print_ubx_sat_data(data[1:])
-#        #else:
-#        #    zavai.info("gps got ubxdebug packet", clid)
-#        #    zavai.info("DATA:", data)
-#
-#    def print_ubx_sat_data(self, ubxinfo):
-#        zavai.info("CH ID SN ELE AZI Used Diff Alm Eph Bad Status")
-#        for sv in ubxinfo:
-#            if sv["CNO"] == 0: continue
-#            svid = sv["SVID"]
-#            used = sv["Flags"] & 0x01
-#            diff = sv["Flags"] & 0x02
-#            almoreph = sv["Flags"] & 0x04
-#            eph = sv["Flags"] & 0x08
-#            bad = sv["Flags"] & 0x10
-#            qi = ("%i: " % sv["QI"]) + {
-#                0: "idle",
-#                1: "searching",
-#                2: "signal acquired",
-#                3: "signal unusable",
-#                4: "code lock",
-#                5: "code&carrier lock",
-#                6: "code&carrier lock",
-#                7: "receiving data"
-#            }[sv["QI"]]
-#            zavai.info("%2d %2d %2d %3d %3d %s %s %s %s %s %s" % (
-#                sv["chn"], sv["SVID"],
-#                sv["CNO"], sv["Elev"], sv["Azim"],
-#                used and "used" or "----",
-#                diff and "diff" or "----",
-#                almoreph and "alm" or "---",
-#                eph and "eph" or "---",
-#                bad and "bad" or "---",
-#                qi))
-#
-#    def print_sat_data(self, satellites):
-#        for sat in satellites:
-#            if sat[4] == 0: continue
-#            zavai.info("PRN %u" % sat[0],
-#                 sat[1] and "used" or "unused",
-#                 "el %u" % sat[2],
-#                 "az %u" % sat[3],
-#                 "snr %u" % sat[4])
 
 # For a list of dbus services, look in /etc/dbus-1/system.d/
 class GPS(zavai.Resource):