5 import osso_wrapper as osso
9 import config , db , gps
15 conf = config.Configuration()
17 class Scanner ( gps.GPSObject ) :
19 def __init__ ( self , ifname="wlan0" ) :
20 gps.GPSObject.__init__( self )
21 self.osso_context = osso.Context("wifi_scanner", "2.0", False)
22 osso_rpc = osso.Rpc(self.osso_context)
23 osso_rpc.rpc_run("org.javiplx.wifiscan", "/org/javiplx/wifiscan", "org.javiplx.wifiscan", "wakeup", wait_reply = True)
24 self.db = db.database( os.path.join( conf.homedir , conf.dbname ) )
26 # Values to be set by wireless scans
33 osso_rpc = osso.Rpc(self.osso_context)
34 osso_rpc.rpc_run("org.javiplx.wifiscan", "/org/javiplx/wifiscan", "org.javiplx.wifiscan", "start")
38 osso_rpc = osso.Rpc(self.osso_context)
39 osso_rpc.rpc_run("org.javiplx.wifiscan", "/org/javiplx/wifiscan", "org.javiplx.wifiscan", "stop")
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 )
53 if self.gps_state == "FIX" :
54 latlon = ( self.device.fix[4] , self.device.fix[5] , self.device.fix[7] )
55 self.store_scan( tstamp , scan_out , latlon )
57 osso.SystemNote(self.osso_context).system_note_infoprint("Found %d APs" % len(scan_out) )
59 self.write_logs( tstamp , scan_out )
63 def store_scan ( self , timestamp , scan_out , gps_info ) :
64 for net in scan_out.split() :
66 items = net.rsplit(":", 1)
67 self.scanlist.append( "%s %5d\n" % ( items[0] , int(items[1]) ) )
68 stored = self.db.get( items[0] )
70 max_rss = int(items[1])
71 if stored[0] > max_rss :
73 self.db.update( items[0] , max_rss , timestamp , gps_info )
76 self.db.add( items[0] , int(items[1]) , timestamp , gps_info )
78 def store_legacy ( self , timestamp , scan_out , gps_info ) :
79 nets = scan_out.split()
82 items = ( nets.pop(0) , nets.pop(0) )
83 self.scanlist.append( "%s %5d\n" % ( items[0] , int(items[1]) ) )
84 stored = self.db.get( items[0] )
86 max_rss = int(items[1])
87 if stored[0] > max_rss :
89 self.db.update( items[0] , max_rss , timestamp , gps_info )
92 self.db.add( items[0] , int(items[1]) , timestamp , gps_info )
94 def write_logs ( self , timestamp , out_str ) :
95 fd = open( os.path.join( conf.homedir , "wiscan_gui.info" ) , 'a' )
96 fd.write( "%s %s %s\n" % ( timestamp , self.gps_info , out_str ) )
99 loclist = open( os.path.join( conf.homedir , "location.info" ) , 'a' )
100 loclist.write ( "%s\n" % ( self.satellites ,) )
103 celllist = open( os.path.join( conf.homedir , "cell.info" ) , 'a' )
104 celllist.write ( "%s\n" % ( self.cell_info ,) )
107 def report ( self ) :
108 return "%s\t%d scan\t%d fp\t%d ap\t%d total ap" % ( gps.GPSObject.report(self) , self.nscan , self.nfp , self.newap , self.db.nrows() )
111 gobject.type_register(Scanner)