10 class WifiScanner ( gobject.GObject ) :
12 def __init__ ( self , ifname="wlan0" ) :
13 gobject.GObject.__init__( self )
14 self.osso_context = osso.Context("wifi_scanner", "2.0", False)
15 osso_rpc = osso.Rpc(self.osso_context)
16 osso_rpc.rpc_run("org.javiplx.wifiscan", "/org/javiplx/wifiscan", "org.javiplx.wifiscan", "wakeup", wait_reply = True)
19 # Values to be set by wireless scans
25 def start ( self , timeout=5000 ) :
26 osso_rpc = osso.Rpc(self.osso_context)
27 osso_rpc.rpc_run("org.javiplx.wifiscan", "/org/javiplx/wifiscan", "org.javiplx.wifiscan", "start")
28 self.scan_timeout = timeout
31 osso_rpc = osso.Rpc(self.osso_context)
32 osso_rpc.rpc_run("org.javiplx.wifiscan", "/org/javiplx/wifiscan", "org.javiplx.wifiscan", "stop")
36 osso_rpc = osso.Rpc(self.osso_context)
38 scan_out = osso_rpc.rpc_run("org.javiplx.wifiscan", "/org/javiplx/wifiscan", "org.javiplx.wifiscan", "scan", wait_reply = True)
39 if self.scan_timeout :
40 gobject.timeout_add( self.scan_timeout , self.scan )
41 # BUG : if scan is called after stop (maybe in other cases), 'ERROR' is returned and split raises exception
44 self.tstamp = time.time()
45 for net in scan_out.split() :
47 items = net.rsplit(":", 1)
48 self.scanlist[ items[0] ] = int(items[1])
49 except Exception , ex :
50 osso.SystemNote(self.osso_context).system_note_infoprint("Exception scanning %s" % ex )
53 return "%d scan\t%d fp" % ( self.nscan , self.nfp )
56 gobject.type_register(WifiScanner)
58 if __name__ == "__main__" :
59 loop = gobject.MainLoop()
60 sample = WifiScanner()
62 def show_scan(sample):
63 gobject.timeout_add( 5000 , show_scan , sample )
64 print "scan results : %s" % sample.report()
65 print " tstamp %s" % sample.tstamp
67 for k,v in sample.scanlist.iteritems() :
69 print " %s %s" % ( k , v )
75 gobject.timeout_add( 5100 , show_scan , sample )