8 class ReplayScanner ( gobject.GObject ) :
10 def __init__ ( self , conf , ifname="wlan0" ) :
11 gobject.GObject.__init__( self )
13 self.db = db.database( os.path.join( conf.homedir , "wifireplay.db" ) )
15 # Values specific to replaying
16 self._file = os.path.join( conf.homedir , "wiscan_gui.info" )
21 # Values to be set by GPSDevice changed events
22 self.info = None, 0, 0, None, None, None, None
23 self.satellites = None
27 # Values to be set by wireless scans
32 # Values from the Scanner object
39 def start ( self , timeout=5000 , writelog=False ) :
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()
58 delta = float(next[0]) - float(self._current[0])
59 gobject.timeout_add( int(1000 / self._speed * delta) , self.scan )
61 self.info = [ self._current[1] ]
62 self.info.extend( map( lambda x : float(x) , self._current[2:8] ) )
63 if self.info[0] == "FIX" :
68 self.tstamp = float(self._current[0])
69 for n in range(10, len(self._current), 2) :
71 self.scanlist[ self._current[n] ] = int(self._current[n+1])
75 for mac,max_rss in self.scanlist.iteritems() :
76 stored = self.db.db.execute( "SELECT rss, n, lat, lon FROM ap WHERE mac='%s'" % mac ).fetchone()
78 if not self.aps.has_key( mac ) :
79 self.aps[ mac ] = list(stored[1:])
80 if stored[0] > max_rss :
82 self.db.update( mac , max_rss , self.tstamp , self.info[4:] )
85 if not self.aps.has_key( mac ) :
86 self.aps[ mac ] = [ 0 , 0 , 0 ]
87 self.db.add( mac , max_rss , self.tstamp , self.info[4:] )
88 if self.aps[mac][0] != 0 :
89 self.oldpos[mac] = self.aps[mac][1] / self.aps[mac][0] , self.aps[mac][2] / self.aps[mac][0]
91 self.aps[mac][1] += self.info[4]
92 self.aps[mac][2] += self.info[5]
100 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() )
103 gobject.type_register(ReplayScanner)
105 if __name__ == "__main__" :
106 loop = gobject.MainLoop()
107 sample = ReplayScanner()
108 def show_scan(wifiscanner):
109 gobject.timeout_add( 5000 , show_scan , sample )
110 print "scan results %s" % wifiscanner.report()
111 print " tstamp %s" % wifiscanner.tstamp
113 for k,v in wifiscanner.scanlist.iteritems() :
115 print " %s %s" % ( k , v )
122 gobject.timeout_add( 5100 , show_scan , sample )