Added basic scanner application
[wifihood] / wifiscanner / wifimap / gps.py
1
2
3 import location
4
5 import hildon
6 import gobject
7
8 class GPSObject ( gobject.GObject ) :
9
10     def __init__ ( self , widget=None ) :
11         gobject.GObject.__init__( self )
12         self._parent = widget
13         self._debug = False
14         self.control = location.GPSDControl.get_default()
15         # properties : maincontext_pointer preferred_interval preferred_method
16         self.method = location.METHOD_GNSS
17         self.device = None
18         self.gps_state = False
19         self.gps_info = None
20         self.update_handler = None
21         self.satellites = None
22         self.cell_info = None
23
24     def set_method ( self , method="gps" ) :
25         if method == "agps" :
26             self.method = location.METHOD_GNSS | location.METHOD_AGNSS
27         else :
28             self.method = location.METHOD_GNSS
29
30     def set_interval ( self , interval="1" ) :
31         if interval == "1" :
32             self.interval = location.INTERVAL_1S
33         elif interval == "2" :
34             self.interval = location.INTERVAL_2S
35         elif interval == "5" :
36             self.interval = location.INTERVAL_5S
37         elif interval == "10" :
38             self.interval = location.INTERVAL_10S
39         elif interval == "20" :
40             self.interval = location.INTERVAL_20S
41         elif interval == "30" :
42             self.interval = location.INTERVAL_30S
43         elif interval == "60" :
44             self.interval = location.INTERVAL_60S
45         elif interval == "120" :
46             self.interval = location.INTERVAL_120S
47
48     def do_start ( self ) :
49         if not self.device :
50             self.control.set_properties(preferred_method=self.method)
51             self.device = location.GPSDevice()
52         if self.update_handler :
53             hildon.hildon_banner_show_information( self._parent , "icon_path" , "GPS already started" )
54         else :
55             self.update_handler = self.device.connect_object("changed", GPSObject.do_update , self)
56             self.control.start()
57
58     # FIXME : Stopping does not work, at least while getting fix
59     def do_stop ( self ) :
60         if self.update_handler :
61             # FIXME : Is this removal OK?
62             del self.update_handler
63             self.update_handler = None
64         self.device.stop()
65         self.control.stop()
66
67     def do_update ( self ) :
68
69         if self.device :
70             if self.device.status == location.GPS_DEVICE_STATUS_NO_FIX :
71             #    if self.gps_state == "FIX" or self.gps_state == "DGPS" :
72             #        banner = hildon.hildon_banner_show_information( self._parent , "icon_path" , "Lost GPS fix" )
73             #        banner.set_timeout( 1500 )
74                 self.gps_state = "NO_FIX"
75             elif self.device.status == location.GPS_DEVICE_STATUS_FIX :
76             #    if self.gps_state == "NO_FIX" :
77             #        banner = hildon.hildon_banner_show_information( self._parent , "icon_path" , "Got GPS fix" )
78             #        banner.set_timeout( 1500 )
79                 self.gps_state = "FIX"
80             elif self.device.status == location.GPS_DEVICE_STATUS_DGPS_FIX :
81             #    if self.gps_state == "NO_FIX" :
82             #        banner = hildon.hildon_banner_show_information( self._parent , "icon_path" , "Got differential GPS fix" )
83             #        banner.set_timeout( 1500 )
84                 self.gps_state = "DGPS"
85
86             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] )
87             self.satellites = self.device.satellites
88             self.cell_info = self.device.cell_info
89
90         #    if self._debug :
91         #        banner = hildon.hildon_banner_show_information( self._parent , "icon_path" , "GPS info : %s" % self.gps_info )
92         #        banner.set_timeout( 300 )
93
94
95 #    mode = device.fix[0]
96 #    if mode == location.GPS_DEVICE_MODE_NOT_SEEN : # This means ??
97 #        print "mode is NOSEEN"
98 #    if mode == location.GPS_DEVICE_MODE_NO_FIX : # This implies device.status == location.GPS_DEVICE_STATUS_NO_FIX
99 #                                                 # and probably device.fix[1] == location.GPS_DEVICE_NONE_SET
100 #        print "mode is NOFIX"
101 #    if mode == location.GPS_DEVICE_MODE_2D :
102 #        print "mode is 2D"
103 #    if mode == location.GPS_DEVICE_MODE_3D :
104 #        print "mode is 3D"
105
106 #    if flags & location.GPS_DEVICE_SPEED_SET :
107 #        print "GPS_DEVICE_SPEED_SET"
108 #    if flags & location.GPS_DEVICE_TRACK_SET :
109 #        print "GPS_DEVICE_TRACK_SET"
110 #    if flags & location.GPS_DEVICE_ALTITUDE_SET :
111 #        print "GPS_DEVICE_ALTITUDE_SET"
112 #    if flags & location.GPS_DEVICE_CLIMB_SET :
113 #        print "GPS_DEVICE_CLIMB_SET"
114
115 gobject.type_register(GPSObject)
116