Revision 62
(checked in by cbc, 12 years ago)
|
Back out changes due to disappearing goto lists in to-glider folder.
|
Line | |
---|
1 |
import sys |
---|
2 |
import re |
---|
3 |
import time |
---|
4 |
import datetime |
---|
5 |
import subprocess |
---|
6 |
|
---|
7 |
pattern = re.compile(r"^GPS Location:\s+(\S+)\s+\S\s+(\S+)" |
---|
8 |
r"\s+\S\s+\S+\s+(\S+)\s+") |
---|
9 |
bad_coordinate = "69696969.000" |
---|
10 |
bad_freshness = "1e+308" |
---|
11 |
stale = 900.0 # position must not be older than this many seconds |
---|
12 |
timeout = datetime.timedelta(0,300) # wait up to this many seconds fo log to be appended |
---|
13 |
|
---|
14 |
glider = sys.argv[1] |
---|
15 |
log = sys.argv[2] |
---|
16 |
|
---|
17 |
handle = open(log) |
---|
18 |
|
---|
19 |
content = [] |
---|
20 |
timer = datetime.datetime.now() |
---|
21 |
while True: |
---|
22 |
line = handle.readline() |
---|
23 |
if line: |
---|
24 |
timer = datetime.datetime.now() |
---|
25 |
content.append(line) |
---|
26 |
match = pattern.search(line) |
---|
27 |
if match: |
---|
28 |
lat, lon, fresh = match.groups() |
---|
29 |
if lat == bad_coordinate: |
---|
30 |
continue |
---|
31 |
if lon == bad_coordinate: |
---|
32 |
continue |
---|
33 |
if fresh == bad_freshness: |
---|
34 |
continue |
---|
35 |
if float(fresh) >= stale: |
---|
36 |
print "\nStale GPS fix for %s: %.2f seconds old in %s." % (glider, float(fresh), log), |
---|
37 |
sys.stdout.flush() |
---|
38 |
continue |
---|
39 |
print "\nFresh GPS fix for %s: %.3f %.3f." % (glider, float(lat), float(lon)), |
---|
40 |
sys.stdout.flush() |
---|
41 |
process = subprocess.Popen([sys.executable, |
---|
42 |
"/home/localuser/pilottools/lb/toolshed/points/points.py", |
---|
43 |
glider, |
---|
44 |
lat, |
---|
45 |
lon, |
---|
46 |
"bearing", |
---|
47 |
"0"]) |
---|
48 |
process.wait() |
---|
49 |
break |
---|
50 |
else: |
---|
51 |
if datetime.datetime.now() - timer > timeout: |
---|
52 |
print "\nTimeout reading %s log %s." % (glider, log) |
---|
53 |
break |
---|
54 |
time.sleep(5) |
---|
55 |
|
---|
56 |
handle.close() |
---|