-
Notifications
You must be signed in to change notification settings - Fork 0
/
station.py
80 lines (65 loc) · 1.98 KB
/
station.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
from GUI.gui import *
from Modules.Communication import *
from Modules.EventManager import *
from Modules.Prediction import Predictor
import sys
from PyQt5.QtWidgets import QApplication
import threading
import time
import yaml
class Configurator:
def __init__(self, file):
self.file = file
self.data = {}
try:
with open(file, 'r') as stream:
self.data=yaml.load(stream)
except Exception as e:
print(e)
def __setitem__(self, key, value):
self.data[key]=value
self.save()
def save(self):
#print(self.data)
with open(self.file, 'w') as outfile:
yaml.dump(self.data, outfile, default_flow_style=False)
def __getitem__(self, key):
return self.data[key]
def get(self, key):
return self.__getitem__(key)
def update(self, new):
self.data.update(new)
self.save()
def all(self):
return copy.deepcopy(self.data)
def __str__(self):
return str(self.data)
class MissionTimer:
def __init__(self):
self.start = time.time()
def get_time(self):
return round(time.time()-self.start, 2)
def reset(self):
self.start = time.time()
def new_reader(conf, obj, call):
if conf['type'] == 'radio':
radio={
'port':conf['port'],
'baudrate':conf['baudrate'],
'timeout':conf['timeout']
}
dr=DataReader(conf['labels'], radio, event_manager = obj['em'], rds=obj['rds'])
reader = threading.Thread(target=dr.keepReading, args=(True, ), kwargs={'call':call,})
reader.start()
conf = Configurator('config.yaml')
dm=DataManager(conf)
obj={'dm':dm, 'em':dm.em, 'rds':dm.ds, 'reader':new_reader,
'type':None, 'sl':SerialLoader(), 'timer':MissionTimer()}
dc = DataCreator(conf, obj)
obj['dc']=dc
obj['predictor'] = Predictor()
reader = threading.Thread(target=dc.loop)
reader.start()
app = QApplication(sys.argv)
win = MainWidgetWindow(conf, obj)
app.exec_()