5 import osso_wrapper as osso
9 import config , db , gps
15 conf = config.Configuration()
17 class Scanner ( gps.GPSObject ) :
19 def __init__ ( self , widget=None , ifname="wlan0" ) :
20 gps.GPSObject.__init__( self , widget )
21 self.osso_context = osso.Context("wifi_scanner", "2.0", False)
22 osso_rpc = osso.Rpc(self.osso_context)
23 scan_out = osso_rpc.rpc_run("org.javiplx.wifiscan", "/org/javiplx/wifiscan", "org.javiplx.wifiscan", "wakeup", wait_reply = True)
29 self.db = db.database( os.path.join( conf.homedir , conf.dbname ) )
32 osso_rpc = osso.Rpc(self.osso_context)
33 scan_out = osso_rpc.rpc_run("org.javiplx.wifiscan", "/org/javiplx/wifiscan", "org.javiplx.wifiscan", "start")
37 osso_rpc = osso.Rpc(self.osso_context)
38 scan_out = osso_rpc.rpc_run("org.javiplx.wifiscan", "/org/javiplx/wifiscan", "org.javiplx.wifiscan", "stop")
42 timestamp = time.time()
43 osso_rpc = osso.Rpc(self.osso_context)
45 scan_out = osso_rpc.rpc_run("org.javiplx.wifiscan", "/org/javiplx/wifiscan", "org.javiplx.wifiscan", "scan", wait_reply = True)
47 except Exception , ex :
48 osso.SystemNote(self.osso_context).system_note_infoprint("Exception scanning %s" % ex )
52 start, end = self.scanlist.get_bounds()
53 self.scanlist.delete( start , end )
54 for net in scan_out.split() :
56 items = net.rsplit(":", 1)
57 out_str += " %s %s" % ( items[0] , items[1] )
59 self.scanlist.insert_at_cursor( "%s %5d\n" % ( items[0] , int(items[1]) ) )
60 stored = self.db.get( items[0] )
62 max_rss = int(items[1])
63 if stored[0] > max_rss :
65 self.db.update( items[0] , max_rss , timestamp )
67 self.db.add( items[0] , int(items[1]) , timestamp )
68 self.aplist[ items[0] ] = 1
69 self.refresh_infowin()
71 osso.SystemNote(self.osso_context).system_note_infoprint("Found %d APs" % len(scan_out) )
73 fd = open( os.path.join( conf.homedir , "wiscan_gui.info" ) , 'a' )
74 fd.write( "%s %s%s\n" % ( timestamp , self.gps_info , out_str ) )
77 loclist = open( os.path.join( conf.homedir , "location.info" ) , 'a' )
78 loclist.write ( "%s\n" % ( self.satellites ,) )
81 celllist = open( os.path.join( conf.homedir , "cell.info" ) , 'a' )
82 celllist.write ( "%s\n" % ( self.cell_info ,) )
87 def set_infowin ( self , statuswin , listwin ) :
88 gps.GPSObject.set_infowin( self , statuswin )
89 self.scanlist = listwin
91 def refresh_infowin ( self ) :
93 self.status.set_text( "%d gps\t%d scan\t%d fp\t%d ap\t%d total ap" % ( self.ngps , self.nscan , self.nfp , len(self.aplist.keys()) , self.db.nrows() ) )
96 gobject.type_register(Scanner)