Skip to content

Commit

Permalink
Fixes issue 40; Fixes issue 51
Browse files Browse the repository at this point in the history
  • Loading branch information
dmknutsen committed Jan 13, 2020
1 parent abdd63b commit 4b34e92
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 56 deletions.
23 changes: 13 additions & 10 deletions Subsystems/cmdGui/CommandSystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,9 @@ def ProcessButtonGeneric(self, idx):
lineEditAddress = getattr(Command.ui, 'lineEdit_'+str(idx))
pktId = str(lineEditPktId.text())
address = str(lineEditAddress.text())
launch_string = 'python ' + cmdClass[0] + ' --title=\"' + cmdPageDesc[idx] + '\" --pktid=' + pktId + ' --file=' + cmdPageDefFile[idx] + ' --address=\"' + address + '\"' + ' --port=' + str(cmdPagePort[idx]) + ' --endian=' + cmdPageEndian[idx]
launch_string = 'python3 ' + cmdClass[0] + ' --title=\"' + cmdPageDesc[idx] + '\" --pktid=' + pktId + ' --file=' + cmdPageDefFile[idx] + ' --address=\"' + address + '\"' + ' --port=' + str(cmdPagePort[idx]) + ' --endian=' + cmdPageEndian[idx]
cmd_args = shlex.split(launch_string)
print launch_string
print (launch_string)
subprocess.Popen(cmd_args)

#
Expand Down Expand Up @@ -227,14 +227,15 @@ def ProcessQuickButton(self, idx):

# if requires parameters
if self.checkParams(quickIdx) == True:
prog = 'python Parameter.py'
prog = 'python3 Parameter.py'
launch_string = prog+' --title=\"'+subsys[quickIdx]+'\" --descrip=\"'+quickCmd[quickIdx]+'\" --idx='+str(idx)+' --host=\"'+address+'\" --port='+str(quickPort[quickIdx])+' --pktid='+pktId+' --endian='+quickEndian[quickIdx]+' --cmdcode='+quickCode[quickIdx]+' --file='+quickParam[quickIdx]

# if doesn't require parameters
else:
launch_string = '../cmdUtil/cmdUtil' + ' --host=\"' + address + '\" --port=' + str(quickPort[quickIdx]) + ' --pktid=' + pktId + ' --endian=' + quickEndian[quickIdx] + ' --cmdcode=' + quickCode[quickIdx]

# print launch_string
print ("This is my launchString")
print (launch_string)
cmd_args = shlex.split(launch_string)
subprocess.Popen(cmd_args)

Expand Down Expand Up @@ -269,7 +270,8 @@ def ProcessQuickButton(self, idx):

i = 0

with open(cmdDefFile, 'rb') as cmdfile:
## with open(cmdDefFile, 'rb') as cmdfile:
with open(cmdDefFile, 'r') as cmdfile:
reader = csv.reader(cmdfile, skipinitialspace = True)
for cmdRow in reader:
try:
Expand All @@ -284,9 +286,9 @@ def ProcessQuickButton(self, idx):
cmdPagePort.append(int(cmdRow[6]))
i += 1
except IndexError:
print "IndexError: list index out of range"
print "This could be due to improper formatting in command-pages.txt."
print "This is a common error caused by blank lines in command-pages.txt"
print ("IndexError: list index out of range")
print ("This could be due to improper formatting in command-pages.txt.")
print ("This is a common error caused by blank lines in command-pages.txt")

#
# Mark the remaining values as invalid
Expand All @@ -311,7 +313,8 @@ def ProcessQuickButton(self, idx):
quickParam = []
quickIndices = []

with open(quickDefFile,'rb') as subFile:
## with open(quickDefFile,'rb') as subFile:
with open(quickDefFile,'r') as subFile:
reader = csv.reader(subFile)
i = 0
for fileRow in reader:
Expand Down Expand Up @@ -644,6 +647,6 @@ def ProcessQuickButton(self, idx):
#
Command.show()
Command.raise_()
print 'Command System started.'
print ('Command System started.')
sys.exit(app.exec_())

17 changes: 9 additions & 8 deletions Subsystems/cmdGui/HTMLDocsParser.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@
import re
import glob
import pickle
#import html.parser

from HTMLParser import HTMLParser
from html.parser import HTMLParser
from struct import *

