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 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( scan_out )
68 def store_scan ( self , timestamp , scan_out , gps_info ) :
69 for net in scan_out.split() :
71 items = net.rsplit(":", 1)
73 self.scanlist.insert_at_cursor( "%s %5d\n" % ( items[0] , int(items[1]) ) )
74 stored = self.db.get( items[0] )
76 max_rss = int(items[1])
77 if stored[0] > max_rss :
79 self.db.update( items[0] , max_rss , timestamp , gps_info )
82 self.db.add( items[0] , int(items[1]) , timestamp , gps_info )
84 def store_legacy ( self , timestamp , scan_out , gps_info ) :
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)