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
26 def set_method ( self , method="gps" ) :
28 self.control.set_properties(preferred_method=location.METHOD_GNSS|location.METHOD_AGNSS)
30 control.set_properties(preferred_method=location.METHOD_GNSS)
32 def set_interval ( self , interval=0 ) :
34 self.control.set_properties(preferred_interval=location.INTERVAL_DEFAULT)
36 self.control.set_properties(preferred_interval=location.INTERVAL_1S)
38 self.control.set_properties(preferred_interval=location.INTERVAL_2S)
40 self.control.set_properties(preferred_interval=location.INTERVAL_5S)
42 self.control.set_properties(preferred_interval=location.INTERVAL_10S)
44 self.control.set_properties(preferred_interval=location.INTERVAL_20S)
46 self.control.set_properties(preferred_interval=location.INTERVAL_30S)
48 self.control.set_properties(preferred_interval=location.INTERVAL_60S)
50 self.control.set_properties(preferred_interval=location.INTERVAL_120S)
53 if not self.device.online :
56 # FIXME : Stopping does not work, at least while getting fix
58 if self.device.online :
64 if self.device.online :
65 if self.device.status == location.GPS_DEVICE_STATUS_NO_FIX :
66 self.gps_state = "NO_FIX"
67 elif self.device.status == location.GPS_DEVICE_STATUS_FIX :
68 self.gps_state = "FIX"
70 self.refresh_infowin()
71 elif self.device.status == location.GPS_DEVICE_STATUS_DGPS_FIX :
72 self.gps_state = "DGPS"
74 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] )
75 self.satellites = self.device.satellites
76 self.cell_info = self.device.cell_info
78 def set_infowin ( self , statuswin ) :
79 self.status = statuswin
81 def refresh_infowin ( self ) :
83 self.status.set_label( "%d gps" % self.ngps )
86 # mode = device.fix[0]
87 # if mode == location.GPS_DEVICE_MODE_NOT_SEEN : # This means ??
88 # print "mode is NOSEEN"
89 # if mode == location.GPS_DEVICE_MODE_NO_FIX : # This implies device.status == location.GPS_DEVICE_STATUS_NO_FIX
90 # # and probably device.fix[1] == location.GPS_DEVICE_NONE_SET
91 # print "mode is NOFIX"
92 # if mode == location.GPS_DEVICE_MODE_2D :
94 # if mode == location.GPS_DEVICE_MODE_3D :
97 # if flags & location.GPS_DEVICE_SPEED_SET :
98 # print "GPS_DEVICE_SPEED_SET"
99 # if flags & location.GPS_DEVICE_TRACK_SET :
100 # print "GPS_DEVICE_TRACK_SET"
101 # if flags & location.GPS_DEVICE_ALTITUDE_SET :
102 # print "GPS_DEVICE_ALTITUDE_SET"
103 # if flags & location.GPS_DEVICE_CLIMB_SET :
104 # print "GPS_DEVICE_CLIMB_SET"
106 gobject.type_register(GPSObject)
108 if __name__ == "__main__" :
109 loop = gobject.MainLoop()
112 def on_stop(control, mainloop):
114 sample.control.connect("gpsd-stopped", on_stop, loop)