5 import osso_wrapper as osso
16 class Scanner ( gps.GPSObject , wifiscan.WifiScanner ) :
18 def __init__ ( self , ifname="wlan0" ) :
19 gps.GPSObject.__init__( self )
20 wifiscan.WifiScanner.__init__( self , ifname )
21 conf = config.Configuration( 'scanner' )
22 self.homedir = conf.homedir
23 self.db = db.database( os.path.join( self.homedir , conf.dbname ) )
25 # Values to be set by wireless scans
28 def start ( self , timeout=5000 ) :
29 gps.GPSObject.start( self )
30 wifiscan.WifiScanner.start( self , timeout )
34 gps.GPSObject.stop( self )
35 wifiscan.WifiScanner.stop( self )
39 wifiscan.WifiScanner.scan( self )
40 for mac,max_rss in self.scanlist.iteritems() :
41 stored = self.db.get( mac )
43 if stored[0] > max_rss :
45 self.db.update( mac , max_rss , self.tstamp , self.info[4:] )
48 self.db.add( mac , max_rss , self.tstamp , self.info[4:] )
51 def write_logs ( self ) :
52 fd = open( os.path.join( self.homedir , "wiscan_gui.info" ) , 'a' )
53 fd.write( "%s %s %s\n" % ( self.tstamp , self.info , self.scanlist ) )
56 loclist = open( os.path.join( self.homedir , "location.info" ) , 'a' )
57 loclist.write ( "%s\n" % ( self.satellites ,) )
60 celllist = open( os.path.join( self.homedir , "cell.info" ) , 'a' )
61 celllist.write ( "%s\n" % ( self.cells ,) )
65 # BUG : if report is called after close, db.nrows() will produce an exception
66 return "%s\t%s\t%d ap\t%d total ap" % ( gps.GPSObject.report(self) , wifiscan.WifiScanner.report(self) , self.newap , self.db.nrows() )
69 gobject.type_register(Scanner)
71 if __name__ == "__main__" :
72 loop = gobject.MainLoop()
74 def on_stop(control, mainloop):
76 sample.control.connect("gpsd-stopped", on_stop, loop)
77 def show_scan(wifiscanner):
78 gobject.timeout_add( 5000 , show_scan , sample )
79 print "scan results %s" % wifiscanner.report()
80 print " tstamp %s" % wifiscanner.tstamp
82 for k,v in wifiscanner.scanlist.iteritems() :
84 print " %s %s" % ( k , v )
91 gobject.timeout_add( 5100 , show_scan , sample )