Skip to content

Commit

Permalink
Fix nasa#72 - Upgrade PyQt4 to PyQt5
Browse files Browse the repository at this point in the history
Further edits based on CCB feedback, and other fixes as necessary
  • Loading branch information
lbleier-GSFC committed May 20, 2020
1 parent e2376f7 commit 931297a
Show file tree
Hide file tree
Showing 12 changed files with 72 additions and 125 deletions.
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
*.pyc
cmdUtil
.DS_Store
Subsystems/cmdGui/CHeaderParser.py
Subsystems/cmdGui/CHeaderParser.py
22 changes: 12 additions & 10 deletions GroundSystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
# CFS Ground System: Setup and manage the main window
#
class GroundSystem(QMainWindow, Ui_MainWindow):

#
# Init the class
#
Expand Down Expand Up @@ -76,7 +75,6 @@ def getSelectedSpacecraftName(self):
#
def DisplayErrorMessage(self, message):
print(message)
# alert = QMessageBox()
self.alert.setText(message)
self.alert.setIcon(QMessageBox.Warning)
self.alert.exec_()
Expand Down Expand Up @@ -104,14 +102,18 @@ def startCmdSystem():
['python3', f'{ROOTDIR}/Subsystems/cmdGui/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 + ' ) & ')
def startFDLSystem(self):
selectedSpacecraft = self.getSelectedSpacecraftName()
if selectedSpacecraft == 'All':
subscription = ''
self.DisplayErrorMessage(
'Cannot open FDL manager.\nNo spacecraft selected.')
else:
subscription = f'--sub=GroundSystem.{selectedSpacecraft}'
subprocess.Popen([
'python3', f'{ROOTDIR}/Subsystems/fdlGui/FdlSystem.py',
subscription
])

# Update the combo box list in gui
def updateIpList(self, ip, name):
Expand Down
16 changes: 8 additions & 8 deletions Guide-GroundSystem.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,17 @@ Future enhancements:
## Install and run

Before launching the Ground System make sure that:

- PyQt4 is installed,
- PyQt5 is installed,
- PyZMQ is installed,
- cmdUtil is compiled.

Installing and running cFS Ground System on Ubuntu:

1. `sudo apt-get install python3-pyqt4`
2. `sudo apt-get install python3-zmq`
3. `sudo apt-get install libcanberra-gtk-module`
4. `cd Subsystems/cmdUtil/ && make`
5. `python3 GroundSystem.py`
1. ```sudo apt-get install python3-pyqt5```
1. ```sudo apt-get install python3-zmq```
1. ```sudo apt-get install libcanberra-gtk-module```
1. ```cd Subsystems/cmdUtil/ && make```
1. ```python3 GroundSystem.py```

The historically included instructions for running on macOS or CentOS are included at the bottom of this document for reference. Please note that instructions have not been maintained. Welcoming instruction contributions if any of these are your platform of choice.

