Add scale factor to speed up replaying
[wifihood] / wifiscanner / wifimap / replay.py
1
2 import config
3
4 import gobject
5
6 import os
7
8 conf = config.Configuration()
9
10 class ReplayScanner ( gobject.GObject ) :
11
12     def __init__ ( self ) :
13         gobject.GObject.__init__( self )
14         self.scan_timeout = 0
15
16         # Values specific to replaying
17         self._file = os.path.join( conf.homedir , "wiscan_gui.info" )
18         self._fd = None
19         self._current = None
20         self._speed = 10
21
22         # Values to be set by GPSDevice changed events
23         self.info = None, 0, 0, None, None, None, None
24         self.satellites = None
25         self.cells = None
26         self.ngps = 0
27
28         # Values to be set by wireless scans
29         self.scanlist = {}
30         self.tstamp = 0
31         self.nscan = 0
32         self.nfp = 0
33
34         # Values from the Scanner object
35         self.newap = 0
36
37     def start ( self , timeout=5000 ) :
38         self.scan_timeout = timeout
39         self._fd = open( self._file )
40         self._current = self._fd.readline().split()
41
42     def stop ( self ) :
43         self.scan_timeout = 0
44         self._fd.close()
45
46     def scan ( self ) :
47
48         if not self.scan_timeout :
49             return
50
51         next = self._fd.readline().split()
52         delta = float(next[0]) - float(self._current[0])
53         gobject.timeout_add( int(1000 / self._speed * delta) , self.scan )
54
55         self.info = self._current[1:8]
56         if self.info[0] == "FIX" :
57             self.ngps += 1
58
59         self.nscan +=1
60         self.scanlist.clear()
61         self.tstamp = float(self._current[0])
62         for n in range(11, len(self._current), 2) :
63             self.nfp += 1
64             self.scanlist[ self._current[n] ] = int(self._current[n+1])
65
66         self._current = next
67
68     def report ( self ) :
69         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 )
70
71
72 gobject.type_register(ReplayScanner)
73
74 if __name__ == "__main__" :
75     loop = gobject.MainLoop()
76     sample = ReplayScanner()
77     def show_scan(wifiscanner):
78         gobject.timeout_add( 5000 , show_scan , sample )
79         print "scan results %s" % wifiscanner.report()
80         print "  tstamp %s" % wifiscanner.tstamp
81         c = 0
82         for k,v in wifiscanner.scanlist.iteritems() :
83            c += 1
84            print "    %s %s" % ( k , v )
85            if c > 5 :
86                print "    ..."
87                break
88         print
89     sample.start()
90     sample.scan()
91     gobject.timeout_add( 5100 , show_scan , sample )
92     loop.run()                                       
93     sample.stop()                                 
94