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 = None
23 self.osso_context = osso.Context("wifi_scanner", "2.0", False)
24 osso_rpc = osso.Rpc(self.osso_context)
25 osso_rpc.rpc_run("org.javiplx.wifiscan", "/org/javiplx/wifiscan", "org.javiplx.wifiscan", "wakeup", wait_reply = True)
31 self.db = db.database( os.path.join( conf.homedir , conf.dbname ) )
34 if self.osso_context :
35 osso_rpc = osso.Rpc(self.osso_context)
36 scan_out = osso_rpc.rpc_run("org.javiplx.wifiscan", "/org/javiplx/wifiscan", "org.javiplx.wifiscan", "start")
40 osso_rpc = osso.Rpc(self.osso_context)
41 scan_out = osso_rpc.rpc_run("org.javiplx.wifiscan", "/org/javiplx/wifiscan", "org.javiplx.wifiscan", "stop")
45 osso_rpc = osso.Rpc(self.osso_context)
47 scan_out = osso_rpc.rpc_run("org.javiplx.wifiscan", "/org/javiplx/wifiscan", "org.javiplx.wifiscan", "scan", wait_reply = True)
49 except Exception , ex :
50 osso.SystemNote(self.osso_context).system_note_infoprint("Exception scanning %s" % ex )
53 start, end = self.scanlist.get_bounds()
54 self.scanlist.delete( start , end )
56 out_str = self.store_scan( scan_out , tstamp , scan_out )
57 self.refresh_infowin( tstamp )
59 osso.SystemNote(self.osso_context).system_note_infoprint("Found %d APs" % len(scan_out) )
61 self.write_logs( out_str )
65 def store_scan ( self , timestamp , scan_out ) :
67 for net in scan_out.split() :
69 items = net.rsplit(":", 1)
70 out_str += " %s %s" % ( items[0] , items[1] )
72 self.scanlist.insert_at_cursor( "%s %5d\n" % ( items[0] , int(items[1]) ) )
73 stored = self.db.get( items[0] )
75 max_rss = int(items[1])
76 if stored[0] > max_rss :
78 self.db.update( items[0] , max_rss , timestamp )
81 self.db.add( items[0] , int(items[1]) , timestamp )
84 def store_logscan ( self , timestamp , scan_out , gps_info=None ) :
85 nets = scan_out.split()
88 items = ( nets.pop(0) , nets.pop(0) )
90 self.scanlist.insert_at_cursor( "%s %5d\n" % ( items[0] , int(items[1]) ) )
91 stored = self.db.get( items[0] )
93 max_rss = int(items[1])
94 if stored[0] > max_rss :
96 self.db.update( items[0] , max_rss , timestamp , gps_info )
99 self.db.add( items[0] , int(items[1]) , timestamp , gps_info )
101 def write_logs ( self , timestamp , out_str ) :
102 fd = open( os.path.join( conf.homedir , "wiscan_gui.info" ) , 'a' )
103 fd.write( "%s %s%s\n" % ( timestamp , self.gps_info , out_str ) )
106 loclist = open( os.path.join( conf.homedir , "location.info" ) , 'a' )
107 loclist.write ( "%s\n" % ( self.satellites ,) )
110 celllist = open( os.path.join( conf.homedir , "cell.info" ) , 'a' )
111 celllist.write ( "%s\n" % ( self.cell_info ,) )
114 def set_infowin ( self , statuswin , listwin ) :
115 gps.GPSObject.set_infowin( self , statuswin )
116 self.scanlist = listwin
118 def refresh_infowin ( self ) :
120 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 , self.newap , self.db.nrows() ) )
123 gobject.type_register(Scanner)