Added a replay scanner to ease development
authorjaviplx <javiplx@gmail.com>
Sun, 1 May 2011 10:52:04 +0000 (10:52 +0000)
committerjaviplx <javiplx@gmail.com>
Sun, 1 May 2011 10:52:04 +0000 (10:52 +0000)
git-svn-id: file:///svnroot/wifihood/branches/cleaning@97 c51dfc6a-5949-4919-9c8e-f207a149c383

wifimap/replay.py [new file with mode: 0644]

diff --git a/wifimap/replay.py b/wifimap/replay.py
new file mode 100644 (file)
index 0000000..520a4dd
--- /dev/null
@@ -0,0 +1,93 @@
+
+import config
+
+import gobject
+
+import os
+
+conf = config.Configuration()
+
+class ReplayScanner ( gobject.GObject ) :
+
+    def __init__ ( self ) :
+        gobject.GObject.__init__( self )
+        self.scan_timeout = 0
+
+        # Values specific to replaying
+        self._file = os.path.join( conf.homedir , "wiscan_gui.info" )
+        self._fd = None
+        self._current = None
+
+        # Values to be set by GPSDevice changed events
+        self.info = None, 0, 0, None, None, None, None
+        self.satellites = None
+        self.cells = None
+        self.ngps = 0
+
+        # Values to be set by wireless scans
+        self.scanlist = {}
+        self.tstamp = 0
+        self.nscan = 0
+        self.nfp = 0
+
+        # Values from the Scanner object
+        self.newap = 0
+
+    def start ( self , timeout=5000 ) :
+        self.scan_timeout = timeout
+        self._fd = open( self._file )
+        self._current = self._fd.readline().split()
+
+    def stop ( self ) :
+        self.scan_timeout = 0
+        self._fd.close()
+
+    def scan ( self ) :
+
+        if not self.scan_timeout :
+            return
+
+        next = self._fd.readline().split()
+        delta = float(next[0]) - float(self._current[0])
+        gobject.timeout_add( int(1000 * delta) , self.scan )
+
+        self.info = self._current[1:8]
+        if self.info[0] == "FIX" :
+            self.ngps += 1
+
+        self.nscan +=1
+        self.scanlist.clear()
+        self.tstamp = float(self._current[0])
+        for n in range(11, len(self._current), 2) :
+            self.nfp += 1
+            self.scanlist[ self._current[n] ] = int(self._current[n+1])
+
+        self._current = next
+
+    def report ( self ) :
+        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 )
+
+
+gobject.type_register(ReplayScanner)
+
+if __name__ == "__main__" :
+    loop = gobject.MainLoop()
+    sample = ReplayScanner()
+    def show_scan(wifiscanner):
+        gobject.timeout_add( 5000 , show_scan , sample )
+        print "scan results %s" % wifiscanner.report()
+        print "  tstamp %s" % wifiscanner.tstamp
+        c = 0
+        for k,v in wifiscanner.scanlist.iteritems() :
+           c += 1
+           print "    %s %s" % ( k , v )
+           if c > 5 :
+               print "    ..."
+               break
+        print
+    sample.start()
+    sample.scan()
+    gobject.timeout_add( 5100 , show_scan , sample )
+    loop.run()                                       
+    sample.stop()                                 
+