add a validity check for iw command
This commit is contained in:
parent
ab41f16168
commit
232d4cf98c
|
|
@ -7,7 +7,26 @@ import time
|
||||||
import argparse
|
import argparse
|
||||||
import subprocess
|
import subprocess
|
||||||
|
|
||||||
from numpy import min, max, median, mean, std
|
from numpy import median
|
||||||
|
|
||||||
|
|
||||||
|
def which(program):
|
||||||
|
'''
|
||||||
|
check if a certain program exists
|
||||||
|
'''
|
||||||
|
def is_executable(fp):
|
||||||
|
return os.path.isfile(fp) and os.access(fp, os.X_OK)
|
||||||
|
fp, fn = os.path.split(program)
|
||||||
|
if fp:
|
||||||
|
if is_executable(program):
|
||||||
|
return program
|
||||||
|
else:
|
||||||
|
for path in os.environ["PATH"].split(os.pathsep):
|
||||||
|
path = path.strip('"')
|
||||||
|
exec_file = os.path.join(path, program)
|
||||||
|
if is_executable(exec_file):
|
||||||
|
return exec_file
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
class Measurement(object):
|
class Measurement(object):
|
||||||
|
|
@ -30,6 +49,31 @@ class Measurement(object):
|
||||||
r"distance: ([0-9\-]+) cm"
|
r"distance: ([0-9\-]+) cm"
|
||||||
)
|
)
|
||||||
self.cali = cali
|
self.cali = cali
|
||||||
|
if not self.check_iw_validity():
|
||||||
|
exit(127) # command not found
|
||||||
|
|
||||||
|
def check_iw_validity(self):
|
||||||
|
'''
|
||||||
|
check if iw exists and support FTM commands
|
||||||
|
'''
|
||||||
|
iwPath = which('iw')
|
||||||
|
if iwPath is None:
|
||||||
|
print('Err: iw command not found!')
|
||||||
|
return False
|
||||||
|
p = subprocess.Popen(
|
||||||
|
"iw --help | grep FTM",
|
||||||
|
stdout=subprocess.PIPE,
|
||||||
|
stderr=subprocess.PIPE,
|
||||||
|
shell=True
|
||||||
|
)
|
||||||
|
out, err = p.communicate()
|
||||||
|
if err:
|
||||||
|
print('Err: {0}'.format(err))
|
||||||
|
return False
|
||||||
|
if 'FTM' not in out:
|
||||||
|
print('Err: iw command does not support FTM')
|
||||||
|
return False
|
||||||
|
return True
|
||||||
|
|
||||||
def prepare_config_file(self, targets):
|
def prepare_config_file(self, targets):
|
||||||
if not isinstance(targets, dict):
|
if not isinstance(targets, dict):
|
||||||
|
|
@ -111,12 +155,12 @@ def wrapper(args):
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
counter = 1
|
counter = 1
|
||||||
while 1:
|
|
||||||
print('Round {0}'.format(counter))
|
|
||||||
with Measurement(
|
with Measurement(
|
||||||
args['interface'],
|
args['interface'],
|
||||||
ofp=args['filepath'], cali=args['cali']
|
ofp=args['filepath'], cali=args['cali']
|
||||||
) as m:
|
) as m:
|
||||||
|
while 1:
|
||||||
|
print('Round {0}'.format(counter))
|
||||||
try:
|
try:
|
||||||
m.prepare_config_file(args['config_entry'])
|
m.prepare_config_file(args['config_entry'])
|
||||||
# only print out results
|
# only print out results
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue