From 040a880d682d1870c05a7bd23af521389e7ced1a Mon Sep 17 00:00:00 2001 From: HappyZ Date: Thu, 1 Feb 2018 15:51:38 -0600 Subject: [PATCH] mod parser and config entry for new format --- calibrate.sh | 3 +-- config_entry | 2 +- iw_parser.py | 24 +++++++++++++++++------- libMeasurement.py | 17 +++++++++++------ 4 files changed, 30 insertions(+), 16 deletions(-) diff --git a/calibrate.sh b/calibrate.sh index a20f366..b98c482 100755 --- a/calibrate.sh +++ b/calibrate.sh @@ -1,6 +1,5 @@ #!/bin/bash -for i in `seq 1 1000`; do +for i in `seq 1 100`; do sudo /usr/sbin/iw wlp58s0 measurement ftm_request config_entry | tail -n +3 >> result_$1 - sleep 0.01 done diff --git a/config_entry b/config_entry index a6b4196..d9547fa 100755 --- a/config_entry +++ b/config_entry @@ -1 +1 @@ -34:f6:4b:5e:69:1f bw=20 cf=2462 retries=5 asap +34:f6:4b:5e:69:1f bw=20 cf=2462 retries=3 asap spb=255 diff --git a/iw_parser.py b/iw_parser.py index 3cac4cc..2ef537a 100755 --- a/iw_parser.py +++ b/iw_parser.py @@ -11,17 +11,27 @@ def wrapper(args): if not args['filepath'] or not os.path.isfile(args['filepath']): return results = [] + regex = ( + r"Target: (([0-9a-f]{2}:*){6}), " + + r"status: ([0-9]), rtt: ([0-9\-]+) \(±([0-9\-]+)\) psec, " + + r"distance: ([0-9\-]+) \(±([0-9\-]+)\) cm, rssi: ([0-9\-]+) dBm" + ) with open(args['filepath']) as f: for line in f: - tmp = line.rstrip().split(', ') - status = int(tmp[1].split(' ')[1]) - if status is not 0: + match = re.search(regex, line) + if match: + mac = match.group(1) + status = int(match.group(3)) + rtt = int(match.group(4)) + rtt_var = int(match.group(5)) + raw_distance = int(match.group(6)) + raw_distance_var = int(match.group(7)) + rssi = int(match.group(8)) + else: continue - psec = int(tmp[2].split(' ')[1]) - distance = int(tmp[3].split(' ')[1]) - if distance < -1000: + if status is not 0 or raw_distance < -1000: continue - results.append(distance * args['cali'][0] + args['cali'][1]) + results.append(raw_distance * args['cali'][0] + args['cali'][1]) print('statics of results') print('* num of valid data: {0}'.format(len(results))) print('* min: {0:.2f}cm'.format(min(results))) diff --git a/libMeasurement.py b/libMeasurement.py index 9d2823b..23da4e8 100755 --- a/libMeasurement.py +++ b/libMeasurement.py @@ -39,7 +39,8 @@ class Measurement(object): try: self.outf = open(ofp, 'w') self.outf.write( - 'MAC,caliDist(cm),rawRTT(psec),rawDist(cm),time(sec)\n' + 'MAC,caliDist(cm),rawRTT(psec),rawRTTVar,rawDist(cm),' + + 'rawDistVar,rssi(dBm),time(sec)\n' ) except Exception as e: print(str(e)) @@ -121,18 +122,22 @@ class Measurement(object): result.append((mac, distance, rtt, raw_distance)) if self.outf is not None: self.outf.write( - "{0},{1:.2f},{2},{3},{4:.6f}\n".format( - mac, distance, rtt, raw_distance, time.time() + "{0},{1:.2f},{2},{3},{4},{5},{6},{7:.6f}\n".format( + mac, distance, rtt, rtt_var, + raw_distance, raw_distance_var, + rssi, time.time() ) ) return result - def get_distance_median(self, rounds=10): + def get_distance_median(self, rounds=1): ''' use median instead of mean for less bias with small number of rounds ''' result = {} median_result = {} + if rounds < 1: + rounds = 1 for i in range(rounds): # no guarantee that all rounds are successful for each in self.get_distance_once(): @@ -199,9 +204,9 @@ def main(): ) p.add_argument( '--rounds', - default=10, + default=3, type=int, - help="how many rounds to run one command; default is 10" + help="how many rounds to run one command; default is 3" ) p.add_argument( '--interface', '-i',