Skip to content

Commit

Permalink
(WIP) Fixes nasa#72, upgrade PyQt4 to PyQt5
Browse files Browse the repository at this point in the history
Implement other fixes as needed
  • Loading branch information
lbleier-GSFC committed May 7, 2020
1 parent be45b09 commit ac9251f
Show file tree
Hide file tree
Showing 10 changed files with 134 additions and 74 deletions.
4 changes: 2 additions & 2 deletions RoutingService.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
28 changes: 16 additions & 12 deletions Subsystems/tlmGUI/EventMessage.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,21 +62,23 @@

import getopt
import sys
from struct import unpack
from pathlib import Path

import zmq
from PyQt5.QtCore import QThread, pyqtSignal
from PyQt5.QtWidgets import QApplication, QDialog

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}')
Expand All @@ -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])
self.packetCount.setValue(self.pktCount)
packetSeq = unpack(">H", datagram[2:4])
seqCount = packetSeq[0] & 0x3FFF
self.sequenceCount.setValue(seqCount)

#
# Get App Name, Event ID, Type and Event Text!
Expand Down Expand Up @@ -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
Expand All @@ -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()
Expand All @@ -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
Expand All @@ -164,7 +169,6 @@ def usage():


if __name__ == '__main__':

#
# Set defaults for the arguments
#
Expand Down
25 changes: 13 additions & 12 deletions Subsystems/tlmGUI/EventMessageDialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -52,22 +52,23 @@ 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)
self.eventOutput.setObjectName("eventOutput")
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"))

33 changes: 25 additions & 8 deletions Subsystems/tlmGUI/EventMessageDialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,20 @@
</property>
<property name="maximumSize">
<size>
<width>120</width>
<height>17</height>
<width>135</width>
<height>29</height>
</size>
</property>
<property name="text">
<string>Packet Count</string>
<string>Sequence Count</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="packetCount">
<widget class="QSpinBox" name="sequenceCount">
<property name="readOnly">
<bool>true</bool>
</property>
Expand Down Expand Up @@ -121,9 +121,9 @@
</spacer>
</item>
<item>
<widget class="QPushButton" name="btnClose">
<property name="text">
<string>Close</string>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="standardButtons">
<set>QDialogButtonBox::Close</set>
</property>
</widget>
</item>
Expand All @@ -139,5 +139,22 @@
</layout>
</widget>
<resources/>
<connections/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>clicked(QAbstractButton*)</signal>
<receiver>EventMessageDialog</receiver>
<slot>close()</slot>
<hints>
<hint type="sourcelabel">
<x>540</x>
<y>25</y>
</hint>
<hint type="destinationlabel">
<x>295</x>
<y>138</y>
</hint>
</hints>
</connection>
</connections>
</ui>
23 changes: 11 additions & 12 deletions Subsystems/tlmGUI/GenericTelemetry.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)

#
Expand All @@ -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
Expand All @@ -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)
Expand All @@ -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
Expand All @@ -138,7 +143,6 @@ def usage():
# Main
#
if __name__ == '__main__':

#
# Set defaults for the arguments
#
Expand Down Expand Up @@ -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

#
Expand Down
9 changes: 5 additions & 4 deletions Subsystems/tlmGUI/GenericTelemetryDialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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):
Expand All @@ -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"))
Expand Down
25 changes: 21 additions & 4 deletions Subsystems/tlmGUI/GenericTelemetryDialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -168,9 +168,9 @@
</spacer>
</item>
<item>
<widget class="QPushButton" name="btnClose">
<property name="text">
<string>Close</string>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="standardButtons">
<set>QDialogButtonBox::Close</set>
</property>
</widget>
</item>
Expand Down Expand Up @@ -2125,5 +2125,22 @@
</widget>
</widget>
<resources/>
<connections/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>clicked(QAbstractButton*)</signal>
<receiver>GenericTelemetryDialog</receiver>
<slot>close()</slot>
<hints>
<hint type="sourcelabel">
<x>99</x>
<y>46</y>
</hint>
<hint type="destinationlabel">
<x>522</x>
<y>407</y>
</hint>
</hints>
</connection>
</connections>
</ui>
Loading

0 comments on commit ac9251f

Please sign in to comment.