-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.py
98 lines (80 loc) · 2.13 KB
/
index.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import os
import sys
import threading
import time
from subprocess import call
from bin.GpsPoller import GpsPoller
import bin.Forcast as forecast
import bin.Output as output
import bin.Logger as logger
class Controller():
def __init__(self):
#different states of the program
self.finding_fix = False
self.getting_grib = False
self.setting_course = False
#classes controlled by controller
self.gpsp = None
self.logger = None
self.forcast = None
#object variables
self.curr_fix = None
def get_threads(self):
return self.threads
def get_current_step(self):
if self.finding_fix:
return "fixing"
elif self.getting_grib:
return "gribbing"
elif self.setting_course:
return "coursing"
def end(self):
self.finding_fix = False
self.getting_grib = False
self.setting_course = False
self.gpsp = None
def main(self):
print "Beginning Main Loop"
while(True):
print "Aquiring Accurate Fix"
call(['./bin/gpsd_toggle.sh'])
self.curr_fix = self.fix()
print "Fix: " + str(self.curr_fix.fix.latitude) + ", " + str(self.curr_fix.fix.longitude)
logger.write_file(self.curr_fix.fix)
print "Downloading Forecast Information"
grid = forecast.get_forecast(self.curr_fix.fix)
print grid
call(['./bin/gpsd_toggle.sh'])
#TODO max regression
grid = None
print "Sleeping 6 hours"
time.sleep(21600)
def fix(self):
#control flow for the program
#find fix first
try:
self.finding_fix = True
self.gpsp = GpsPoller()
self.gpsp.start()
while self.finding_fix:
report = self.gpsp.get_current_value()
if report.fix.epx < 30 and report.fix.epy < 30:
self.gpsp.running = False
self.finding_fix = False
return self.gpsp.get_current_value()
sleep(5)
except:
self.gpsp.running = False
self.finding_fix = False
self.gpsp = None
print "unexpected error:", sys.exc_info()[0]
if __name__ == '__main__':
print "Starting Navigation"
controller = Controller()
controller.main()
#while(True):
# print "Aquiring Accurate Fix"
# curr_fix = controller.fix()
# forecast.get_forecast(curr_fix.fix)
# print "Sleeping for 6 hours"
# time.sleep(21600)