class HTMLDocsParser(HTMLParser):
Expand Down Expand Up @@ -155,15 +156,15 @@ def findStringLen(self, keyword):
stringLen.append(keyword)


print "DATA TYPES:", dataTypesOrig
print "PARAM NAMES: ", paramNames
print "PARAM STRING LEN:", paramLen
print "PARAM DESC: ", paramDesc
print "UNIX DATA TYPES:", dataTypesNew
print "STRING LENGTH:", stringLen, "\n"
print ("DATA TYPES:", dataTypesOrig)
print ("PARAM NAMES: ", paramNames)
print ("PARAM STRING LEN:", paramLen)
print ("PARAM DESC: ", paramDesc)
print ("UNIX DATA TYPES:", dataTypesNew)
print ("STRING LENGTH:", stringLen, "\n")

except ValueError:
print "Data Fields not found in HTML file"
print ("Data Fields not found in HTML file")

# write data to a file
file_split = re.split('/|\.', html_file)
Expand Down
4 changes: 3 additions & 1 deletion Subsystems/cmdGui/Parameter.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,13 @@
import shlex
import re
import pickle
#import html.parser

from PyQt4 import QtGui, QtNetwork
from ParameterDialog import Ui_Dialog
from HTMLParser import HTMLParser
from html.parser import HTMLParser
from HTMLDocsParser import HTMLDocsParser
#from html.parser import HTMLDocsParser
from struct import *

class Parameter(QtGui.QDialog):
Expand Down
10 changes: 6 additions & 4 deletions Subsystems/cmdGui/UdpCommands.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,12 @@
import subprocess
import shlex
import pickle
#import html.parser
#import html.DocsParser

from PyQt4 import QtGui
from GenericCommandDialog import Ui_GenericCommandDialog
from HTMLParser import HTMLParser
from html.parser import HTMLParser
from HTMLDocsParser import HTMLDocsParser
from struct import *

Expand Down Expand Up @@ -166,7 +168,7 @@ def ProcessSendButtonGeneric(self, idx):

# If parameters are required, launches Parameters page
if param_bool == True:
prog = 'python Parameter.py'
prog = 'python3 Parameter.py'
launch_string = prog+' --title=\"'+pageTitle+'\" --descrip=\"'+cmdDesc[idx]+'\" --idx='+str(idx)+' --host=\"'+address+'\" --port='+str(pagePort)+' --pktid='+str(pagePktId)+' --endian='+pageEndian+' --cmdcode='+cmdCodes[idx]+' --file='+param_files[idx]

# If parameters not required, directly calls cmdUtil to send command
Expand All @@ -183,8 +185,8 @@ def ProcessSendButtonGeneric(self, idx):
# Display usage
#
def usage():
print "Must specify --title=<page name> --file=<cmd_def_file> --pktid=<packet_app_id(hex)> --endian=<LE|BE> --address=<IP address> --port=<UDP port>"
print " example: --title=\"Executive Services\" --file=cfe-es-cmds.txt --pktid=1806 --endian=LE --address=127.0.0.1 --port=1234"
print ("Must specify --title=<page name> --file=<cmd_def_file> --pktid=<packet_app_id(hex)> --endian=<LE|BE> --address=<IP address> --port=<UDP port>" )
print (" example: --title=\"Executive Services\" --file=cfe-es-cmds.txt --pktid=1806 --endian=LE --address=127.0.0.1 --port=1234" )

#
# Main
Expand Down
22 changes: 12 additions & 10 deletions Subsystems/tlmGUI/EventMessage.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ def processPendingDatagrams(self, datagram):
#
# Not accounting for endian right now!
#
appName = "".join(unpack("<20s",datagram[12:32]))
eventText = "".join(unpack("<122sxx",datagram[44:]))
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
Expand All @@ -121,24 +121,26 @@ def __init__(self, mainWindow, subscription, appId):
self.context = zmq.Context()
self.subscriber = self.context.socket(zmq.SUB)
self.subscriber.connect("ipc:///tmp/GroundSystem")
self.subscriber.setsockopt(zmq.SUBSCRIBE, subscription)

print ("subscription: %s" % subscription)
self.subscriber.setsockopt_string(zmq.SUBSCRIBE, "GroundSystem.Spacecraft1.TelemetryPackets.0x808")

