Skip to content

Commit

Permalink
Enhancement nasa#103 - further corrections and cleanup
Browse files Browse the repository at this point in the history
Also removed the shareddata.py file; no longer needed
at this time
  • Loading branch information
lbleier-GSFC committed Jul 6, 2020
1 parent b017500 commit fb58248
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 52 deletions.
2 changes: 1 addition & 1 deletion Subsystems/cmdGui/CommandSystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def ProcessQuickButton(self, idx):
# f'--cmdcode={quickCode[qIdx]}')

def closeEvent(self, event):
if self.mcu.mm:
if self.mcu:
self.mcu.mm.close()
super().closeEvent(event)

Expand Down
26 changes: 10 additions & 16 deletions Subsystems/cmdGui/MiniCmdUtil.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,13 @@
## to support the GroundSystem GUI

import mmap
import sys
from pathlib import Path
import socket
from collections import namedtuple

ROOTDIR = Path(sys.argv[0]).resolve().parent
sys.path.append(str(ROOTDIR.parent.parent))
## The two preceding lines must be above
## the next import or the import will fail
from shareddata import sock


class MiniCmdUtil:
checksum = 0xFF
cfsCmdSecHdr = bytearray(2)
## Class objects
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
TypeSignature = namedtuple("TypeSignature", 'byteLen, signed, endian')
dataTypes = {
("b", "int8", "byte"): TypeSignature(1, True, None),
Expand Down Expand Up @@ -75,9 +68,10 @@ def __init__(self,

self.cmdOffsetPri = 0
self.cmdOffsetSec = 0
self.checksum = 0xFF
self.cfsCmdSecHdr = bytearray(2)

def assemblePriHeader(self):
self._getOffsets()
ccsdsPri = bytearray(6)
ccsdsPri[:2] = self.pktID.to_bytes(2, byteorder='big')
ccsdsPri[2:4] = (0xC000).to_bytes(2, byteorder='big')
Expand Down Expand Up @@ -125,14 +119,14 @@ def assemblePayload(self):

def assemblePacket(self):
self._getOffsets()
pri = self.assemblePriHeader()
self.packet.extend(pri)
priHeader = self.assemblePriHeader()
self.packet.extend(priHeader)
priOffset = bytearray(self.cmdOffsetPri)
self.packet.extend(priOffset)
self.cfsCmdSecHdr[0] = self.cmdCode
secOffset = bytearray(self.cmdOffsetSec)
for b in b''.join(
(pri, priOffset, self.cfsCmdSecHdr, secOffset, self.payload)):
for b in b''.join((priHeader, priOffset, self.cfsCmdSecHdr, secOffset,
self.payload)):
self.checksum ^= b
self.cfsCmdSecHdr[1] = self.checksum
self.packet.extend(self.cfsCmdSecHdr)
Expand All @@ -148,7 +142,7 @@ def sendPacket(self):
if (i + 1) % 8 == 0:
print()
print()
bytesSent = sock.sendto(self.packet, (self.host, self.port))
bytesSent = self.sock.sendto(self.packet, (self.host, self.port))
return bytesSent > 0

def _getOffsets(self):
Expand Down
3 changes: 2 additions & 1 deletion Subsystems/cmdGui/Parameter.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ def ProcessSendButton(self):
self.status_box.setText('Error occured')

def closeEvent(self, event):
self.mcu.mm.close()
if self.mcu:
self.mcu.mm.close()
super().closeEvent(event)


Expand Down
3 changes: 2 additions & 1 deletion Subsystems/cmdGui/UdpCommands.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@ def ProcessSendButtonGeneric(self, idx):
# f'--endian={pageEndian} --cmdcode={cmdCodes[idx]}')

def closeEvent(self, event):
self.mcu.mm.close()
if self.mcu:
self.mcu.mm.close()
super().closeEvent(event)


Expand Down
15 changes: 9 additions & 6 deletions Subsystems/tlmGUI/EventMessage.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,10 @@
# uint8 Spare2; 167

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

import zmq
from PyQt5.QtCore import QThread, pyqtSignal
Expand All @@ -61,10 +62,6 @@
from Ui_EventMessageDialog import Ui_EventMessageDialog

ROOTDIR = Path(sys.argv[0]).resolve().parent
sys.path.append(str(ROOTDIR.parent.parent))
## The two preceding lines must be above
## the next import or the import will fail
from shareddata import tlmOffset


class EventMessageTelemetry(QDialog, Ui_EventMessageDialog):
Expand All @@ -80,6 +77,9 @@ def __init__(self, aid):
4: "CRITICAL"
}

with open("/tmp/OffsetData", "r+b") as f:
self.mm = mmap.mmap(f.fileno(), 0, prot=mmap.PROT_READ)

def initEMTlmReceiver(self, subscr):
self.setWindowTitle(f'{pageTitle} for: {subscr}')
self.thread = EMTlmReceiver(subscr, self.appId)
Expand All @@ -100,7 +100,10 @@ def processPendingDatagrams(self, datagram):
#
# Get App Name, Event ID, Type and Event Text!
#
print(tlmOffset)
try:
tlmOffset = self.mm[0]
except ValueError:
pass
startByte = 12 + tlmOffset
appName = datagram[startByte:startByte + 20].decode('utf-8', 'ignore')
eventID = int.from_bytes(datagram[startByte + 20:startByte + 22],
Expand Down
27 changes: 0 additions & 27 deletions shareddata.py

This file was deleted.

0 comments on commit fb58248

Please sign in to comment.