5 import hildongtk.osso as osso
16 class Scanner ( gps.GPSObject , wifiscan.WifiScanner ) :
18 def __init__ ( self , conf , ifname="wlan0" ) :
19 gps.GPSObject.__init__( self )
20 wifiscan.WifiScanner.__init__( self , ifname )
21 self.db = db.database( os.path.join( conf.homedir , conf.dbname ) )
22 self.homedir = conf.homedir
26 # Values to be set by wireless scans
32 def start ( self , timeout=5000 , writelog=False ) :
33 gps.GPSObject.start( self )
34 wifiscan.WifiScanner.start( self , timeout )
39 gps.GPSObject.stop( self )
40 wifiscan.WifiScanner.stop( self )
45 wifiscan.WifiScanner.scan( self )
48 for mac,max_rss in self.scanlist.iteritems() :
49 stored = self.db.db.execute( "SELECT rss, n, lat, lon FROM ap WHERE mac='%s'" % mac ).fetchone()
51 if not self.aps.has_key( mac ) :
52 self.aps[ mac ] = list(stored[1:])
53 if stored[0] > max_rss :
55 self.db.update( mac , max_rss , self.tstamp , self.info[4:] )
58 if not self.aps.has_key( mac ) :
59 self.aps[ mac ] = [ 0 , 0 , 0 ]
60 self.db.add( mac , max_rss , self.tstamp , self.info[4:] )
61 if self.aps[mac][0] != 0 :
62 self.oldpos[mac] = self.aps[mac][1] / self.aps[mac][0] , self.aps[mac][2] / self.aps[mac][0]
64 self.aps[mac][1] += self.info[4]
65 self.aps[mac][2] += self.info[5]
72 def write_logs ( self ) :
73 fd = open( os.path.join( self.homedir , "wiscan_gui.info" ) , 'a' )
74 fd.write( "%s %s %s\n" % ( self.tstamp , " ".join(self.info) , " ".join(self.scanlist) ) )
77 loclist = open( os.path.join( self.homedir , "location.info" ) , 'a' )
78 loclist.write ( "%s\n" % ( self.satellites ,) )
81 celllist = open( os.path.join( self.homedir , "cell.info" ) , 'a' )
82 celllist.write ( "%s\n" % ( self.cells ,) )
86 # BUG : if report is called after close, db.nrows() will produce an exception
87 return "%s\t%s\t%d ap\t%d total ap" % ( gps.GPSObject.report(self) , wifiscan.WifiScanner.report(self) , self.newap , self.db.nrows() )
90 gobject.type_register(Scanner)
92 if __name__ == "__main__" :
93 loop = gobject.MainLoop()
95 def on_stop(control, mainloop):
97 sample.control.connect("gpsd-stopped", on_stop, loop)
98 def show_scan(wifiscanner):
99 gobject.timeout_add( 5000 , show_scan , sample )
100 print "scan results %s" % wifiscanner.report()
101 print " tstamp %s" % wifiscanner.tstamp
103 for k,v in wifiscanner.scanlist.iteritems() :
105 print " %s %s" % ( k , v )
112 gobject.timeout_add( 5100 , show_scan , sample )