def run(self):
while True:
# Read envelope with address
[address, datagram] = self.subscriber.recv_multipart()
#print("[%s] %s" % (address, datagram))
print("Address: %s " % (address))
print ("selfAPID: %s" % self.appId)
# Ignore if not an event message
if self.appId not in address: continue
if self.appId not in str(address): continue
self.emit(self.signalTlmDatagram, 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>")
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)")


if __name__ == '__main__':
Expand Down Expand Up @@ -187,7 +189,7 @@ 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 = '<'
Expand Down
28 changes: 17 additions & 11 deletions Subsystems/tlmGUI/GenericTelemetry.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import getopt
import pdb
import zmq
import struct

from PyQt4 import QtGui, QtCore
from GenericTelemetryDialog import Ui_GenericTelemetryDialog
Expand All @@ -47,15 +48,19 @@ def __init__(self):
#
def displayTelemetryItem(self, datagram, tlmIndex, labelField, valueField):
if tlmItemIsValid[tlmIndex] == True:
TlmField = unpack(tlmItemFormat[tlmIndex], datagram[int(tlmItemStart[tlmIndex]):(int(tlmItemStart[tlmIndex]) + int(tlmItemSize[tlmIndex]))])
TlmField1 = tlmItemFormat[tlmIndex]
if TlmField1[:1] == "<":
TlmField1 = TlmField1[1:]
TlmField2 = datagram[int(tlmItemStart[tlmIndex]):(int(tlmItemStart[tlmIndex]) + int(tlmItemSize[tlmIndex]))]
TlmField = struct.unpack( TlmField1, TlmField2)
if tlmItemDisplayType[tlmIndex] == 'Dec':
valueField.setText(str(TlmField[0]))
elif tlmItemDisplayType[tlmIndex] == 'Hex':
valueField.setText(hex(TlmField[0]))
elif tlmItemDisplayType[tlmIndex] == 'Enm':
valueField.setText(tlmItemEnum[tlmIndex][int(TlmField[0])])
elif tlmItemDisplayType[tlmIndex] == 'Str':
valueField.setText(TlmField[0])
valueField.setText(TlmField[0].decode('utf-8','ignore'))
labelField.setText(tlmItemDesc[tlmIndex])
else:
labelField.setText("(unused)")
Expand Down Expand Up @@ -135,13 +140,13 @@ def __init__(self, mainWindow, subscription):
self.context = zmq.Context()
self.subscriber = self.context.socket(zmq.SUB)
self.subscriber.connect("ipc:///tmp/GroundSystem")
self.subscriber.setsockopt(zmq.SUBSCRIBE, subscription)
myTlmPgAPID = subscription.split(".",1)
mySubscription = "GroundSystem.Spacecraft1.TelemetryPackets." + str(myTlmPgAPID[1])
self.subscriber.setsockopt_string(zmq.SUBSCRIBE, mySubscription)

def run(self):
while True:
# Read envelope with address
[address, datagram] = self.subscriber.recv_multipart()
#print("[%s] %s" % (address, datagram))
# Send signal with received packet to front-end/GUI
self.emit(self.signalTlmDatagram, datagram)

Expand All @@ -150,9 +155,9 @@ def run(self):
# 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> --sub=<subscriber_string>"
print " example: --title=Executive Services --port=10800 --appid=800 --file=cfe-es-hk-table.txt --endian=L --sub=GroundSystem.Spacecraft1.0x886"
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> --sub=<subscriber_string>")
print (" example: --title=Executive Services --port=10800 --appid=800 --file=cfe-es-hk-table.txt --endian=L --sub=GroundSystem.Spacecraft1.0x886")
print (" (quotes are not on the title string in this example)" )

#
# Main
Expand Down Expand Up @@ -198,7 +203,7 @@ def usage():
if len(subscription) == 0:
subscription = "GroundSystem"

print 'Generic Telemetry Page started. Subscribed to ' + subscription
print ('Generic Telemetry Page started. Subscribed to ' + subscription)

if endian == 'L':
py_endian = '<'
Expand All @@ -225,8 +230,10 @@ def usage():
tlmItemEnum = [[] for i in range(40)]
i = 0

