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 )
57 if self.gps_state == "FIX" :
58 latlon = ( self.device.fix[4] , self.device.fix[5] , self.device.fix[7] )
59 out_str = self.store_scan( scan_out , tstamp , scan_out , latlon )
60 self.refresh_infowin( tstamp )
62 osso.SystemNote(self.osso_context).system_note_infoprint("Found %d APs" % len(scan_out) )
64 self.write_logs( out_str )
68 def store_scan ( self , timestamp , scan_out , gps_info ) :
70 for net in scan_out.split() :
72 items = net.rsplit(":", 1)
73 out_str += " %s %s" % ( items[0] , items[1] )
75 self.scanlist.insert_at_cursor( "%s %5d\n" % ( items[0] , int(items[1]) ) )
76 stored = self.db.get( items[0] )
78 max_rss = int(items[1])
79 if stored[0] > max_rss :
81 self.db.update( items[0] , max_rss , timestamp , gps_info )
84 self.db.add( items[0] , int(items[1]) , timestamp , gps_info )
87 def store_logscan ( self , timestamp , scan_out , gps_info ) :
88 nets = scan_out.split()
91 items = ( nets.pop(0) , nets.pop(0) )
93 self.scanlist.insert_at_cursor( "%s %5d\n" % ( items[0] , int(items[1]) ) )
94 stored = self.db.get( items[0] )
96 max_rss = int(items[1])
97 if stored[0] > max_rss :
99 self.db.update( items[0] , max_rss , timestamp , gps_info )
102 self.db.add( items[0] , int(items[1]) , timestamp , gps_info )
104 def write_logs ( self , timestamp , out_str ) :
105 fd = open( os.path.join( conf.homedir , "wiscan_gui.info" ) , 'a' )
106 fd.write( "%s %s%s\n" % ( timestamp , self.gps_info , out_str ) )
109 loclist = open( os.path.join( conf.homedir , "location.info" ) , 'a' )
110 loclist.write ( "%s\n" % ( self.satellites ,) )
113 celllist = open( os.path.join( conf.homedir , "cell.info" ) , 'a' )
114 celllist.write ( "%s\n" % ( self.cell_info ,) )
117 def set_infowin ( self , statuswin , listwin ) :
118 gps.GPSObject.set_infowin( self , statuswin )
119 self.scanlist = listwin
121 def refresh_infowin ( self ) :
123 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() ) )
126 gobject.type_register(Scanner)