Skip to content

Commit

Permalink
WIP Fix nasa#72 - Upgrade PyQt and implement fixes/cleanup/refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
lbleier-GSFC committed Apr 27, 2020
1 parent 10f55fd commit dd912cd
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 57 deletions.
8 changes: 4 additions & 4 deletions GroundSystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
from MainWindow import Ui_MainWindow
from RoutingService import RoutingService

ROOTDIR = Path(sys.argv[0]).resolve().parent


#
# CFS Ground System: Setup and manage the main window
Expand All @@ -44,8 +46,6 @@ def __init__(self):
super().__init__()
self.setupUi((self))

self.rootDir = Path(sys.argv[0]).resolve().parent

self.RoutingService = None

self.pushButtonStartTlm.clicked.connect(self.startTlmSystem)
Expand Down Expand Up @@ -93,14 +93,14 @@ def startTlmSystem(self):
subscription = f'--sub=GroundSystem.{selectedSpacecraft}.TelemetryPackets'

# Open Telemetry System
system_call = f'python3 {self.rootDir}/Subsystems/tlmGUI/TelemetrySystem.py {subscription}'
system_call = f'python3 {ROOTDIR}/Subsystems/tlmGUI/TelemetrySystem.py {subscription}'
args = shlex.split(system_call)
subprocess.Popen(args)

# Start command system
def startCmdSystem(self):
subprocess.Popen(
['python3', f'{self.rootDir}/Subsystems/cmdGui/CommandSystem.py'])
['python3', f'{ROOTDIR}/Subsystems/cmdGui/CommandSystem.py'])

# Start FDL-FUL gui system
#def startFDLSystem(self):
Expand Down
13 changes: 7 additions & 6 deletions Subsystems/cmdGui/CommandSystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@
import sys
from pathlib import Path

from PyQt5.QtWidgets import QDialog, QApplication
from PyQt5.QtWidgets import QApplication, QDialog

from CommandSystemDialog import Ui_CommandSystemDialog

ROOTDIR = Path(sys.argv[0]).resolve().parent

class CommandSystem(QDialog, Ui_CommandSystemDialog):

