Skip to content

Commit

Permalink
WIP: Enhancement nasa#103 - updates to miniCmdUtil
Browse files Browse the repository at this point in the history
  • Loading branch information
lbleier-GSFC committed Jun 24, 2020
1 parent 8ad565c commit 6d3f7ed
Showing 1 changed file with 41 additions and 4 deletions.
45 changes: 41 additions & 4 deletions Subsystems/cmdGui/MiniCmdUtil.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import socket
import sys
from pathlib import Path
from collections import namedtuple

ROOTDIR = Path().resolve().parent
sys.path.append(ROOTDIR.parent.parent)
Expand All @@ -35,6 +36,23 @@
class MiniCmdUtil:
ccsdsExt = bytearray(4)
cfsCmdSecHdr = bytearray(2)
TypeSignature = namedtuple("TypeSignature", 'byteLen, signed, endian')
dataTypes = {
("b", "int8", "byte"): TypeSignature(1, True, None),
("m", "uint8"): TypeSignature(1, False, None),
("h", "int16", "half"): TypeSignature(2, True, None),
("n", "uint16"): TypeSignature(2, False, None),
("l", "int32", "long", "word"): TypeSignature(4, True, None),
("o", "uint32"): TypeSignature(4, False, None),
("q", "int64"): TypeSignature(8, True, None),
("p", "uint64"): TypeSignature(8, False, None),
("i", "int16b"): TypeSignature(2, True, "big"),
("j", "int32b"): TypeSignature(4, True, "big"),
("k", "int64b"): TypeSignature(8, True, "big"),
("w", "uint16b"): TypeSignature(2, False, "big"),
("x", "uint32b"): TypeSignature(4, False, "big"),
("y", "uint64b"): TypeSignature(8, False, "big")
}

def __init__(self,
host="127.0.0.1",
Expand All @@ -44,12 +62,10 @@ def __init__(self,
pktID=None,
cmdCode=None,
payload=None):
endians = {"BE": ">", "LE": "<"}
self.dataTypes = {"byte": 8, "half": 16, "long": 32}

self.host = host
self.port = port
self.endian = ">" if endian == "BE" else "<"
self.endian = "big" if endian == "BE" else "little"
self.pktID = pktID
self.cmdCode = cmdCode
self.hdrVer = hdrVer
Expand All @@ -68,4 +84,25 @@ def assemblePriHeader(self):


def assemblePayload(self):
pass
completePayload = bytearray(0)
paramList = self.payload.split(" ")
for param in paramList:
if "--string" not in param: ## non-string param
items = param.split("=") ## e.g. ["--uint16", "2"]
dataType = items[0].strip("-") ## Remove "--" prefix
dataVal = int(items[1]) ## "2" --> 2
for key in self.dataTypes: ## Loop thru dictionary
if dataType in key: ## Check if "uint16" in key tuple
## Get the TypeSignature tuple
typeSig = self.dataTypes[key]
break ## Stop checking dictionary
## If TypeSignature endian is None, get the user-provided endian
## Otherwise get the TypeSignature endian
endian = typeSig.endian or self.endian
## Convert to bytes of correct length, endianess, and sign
dataValb = dataVal.to_bytes(typeSig.byteLen,
byteorder=endian,
signed=typeSig.signed)
completePayload.extend(dataValb) ## Add data to bytearray
else:
pass

0 comments on commit 6d3f7ed

Please sign in to comment.