3 # Satellite monitor for Gypsy, based on the zhone satellite monitor
5 # Copyright (C) 2009 Enrico Zini <enrico@enricozini.org>
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program; if not, write to the Free Software
19 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 import dbus.mainloop.glib
27 from gettext import gettext as _
32 2: _("signal acquired"),
33 3: _("signal unusable"),
35 5: _("code&carrier lock"),
36 6: _("code&carrier lock"),
37 7: _("receiving data")
43 self.bus = dbus.SystemBus()
45 # see mdbus -s org.freesmartphone.ousaged /org/freesmartphone/Usage
46 self.usage = self.bus.get_object('org.freesmartphone.ousaged', '/org/freesmartphone/Usage')
47 self.usage = dbus.Interface(self.usage, "org.freesmartphone.Usage")
49 # see mdbus -s org.freesmartphone.ogpsd /org/freedesktop/Gypsy
50 gps = self.bus.get_object('org.freesmartphone.ogpsd', '/org/freedesktop/Gypsy')
51 self.gps = dbus.Interface(gps, "org.freedesktop.Gypsy.Device")
52 self.gps_ubx = dbus.Interface(gps, 'org.freesmartphone.GPS.UBX')
54 # This piece of machinery is taken from Zhone
55 self.debug_busy = None
56 self.debug_want = set( ["NAV-STATUS", "NAV-SVINFO"] )
57 self.debug_have = set()
58 self.debug_error = set()
62 def debug_update(self):
63 if self.debug_busy is None:
64 pending = self.debug_want - self.debug_have - self.debug_error
66 self.debug_busy = pending.pop()
67 self.gps_ubx.SetDebugFilter(
70 reply_handler=self.on_debug_reply,
71 error_handler=self.on_debug_error,
74 def debug_request(self):
75 self.debug_have = set()
78 def on_debug_reply(self):
79 self.debug_have.add(self.debug_busy)
80 self.debug_busy = None
83 def on_debug_error(self, e):
84 zavai.info(e, "error while requesting debug packet %s" % self.debug_busy)
85 self.debug_error.add(self.debug_busy)
86 self.debug_busy = None
89 def on_satellites_changed(self, satellites):
92 def on_ubxdebug_packet(self, clid, length, data):
93 self.callback(clid, length, data)
96 self.usage.RequestResource('GPS')
98 # TODO: find out how come sometimes these events are not sent
99 self.bus.add_signal_receiver(
100 self.on_satellites_changed, 'SatellitesChanged', 'org.freedesktop.Gypsy.Satellite',
101 'org.freesmartphone.ogpsd', '/org/freedesktop/Gypsy')
102 self.bus.add_signal_receiver(
103 self.on_ubxdebug_packet, 'DebugPacket', 'org.freesmartphone.GPS.UBX',
104 'org.freesmartphone.ogpsd', '/org/freedesktop/Gypsy')
108 self.bus.remove_signal_receiver(
109 self.on_satellites_changed, 'SatellitesChanged', 'org.freedesktop.Gypsy.Satellite',
110 'org.freesmartphone.ogpsd', '/org/freedesktop/Gypsy')
111 self.bus.remove_signal_receiver(
112 self.on_ubxdebug_packet, 'DebugPacket', 'org.freesmartphone.GPS.UBX',
113 'org.freesmartphone.ogpsd', '/org/freedesktop/Gypsy')
114 self.usage.ReleaseResource('GPS')
116 class SatelliteMonitor(gtk.Window):
117 def __init__(self, **kw):
118 super(SatelliteMonitor, self).__init__()
120 self.set_title(_("Satellite monitor"))
122 self.gps = GPSMonitor()
123 self.gps.callback = self.on_ubxdebug_packet
125 self.store = gtk.ListStore(str, str, str, str, str, str, str, str, str, str, str)
126 self.view = gtk.TreeView(self.store)
127 renderer = gtk.CellRendererText()
128 for idx, name in enumerate((_("CH"), _("ID"), _("SN"), _("ELE"), _("AZI"),
129 _("Used"), _("Diff"), _("Alm"), _("Eph"),
130 _("Bad"), _("Status"))):
131 col = gtk.TreeViewColumn(name)
132 col.pack_start(renderer, False)
133 col.add_attribute(renderer, "text", idx)
134 self.view.append_column(col)
137 self.connect("destroy", gtk.main_quit)
138 self.set_size_request(100, 200)
141 def start(self, *args):
144 def stop(self, *args):
147 def on_ubxdebug_packet(self, clid, length, data):
148 # In zhone it is cbUBXDebugPacket
149 #if clid == "NAV-STATUS" and data:
150 # i = ["%s: %d" % (k, data[0][k]) for k in sorted(data[0].keys())]
151 # zavai.info("Status:", " ".join(i))
152 ## if data[0]['TTFF']:
153 ## zavai.info("TTFF: %f", data[0]['TTFF']/1000.0)
154 if clid == "NAV-SVINFO":
155 self.handle_ubx_sat_data(data[1:])
157 # zavai.info("gps got ubxdebug packet", clid)
158 # zavai.info("DATA:", data)
160 def handle_ubx_sat_data(self, ubxinfo):
161 #zavai.info("CH ID SN ELE AZI Used Diff Alm Eph Bad Status")
164 if sv["CNO"] == 0: continue
166 used = sv["Flags"] & 0x01
167 diff = sv["Flags"] & 0x02
168 almoreph = sv["Flags"] & 0x04
169 eph = sv["Flags"] & 0x08
170 bad = sv["Flags"] & 0x10
171 qi = ("%i: " % sv["QI"]) + SAT_QI_NAMES.get(sv["QI"], _("Unknown"))
178 used and "used" or "",
179 diff and "diff" or "",
180 almoreph and "alm" or "",
185 if __name__ == "__main__":
186 dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
188 app = SatelliteMonitor()