-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.py
136 lines (99 loc) · 4.9 KB
/
main.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
from PyQt5 import QtGui
from PyQt5.QtCore import QThreadPool
from PyQt5.QtWidgets import QMainWindow, QApplication, QVBoxLayout, QWidget, QTabWidget, QScrollArea
from widgets.display import Display
from widgets.mechanisms import Mechanisms
from widgets.sensors import Sensors
from widgets.table import Table
from widgets.charts import Charts
from pyqtgraph.console import ConsoleWidget
from widgets.buttons import Buttons
from threads.receivers.tester import Tester
from threads.communication import Communication
from threads.blank import Blank
import hjson
from datetime import date
import sys
class MainWindow(QMainWindow):
def __init__(self, *args, **kwargs):
super(MainWindow, self).__init__(*args, **kwargs)
self.setWindowTitle("Stardust Ground Station")
self.setWindowIcon(QtGui.QIcon('images/stardust.ico'))
self.resize(1000, 600)
self.logFile = 'logs/StardustGroundStation' + str(date.today()) + '.txt'
with open("config.hjson", "r") as file:
config = hjson.load(file)
self.sock_rx = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
self.sock_tx = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
self.ip_rx = config['UDP_rx']['ip']
self.port_rx = int(config['UDP_rx']['port'])
self.ip_tx = config['UDP_tx']['ip']
self.port_tx = int(config['UDP_tx']['port'])
self.sock_rx.bind((self.ip_rx, self.port_rx))
self.layout = QVBoxLayout()
self.updatableWidgets = []
self.display = Display(structure=config['basics'], units=config['units'], phases=config['phases'])
self.layout.addWidget(self.display)
self.updatableWidgets.append(self.display)
self.tabsTop = QTabWidget()
self.layout.addWidget(self.tabsTop)
self.sensors = Sensors(structure=config['sensors'], units=config['units'])
self.tabsTop.addTab(self.sensors, 'Sensors')
self.updatableWidgets.append(self.sensors)
self.mechanisms = Mechanisms(structure=config['mechanisms'], statuses=config['statuses'])
self.tabsTop.addTab(self.mechanisms, 'Mechanisms')
self.updatableWidgets.append(self.mechanisms)
self.tabsBottom = QTabWidget()
self.layout.addWidget(self.tabsBottom)
if config['table']:
self.table = Table(header_labels=config['labels'], max_size=config['maxSize'])
self.updatableWidgets.append(self.table)
self.tabsBottom.addTab(self.table, 'Table')
if config['charts']:
self.charts = Charts(structure=config['sensors'], units=config['units'],
time_index=config['basics'][list(config['basics'].keys())[2]])
self.updatableWidgets.append(self.charts)
self.scrollCharts = QScrollArea()
self.scrollCharts.setWidgetResizable(True)
self.scrollCharts.setWidget(self.charts)
self.tabsBottom.addTab(self.scrollCharts, 'Charts')
if config['console']:
self.console = ConsoleWidget()
self.tabsBottom.addTab(ConsoleWidget(), 'Console')
if config['buttons']:
self.buttons = Buttons(socket=self.sock_tx, udp_ip_tx=self.ip_tx, udp_port_tx=self.port_tx, phases=config['phases'], valves=config['mechanisms']['Valves']['name'], valvestatuses=config['statuses']['valves'], pumps=config['mechanisms']['Pumps']['name'])
self.updatableWidgets.append(self.buttons)
self.tabsBottom.addTab(self.buttons, 'Function Buttons')
self.widget = QWidget()
self.widget.setLayout(self.layout)
self.setCentralWidget(self.widget)
self.testDataRandom = []
self.receiversThreadPool = QThreadPool()
self.communicate(ip=config['UDP']['ip'], port=config['UDP']['port'], mechs=config['mechanisms'], status=list(config['basics'])[1])
del config
def updateGUI(self, data):
for widget in self.updatableWidgets:
widget.updateGUI(data)
#print(self.receiversThreadPool.activeThreadCount())
def printToFile(self, data):
file = open(self.logFile, 'a+')
file.write(data)
file.close()
def testing(self):
tester = Tester(self)
tester.signals.result.connect(self.updateGUI)
self.receiversThreadPool.start(tester)
def communicate(self):
comms = Communication(self.sock_rx, self.sock_tx, self.ip_tx, self.port_tx, 60)
comms.signals.input_list.connect(self.updateGUI)
comms.signals.input_string.connect(self.printToFile)
self.receiversThreadPool.start(comms)
def blanking(self):
blanker = Blank()
self.receiversThreadPool.start(blanker)
def test():
print("Test")
app = QApplication(sys.argv)
window = MainWindow()
window.show()
sys.exit(app.exec_())