9 conf = config.Configuration()
11 class ReplayScanner ( gobject.GObject ) :
13 def __init__ ( self ) :
14 gobject.GObject.__init__( self )
16 self.db = db.database( os.path.join( conf.homedir , "wifireplay.db" ) )
18 # Values specific to replaying
19 self._file = os.path.join( conf.homedir , "wiscan_gui.info" )
24 # Values to be set by GPSDevice changed events
25 self.info = None, 0, 0, None, None, None, None
26 self.satellites = None
30 # Values to be set by wireless scans
36 # Values from the Scanner object
39 def start ( self , timeout=5000 ) :
40 self.scan_timeout = timeout
42 self._fd = open( self._file )
43 self._current = self._fd.readline().split()
52 if not self.scan_timeout :
55 next = self._fd.readline().split()
56 delta = float(next[0]) - float(self._current[0])
57 gobject.timeout_add( int(1000 / self._speed * delta) , self.scan )
59 self.info = [ self._current[1] ]
60 self.info.extend( map( lambda x : float(x) , self._current[2:8] ) )
61 if self.info[0] == "FIX" :
66 self.tstamp = float(self._current[0])
67 for n in range(11, len(self._current), 2) :
69 self.scanlist[ self._current[n] ] = int(self._current[n+1])
71 for mac,max_rss in self.scanlist.iteritems() :
72 stored = self.db.get( mac )
74 if stored[0] > max_rss :
76 self.db.update( mac , max_rss , self.tstamp , self.info[4:] )
79 self.db.add( mac , max_rss , self.tstamp , self.info[4:] )
84 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 )
87 gobject.type_register(ReplayScanner)
89 if __name__ == "__main__" :
90 loop = gobject.MainLoop()
91 sample = ReplayScanner()
92 def show_scan(wifiscanner):
93 gobject.timeout_add( 5000 , show_scan , sample )
94 print "scan results %s" % wifiscanner.report()
95 print " tstamp %s" % wifiscanner.tstamp
97 for k,v in wifiscanner.scanlist.iteritems() :
99 print " %s %s" % ( k , v )
106 gobject.timeout_add( 5100 , show_scan , sample )