diff --git a/GroundSystem.py b/GroundSystem.py index e21ae8c..d76c11e 100644 --- a/GroundSystem.py +++ b/GroundSystem.py @@ -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 @@ -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) @@ -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): diff --git a/Subsystems/cmdGui/CommandSystem.py b/Subsystems/cmdGui/CommandSystem.py index c18803e..33802b5 100644 --- a/Subsystems/cmdGui/CommandSystem.py +++ b/Subsystems/cmdGui/CommandSystem.py @@ -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): @@ -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]}') @@ -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}\" ' @@ -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]}') @@ -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: @@ -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] != '#': diff --git a/Subsystems/cmdGui/Parameter.py b/Subsystems/cmdGui/Parameter.py index e4242c6..17c877d 100644 --- a/Subsystems/cmdGui/Parameter.py +++ b/Subsystems/cmdGui/Parameter.py @@ -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): @@ -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 @@ -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) diff --git a/Subsystems/cmdGui/UdpCommands.py b/Subsystems/cmdGui/UdpCommands.py index a2ce43b..4192e70 100644 --- a/Subsystems/cmdGui/UdpCommands.py +++ b/Subsystems/cmdGui/UdpCommands.py @@ -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): @@ -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 @@ -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} ' @@ -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]}') @@ -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) diff --git a/Subsystems/tlmGUI/GenericTelemetry.py b/Subsystems/tlmGUI/GenericTelemetry.py index 520cf85..ee8340b 100644 --- a/Subsystems/tlmGUI/GenericTelemetry.py +++ b/Subsystems/tlmGUI/GenericTelemetry.py @@ -23,6 +23,7 @@ import csv import getopt import sys +from pathlib import Path from struct import unpack import zmq @@ -31,6 +32,7 @@ from GenericTelemetryDialog import Ui_GenericTelemetryDialog +ROOTDIR = Path(sys.argv[0]).resolve().parent class SubsystemTelemetry(QDialog, Ui_GenericTelemetryDialog): @@ -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 = "" @@ -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] != '#': diff --git a/Subsystems/tlmGUI/TelemetrySystem.py b/Subsystems/tlmGUI/TelemetrySystem.py index b0c069e..b6baa65 100644 --- a/Subsystems/tlmGUI/TelemetrySystem.py +++ b/Subsystems/tlmGUI/TelemetrySystem.py @@ -24,6 +24,7 @@ import shlex import subprocess import sys +from pathlib import Path from struct import unpack import zmq @@ -32,6 +33,7 @@ from TelemetrySystemDialog import Ui_TelemetrySystemDialog +ROOTDIR = Path(sys.argv[0]).resolve().parent class TelemetrySystem(QDialog, Ui_TelemetrySystemDialog): @@ -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}') @@ -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 @@ -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 @@ -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 = ""