5 import hildongtk.osso as osso
13 class WifiScanner ( gobject.GObject ) :
15 def __init__ ( self , ifname="wlan0" ) :
16 gobject.GObject.__init__( self )
17 self.osso_context = osso.Context("wifi_scanner", "2.0", False)
18 osso_rpc = osso.Rpc(self.osso_context)
19 osso_rpc.rpc_run("org.javiplx.wifiscan", "/org/javiplx/wifiscan", "org.javiplx.wifiscan", "wakeup", wait_reply = True)
22 # Values to be set by wireless scans
28 def start ( self , timeout=5000 ) :
29 osso_rpc = osso.Rpc(self.osso_context)
30 osso_rpc.rpc_run("org.javiplx.wifiscan", "/org/javiplx/wifiscan", "org.javiplx.wifiscan", "start")
31 self.scan_timeout = timeout
34 osso_rpc = osso.Rpc(self.osso_context)
35 osso_rpc.rpc_run("org.javiplx.wifiscan", "/org/javiplx/wifiscan", "org.javiplx.wifiscan", "stop")
39 osso_rpc = osso.Rpc(self.osso_context)
41 scan_out = osso_rpc.rpc_run("org.javiplx.wifiscan", "/org/javiplx/wifiscan", "org.javiplx.wifiscan", "scan", wait_reply = True)
42 if self.scan_timeout :
43 gobject.timeout_add( self.scan_timeout , self.scan )
44 # BUG : if scan is called after stop (maybe in other cases), 'ERROR' is returned and split raises exception
47 self.tstamp = time.time()
48 for net in scan_out.split() :
50 items = net.rsplit(":", 1)
51 self.scanlist[ items[0] ] = int(items[1])
52 except Exception , ex :
53 osso.SystemNote(self.osso_context).system_note_infoprint("Exception scanning %s" % ex )
56 return "%d scan\t%d fp" % ( self.nscan , self.nfp )
59 gobject.type_register(WifiScanner)
61 if __name__ == "__main__" :
62 loop = gobject.MainLoop()
63 sample = WifiScanner()
65 def show_scan(sample):
66 gobject.timeout_add( 5000 , show_scan , sample )
67 print "scan results : %s" % sample.report()
68 print " tstamp %s" % sample.tstamp
70 for k,v in sample.scanlist.iteritems() :
72 print " %s %s" % ( k , v )
78 gobject.timeout_add( 5100 , show_scan , sample )