Package killerbee :: Package zbwardrive :: Module zbwardrive
[hide private]
[frames] | no frames]

Source Code for Module killerbee.zbwardrive.zbwardrive

 1  #!/usr/bin/env python 
 2   
 3  # ZBWarDrive 
 4  # rmspeers 2010-13 
 5  # ZigBee/802.15.4 WarDriving Platform 
 6   
 7  from time import sleep 
 8  from usb import USBError 
 9   
10  from killerbee import KillerBee, kbutils 
11  from db import ZBScanDB 
12  from scanning import doScan 
13   
14  GPS_FREQUENCY=3 #in seconds 
15   
16  # GPS Poller 
17 -def gpsdPoller(currentGPS):
18 ''' 19 @type currentGPS multiprocessing.Manager dict manager 20 @arg currentGPS store relavent pieces of up-to-date GPS info 21 ''' 22 import gps 23 gpsd = gps.gps() 24 gpsd.poll() 25 gpsd.stream() 26 27 try: 28 while True: 29 gpsd.poll() 30 if gpsd.fix.mode > 1: #1=NO_FIX, 2=FIX, 3=DGPS_FIX 31 lat = gpsd.fix.latitude 32 lng = gpsd.fix.longitude 33 alt = gpsd.fix.altitude 34 #print 'latitude ' , lat 35 #print 'longitude ' , lng 36 #TODO do we want to use the GPS time in any way? 37 #print 'time utc ' , gpsd.utc,' + ', gpsd.fix.time 38 #print 'altitude (m)' , alt 39 currentGPS['lat'] = lat 40 currentGPS['lng'] = lng 41 currentGPS['alt'] = alt 42 else: 43 print "Waiting for a GPS fix." 44 #TODO timeout lat/lng/alt values if too old...? 45 sleep(GPS_FREQUENCY) 46 except KeyboardInterrupt: 47 print "Got KeyboardInterrupt in gpsdPoller, returning." 48 return
49 50 # startScan 51 # Detects attached interfaces 52 # Initiates scanning using doScan()
53 -def startScan(zbdb, currentGPS, verbose=False, dblog=False, agressive=False, include=[], ignore=None):
54 try: 55 kb = KillerBee() 56 except USBError, e: 57 if e.args[0].find('Operation not permitted') >= 0: 58 print 'Error: Permissions error, try running using sudo.' 59 else: 60 print 'Error: USBError:', e 61 return False 62 except Exception, e: 63 #print 'Error: Missing KillerBee USB hardware:', e 64 print 'Error: Issue starting KillerBee instance:', e 65 return False 66 for kbdev in kbutils.devlist(gps=ignore, include=include): 67 print 'Found device at %s: \'%s\'' % (kbdev[0], kbdev[1]) 68 zbdb.store_devices( 69 kbdev[0], #devid 70 kbdev[1], #devstr 71 kbdev[2]) #devserial 72 kb.close() 73 doScan(zbdb, currentGPS, verbose=verbose, dblog=dblog, agressive=agressive) 74 return True
75