9 class ReplayScanner ( gobject.GObject ) :
11 def __init__ ( self , ifname="wlan0" ) :
12 gobject.GObject.__init__( self )
14 conf = config.Configuration( 'scanner' )
15 self.db = db.database( os.path.join( conf.homedir , "wifireplay.db" ) )
17 # Values specific to replaying
18 self._file = os.path.join( conf.homedir , "wiscan_gui.info" )
23 # Values to be set by GPSDevice changed events
24 self.info = None, 0, 0, None, None, None, None
25 self.satellites = None
29 # Values to be set by wireless scans
35 # Values from the Scanner object
40 def start ( self , timeout=5000 ) :
41 self.scan_timeout = timeout
43 self._fd = open( self._file )
44 self._current = self._fd.readline().split()
53 if not self.scan_timeout :
56 next = self._fd.readline().split()
59 delta = float(next[0]) - float(self._current[0])
60 gobject.timeout_add( int(1000 / self._speed * delta) , self.scan )
62 self.info = [ self._current[1] ]
63 self.info.extend( map( lambda x : float(x) , self._current[2:8] ) )
64 if self.info[0] == "FIX" :
69 self.tstamp = float(self._current[0])
70 for n in range(10, len(self._current), 2) :
72 self.scanlist[ self._current[n] ] = int(self._current[n+1])
76 for mac,max_rss in self.scanlist.iteritems() :
77 stored = self.db.db.execute( "SELECT rss, lat/n, lon/n FROM ap WHERE mac='%s'" % mac ).fetchone()
79 self.aps.append( stored[1:] )
80 if stored[0] > max_rss :
82 self.db.update( mac , max_rss , self.tstamp , self.info[4:] )
85 self.db.add( mac , max_rss , self.tstamp , self.info[4:] )
93 return "%d gps\t%d scan\t%d fp\t%d ap\t%d total ap" % ( self.ngps , self.nscan , self.nfp , self.newap , self.db.nrows() )
96 gobject.type_register(ReplayScanner)
98 if __name__ == "__main__" :
99 loop = gobject.MainLoop()
100 sample = ReplayScanner()
101 def show_scan(wifiscanner):
102 gobject.timeout_add( 5000 , show_scan , sample )
103 print "scan results %s" % wifiscanner.report()
104 print " tstamp %s" % wifiscanner.tstamp
106 for k,v in wifiscanner.scanlist.iteritems() :
108 print " %s %s" % ( k , v )
115 gobject.timeout_add( 5100 , show_scan , sample )