Expand All @@ -46,7 +45,8 @@ This section was made to help developers who are adding core Flight Software (cF

The `CHeaderParser.py` program that should be found in:

````groundsystem/subsystems/cmdgui```
```GroundSystem/Subsystems/cmdGui```

Is an interactive, command-line based program to help walk developers through the process of adding custom cFS applications to the Ground System. Along with `CHeaderParser.py` is a configuration file that CHeaderParser uses to find the proper header files for your "new" cFS application. This file is named `CHeaderParser-hdr-paths.txt`, and should be placed in the same directory as `CHeaderParser.py`.

Expected file structure:
Expand Down
2 changes: 0 additions & 2 deletions RoutingService.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,6 @@ def forwardMessage(self, datagram, hostName):
def getPktId(datagram):
# Read the telemetry header
streamId = unpack(">H", datagram[:2])
# Uncomment the next line to debug
# print("Packet ID =", hex(streamId))
return hex(streamId[0])

# Close ZMQ vars
Expand Down
42 changes: 5 additions & 37 deletions Subsystems/cmdGui/CHeaderParser.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,6 @@ def getFileList(filename='CHeaderParser-hdr-paths.txt'):
l = l.strip()
if l and not l.startswith("#"):
paths.append(l)
# Don't worry about comment lines
# if line.find('#') == -1:
# Don't worry about empty lines
# if line != '':
# Add line to list of paths
# paths.append(line)
print(f"Using header files found in {filename}")
# Send paths back to caller function
return paths
Expand Down Expand Up @@ -149,8 +143,6 @@ def getFileList(filename='CHeaderParser-hdr-paths.txt'):
for single_line in single_hdr:
master_hdr.append(single_line)

#print "Master Header Length: " + str(len(master_hdr))

# Reads and saves command and parameter information
# Look through each line of the header file for command definitions
for single_line in master_hdr:
Expand Down Expand Up @@ -180,9 +172,6 @@ def getFileList(filename='CHeaderParser-hdr-paths.txt'):
# structure
single_line = single_line[:single_line.rfind('//')]

#else:
# print "Did not find any comments in definition."

# Split single line into list for indexing
definition = single_line.split()

Expand All @@ -195,30 +184,15 @@ def getFileList(filename='CHeaderParser-hdr-paths.txt'):
cmdDesc.append(definition[1])
cmdCodes.append(definition[2])

#else:
# print "length not 3, see line below"
# print definition

#print ("List of Command Descriptions Below:")
#print (cmdDesc)
#print ("--------------------------------------------------------------")
#print ("List of Command Codes Below:")
#print (cmdCodes)
#print ("--------------------------------------------------------------")

print(
"We need to save the command into to a pickle file in 'CommandFile/'. "
)
print(
"Please do not use any spaces/quotes in your filename. Ex: my_app_cmd_file"
)
print(("We need to save the command into to a pickle file "
"in 'CommandFile/'.\nPlease do not use any spaces/quotes "
"in your filename. Ex: my_app_cmd_file"))
cmd_file_name = input(
"What would you like the command file to be saved as? ")

# starting from last index (-1) going backward
# (from example above) file_split[-2] = app_msg
# therefore picklefile = CommandFiles/app_msg
#pickle_file = 'CommandFiles/'+file_split[-2]
pickle_file = f'{ROOTDIR}/CommandFiles/{cmd_file_name}'

# Open pickle file for storing command codes/descriptions
Expand Down Expand Up @@ -456,14 +430,8 @@ def getFileList(filename='CHeaderParser-hdr-paths.txt'):

print("Array size:", array_size)

# Set flag initially to false in order to get into while loop
# array_size_within_limit = False

# Check conditions before loop to see if loop is even necessary
# array_size_within_limit = array_size.isdigit() and int(
# array_size) in range(129)

# This while loop will make sure that the user input is both
# This while loop will make sure that
# the user input is both
# - a valid integer
# - between 0 and 128 (inclusively)
while not array_size.isdigit() or int(
Expand Down
2 changes: 1 addition & 1 deletion Subsystems/cmdGui/CommandSystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def checkParams(idx):
pickle_file = f'{ROOTDIR}/ParameterFiles/{quickParam[idx]}'
try:
with open(pickle_file, 'rb') as pickle_obj:
_, paramNames, _, _, _, _ = pickle.load(pickle_obj)
paramNames = pickle.load(pickle_obj)[1]
return len(paramNames) > 0
except IOError:
return False
Expand Down
89 changes: 43 additions & 46 deletions Subsystems/cmdGui/HTMLDocsParser.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,14 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
import sys
import csv
import getopt
import subprocess
import shlex
import re

import glob
import pickle

import re
from html.parser import HTMLParser
from struct import *


class HTMLDocsParser(HTMLParser):

#
# Initializes allData variable
#
Expand All @@ -42,15 +35,16 @@ def reset(self):
#
# Appends HTML file content to allData variable
#
def handle_data(self, text):
if text.strip() != '': # excludes new lines
self.allData.append(text.strip())
def handle_data(self, data):
if data.strip(): # excludes new lines
self.allData.append(data.strip())

#
# Determines UNIX data type of parameter
#
def findDataTypeNew(self, dataTypeOrig, paramLen):
if paramLen != '': # assumes all string types have length enclosed in brackets
@staticmethod
def findDataTypeNew(dataTypeOrig, paramLn):
if paramLn: # assumes all string types have length enclosed in brackets
return '--string'
if dataTypeOrig in ('uint8', 'boolean'):
return '--byte'
Expand All @@ -65,25 +59,25 @@ def findDataTypeNew(self, dataTypeOrig, paramLen):
#
# Determines character array size for string types
#
def findStringLen(self, keyword):
@staticmethod
def findStringLen(kywd):
hdr_files = glob.glob('../../../build/cpu1/inc/*.h')
hdr_files += glob.glob('../../fsw/cfe-core/src/inc/cfe_*.h')
hdr_files += glob.glob('../../fsw/mission_inc/cfe_mission_cfg.h')
val = ''
found = False
i = 0
k = 0

while not found and i < len(hdr_files):
with open(hdr_files[i]) as hdr_obj:
while not found and k < len(hdr_files):
with open(hdr_files[k]) as hdr_obj:
file_lines = hdr_obj.readlines()
j = 0
while found == False and j < len(file_lines):
if '#define ' + keyword in file_lines[j]:
l = 0
while not found and l < len(file_lines):
if f'#define {kywd}' in file_lines[l]:
found = True
val = file_lines[j].split()[2]
j += 1
i += 1

val = file_lines[l].split()[2]
l += 1
k += 1
return val


Expand All @@ -104,7 +98,7 @@ def findStringLen(self, keyword):
with open(html_file) as file_obj: # opens HTML file
reader = file_obj.read() # reads HTML file
parser.feed(reader) # feeds file contents to parser
data = parser.allData
allData = parser.allData

dataTypesOrig = [] # uint8, uint16, uint32, char, boolean
paramNames = [] # parameter name
Expand All @@ -114,32 +108,35 @@ def findStringLen(self, keyword):
stringLen = [] # evaluated parameter length

try:
i = data.index("Data Fields") + 1
j = data.index("Detailed Description")
while i < j: # iterates through lines between Data Fields and Detailed Description

i = allData.index("Data Fields") + 1
j = allData.index("Detailed Description")
# iterates through lines between Data Fields and Detailed Description
while i < j:
# skips header parameters
if 'Header' in data[i + 1] or 'Hdr' in data[i + 1]:
if any([x in allData[i + 1] for x in ('Header', 'Hdr')]):
# if 'Header' in data[i + 1] or 'Hdr' in data[i + 1]:
i += 1
while 'uint' not in data[i] and 'char' not in data[
i] and i < j:
while not any(
[x in allData[i]
for x in ('uint', 'char')]) and i < j:
# while 'uint' not in data[i] and 'char' not in data[
# i] and i < j:
i += 1

else:
dataTypesOrig.append(data[i]) # stores data type
dataTypesOrig.append(allData[i]) # stores data type
i += 1
paramNames.append(data[i]) # stores parameter name
paramNames.append(allData[i]) # stores parameter name
i += 1
param_len = ''
if '[' in data[i]:
param_len = data[
if '[' in allData[i]:
param_len = allData[
i] # stores string length if provided
i += 1
paramLen.append(param_len)
desc_string = ''
while 'uint' not in data[i] and 'char' not in data[
i] and i < j:
desc_string = desc_string + ' ' + data[i]
while not any([x in allData[i] for x in ('uint', 'char')]) and i < j:
desc_string = f'{desc_string} {allData[i]}'
i += 1
paramDesc.append(desc_string.lstrip()
) # stores parameter description
Expand All @@ -152,15 +149,15 @@ def findStringLen(self, keyword):
# finds size of character array if type --string
keyword = ''
if dataTypeNew == '--string':
keyword = re.sub('\[|\]|\(|\)', '',
keyword = re.sub(r'\[|\]|\(|\)', '',
paramLen[-1]) # removes brackets
while keyword.isdigit() == False:
while not keyword.isdigit():
keyword = parser.findStringLen(keyword)
keyword = re.sub('\[|\]|\(|\)', '', keyword)
keyword = re.sub(r'\[|\]|\(|\)', '', keyword)
if keyword == '0':
keyword = input(
paramLen[-1] +
' not found. Please enter value manually: ')
f'{paramLen[-1]} not found. Please enter value manually: '
)
stringLen.append(keyword)

print("DATA TYPES:", dataTypesOrig)
Expand All @@ -174,7 +171,7 @@ def findStringLen(self, keyword):
print("Data Fields not found in HTML file")

# write data to a file
file_split = re.split('/|\.', html_file)
file_split = re.split(r'/|\.', html_file)
pickle_file = 'ParameterFiles/' + file_split[-2]
with open(pickle_file, 'wb') as pickle_obj:
pickle.dump([
Expand Down
4 changes: 0 additions & 4 deletions Subsystems/cmdGui/Parameter.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@


class Parameter(QDialog, Ui_Dialog):

#
# Initializes Parameter class
#
Expand Down Expand Up @@ -65,12 +64,10 @@ def ProcessSendButton(self):
param_list.append(f'{dataType}={input_list[k]}') # --byte=4
k += 1
param_string = ' '.join(param_list)
# print(param_string)
launch_string = (
f'{ROOTDIR}/../cmdUtil/cmdUtil --host={pageAddress} '
f'--port={pagePort} --pktid={pagePktId} --endian={pageEndian} '
f'--cmdcode={cmdCode} {param_string.strip()}')
# print launch_string
cmd_args = shlex.split(launch_string)
subprocess.Popen(cmd_args)
self.status_box.setText('Command sent!')
Expand All @@ -80,7 +77,6 @@ def ProcessSendButton(self):
# Main method
#
if __name__ == '__main__':

#
# Initializes variables
#
Expand Down
Loading

0 comments on commit 931297a

Please sign in to comment.