5 import hildongtk.location as location
10 class GPSObject ( gobject.GObject ) :
12 def __init__ ( self ) :
13 gobject.GObject.__init__( self )
15 self.control = location.GPSDControl.get_default()
16 self.control.set_properties(preferred_method=location.METHOD_GNSS,
17 preferred_interval=location.INTERVAL_DEFAULT)
18 self.device = location.GPSDevice()
19 self.device.connect_object("changed", GPSObject.update , self)
21 # Values to be set by GPSDevice changed events
22 self.info = None, 0, 0, None, None, None, None
23 self.satellites = None
27 def set_method ( self , method="gps" ) :
29 self.control.set_properties(preferred_method=location.METHOD_GNSS|location.METHOD_AGNSS)
31 control.set_properties(preferred_method=location.METHOD_GNSS)
33 def set_interval ( self , interval=0 ) :
35 self.control.set_properties(preferred_interval=location.INTERVAL_DEFAULT)
37 self.control.set_properties(preferred_interval=location.INTERVAL_1S)
39 self.control.set_properties(preferred_interval=location.INTERVAL_2S)
41 self.control.set_properties(preferred_interval=location.INTERVAL_5S)
43 self.control.set_properties(preferred_interval=location.INTERVAL_10S)
45 self.control.set_properties(preferred_interval=location.INTERVAL_20S)
47 self.control.set_properties(preferred_interval=location.INTERVAL_30S)
49 self.control.set_properties(preferred_interval=location.INTERVAL_60S)
51 self.control.set_properties(preferred_interval=location.INTERVAL_120S)
54 if not self.device.online :
57 # FIXME : Stopping does not work, at least while getting fix
59 if self.device.online :
64 if self.device.online :
65 if self.device.status == location.GPS_DEVICE_STATUS_FIX :
68 elif self.device.status == location.GPS_DEVICE_STATUS_DGPS_FIX :
70 # FIXME : Increase also ngps here ???
74 lat , lon , alt = None , None , None
75 if self.device.fix[1] & location.GPS_DEVICE_LATLONG_SET:
76 lat , lon = self.device.fix[4:6]
77 if self.device.fix[1] & location.GPS_DEVICE_ALTITUDE_SET:
78 alt = self.device.fix[7]
79 # FIXME : get time from GPS fix
80 self.info = state , self.device.satellites_in_view , self.device.satellites_in_use , self.device.fix[2] , lat , lon , alt
81 self.satellites = self.device.satellites
82 self.cells = self.device.cell_info
84 self.info = None, 0, 0, None, None, None, None
87 return "%d gps" % self.ngps
89 gobject.type_register(GPSObject)
91 if __name__ == "__main__" :
92 loop = gobject.MainLoop()
94 def on_stop(control, mainloop):
96 sample.control.connect("gpsd-stopped", on_stop, loop)