Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 78
Expand file tree
/
Copy pathGroundSystem.py
More file actions
Latest commit
210 lines (173 loc) · 6.9 KB
/
Copy pathGroundSystem.py
File metadata and controls
210 lines (173 loc) · 6.9 KB
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
# !/usr/bin/env python3
#
# NASA Docket No. GSC-19,200-1, and identified as "cFS Draco"
#
# Copyright (c) 2023 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.
#
importshlex
importsubprocess
importsys
importos
importsignal
importpathlib
importgetpass
fromPyQt5.QtWidgetsimportQApplication, QMainWindow, QMessageBox
fromRoutingServiceimportRoutingService
fromUiMainWindowimportUiMainWindow
from_versionimport__version__as_version
from_versionimport_version_string
__version__=_version
# ROOTDIR = Path(sys.argv[0]).resolve().parent
ROOTDIR=pathlib.Path(__file__).parent.absolute()
#
# CFS Ground System: Setup and manage the main window
#
classGroundSystem(QMainWindow, UiMainWindow):
TLM_HDR_V1_OFFSET=4
TLM_HDR_V2_OFFSET=4
CMD_HDR_PRI_V1_OFFSET=0
CMD_HDR_SEC_V1_OFFSET=0
CMD_HDR_PRI_V2_OFFSET=4
CMD_HDR_SEC_V2_OFFSET=4
#
# Init the class
#
def__init__(self):
super().__init__()
self.setupUi(self)
self.routing_service=None
self.alert=QMessageBox()
# set initial defaults
self.sb_tlm_offset.setValue(self.TLM_HDR_V1_OFFSET)
self.sb_cmd_offset_pri.setValue(self.CMD_HDR_PRI_V1_OFFSET)
self.sb_cmd_offset_sec.setValue(self.CMD_HDR_SEC_V1_OFFSET)
self.push_button_start_tlm.clicked.connect(self.start_tlm_system)
self.push_button_start_cmd.clicked.connect(self.start_cmd_system)
self.cb_tlm_header_ver.currentIndexChanged.connect(self.set_tlm_offset)
self.cb_cmd_header_ver.currentIndexChanged.connect(self.set_cmd_offsets)
forsbin (self.sb_tlm_offset, self.sb_cmd_offset_pri, self.sb_cmd_offset_sec):
sb.valueChanged.connect(self.save_offsets)
# Init lists
self.ip_addresses_list= ['All']
self.spacecraft_names= ['All']
defcloseEvent(self, evnt):
ifself.routing_service:
self.routing_service.stop()
print("Stopped routing service")
os.kill(0, signal.SIGKILL)
super().closeEvent(evnt)
# Read the selected spacecraft from combo box on GUI
defget_selected_spacecraft_address(self):
returnself.combo_box_ip_addresses.currentText().strip()
# Returns the name of the selected spacecraft
defget_selected_spacecraft_name(self):
returnself.spacecraft_names[self.ip_addresses_list.index(
self.get_selected_spacecraft_address())].strip()
#
# Display popup with error
#
defdisplay_error_message(self, message):
print(message)
self.alert.setText(message)
self.alert.setIcon(QMessageBox.Warning)
self.alert.exec_()
# Start the telemetry system for the selected spacecraft
defstart_tlm_system(self):
# Setup the subscription (to let the telemetry
# system know the messages it will be receiving)
subscription='--sub=GroundSystem'
selected_spacecraft=self.get_selected_spacecraft_name()
ifselected_spacecraft!='All':
subscription+=f'.{selected_spacecraft}.TelemetryPackets'
# Open Telemetry System
system_call=f'python3 {ROOTDIR}/Subsystems/tlmGUI/TelemetrySystem.py {subscription}'
args=shlex.split(system_call)
subprocess.Popen(args)
# Start command system
@staticmethod
defstart_cmd_system():
subprocess.Popen(
['python3', f'{ROOTDIR}/Subsystems/cmdGui/CommandSystem.py'])
# Start FDL-FUL gui system
defstart_fdl_system(self):
selected_spacecraft=self.get_selected_spacecraft_name()
ifselected_spacecraft=='All':
self.display_error_message(
'Cannot open FDL manager.\nNo spacecraft selected.')
else:
subscription=f'--sub=GroundSystem.{selected_spacecraft}'
subprocess.Popen([
'python3', f'{ROOTDIR}/Subsystems/fdlGui/FdlSystem.py',
subscription
])
defset_tlm_offset(self):
selected_ver=self.cb_tlm_header_ver.currentText().strip()
ifselected_ver=="Custom":
self.sb_tlm_offset.setEnabled(True)
else:
self.sb_tlm_offset.setEnabled(False)
ifselected_ver=="1":
self.sb_tlm_offset.setValue(self.TLM_HDR_V1_OFFSET)
elifselected_ver=="2":
self.sb_tlm_offset.setValue(self.TLM_HDR_V2_OFFSET)
defset_cmd_offsets(self):
selected_ver=self.cb_cmd_header_ver.currentText().strip()
ifselected_ver=="Custom":
self.sb_cmd_offset_pri.setEnabled(True)
self.sb_cmd_offset_sec.setEnabled(True)
else:
self.sb_cmd_offset_pri.setEnabled(False)
self.sb_cmd_offset_sec.setEnabled(False)
ifselected_ver=="1":
self.sb_cmd_offset_pri.setValue(self.CMD_HDR_PRI_V1_OFFSET)
self.sb_cmd_offset_sec.setValue(self.CMD_HDR_SEC_V1_OFFSET)
elifselected_ver=="2":
self.sb_cmd_offset_pri.setValue(self.CMD_HDR_PRI_V2_OFFSET)
self.sb_cmd_offset_sec.setValue(self.CMD_HDR_SEC_V2_OFFSET)
defsave_offsets(self):
offsets=bytes((self.sb_tlm_offset.value(), self.sb_cmd_offset_pri.value(),
self.sb_cmd_offset_sec.value()))
withopen(f"/tmp/OffsetData-{getpass.getuser()}", "wb") asf:
f.write(offsets)
# Update the combo box list in gui
defupdate_ip_list(self, ip, name):
self.ip_addresses_list.append(ip)
self.spacecraft_names.append(name)
self.combo_box_ip_addresses.addItem(ip)
# Start the routing service (see RoutingService.py)
definit_routing_service(self):
self.routing_service=RoutingService()
self.routing_service.signal_update_ip_list.connect(self.update_ip_list)
self.routing_service.start()
#
# Main
#
defmain():
# Report Version Number upon startup
print(_version_string)
# Init app
app=QApplication(sys.argv)
# Init main window
main_window=GroundSystem()
# Show and put window on front
main_window.show()
main_window.raise_()
# Start the Routing Service
main_window.init_routing_service()
main_window.save_offsets()
# Execute the app
sys.exit(app.exec_())
if__name__=="__main__":
main()