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
41 def start ( self , timeout=5000 , writelog=False ) :
42 self.scan_timeout = timeout
44 self._fd = open( self._file )
45 self._current = self._fd.readline().split()
54 if not self.scan_timeout :
57 next = self._fd.readline().split()
60 delta = float(next[0]) - float(self._current[0])
61 gobject.timeout_add( int(1000 / self._speed * delta) , self.scan )
63 self.info = [ self._current[1] ]
64 self.info.extend( map( lambda x : float(x) , self._current[2:8] ) )
65 if self.info[0] == "FIX" :
70 self.tstamp = float(self._current[0])
71 for n in range(10, len(self._current), 2) :
73 self.scanlist[ self._current[n] ] = int(self._current[n+1])
77 for mac,max_rss in self.scanlist.iteritems() :
78 stored = self.db.db.execute( "SELECT rss, n, lat, lon FROM ap WHERE mac='%s'" % mac ).fetchone()
80 if not self.aps.has_key( mac ) :
81 self.aps[ mac ] = list(stored[1:])
82 if stored[0] > max_rss :
84 self.db.update( mac , max_rss , self.tstamp , self.info[4:] )
87 if not self.aps.has_key( mac ) :
88 self.aps[ mac ] = [ 0 , 0 , 0 ]
89 self.db.add( mac , max_rss , self.tstamp , self.info[4:] )
90 if self.aps[mac][0] != 0 :
91 self.oldpos[mac] = self.aps[mac][1] / self.aps[mac][0] , self.aps[mac][2] / self.aps[mac][0]
93 self.aps[mac][1] += self.info[4]
94 self.aps[mac][2] += self.info[5]
101 def report ( self ) :
102 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() )
105 gobject.type_register(ReplayScanner)
107 if __name__ == "__main__" :
108 loop = gobject.MainLoop()
109 sample = ReplayScanner()
110 def show_scan(wifiscanner):
111 gobject.timeout_add( 5000 , show_scan , sample )
112 print "scan results %s" % wifiscanner.report()
113 print " tstamp %s" % wifiscanner.tstamp
115 for k,v in wifiscanner.scanlist.iteritems() :
117 print " %s %s" % ( k , v )
124 gobject.timeout_add( 5100 , show_scan , sample )