From ac9251f049af3d9c0ad457728a58374a558bae8f Mon Sep 17 00:00:00 2001 From: Leor Bleier Date: Thu, 7 May 2020 17:58:06 -0400 Subject: [PATCH] (WIP) Fixes #72, upgrade PyQt4 to PyQt5 Implement other fixes as needed --- RoutingService.py | 4 +-- Subsystems/tlmGUI/EventMessage.py | 28 +++++++++-------- Subsystems/tlmGUI/EventMessageDialog.py | 25 ++++++++-------- Subsystems/tlmGUI/EventMessageDialog.ui | 33 ++++++++++++++++----- Subsystems/tlmGUI/GenericTelemetry.py | 23 +++++++------- Subsystems/tlmGUI/GenericTelemetryDialog.py | 9 +++--- Subsystems/tlmGUI/GenericTelemetryDialog.ui | 25 +++++++++++++--- Subsystems/tlmGUI/TelemetrySystem.py | 23 +++++++------- Subsystems/tlmGUI/TelemetrySystemDialog.py | 11 +++---- Subsystems/tlmGUI/TelemetrySystemDialog.ui | 27 +++++++++++++---- 10 files changed, 134 insertions(+), 74 deletions(-) diff --git a/RoutingService.py b/RoutingService.py index 061e3cd..0ea2d0b 100644 --- a/RoutingService.py +++ b/RoutingService.py @@ -119,10 +119,10 @@ def forwardMessage(self, datagram, hostName): @staticmethod def getPktId(datagram): # Read the telemetry header - streamId, _, _ = unpack(">HHH", datagram[:6]) + streamId = unpack(">H", datagram[:2]) # Uncomment the next line to debug # print("Packet ID =", hex(streamId)) - return hex(streamId) + return hex(streamId[0]) # Close ZMQ vars def stop(self): diff --git a/Subsystems/tlmGUI/EventMessage.py b/Subsystems/tlmGUI/EventMessage.py index 0e79083..f096e36 100644 --- a/Subsystems/tlmGUI/EventMessage.py +++ b/Subsystems/tlmGUI/EventMessage.py @@ -62,6 +62,8 @@ import getopt import sys +from struct import unpack +from pathlib import Path import zmq from PyQt5.QtCore import QThread, pyqtSignal @@ -69,14 +71,14 @@ from EventMessageDialog import Ui_EventMessageDialog +ROOTDIR = Path(sys.argv[0]).resolve().parent + class EventMessageTelemetry(QDialog, Ui_EventMessageDialog): def __init__(self, aid): super().__init__() self.setupUi(self) self.appId = aid - self.pktCount = 0 - self.btnClose.clicked.connect(self.closeWin) def initEMTlmReceiver(self, subscr): self.setWindowTitle(f'{pageTitle} for: {subscr}') @@ -87,15 +89,13 @@ def initEMTlmReceiver(self, subscr): # This method processes packets. Called when the TelemetryReceiver receives a message/packet def processPendingDatagrams(self, datagram): - - self.pktCount += 1 - # Packet Header # uint16 StreamId; 0 # uint16 Sequence; 2 # uint16 Length; 4 - # PktSequence = unpack("H", datagram[2:4]) + seqCount = packetSeq[0] & 0x3FFF + self.sequenceCount.setValue(seqCount) # # Get App Name, Event ID, Type and Event Text! @@ -123,9 +123,13 @@ def processPendingDatagrams(self, datagram): eventString = f"EVENT --> {appName} - {EventType} Event ID: {EventID}: {eventText}" self.eventOutput.appendPlainText(eventString) - def closeWin(self): - self.thread.quit() - self.close() + ## Reimplements closeEvent + ## to properly quit the thread + ## and close the window + def closeEvent(self, event): + self.thread.runs = False + self.thread.wait(2000) + super().closeEvent(event) # Subscribes and receives zeroMQ messages @@ -136,6 +140,7 @@ class EMTlmReceiver(QThread): def __init__(self, subscr, aid): super().__init__() self.appId = aid + self.runs = True # Init zeroMQ self.context = zmq.Context() @@ -145,7 +150,7 @@ def __init__(self, subscr, aid): self.subscriber.setsockopt_string(zmq.SUBSCRIBE, subscriptionString) def run(self): - while True: + while self.runs: # Read envelope with address address, datagram = self.subscriber.recv_multipart() # Ignore if not an event message @@ -164,7 +169,6 @@ def usage(): if __name__ == '__main__': - # # Set defaults for the arguments # diff --git a/Subsystems/tlmGUI/EventMessageDialog.py b/Subsystems/tlmGUI/EventMessageDialog.py index b7d2a8b..8c22a66 100644 --- a/Subsystems/tlmGUI/EventMessageDialog.py +++ b/Subsystems/tlmGUI/EventMessageDialog.py @@ -23,16 +23,16 @@ def setupUi(self, EventMessageDialog): sizePolicy.setHeightForWidth(self.label_2.sizePolicy().hasHeightForWidth()) self.label_2.setSizePolicy(sizePolicy) self.label_2.setMinimumSize(QtCore.QSize(91, 17)) - self.label_2.setMaximumSize(QtCore.QSize(120, 17)) + self.label_2.setMaximumSize(QtCore.QSize(135, 29)) self.label_2.setAlignment(QtCore.Qt.AlignRight|QtCore.Qt.AlignTrailing|QtCore.Qt.AlignVCenter) self.label_2.setObjectName("label_2") self.horizontalLayout.addWidget(self.label_2) - self.packetCount = QtWidgets.QSpinBox(EventMessageDialog) - self.packetCount.setReadOnly(True) - self.packetCount.setButtonSymbols(QtWidgets.QAbstractSpinBox.NoButtons) - self.packetCount.setMaximum(16384) - self.packetCount.setObjectName("packetCount") - self.horizontalLayout.addWidget(self.packetCount) + self.sequenceCount = QtWidgets.QSpinBox(EventMessageDialog) + self.sequenceCount.setReadOnly(True) + self.sequenceCount.setButtonSymbols(QtWidgets.QAbstractSpinBox.NoButtons) + self.sequenceCount.setMaximum(16384) + self.sequenceCount.setObjectName("sequenceCount") + self.horizontalLayout.addWidget(self.sequenceCount) spacerItem = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum) self.horizontalLayout.addItem(spacerItem) self.line = QtWidgets.QFrame(EventMessageDialog) @@ -52,9 +52,10 @@ def setupUi(self, EventMessageDialog): self.horizontalLayout.addItem(spacerItem1) spacerItem2 = QtWidgets.QSpacerItem(81, 31, QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Minimum) self.horizontalLayout.addItem(spacerItem2) - self.btnClose = QtWidgets.QPushButton(EventMessageDialog) - self.btnClose.setObjectName("btnClose") - self.horizontalLayout.addWidget(self.btnClose) + self.buttonBox = QtWidgets.QDialogButtonBox(EventMessageDialog) + self.buttonBox.setStandardButtons(QtWidgets.QDialogButtonBox.Close) + self.buttonBox.setObjectName("buttonBox") + self.horizontalLayout.addWidget(self.buttonBox) self.verticalLayout.addLayout(self.horizontalLayout) self.eventOutput = QtWidgets.QPlainTextEdit(EventMessageDialog) self.eventOutput.setReadOnly(True) @@ -62,12 +63,12 @@ def setupUi(self, EventMessageDialog): self.verticalLayout.addWidget(self.eventOutput) self.retranslateUi(EventMessageDialog) + self.buttonBox.clicked['QAbstractButton*'].connect(EventMessageDialog.close) QtCore.QMetaObject.connectSlotsByName(EventMessageDialog) def retranslateUi(self, EventMessageDialog): _translate = QtCore.QCoreApplication.translate EventMessageDialog.setWindowTitle(_translate("EventMessageDialog", "Event Messages")) - self.label_2.setText(_translate("EventMessageDialog", "Packet Count")) + self.label_2.setText(_translate("EventMessageDialog", "Sequence Count")) self.label.setText(_translate("EventMessageDialog", "Events")) - self.btnClose.setText(_translate("EventMessageDialog", "Close")) diff --git a/Subsystems/tlmGUI/EventMessageDialog.ui b/Subsystems/tlmGUI/EventMessageDialog.ui index 8acfbe5..425576c 100644 --- a/Subsystems/tlmGUI/EventMessageDialog.ui +++ b/Subsystems/tlmGUI/EventMessageDialog.ui @@ -32,12 +32,12 @@ - 120 - 17 + 135 + 29 - Packet Count + Sequence Count Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter @@ -45,7 +45,7 @@ - + true @@ -121,9 +121,9 @@ - - - Close + + + QDialogButtonBox::Close @@ -139,5 +139,22 @@ - + + + buttonBox + clicked(QAbstractButton*) + EventMessageDialog + close() + + + 540 + 25 + + + 295 + 138 + + + + diff --git a/Subsystems/tlmGUI/GenericTelemetry.py b/Subsystems/tlmGUI/GenericTelemetry.py index 0dca39a..4be90b9 100644 --- a/Subsystems/tlmGUI/GenericTelemetry.py +++ b/Subsystems/tlmGUI/GenericTelemetry.py @@ -43,7 +43,6 @@ class SubsystemTelemetry(QDialog, Ui_GenericTelemetryDialog): def __init__(self): super().__init__() self.setupUi(self) - self.btnClose.clicked.connect(self.closeWin) # # This method Decodes a telemetry item from the packet and displays it @@ -85,7 +84,7 @@ def processPendingDatagrams(self, datagram): # Show sequence number # packetSeq = unpack(">H", datagram[2:4]) - seqCount = packetSeq[0] & 0x3FF ## sequence count mask + seqCount = packetSeq[0] & 0x3FFF ## sequence count mask self.sequenceCount.setValue(seqCount) # @@ -96,9 +95,13 @@ def processPendingDatagrams(self, datagram): itemValuele = getattr(self, f"itemValueLineEdit_{k+1}") self.displayTelemetryItem(datagram, k, itemLabelpte, itemValuele) - def closeWin(self): - self.thread.quit() - self.close() + ## Reimplements closeEvent + ## to properly quit the thread + ## and close the window + def closeEvent(self, event): + self.thread.runs = False + self.thread.wait(2000) + super().closeEvent(event) # Subscribes and receives zeroMQ messages @@ -108,6 +111,8 @@ class GTTlmReceiver(QThread): def __init__(self, subscr): super().__init__() + self.runs = True + # Init zeroMQ context = zmq.Context() self.subscriber = context.socket(zmq.SUB) @@ -117,7 +122,7 @@ def __init__(self, subscr): self.subscriber.setsockopt_string(zmq.SUBSCRIBE, mySubscription) def run(self): - while True: + while self.runs: # Read envelope with address address, datagram = self.subscriber.recv_multipart() # Send signal with received packet to front-end/GUI @@ -138,7 +143,6 @@ def usage(): # Main # if __name__ == '__main__': - # # Set defaults for the arguments # @@ -212,15 +216,10 @@ def usage(): tlmItemFormat.append(row[2] + row[3]) else: tlmItemFormat.append(py_endian + row[3]) - tlmItemDisplayType.append(row[4]) if row[4] == 'Enm': for m in range(5, 9): tlmItemEnum[i].append(row[m]) - # tlmItemEnum[i].append(row[5]) - # tlmItemEnum[i].append(row[6]) - # tlmItemEnum[i].append(row[7]) - # tlmItemEnum[i].append(row[8]) i += 1 # diff --git a/Subsystems/tlmGUI/GenericTelemetryDialog.py b/Subsystems/tlmGUI/GenericTelemetryDialog.py index 9c2faa0..85e1944 100644 --- a/Subsystems/tlmGUI/GenericTelemetryDialog.py +++ b/Subsystems/tlmGUI/GenericTelemetryDialog.py @@ -71,9 +71,10 @@ def setupUi(self, GenericTelemetryDialog): self.horizontalLayout.addLayout(self.verticalLayout_3) spacerItem2 = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum) self.horizontalLayout.addItem(spacerItem2) - self.btnClose = QtWidgets.QPushButton(self.layoutWidget) - self.btnClose.setObjectName("btnClose") - self.horizontalLayout.addWidget(self.btnClose) + self.buttonBox = QtWidgets.QDialogButtonBox(self.layoutWidget) + self.buttonBox.setStandardButtons(QtWidgets.QDialogButtonBox.Close) + self.buttonBox.setObjectName("buttonBox") + self.horizontalLayout.addWidget(self.buttonBox) self.label_6 = QtWidgets.QLabel(GenericTelemetryDialog) self.label_6.setGeometry(QtCore.QRect(29, 750, 711, 19)) font = QtGui.QFont() @@ -843,6 +844,7 @@ def setupUi(self, GenericTelemetryDialog): self.horizontalLayout_5.addWidget(self.label_9) self.retranslateUi(GenericTelemetryDialog) + self.buttonBox.clicked['QAbstractButton*'].connect(GenericTelemetryDialog.close) QtCore.QMetaObject.connectSlotsByName(GenericTelemetryDialog) def retranslateUi(self, GenericTelemetryDialog): @@ -851,7 +853,6 @@ def retranslateUi(self, GenericTelemetryDialog): self.subSystemTelemetryPageLabel.setText(_translate("GenericTelemetryDialog", "Subsystem Telemetry Page")) self.packetIdLabel.setText(_translate("GenericTelemetryDialog", "Packet ID")) self.label_5.setText(_translate("GenericTelemetryDialog", "Sequence Count")) - self.btnClose.setText(_translate("GenericTelemetryDialog", "Close")) self.label_6.setText(_translate("GenericTelemetryDialog", "*No packets? Remember to select the IP address of your spacecraft in the Main Window.")) self.label.setText(_translate("GenericTelemetryDialog", "Telemetry Point Label")) self.label_8.setText(_translate("GenericTelemetryDialog", "Telemetry Point Value")) diff --git a/Subsystems/tlmGUI/GenericTelemetryDialog.ui b/Subsystems/tlmGUI/GenericTelemetryDialog.ui index 012a5e0..fa9ecc6 100644 --- a/Subsystems/tlmGUI/GenericTelemetryDialog.ui +++ b/Subsystems/tlmGUI/GenericTelemetryDialog.ui @@ -168,9 +168,9 @@ - - - Close + + + QDialogButtonBox::Close @@ -2125,5 +2125,22 @@ - + + + buttonBox + clicked(QAbstractButton*) + GenericTelemetryDialog + close() + + + 99 + 46 + + + 522 + 407 + + + + diff --git a/Subsystems/tlmGUI/TelemetrySystem.py b/Subsystems/tlmGUI/TelemetrySystem.py index f36bc9b..4b5678b 100644 --- a/Subsystems/tlmGUI/TelemetrySystem.py +++ b/Subsystems/tlmGUI/TelemetrySystem.py @@ -51,8 +51,6 @@ def __init__(self): self.pktCount = 0 self.subscription = None - self.btnClose.clicked.connect(self.closeWin) - for k in range(21): pushButton = getattr(self, f"pushButton_{k}") pushButton.clicked.connect( @@ -116,13 +114,13 @@ def processPendingDatagrams(self, datagram): # # Decode the packet and forward it to the correct port (if there is one) # - streamId, _, _ = unpack(">3H", datagram[:6]) + streamId = unpack(">H", datagram[:2]) # Uncomment the next two lines to debug - # print "Packet ID = " , hex(streamId) + # print("Packet ID =", hex(streamId[0])) # self.dumpPacket(datagram) for l in range(21): - if streamId == tlmPageAppid[l]: + if streamId[0] == tlmPageAppid[l]: # send_host = "127.0.0.1" # send_port = tlmPagePort[l] # sendSocket.sendto(datagram, (send_host, send_port)) @@ -138,9 +136,13 @@ def processPendingDatagrams(self, datagram): countSpinBox_l = getattr(self, f"countSpinBox_{l+1}") countSpinBox_l.setValue(tlmPageCount[l]) - def closeWin(self): - self.thread.quit() - self.close() + ## Reimplements closeEvent + ## to properly quit the thread + ## and close the window + def closeEvent(self, event): + self.thread.runs = False + self.thread.wait(2000) + super().closeEvent(event) # Subscribes and receives zeroMQ messages @@ -150,6 +152,8 @@ class TSTlmReceiver(QThread): def __init__(self, subscr): super().__init__() + self.runs = True + # Init zeroMQ context = zmq.Context() self.subscriber = context.socket(zmq.SUB) @@ -157,7 +161,7 @@ def __init__(self, subscr): self.subscriber.setsockopt_string(zmq.SUBSCRIBE, subscr) def run(self): - while True: + while self.runs: # Receive and read envelope with address address, datagram = self.subscriber.recv_multipart() # Send signal with received packet to front-end/GUI @@ -168,7 +172,6 @@ def run(self): # Main # if __name__ == '__main__': - # # Init the QT application and the telemetry dialog class # diff --git a/Subsystems/tlmGUI/TelemetrySystemDialog.py b/Subsystems/tlmGUI/TelemetrySystemDialog.py index 10aed45..379b38b 100644 --- a/Subsystems/tlmGUI/TelemetrySystemDialog.py +++ b/Subsystems/tlmGUI/TelemetrySystemDialog.py @@ -50,9 +50,10 @@ def setupUi(self, TelemetrySystemDialog): self.horizontalLayout_3.addLayout(self.horizontalLayout_2) spacerItem6 = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum) self.horizontalLayout_3.addItem(spacerItem6) - self.btnClose = QtWidgets.QPushButton(TelemetrySystemDialog) - self.btnClose.setObjectName("btnClose") - self.horizontalLayout_3.addWidget(self.btnClose) + self.buttonBox = QtWidgets.QDialogButtonBox(TelemetrySystemDialog) + self.buttonBox.setStandardButtons(QtWidgets.QDialogButtonBox.Close) + self.buttonBox.setObjectName("buttonBox") + self.horizontalLayout_3.addWidget(self.buttonBox) self.verticalLayout.addLayout(self.horizontalLayout_3) self.horizontalLayout_4 = QtWidgets.QHBoxLayout() self.horizontalLayout_4.setObjectName("horizontalLayout_4") @@ -71,7 +72,7 @@ def setupUi(self, TelemetrySystemDialog): self.scrollArea.setWidgetResizable(True) self.scrollArea.setObjectName("scrollArea") self.scrollAreaWidgetContents = QtWidgets.QWidget() - self.scrollAreaWidgetContents.setGeometry(QtCore.QRect(0, -216, 591, 1000)) + self.scrollAreaWidgetContents.setGeometry(QtCore.QRect(0, 0, 591, 1000)) self.scrollAreaWidgetContents.setMinimumSize(QtCore.QSize(0, 1000)) self.scrollAreaWidgetContents.setObjectName("scrollAreaWidgetContents") self.layoutWidget = QtWidgets.QWidget(self.scrollAreaWidgetContents) @@ -875,6 +876,7 @@ def setupUi(self, TelemetrySystemDialog): self.verticalLayout.addWidget(self.scrollArea) self.retranslateUi(TelemetrySystemDialog) + self.buttonBox.clicked['QAbstractButton*'].connect(TelemetrySystemDialog.close) QtCore.QMetaObject.connectSlotsByName(TelemetrySystemDialog) def retranslateUi(self, TelemetrySystemDialog): @@ -882,7 +884,6 @@ def retranslateUi(self, TelemetrySystemDialog): TelemetrySystemDialog.setWindowTitle(_translate("TelemetrySystemDialog", "Dialog")) self.label.setText(_translate("TelemetrySystemDialog", "cFE/CFS Subsystem Telemetry")) self.label_6.setText(_translate("TelemetrySystemDialog", "Packets Received")) - self.btnClose.setText(_translate("TelemetrySystemDialog", "Close")) self.label_2.setText(_translate("TelemetrySystemDialog", "Available Pages")) self.label_3.setText(_translate("TelemetrySystemDialog", "Subsystem/Page")) self.label_4.setText(_translate("TelemetrySystemDialog", "Packet ID")) diff --git a/Subsystems/tlmGUI/TelemetrySystemDialog.ui b/Subsystems/tlmGUI/TelemetrySystemDialog.ui index 7c4b728..50258c8 100644 --- a/Subsystems/tlmGUI/TelemetrySystemDialog.ui +++ b/Subsystems/tlmGUI/TelemetrySystemDialog.ui @@ -152,9 +152,9 @@ - - - Close + + + QDialogButtonBox::Close @@ -221,7 +221,7 @@ 0 - -216 + 0 591 1000 @@ -2277,5 +2277,22 @@ - + + + buttonBox + clicked(QAbstractButton*) + TelemetrySystemDialog + close() + + + 574 + 57 + + + 312 + 453 + + + +