# sat_monitor - zavai satellite monitor # # Copyright (C) 2009 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 # 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(renderer, "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("app.satellite_monitor") monitor.start() def init(conf = None, registry = None, **kw): registry.register("app.satellite_monitor", SatelliteMonitor) menu_gps = registry.menu("main.gps") monitor = zavai.MenuButton(_("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")))