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
38 def start ( self , timeout=5000 ) :
39 self.scan_timeout = timeout
41 self._fd = open( self._file )
42 self._current = self._fd.readline().split()
51 if not self.scan_timeout :
54 next = self._fd.readline().split()
57 delta = float(next[0]) - float(self._current[0])
58 gobject.timeout_add( int(1000 / self._speed * delta) , self.scan )
60 self.info = [ self._current[1] ]
61 self.info.extend( map( lambda x : float(x) , self._current[2:8] ) )
62 if self.info[0] == "FIX" :
67 self.tstamp = float(self._current[0])
68 for n in range(10, len(self._current), 2) :
70 self.scanlist[ self._current[n] ] = int(self._current[n+1])
72 for mac,max_rss in self.scanlist.iteritems() :
73 stored = self.db.get( mac )
75 if stored[0] > max_rss :
77 self.db.update( mac , max_rss , self.tstamp , self.info[4:] )
80 self.db.add( mac , max_rss , self.tstamp , self.info[4:] )
85 return "%d gps\t%d scan\t%d fp\t%d ap\t%d total ap" % ( self.ngps , self.nscan , self.nfp , self.newap , -1 )
88 gobject.type_register(ReplayScanner)
90 if __name__ == "__main__" :
91 loop = gobject.MainLoop()
92 sample = ReplayScanner()
93 def show_scan(wifiscanner):
94 gobject.timeout_add( 5000 , show_scan , sample )
95 print "scan results %s" % wifiscanner.report()
96 print " tstamp %s" % wifiscanner.tstamp
98 for k,v in wifiscanner.scanlist.iteritems() :
100 print " %s %s" % ( k , v )
107 gobject.timeout_add( 5100 , show_scan , sample )