# Values to be set by GPSDevice changed events
self.gps_state = False
- self.gps_info = "NO_FIX 0 0 NaN NaN NaN NaN NaN NaN NaN"
+ self.gps_info = "NO_FIX", 0, 0, None, None, None, None, None, None, None
self.satellites = None
self.cell_info = None
self.ngps = 0
elif self.device.status == location.GPS_DEVICE_STATUS_DGPS_FIX :
self.gps_state = "DGPS"
- 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] )
+ 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]
self.satellites = self.device.satellites
self.cell_info = self.device.cell_info
if __name__ == "__main__" :
loop = gobject.MainLoop()
sample = GPSObject()
- print dir(sample)
def on_stop(control, mainloop):
mainloop.quit()
sample.control.connect("gpsd-stopped", on_stop, loop)
--- /dev/null
+
+try :
+ import osso
+except :
+ import osso_wrapper as osso
+
+import time
+
+import config , db
+import gps , wifiscan
+
+import gobject
+
+import os
+
+conf = config.Configuration()
+
+class Scanner ( gps.GPSObject , wifiscan.WifiScanner ) :
+
+ def __init__ ( self , ifname="wlan0" ) :
+ gps.GPSObject.__init__( self )
+ wifiscan.WifiScanner.__init__( self )
+ self.db = db.database( os.path.join( conf.homedir , conf.dbname ) )
+
+ # Values to be set by wireless scans
+ self.newap = 0
+
+ def start ( self , timeout=5000 ) :
+ gps.GPSObject.start( self )
+ wifiscan.WifiScanner.start( self , timeout )
+ self.db.open()
+
+ def stop ( self ) :
+ gps.GPSObject.stop( self )
+ wifiscan.WifiScanner.stop( self )
+ self.db.close()
+
+ def scan ( self ) :
+ wifiscan.WifiScanner.scan( self )
+ latlon = None
+ if self.gps_state == "FIX" :
+ latlon = gps_info[4] , gps_info[5] , gps_info[6]
+ for mac,max_rss in self.scanlist.iteritems() :
+ stored = self.db.get( mac )
+ if stored :
+ if stored[0] > max_rss :
+ max_rss = stored[0]
+ self.db.update( mac , max_rss , self.tstamp , latlon )
+ else :
+ self.newap += 1
+ self.db.add( mac , max_rss , self.tstamp , latlon )
+ self.write_logs()
+
+ 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.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 :
+ celllist = open( os.path.join( conf.homedir , "cell.info" ) , 'a' )
+ celllist.write ( "%s\n" % ( self.cell_info ,) )
+ celllist.close()
+
+ def report ( self ) :
+ return "%s\t%s\t%d ap\t%d total ap" % ( gps.GPSObject.report(self) , wifiscan.WifiScanner.report(self) , self.newap , self.db.nrows() )
+
+
+gobject.type_register(Scanner)
+
+if __name__ == "__main__" :
+ loop = gobject.MainLoop()
+ sample = Scanner()
+ def on_stop(control, mainloop):
+ mainloop.quit()
+ sample.control.connect("gpsd-stopped", on_stop, loop)
+ def show_scan(wifiscanner):
+ gobject.timeout_add( 5000 , show_scan , sample )
+ print "scan results %s" % wifiscanner.report()
+ print " tstamp %s" % wifiscanner.tstamp
+ c = 0
+ for k,v in wifiscanner.scanlist.iteritems() :
+ c += 1
+ print " %s %s" % ( k , v )
+ if c > 5 :
+ print " ..."
+ break
+ print
+ sample.start()
+ sample.scan()
+ gobject.timeout_add( 5100 , show_scan , sample )
+ loop.run()
+ sample.stop()
+
self.osso_context = osso.Context("wifi_scanner", "2.0", False)
osso_rpc = osso.Rpc(self.osso_context)
osso_rpc.rpc_run("org.javiplx.wifiscan", "/org/javiplx/wifiscan", "org.javiplx.wifiscan", "wakeup", wait_reply = True)
+ self.scan_timeout = 0
# Values to be set by wireless scans
- self.scanlist = []
+ self.scanlist = {}
self.tstamp = 0
self.nscan = 0
self.nfp = 0
- def start ( self ) :
+ def start ( self , timeout=5000 ) :
osso_rpc = osso.Rpc(self.osso_context)
osso_rpc.rpc_run("org.javiplx.wifiscan", "/org/javiplx/wifiscan", "org.javiplx.wifiscan", "start")
+ self.scan_timeout = timeout
def stop ( self ) :
osso_rpc = osso.Rpc(self.osso_context)
osso_rpc.rpc_run("org.javiplx.wifiscan", "/org/javiplx/wifiscan", "org.javiplx.wifiscan", "stop")
+ self.scan_timeout = 0
def scan ( self ) :
osso_rpc = osso.Rpc(self.osso_context)
try :
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 , WifiScanner.scan , self )
self.nscan +=1
- del self.scanlist[:]
+ self.scanlist.clear()
self.tstamp = time.time()
for net in scan_out.split() :
self.nfp += 1
items = net.rsplit(":", 1)
- self.scanlist.append( "%s %5d\n" % ( items[0] , int(items[1]) ) )
+ self.scanlist[ items[0] ] = int(items[1])
except Exception , ex :
osso.SystemNote(self.osso_context).system_note_infoprint("Exception scanning %s" % ex )
loop = gobject.MainLoop()
sample = WifiScanner()
sample.start()
- for i in range(10) :
- sample.scan()
+ def show_scan(sample):
+ gobject.timeout_add( 5000 , show_scan , sample )
print "scan results : %s" % sample.report()
- print " tsamp %s\n %s" % ( sample.tstamp , " ".join( sample.scanlist ) )
+ print " tstamp %s" % sample.tstamp
+ c = 0
+ for k,v in sample.scanlist.iteritems() :
+ c += 1
+ print " %s %s" % ( k , v )
+ if c > 5 :
+ print " ..."
+ break
print
+ sample.scan()
+ gobject.timeout_add( 5100 , show_scan , sample )
+ loop.run()
sample.stop()