Improvement and code reorganization of GPSObject
authorjaviplx <javiplx@gmail.com>
Sat, 30 Apr 2011 14:24:29 +0000 (14:24 +0000)
committerjaviplx <javiplx@gmail.com>
Sat, 30 Apr 2011 14:24:29 +0000 (14:24 +0000)
git-svn-id: file:///svnroot/wifihood/branches/cleaning@95 c51dfc6a-5949-4919-9c8e-f207a149c383

wifimap/gps.py
wifimap/scanner.py
wifimap/wifiscan.py

index d37105d..aaaf4fe 100644 (file)
@@ -16,10 +16,9 @@ class GPSObject ( gobject.GObject ) :
         self.device.connect_object("changed", GPSObject.update , self)
 
         # Values to be set by GPSDevice changed events
-        self.gps_state = False
-        self.gps_info = "NO_FIX", 0, 0, None, None, None, None, None, None, None
+        self.info = None, 0, 0, None, None, None, None
         self.satellites = None
-        self.cell_info = None
+        self.cells = None
         self.ngps = 0
 
     def set_method ( self , method="gps" ) :
@@ -59,43 +58,31 @@ class GPSObject ( gobject.GObject ) :
 
     def update ( self ) :
 
-        self.gps_state = None
         if self.device.online :
-            if self.device.status == location.GPS_DEVICE_STATUS_NO_FIX :
-                self.gps_state = "NO_FIX"
-            elif self.device.status == location.GPS_DEVICE_STATUS_FIX :
-                self.gps_state = "FIX"
+            if self.device.status == location.GPS_DEVICE_STATUS_FIX :
+                state = "FIX"
                 self.ngps += 1
             elif self.device.status == location.GPS_DEVICE_STATUS_DGPS_FIX :
-                self.gps_state = "DGPS"
-
-            self.gps_info = 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]
+                state = "DGPS"
+                # FIXME : Increase also ngps here ???
+            else :
+                state = None
+
+            lat , lon , alt = None , None , None
+            if self.device.fix[1] & location.GPS_DEVICE_LATLONG_SET:
+                lat , lon = device.fix[4:6]
+            if self.device.fix[1] & location.GPS_DEVICE_ALTITUDE_SET:
+                alt = device.fix[7]
+            # FIXME : get time from GPS fix
+            self.info = state , self.device.satellites_in_view , self.device.satellites_in_use , self.device.fix[2] , lat , lon , alt
             self.satellites = self.device.satellites
-            self.cell_info = self.device.cell_info
+            self.cells = self.device.cell_info
+        else :
+            self.info = None, 0, 0, None, None, None, None
 
     def report ( self ) :
         return "%d gps" % self.ngps
 
-#    mode = device.fix[0]
-#    if mode == location.GPS_DEVICE_MODE_NOT_SEEN : # This means ??
-#        print "mode is NOSEEN"
-#    if mode == location.GPS_DEVICE_MODE_NO_FIX : # This implies device.status == location.GPS_DEVICE_STATUS_NO_FIX
-#                                                 # and probably device.fix[1] == location.GPS_DEVICE_NONE_SET
-#        print "mode is NOFIX"
-#    if mode == location.GPS_DEVICE_MODE_2D :
-#        print "mode is 2D"
-#    if mode == location.GPS_DEVICE_MODE_3D :
-#        print "mode is 3D"
-
-#    if flags & location.GPS_DEVICE_SPEED_SET :
-#        print "GPS_DEVICE_SPEED_SET"
-#    if flags & location.GPS_DEVICE_TRACK_SET :
-#        print "GPS_DEVICE_TRACK_SET"
-#    if flags & location.GPS_DEVICE_ALTITUDE_SET :
-#        print "GPS_DEVICE_ALTITUDE_SET"
-#    if flags & location.GPS_DEVICE_CLIMB_SET :
-#        print "GPS_DEVICE_CLIMB_SET"
-
 gobject.type_register(GPSObject)
 
 if __name__ == "__main__" :
index 2707e94..728695b 100644 (file)
@@ -38,8 +38,8 @@ class Scanner ( gps.GPSObject , wifiscan.WifiScanner ) :
     def scan ( self ) :
         wifiscan.WifiScanner.scan( self )
         latlon = None
-        if self.gps_state == "FIX" :
-            latlon = self.gps_info[4] , self.gps_info[5] , self.gps_info[6]
+        if self.info :
+            latlon = self.info[4:]
         for mac,max_rss in self.scanlist.iteritems() :
             stored = self.db.get( mac )
             if stored :
@@ -53,18 +53,19 @@ class Scanner ( gps.GPSObject , wifiscan.WifiScanner ) :
 
     def write_logs ( self ) :
             fd = open( os.path.join( conf.homedir , "wiscan_gui.info" ) , 'a' )
-            fd.write( "%s %s %s\n" % ( self.tstamp , self.gps_info , self.scanlist ) )
+            fd.write( "%s %s %s\n" % ( self.tstamp , self.info , self.scanlist ) )
             fd.close()
             if self.satellites :
                 loclist = open( os.path.join( conf.homedir , "location.info" ) , 'a' )
                 loclist.write ( "%s\n" % ( self.satellites ,) )
                 loclist.close()
-            if self.cell_info :
+            if self.cells :
                 celllist = open( os.path.join( conf.homedir , "cell.info" ) , 'a' )
-                celllist.write ( "%s\n" % ( self.cell_info ,) )
+                celllist.write ( "%s\n" % ( self.cells ,) )
                 celllist.close()
 
     def report ( self ) :
+        # BUG : if report is called after close, db.nrows() will produce an exception
         return "%s\t%s\t%d ap\t%d total ap" % ( gps.GPSObject.report(self) , wifiscan.WifiScanner.report(self) , self.newap , self.db.nrows() )
 
 
index eeca6c2..33221b0 100644 (file)
@@ -41,6 +41,7 @@ class WifiScanner ( gobject.GObject ) :
             scan_out = osso_rpc.rpc_run("org.javiplx.wifiscan", "/org/javiplx/wifiscan", "org.javiplx.wifiscan", "scan", wait_reply = True)
             if self.scan_timeout :
                 gobject.timeout_add( self.scan_timeout , self.scan )
+            # BUG : if scan is called after stop (maybe in other cases), 'ERROR' is returned and split raises exception
             self.nscan +=1
             self.scanlist.clear()
             self.tstamp = time.time()