7 class GPSObject ( gobject.GObject ) :
9 def __init__ ( self ) :
10 gobject.GObject.__init__( self )
12 self.control = location.GPSDControl.get_default()
13 self.control.set_properties(preferred_method=location.METHOD_GNSS,
14 preferred_interval=location.INTERVAL_DEFAULT)
15 self.device = location.GPSDevice()
16 self.device.connect_object("changed", GPSObject.update , self)
18 # Values to be set by GPSDevice changed events
19 self.info = None, 0, 0, None, None, None, None
20 self.satellites = None
24 def set_method ( self , method="gps" ) :
26 self.control.set_properties(preferred_method=location.METHOD_GNSS|location.METHOD_AGNSS)
28 control.set_properties(preferred_method=location.METHOD_GNSS)
30 def set_interval ( self , interval=0 ) :
32 self.control.set_properties(preferred_interval=location.INTERVAL_DEFAULT)
34 self.control.set_properties(preferred_interval=location.INTERVAL_1S)
36 self.control.set_properties(preferred_interval=location.INTERVAL_2S)
38 self.control.set_properties(preferred_interval=location.INTERVAL_5S)
40 self.control.set_properties(preferred_interval=location.INTERVAL_10S)
42 self.control.set_properties(preferred_interval=location.INTERVAL_20S)
44 self.control.set_properties(preferred_interval=location.INTERVAL_30S)
46 self.control.set_properties(preferred_interval=location.INTERVAL_60S)
48 self.control.set_properties(preferred_interval=location.INTERVAL_120S)
51 if not self.device.online :
54 # FIXME : Stopping does not work, at least while getting fix
56 if self.device.online :
61 if self.device.online :
62 if self.device.status == location.GPS_DEVICE_STATUS_FIX :
65 elif self.device.status == location.GPS_DEVICE_STATUS_DGPS_FIX :
67 # FIXME : Increase also ngps here ???
71 lat , lon , alt = None , None , None
72 if self.device.fix[1] & location.GPS_DEVICE_LATLONG_SET:
73 lat , lon = device.fix[4:6]
74 if self.device.fix[1] & location.GPS_DEVICE_ALTITUDE_SET:
76 # FIXME : get time from GPS fix
77 self.info = state , self.device.satellites_in_view , self.device.satellites_in_use , self.device.fix[2] , lat , lon , alt
78 self.satellites = self.device.satellites
79 self.cells = self.device.cell_info
81 self.info = None, 0, 0, None, None, None, None
84 return "%d gps" % self.ngps
86 gobject.type_register(GPSObject)
88 if __name__ == "__main__" :
89 loop = gobject.MainLoop()
91 def on_stop(control, mainloop):
93 sample.control.connect("gpsd-stopped", on_stop, loop)