Added basic scanner application
[wifihood] / wifiscanner / wifimap / wifiscan.py
1
2 import osso
3
4 import time
5
6 import gps
7
8 import gobject
9
10 class Scanner ( gps.GPSObject ) :
11
12     def __init__ ( self , widget=None , ifname="wlan0" ) :
13         gps.GPSObject.__init__( self , widget )
14         self.osso_context = osso.Context("wifi_scanner", "2.0", False)
15         self._timer = None
16
17     def start ( self ) :
18         osso_rpc = osso.Rpc(self.osso_context)
19         scan_out = osso_rpc.rpc_run("org.javiplx.wifiscan", "/org/javiplx/wifiscan", "org.javiplx.wifiscan", "start")
20         osso.SystemNote(self.osso_context).system_note_infoprint("WifiScand started")
21
22     def stop ( self ) :
23         osso_rpc = osso.Rpc(self.osso_context)
24         scan_out = osso_rpc.rpc_run("org.javiplx.wifiscan", "/org/javiplx/wifiscan", "org.javiplx.wifiscan", "stop")
25         osso.SystemNote(self.osso_context).system_note_infoprint("WifiScand stopped")
26
27     def scan ( self ) :
28         osso_rpc = osso.Rpc(self.osso_context)
29         try :
30             scan_out = osso_rpc.rpc_run("org.javiplx.wifiscan", "/org/javiplx/wifiscan", "org.javiplx.wifiscan", "scan", wait_reply = True)
31         except Exception , ex :
32             osso.SystemNote(self.osso_context).system_note_infoprint("Exception scanning %s" % ex )
33             return True
34         #osso.SystemNote(self.osso_context).system_note_infoprint("Found %d APs" % len(scan_out.split()) )
35         out_str = ""
36         for net in scan_out.split() :
37             items = net.rsplit(":", 1)
38             out_str += " %s %s" % ( items[0] , items[1] )
39         if self._debug :
40         # Use osso or hildon for notes ???
41             osso.SystemNote(self.osso_context).system_note_infoprint("Found %d APs" % len(scan_out) )
42         #    hildon.hildon_banner_show_information( self._parent , "icon_path" , "Found %d APs" % len(scan_out) )
43         else :
44             fd = open( "/home/user/MyDocs/wiscan_gui.info" , 'a' )
45             fd.write( "%s %s%s\n" % ( time.time() , self.gps_info , out_str ) )
46             fd.close()
47             if self.satellites :
48                 loclist = open( "/home/user/MyDocs/location.info" , 'a' )
49                 loclist.write ( "%s\n" % ( self.satellites ,) )
50                 loclist.close()
51             if self.cell_info :
52             #    osso.SystemNote(self.osso_context).system_note_infoprint("Found Cell : %s" % ( self.cell_info ,) )
53                 celllist = open( "/home/user/MyDocs/cell.info" , 'a' )
54                 celllist.write ( "%s\n" % ( self.cell_info ,) )
55                 celllist.close()
56
57         return True
58
59
60 gobject.type_register(Scanner)
61