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.gps_state = False
20 self.gps_info = "NO_FIX 0 0 NaN NaN NaN NaN NaN NaN NaN"
21 self.satellites = None
25 def set_method ( self , method="gps" ) :
27 self.control.set_properties(preferred_method=location.METHOD_GNSS|location.METHOD_AGNSS)
29 control.set_properties(preferred_method=location.METHOD_GNSS)
31 def set_interval ( self , interval=0 ) :
33 self.control.set_properties(preferred_interval=location.INTERVAL_DEFAULT)
35 self.control.set_properties(preferred_interval=location.INTERVAL_1S)
37 self.control.set_properties(preferred_interval=location.INTERVAL_2S)
39 self.control.set_properties(preferred_interval=location.INTERVAL_5S)
41 self.control.set_properties(preferred_interval=location.INTERVAL_10S)
43 self.control.set_properties(preferred_interval=location.INTERVAL_20S)
45 self.control.set_properties(preferred_interval=location.INTERVAL_30S)
47 self.control.set_properties(preferred_interval=location.INTERVAL_60S)
49 self.control.set_properties(preferred_interval=location.INTERVAL_120S)
52 if not self.device.online :
55 # FIXME : Stopping does not work, at least while getting fix
57 if self.device.online :
63 if self.device.online :
64 if self.device.status == location.GPS_DEVICE_STATUS_NO_FIX :
65 self.gps_state = "NO_FIX"
66 elif self.device.status == location.GPS_DEVICE_STATUS_FIX :
67 self.gps_state = "FIX"
69 self.refresh_infowin()
70 elif self.device.status == location.GPS_DEVICE_STATUS_DGPS_FIX :
71 self.gps_state = "DGPS"
73 self.gps_info = "%s %d %d %s %s %s %s %s %s %s" % ( self.gps_state , self.device.satellites_in_use , self.device.satellites_in_view , self.device.fix[2] , self.device.fix[4] , self.device.fix[5] , self.device.fix[7] , self.device.fix[9] , self.device.fix[11] , self.device.fix[13] )
74 self.satellites = self.device.satellites
75 self.cell_info = self.device.cell_info
78 return "%d gps" % self.ngps
80 # mode = device.fix[0]
81 # if mode == location.GPS_DEVICE_MODE_NOT_SEEN : # This means ??
82 # print "mode is NOSEEN"
83 # if mode == location.GPS_DEVICE_MODE_NO_FIX : # This implies device.status == location.GPS_DEVICE_STATUS_NO_FIX
84 # # and probably device.fix[1] == location.GPS_DEVICE_NONE_SET
85 # print "mode is NOFIX"
86 # if mode == location.GPS_DEVICE_MODE_2D :
88 # if mode == location.GPS_DEVICE_MODE_3D :
91 # if flags & location.GPS_DEVICE_SPEED_SET :
92 # print "GPS_DEVICE_SPEED_SET"
93 # if flags & location.GPS_DEVICE_TRACK_SET :
94 # print "GPS_DEVICE_TRACK_SET"
95 # if flags & location.GPS_DEVICE_ALTITUDE_SET :
96 # print "GPS_DEVICE_ALTITUDE_SET"
97 # if flags & location.GPS_DEVICE_CLIMB_SET :
98 # print "GPS_DEVICE_CLIMB_SET"
100 gobject.type_register(GPSObject)
102 if __name__ == "__main__" :
103 loop = gobject.MainLoop()
106 def on_stop(control, mainloop):
108 sample.control.connect("gpsd-stopped", on_stop, loop)