forked from nasa/cFS-GroundSystem
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGroundSystem.py
139 lines (115 loc) · 4.35 KB
/
GroundSystem.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
137
138
#
# GSC-18128-1, "Core Flight Executive Version 6.7"
#
# Copyright (c) 2006-2019 United States Government as represented by
# the Administrator of the National Aeronautics and Space Administration.
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
#cFS Ground System Version 2.0.0
#
#!/usr/bin/env python
#
import sys
import os
import socket
import zmq
from PyQt4 import QtGui, QtNetwork, QtCore
from MainWindow import Ui_MainWindow
from RoutingService import RoutingService
#
# CFS Ground System: Setup and manage the main window
#
class GroundSystem(QtGui.QMainWindow):
#
# Init the class
#
def __init__(self, parent=None):
QtGui.QMainWindow.__init__(self)
# Init lists
self.ipAddressesList = ['All']
self.spacecraftNames = ['All']
# Init GUI and set callback methods for buttons
self.ui = Ui_MainWindow()
self.ui.setupUi(self)
self.ui.pushButtonStartTlm.clicked.connect(self.startTlmSystem)
self.ui.pushButtonStartCmd.clicked.connect(self.startCmdSystem)
def closeEvent(self, evnt):
if self.RoutingService:
self.RoutingService.stop()
print ("Stopped routing service")
super(GroundSystem, self).closeEvent(evnt)
# Read the selected spacecraft from combo box on GUI
def getSelectedSpacecraftAddress(self):
return str(self.ui.comboBoxIpAddresses.currentText())
# Returns the name of the selected spacecraft
def getSelectedSpacecraftName(self):
return self.spacecraftNames[self.ipAddressesList.index(self.getSelectedSpacecraftAddress())]
#
# Display popup with error
#
def DisplayErrorMessage(self, message):
print (message)
alert = QtGui.QMessageBox()
alert.setText(message)
alert.setIcon(QtGui.QMessageBox.Warning)
alert.exec_()
# Start the telemetry system for the selected spacecraft
def startTlmSystem(self):
selectedSpacecraft = self.getSelectedSpacecraftName()
# Setup the subscription (to let know the telemetry system the messages it will be receiving)
if selectedSpacecraft == 'All':
subscription = '--sub=GroundSystem'
else:
subscription = '--sub=GroundSystem.' + selectedSpacecraft + '.TelemetryPackets'
# Open Telemetry System
system_call = '( cd Subsystems/tlmGUI/ && python3 TelemetrySystem.py ' + subscription + ' ) & '
os.system(system_call)
# Start command system
def startCmdSystem(self):
os.system('( cd Subsystems/cmdGui/ && python3 CommandSystem.py ) & ')
# Start FDL-FUL gui system
#def startFDLSystem(self):
# selectedSpacecraft = self.getSelectedSpacecraftName()
# if selectedSpacecraft == 'All':
# subscription = ''
# self.DisplayErrorMessage('Cannot open FDL manager.\nNo spacecraft selected.')
# else:
# subscription = '--sub=GroundSystem.' + selectedSpacecraft
# os.system('( cd Subsystems/fdlGui/ && python FdlSystem.py ' + subscription + ' ) & ')
# Update the combo box list in gui
def updateIpList(self, ip, name):
self.ipAddressesList.append(ip)
self.spacecraftNames.append(name)
self.ui.comboBoxIpAddresses.addItem(ip)
# Start the routing service (see RoutingService.py)
def initRoutingService(self):
self.RoutingService = RoutingService(self)
self.connect(self.RoutingService, self.RoutingService.signalUpdateIpList, self.updateIpList)
self.RoutingService.start()
#
# Main
#
if __name__ == "__main__":
# Init app
app = QtGui.QApplication(sys.argv)
# Init main window
MainWindow = GroundSystem()
# Show and put window on front
MainWindow.show()
MainWindow.raise_()
# Start the Routing Service
MainWindow.initRoutingService()
# Execute the app
sys.exit(app.exec_())