with open(tlmDefFile, 'rb') as tlmfile:
# with open(tlmDefFile, 'rb') as tlmfile:
with open(tlmDefFile, 'r') as tlmfile:
reader = csv.reader(tlmfile, skipinitialspace = True)
print ("Reading file: %s" % tlmDefFile )
for row in reader:
if row[0][0] != '#':
tlmItemIsValid.append(True)
Expand All @@ -237,7 +244,6 @@ def usage():
tlmItemFormat.append(row[2]+row[3])
else:
tlmItemFormat.append(py_endian + row[3])

tlmItemDisplayType.append(row[4])
if row[4] == 'Enm':
tlmItemEnum[i].append(row[5])
Expand Down
24 changes: 12 additions & 12 deletions Subsystems/tlmGUI/TelemetrySystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@ def dumpPacket(packetData):
appIdString = "%02X" % ord(packetData[0])
appIdString = appIdString + "%02X" % ord(packetData[1])
appId = (ord(packetData[0]) << 8) + (ord(packetData[1]))
print "\n-----------------------------------------------"
print "\nPacket: App ID = ", hex(appId)
print "\nPacket Data: ", strToHex(packetData)
print ("\n-----------------------------------------------")
print ("\nPacket: App ID = ", hex(appId))
print ("\nPacket Data: ", strToHex(packetData))

#
# Button press methods
Expand Down Expand Up @@ -135,7 +135,7 @@ def ProcessButtonGeneric(self, idx):
tempSub = self.subscription + '.' + hex(tlmPageAppid[idx])
if tlmPageIsValid[idx] == True:
# need to extract data from fields, then start page with right params
launch_string = 'python ' + tlmClass[idx] + ' --title=\"' + tlmPageDesc[idx] + '\" --appid=' + hex(tlmPageAppid[idx]) + ' --port=' + str(tlmPagePort[idx]) + ' --file=' + tlmPageDefFile[idx] + ' --endian=' + endian + ' --sub=' + tempSub
launch_string = 'python3 ' + tlmClass[idx] + ' --title=\"' + tlmPageDesc[idx] + '\" --appid=' + hex(tlmPageAppid[idx]) + ' --port=' + str(tlmPagePort[idx]) + ' --file=' + tlmPageDefFile[idx] + ' --endian=' + endian + ' --sub=' + tempSub
cmd_args = shlex.split(launch_string)
subprocess.Popen(cmd_args)

Expand Down Expand Up @@ -168,10 +168,10 @@ def dumpPacket(packetData):
appIdString = "%02X" % ord(packetData[0])
appIdString = appIdString + "%02X" % ord(packetData[1])
appId = (ord(packetData[0]) << 8) + (ord(packetData[1]))
print appIdString
print "\nPacket: App ID = ", hex(appId)
print "\nPacket Data: ", strToHex(packetData)
print "\n-----------------------------------------------"
print (appIdString)
print ("\nPacket: App ID = ", hex(appId))
print ("\nPacket Data: ", strToHex(packetData))
print ("\n-----------------------------------------------")

#
# Show number of packets received
Expand Down Expand Up @@ -256,7 +256,7 @@ def __init__(self, mainWindow, subscription):
self.context = zmq.Context()
self.subscriber = self.context.socket(zmq.SUB)
self.subscriber.connect("ipc:///tmp/GroundSystem")
self.subscriber.setsockopt(zmq.SUBSCRIBE, subscription)
self.subscriber.setsockopt_string(zmq.SUBSCRIBE, subscription)

def run(self):
while True:
Expand Down Expand Up @@ -298,9 +298,9 @@ def run(self):
subscription = arg

if len(subscription) == 0:
subscription = "GroundSystem"
subscription = "GroundSystem"

print 'Telemetry System started. Subscribed to ' + subscription
print ('Telemetry System started. Subscribed to ' + subscription)
#
# Read in the contents of the telemetry packet defintion
#
Expand All @@ -313,7 +313,7 @@ def run(self):
tlmPageDefFile = []
i = 0

with open(tlmDefFile, 'rb') as tlmfile:
with open(tlmDefFile, 'r') as tlmfile:
reader = csv.reader(tlmfile, skipinitialspace = True)
for row in reader:
if row[0][0] != '#':
Expand Down

0 comments on commit 4b34e92

Please sign in to comment.