Skip to content

Commit

Permalink
WIP Fix nasa#72 - Upgrade to PyQt5 and fix/update/clean as needed
Browse files Browse the repository at this point in the history
  • Loading branch information
lbleier-GSFC committed Apr 21, 2020
1 parent 595a54e commit ac26d55
Show file tree
Hide file tree
Showing 3 changed files with 451 additions and 482 deletions.
113 changes: 57 additions & 56 deletions Subsystems/tlmGUI/EventMessage.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@
#!/usr/bin/env python
#
# EVS Events page
#
#
# The EVS Event Message has the following format
#
#
#
# ES HK format:
#
# Packet Header
# uint16 StreamId; 0
# uint16 StreamId; 0
# uint16 Sequence; 2
# uint16 Length; 4
# uint16 Length; 4

# Tlm Secondary Header
# uint32 seconds 6
Expand All @@ -40,126 +40,130 @@
# Event format:
#
# Packet Header
# uint16 StreamId;
# uint16 Sequence;
# uint16 Length;
# uint16 StreamId;
# uint16 Sequence;
# uint16 Length;

# Tlm Secondary Header
# uint32 seconds
# uint16 subseconds

# Packet ID
# char AppName[20]
# uint16 EventID;
# uint16 EventType;
# uint32 SpacecraftID;
# char AppName[20]
# uint16 EventID;
# uint16 EventType;
# uint32 SpacecraftID;
# uint32 ProcessorID;

# Message
# char Message[122];
# uint8 Spare1;
# uint8 Spare2;
# char Message[122];
# uint8 Spare1;
# uint8 Spare2;

import sys
import getopt
import zmq

from PyQt4 import QtGui, QtCore
from PyQt5.QtWidgets import QDialog, QApplication
from PyQt5.QtCore import QThread, pyqtSignal
from EventMessageDialog import Ui_EventMessageDialog
from struct import *
# from struct import *


class EventMessageTelemetry(QtGui.QDialog):
class EventMessageTelemetry(QDialog, Ui_EventMessageDialog):

pktCount = 0

def __init__(self, appId):
QtGui.QDialog.__init__(self)
super().__init__()
self.appId = appId
self.ui = Ui_EventMessageDialog()
self.ui.setupUi(self)

self.setupUi(self)

def initTlmReceiver(self, subscription):
self.setWindowTitle(pageTitle + ' for: ' + subscription)
self.setWindowTitle(f'{pageTitle} for: {subscription}')
self.thread = TlmReceiver(self, subscription, self.appId)
self.connect(self.thread, self.thread.signalTlmDatagram, self.processPendingDatagrams)
self.connect(self.thread, self.thread.signalTlmDatagram,
self.processPendingDatagrams)
self.thread.start()

# 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 StreamId; 0
# uint16 Sequence; 2
# uint16 Length; 4
# uint16 Length; 4
# PktSequence = unpack("<H",datagram[2:4])
self.ui.sequenceCount.setText(str(self.pktCount))

#
# Not accounting for endian right now!
#
appName = datagram[12:32].decode('utf-8','ignore')
eventText = datagram[44:].decode('utf-8','ignore')
appName = datagram[12:32].decode('utf-8', 'ignore')
eventText = datagram[44:].decode('utf-8', 'ignore')
appName = appName.split("\0")[0]
eventText = eventText.split("\0")[0]
eventString = "EVENT ---> "+ appName + " : " + eventText
eventString = "EVENT ---> " + appName + " : " + eventText
self.ui.eventOutput.append(eventString)


# Subscribes and receives zeroMQ messages
class TlmReceiver(QtCore.QThread):

def __init__(self, mainWindow, subscription, appId):
QtCore.QThread.__init__(self)
self.appId = appId
class TlmReceiver(QThread):
# Setup signal to communicate with front-end GUI
signalTlmDatagram = pyqtSignal(object, name="TlmDatagram")

# Setup signal to communicate with front-end GUI
self.signalTlmDatagram = QtCore.SIGNAL("TlmDatagram")
def __init__(self, subscription, appId):
super().__init__(self)
self.appId = appId

# Init zeroMQ
self.context = zmq.Context()
self.context = zmq.Context()
self.subscriber = self.context.socket(zmq.SUB)
self.subscriber.connect("ipc:///tmp/GroundSystem")
subscriptionString = str(subscription) + ".Spacecraft1.TelemetryPackets." + str(appId)
subscriptionString = f"{str(subscription)}.Spacecraft1.TelemetryPackets.{str(appId)}"
self.subscriber.setsockopt_string(zmq.SUBSCRIBE, subscriptionString)

def run(self):
while True:
# Read envelope with address
[address, datagram] = self.subscriber.recv_multipart()
address, datagram = self.subscriber.recv_multipart()

# Ignore if not an event message
if self.appId not in str(address): continue
self.emit(self.signalTlmDatagram, datagram)
if self.appId in str(address):
self.signalTlmDatagram.emit(datagram)


#
# Display usage
#
def usage():
print ("Must specify --title=<page name> --port=<udp_port> --appid=<packet_app_id(hex)> --endian=<endian(L|B) --file=<tlm_def_file>")
print (" example: --title=Executive Services --port=10800 --appid=800 --file=cfe-es-hk-table.txt --endian=L")
print (" (quotes are not on the title string in this example)")
print(("Must specify --title=\"<page name>\" --port=<udp_port> "
"--appid=<packet_app_id(hex)> --endian=<endian(L|B) "
"--file=<tlm_def_file>\n\nexample: --title=\"Executive Services\" "
"--port=10800 --appid=800 --file=cfe-es-hk-table.txt --endian=L"))


if __name__ == '__main__':

if __name__ == '__main__':

#
# Set defaults for the arguments
#
pageTitle = "Event Messages"
udpPort = 10000
udpPort = 10000
appId = 999
tlmDefFile = "not-needed.txt"
endian = "L"
subscription = ""

#
# process cmd line args
# process cmd line args
#
try:
opts, args = getopt.getopt(sys.argv[1:], "htpafl", ["help", "title=", "port=", "appid=","file=", "endian=", "sub="])
opts, args = getopt.getopt(
sys.argv[1:], "htpafl",
["help", "title=", "port=", "appid=", "file=", "endian=", "sub="])
except getopt.GetoptError:
usage()
sys.exit(2)
Expand Down Expand Up @@ -188,17 +192,14 @@ def usage():
if len(arr) < 3:
subscription = 'GroundSystem'

print ('Event Messages Page started. Subscribed to ' + subscription)
print('Event Messages Page started. Subscribed to', subscription)

if endian == 'L':
py_endian = '<'
else:
py_endian = '>'
py_endian = '<' if endian == 'L' else '>'

#
# Init the QT application and the Event Message class
#
app = QtGui.QApplication(sys.argv)
app = QApplication(sys.argv)
Telem = EventMessageTelemetry(appId)

# Display the page
Expand Down
Loading

0 comments on commit ac26d55

Please sign in to comment.