6 import config , db , gps
12 conf = config.Configuration()
14 class Scanner ( gps.GPSObject ) :
16 def __init__ ( self , widget=None , ifname="wlan0" ) :
17 gps.GPSObject.__init__( self , widget )
18 self.osso_context = osso.Context("wifi_scanner", "2.0", False)
19 osso_rpc = osso.Rpc(self.osso_context)
20 scan_out = osso_rpc.rpc_run("org.javiplx.wifiscan", "/org/javiplx/wifiscan", "org.javiplx.wifiscan", "wakeup", wait_reply = True)
26 self.db = db.database( os.path.join( conf.homedir , conf.dbname ) )
29 osso_rpc = osso.Rpc(self.osso_context)
30 scan_out = osso_rpc.rpc_run("org.javiplx.wifiscan", "/org/javiplx/wifiscan", "org.javiplx.wifiscan", "start")
34 osso_rpc = osso.Rpc(self.osso_context)
35 scan_out = osso_rpc.rpc_run("org.javiplx.wifiscan", "/org/javiplx/wifiscan", "org.javiplx.wifiscan", "stop")
39 timestamp = time.time()
40 osso_rpc = osso.Rpc(self.osso_context)
42 scan_out = osso_rpc.rpc_run("org.javiplx.wifiscan", "/org/javiplx/wifiscan", "org.javiplx.wifiscan", "scan", wait_reply = True)
44 except Exception , ex :
45 osso.SystemNote(self.osso_context).system_note_infoprint("Exception scanning %s" % ex )
49 start, end = self.scanlist.get_bounds()
50 self.scanlist.delete( start , end )
51 for net in scan_out.split() :
53 items = net.rsplit(":", 1)
54 out_str += " %s %s" % ( items[0] , items[1] )
56 self.scanlist.insert_at_cursor( "%s %5d\n" % ( items[0] , int(items[1]) ) )
57 stored = self.db.get( items[0] )
59 max_rss = int(items[1])
60 if stored[0] > max_rss :
62 self.db.update( items[0] , max_rss , timestamp )
64 self.db.add( items[0] , int(items[1]) , timestamp )
65 self.aplist[ items[0] ] = 1
66 self.refresh_infowin()
68 # Use osso or hildon for notes ???
69 osso.SystemNote(self.osso_context).system_note_infoprint("Found %d APs" % len(scan_out) )
70 # hildon.hildon_banner_show_information( self._parent , "icon_path" , "Found %d APs" % len(scan_out) )
72 fd = open( os.path.join( conf.homedir , "wiscan_gui.info" ) , 'a' )
73 fd.write( "%s %s%s\n" % ( timestamp , self.gps_info , out_str ) )
76 loclist = open( os.path.join( conf.homedir , "location.info" ) , 'a' )
77 loclist.write ( "%s\n" % ( self.satellites ,) )
80 celllist = open( os.path.join( conf.homedir , "cell.info" ) , 'a' )
81 celllist.write ( "%s\n" % ( self.cell_info ,) )
86 def set_infowin ( self , statuswin , listwin ) :
87 gps.GPSObject.set_infowin( self , statuswin )
88 self.scanlist = listwin
90 def refresh_infowin ( self ) :
92 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() ) )
95 gobject.type_register(Scanner)