Expand Down Expand Up @@ -59,7 +60,7 @@ def ProcessButtonGeneric(self, idx):
pktId = lePID.text()
address = leAddr.text()
launch_string = (
f'python3 {cmdClass[0]} '
f'python3 {ROOTDIR}/{cmdClass[0]} '
f'--title=\"{cmdPageDesc[idx]}\" --pktid={pktId} '
f'--file={cmdPageDefFile[idx]} --address=\"{address}\" '
f'--port={cmdPagePort[idx]} --endian={cmdPageEndian[idx]}')
Expand Down Expand Up @@ -93,7 +94,7 @@ def ProcessQuickButton(self, idx):
# if requires parameters
if self.checkParams(qIdx):
launch_string = (
f'python3 Parameter.py '
f'python3 f{ROOTDIR}/Parameter.py '
f'--title=\"{subsys[qIdx]}\" '
f'--descrip=\"{quickCmd[qIdx]}\" '
f'--idx={idx} --host=\"{address}\" '
Expand All @@ -103,7 +104,7 @@ def ProcessQuickButton(self, idx):
# if doesn't require parameters
else:
launch_string = (
f'../cmdUtil/cmdUtil '
f'{ROOTDIR}/../cmdUtil/cmdUtil '
f'--host=\"{address}\" --port={quickPort[qIdx]} '
f'--pktid={pktId} --endian={quickEndian[qIdx]} '
f'--cmdcode={quickCode[qIdx]}')
Expand Down Expand Up @@ -135,7 +136,7 @@ def ProcessQuickButton(self, idx):

i = 0

with open(cmdDefFile) as cmdfile:
with open(f"{ROOTDIR}/{cmdDefFile}") as cmdfile:
reader = csv.reader(cmdfile, skipinitialspace=True)
for cmdRow in reader:
try:
Expand Down Expand Up @@ -171,7 +172,7 @@ def ProcessQuickButton(self, idx):
quickEndian, quickAddress, quickPort, quickParam, \
quickIndices = ([] for _ in range(10))

with open(quickDefFile) as subFile:
with open(f'{ROOTDIR}/{quickDefFile}') as subFile:
reader = csv.reader(subFile)
for fileRow in reader:
if fileRow[0][0] != '#':
Expand Down
20 changes: 12 additions & 8 deletions Subsystems/cmdGui/Parameter.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,21 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
#pylint: disable=invalid-name, missing-function-docstring, missing-class-docstring, missing-module-docstring
import getopt
import pickle
import re
import shlex
import subprocess
import sys
from pathlib import Path

from PyQt5.QtWidgets import QApplication, QDialog

from HTMLDocsParser import HTMLDocsParser
from ParameterDialog import Ui_Dialog

ROOTDIR = Path(sys.argv[0]).resolve().parent


class Parameter(QDialog, Ui_Dialog):

Expand All @@ -52,17 +54,19 @@ def ProcessSendButton(self):
inputStr = getattr(self, f"input_{j}")
input_list.append(inputStr.toPlainText().strip())

k = 0
param_list = []
for j, currInput in enumerate(input_list):
dataType = dataTypesNew[j]
while input_list[k]:
dataType = dataTypesNew[k]
if dataType == '--string':
param_list.append(f'{dataType}=\"{stringLen[j]}:{currInput}\"')
param_list.append(f'{dataType}=\"{stringLen[k]}:{input_list[k]}\"')
else:
param_list.append(f'{dataType}={currInput}') # --byte=4
param_list.append(f'{dataType}={input_list[k]}') # --byte=4
k += 1
param_string = ' '.join(param_list)
# print param_string
# print(param_string)
launch_string = (
f'../cmdUtil/cmdUtil --host={pageAddress} '
f'{ROOTDIR}/../cmdUtil/cmdUtil --host={pageAddress} '
f'--port={pagePort} --pktid={pagePktId} --endian={pageEndian} '
f'--cmdcode={cmdCode} {param_string.strip()}')
# print launch_string
Expand Down Expand Up @@ -121,7 +125,7 @@ def ProcessSendButton(self):
#
# Gets parameter information from pickle files
#
pickle_file = 'ParameterFiles/' + re.split(r'\.', param_file)[0]
pickle_file = f'{ROOTDIR}/ParameterFiles/' + re.split(r'\.', param_file)[0]
with open(pickle_file, 'rb') as pickle_obj:
dataTypesOrig, paramNames, paramLen, paramDesc, dataTypesNew, stringLen = pickle.load(
pickle_obj)
Expand Down
24 changes: 13 additions & 11 deletions Subsystems/cmdGui/UdpCommands.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,20 @@
# This class could be duplicated to send over another interface
# such as TCP, Cubesat Space Protocol, or Xbee wireless radio
#
#pylint: disable=invalid-name, missing-function-docstring, missing-class-docstring, missing-module-docstring
import sys
import getopt
import subprocess
import shlex
import pickle
import shlex
import subprocess
import sys
from pathlib import Path

from PyQt5.QtWidgets import QApplication, QDialog

from PyQt5.QtWidgets import QDialog, QApplication
from GenericCommandDialog import Ui_GenericCommandDialog
from HTMLDocsParser import HTMLDocsParser

ROOTDIR = Path(sys.argv[0]).resolve().parent


class SubsystemCommands(QDialog, Ui_GenericCommandDialog):

Expand All @@ -65,11 +68,10 @@ def __init__(self):
#
@staticmethod
def checkParams(idx):
pf = f'ParameterFiles/{param_files[idx]}'
pf = f'{ROOTDIR}/ParameterFiles/{param_files[idx]}'
try:
with open(pf, 'rb') as po:
_, paramNames, _, _, _, _ = pickle.load(
po)
_, paramNames, _, _, _, _ = pickle.load(po)
return len(paramNames) > 0 # if has parameters
except IOError:
return False
Expand All @@ -85,7 +87,7 @@ def ProcessSendButtonGeneric(self, idx):
# If parameters are required, launches Parameters page
if param_bool:
launch_string = (
f'python3 Parameter.py --title=\"{pageTitle}\" '
f'python3 {ROOTDIR}/Parameter.py --title=\"{pageTitle}\" '
f'--descrip=\"{cmdDesc[idx]}\" --idx={idx} '
f'--host=\"{address}\" --port={pagePort} '
f'--pktid={pagePktId} --endian={pageEndian} '
Expand All @@ -94,7 +96,7 @@ def ProcessSendButtonGeneric(self, idx):
# If parameters not required, directly calls cmdUtil to send command
else:
launch_string = (
f'../cmdUtil/cmdUtil --host=\"{address}\" '
f'{ROOTDIR}/../cmdUtil/cmdUtil --host=\"{address}\" '
f'--port={pagePort} --pktid={pagePktId} '
f'--endian={pageEndian} --cmdcode={cmdCodes[idx]}')

Expand Down Expand Up @@ -169,7 +171,7 @@ def usage():
#
# Reads commands from command definition file
#
pickle_file = f'CommandFiles/{pageDefFile}'
pickle_file = f'{ROOTDIR}/CommandFiles/{pageDefFile}'
with open(pickle_file, 'rb') as pickle_obj:
cmdDesc, cmdCodes, param_files = pickle.load(pickle_obj)

Expand Down
6 changes: 4 additions & 2 deletions Subsystems/tlmGUI/GenericTelemetry.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import csv
import getopt
import sys
from pathlib import Path
from struct import unpack

import zmq
Expand All @@ -31,6 +32,7 @@

from GenericTelemetryDialog import Ui_GenericTelemetryDialog

ROOTDIR = Path(sys.argv[0]).resolve().parent

class SubsystemTelemetry(QDialog, Ui_GenericTelemetryDialog):

Expand Down Expand Up @@ -139,7 +141,7 @@ def usage():
pageTitle = "Telemetry Page"
udpPort = 10000
appId = 999
tlmDefFile = "telemetry_def.txt"
tlmDefFile = f"{ROOTDIR}/telemetry_def.txt"
endian = "L"
subscription = ""

Expand Down Expand Up @@ -194,7 +196,7 @@ def usage():
tlmItemEnum = [[]] * 40
i = 0

with open(tlmDefFile) as tlmfile:
with open(f"{ROOTDIR}/{tlmDefFile}") as tlmfile:
reader = csv.reader(tlmfile, skipinitialspace=True)
for row in reader:
if row[0][0] != '#':
Expand Down
54 changes: 28 additions & 26 deletions Subsystems/tlmGUI/TelemetrySystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import shlex
import subprocess
import sys
from pathlib import Path
from struct import unpack

import zmq
Expand All @@ -32,6 +33,7 @@

from TelemetrySystemDialog import Ui_TelemetrySystemDialog

ROOTDIR = Path(sys.argv[0]).resolve().parent

class TelemetrySystem(QDialog, Ui_TelemetrySystemDialog):

Expand Down Expand Up @@ -79,7 +81,7 @@ def ProcessButtonGeneric(self, idx):
if tlmPageIsValid[idx]:
# need to extract data from fields, then start page with right params
launch_string = (
f'python3 {tlmClass[idx]} '
f'python3 {ROOTDIR}/{tlmClass[idx]} '
f'--title=\"{tlmPageDesc[idx]}\" --appid={hex(tlmPageAppid[idx])} '
f'--port={tlmPagePort[idx]} --file={tlmPageDefFile[idx]} '
f'--endian={endian} --sub={tempSub}')
Expand All @@ -102,22 +104,22 @@ def processPendingDatagrams(self, datagram):
#
# convert a string of binary bytes to ascii hex
#
def strToHex(aString):
hexStr = ""
for x in aString:
hexStr += f'{ord(x):02X}'
return hexStr

#
# Dump the telemetry packet
#
def dumpPacket(packetData):
appIdString = f"{ord(packetData[0]):02X}"
appIdString = f"{appIdString}{ord(packetData[1]):02X}"
appId = (ord(packetData[0]) << 8) + (ord(packetData[1]))
print("\nPacket: App ID =", hex(appId))
print("\nPacket Data:", strToHex(packetData))
print("\n-----------------------------------------------")
# def strToHex(aString):
# hexStr = ""
# for x in aString:
# hexStr += f'{ord(x):02X}'
# return hexStr

# #
# # Dump the telemetry packet
# #
# def dumpPacket(packetData):
# appIdString = f"{ord(packetData[0]):02X}"
# appIdString = f"{appIdString}{ord(packetData[1]):02X}"
# appId = (ord(packetData[0]) << 8) + (ord(packetData[1]))
# print("\nPacket: App ID =", hex(appId))
# print("\nPacket Data:", strToHex(packetData))
# print("\n-----------------------------------------------")

#
# Show number of packets received
Expand All @@ -132,24 +134,24 @@ def dumpPacket(packetData):

# Uncomment the next two lines to debug
# print "Packet ID = " , hex(streamId)
# dumpPacket(datagram)
for i in range(21):
if streamId == tlmPageAppid[i]:
# self.dumpPacket(datagram)
for l in range(21):
if streamId == tlmPageAppid[l]:
# send_host = "127.0.0.1"
# send_port = tlmPagePort[i]
# sendSocket = socket(AF_INET,SOCK_DGRAM)
# sendSocket.sendto(datagram, (send_host,send_port))

tlmPageCount[i] += 1
tlmPageCount[l] += 1
#
# I wish I knew a better way to update the count field in the GUI
# Maybe store a pointer to the field in the gui
#
if i < 15:
countBrowseri = getattr(self, f"countBrowser_{i}")
if l < 15:
countBrowseri = getattr(self, f"countBrowser_{l}")
else:
countBrowseri = getattr(self, f"countBrowser_{i+1}")
countBrowseri.setText(str(tlmPageCount[i]))
countBrowseri = getattr(self, f"countBrowser_{l+1}")
countBrowseri.setText(str(tlmPageCount[l]))


# Subscribes and receives zeroMQ messages
Expand Down Expand Up @@ -188,7 +190,7 @@ def run(self):
#
# Set defaults for the arguments
#
tlmDefFile = "./Subsystems/tlmGUI/telemetry-pages.txt"
tlmDefFile = f"{ROOTDIR}/telemetry-pages.txt"
endian = "L"
subscription = ""

Expand Down

0 comments on commit dd912cd

Please sign in to comment.