Merge remote-tracking branch 'origin/develop' into kranz/master

This commit is contained in:
Markus Kranz 2022-05-23 16:44:11 +02:00
commit 623e1cc37e
5 changed files with 160 additions and 27 deletions

115
pus_tc/prompt_parameters.py Normal file
View File

@ -0,0 +1,115 @@
from PyQt5.QtWidgets import (
QDialog, QDialogButtonBox, QVBoxLayout, QLabel, QGroupBox, QGridLayout, QLineEdit
)
from PyQt5 import QtCore
from tmtccmd.core.globals_manager import get_global
from tmtccmd.config.definitions import CoreGlobalIds, CoreModeList
class Parameter:
def __init__(self, name: str, defaultValue: str, widget: QLineEdit):
self.name = name
self.defaultValue = defaultValue
self.widget = widget
self.value = self.defaultValue
self.widget.setPlaceholderText(self.defaultValue)
def reset(self):
self.value = self.defaultValue
self.widget.setPlaceholderText(self.defaultValue)
self.widget.setText("")
class ParameterDialog(QDialog):
def __init__(self):
super().__init__()
self.setWindowTitle("Enter Parameters")
Buttons = QDialogButtonBox.Ok | QDialogButtonBox.Cancel | QDialogButtonBox.Reset
self.buttonBox = QDialogButtonBox(Buttons)
self.buttonBox.accepted.connect(self.accept)
self.buttonBox.rejected.connect(self.reject)
self.buttonBox.button(QDialogButtonBox.Reset).clicked.connect(self._reset)
self.data = 1
self.rootLayout = QVBoxLayout()
self.group = QGroupBox("Parameters")
self.rootLayout.addWidget(self.group)
self.rootLayout.addWidget(self.buttonBox)
self.setLayout(self.rootLayout)
self.groupLayout = QGridLayout()
self.group.setLayout(self.groupLayout)
self.parameters = {}
def addParameter(self, name: str, defaultValue: str):
row = self.groupLayout.rowCount() + 1
description = QLabel(name)
self.groupLayout.addWidget(description, row, 0)
valueWidget = QLineEdit()
self.groupLayout.addWidget(valueWidget, row, 1)
parameter = Parameter(name, defaultValue, valueWidget)
self.parameters[name] = parameter
def _reset(self):
for value in self.parameters.values():
value.reset()
def getParameters(self):
output = {}
for key, parameter in self.parameters.items():
if parameter.widget != None:
if parameter.widget.text() != "":
parameter.value = parameter.widget.text()
output[key] = parameter.value
return output
@QtCore.pyqtSlot()
def reject(self):
print("reject")
self._reset()
super().reject()
"""Prompt the user to specify additional Parameters
:param parameterList: array of dictionaries with name and defaultValue attributes
:return: dict with all names as key and user supplied input as value string
"""
def prompt_parameters(parameterList):
gui = get_global(CoreGlobalIds.GUI)
mode = get_global(CoreGlobalIds.MODE)
# gui only works in cont mode right now
if gui and mode == CoreModeList.CONTINUOUS_MODE:
return _gui_prompt(parameterList)
else:
return _cli_prompt(parameterList)
def _gui_prompt(parameterList):
dialog = ParameterDialog()
for parameter in parameterList:
dialog.addParameter(parameter["name"], parameter["defaultValue"])
dialog.exec_()
return dialog.getParameters()
def _cli_prompt(parameterList):
result = {}
for parameter in parameterList:
userInput = input("Specify {} [{}]: ".format(parameter["name"], parameter["defaultValue"]))
if userInput == "":
userInput = parameter["defaultValue"]
result[parameter["name"]] = userInput
return result

View File

@ -1,10 +1,11 @@
from ast import Pass
from tmtccmd.tc.definitions import TcQueueT from tmtccmd.tc.definitions import TcQueueT
from tmtccmd.config import QueueCommands
from .common import command_mode from .common import command_mode
import config.object_ids as obj_ids import config.object_ids as obj_ids
from pus_tc.prompt_parameters import prompt_parameters
class OpCodes: class OpCodes:
THERMAL_CONTROLLER = [obj_ids.THERMAL_CONTROLLER_ID.hex(), "thermal_controller"] THERMAL_CONTROLLER = [obj_ids.THERMAL_CONTROLLER_ID.hex(), "thermal_controller"]
@ -17,12 +18,13 @@ class Info:
def pack_controller_commands(tc_queue: TcQueueT, op_code: str): def pack_controller_commands(tc_queue: TcQueueT, op_code: str):
mode = int(input("Specify mode: (OFF = 0; ON = 1; NORMAL = 2) [2] ") or "2") parameters = prompt_parameters([{"name": "Mode", "defaultValue": "2"}, {
print(mode) "name": "Submode", "defaultValue": "0"}])
mode = int(parameters["Mode"])
if mode < 0 or mode > 2: if mode < 0 or mode > 2:
print("Invalid Mode, defaulting to OFF") print("Invalid Mode, defaulting to OFF")
mode = 0 mode = 0
submode = int(input("Specify submode [0]: ") or "0") submode = int(parameters["Submode"])
command_mode( command_mode(
object_id=get_object_from_op_code(op_code), object_id=get_object_from_op_code(op_code),
mode=mode, mode=mode,
@ -31,6 +33,16 @@ def pack_controller_commands(tc_queue: TcQueueT, op_code: str):
info=op_code + " to " + str(mode) + "," + str(submode), info=op_code + " to " + str(mode) + "," + str(submode),
) )
tc_queue.appendleft((QueueCommands.WAIT, 20))
command_mode(
object_id=get_object_from_op_code(op_code),
mode=0,
submode=0,
tc_queue=tc_queue,
info=op_code + " to 0,0",
)
def get_object_from_op_code(op_code: str): def get_object_from_op_code(op_code: str):
try: try:

View File

@ -18,25 +18,24 @@ def handle_thermal_controller_hk_data(
# get all the floats # get all the floats
tm_data = struct.unpack("!ffffffffffffffff", hk_data[: 16 * 4]) tm_data = struct.unpack("!ffffffffffffffff", hk_data[: 16 * 4])
parsed_data = {}
# put them into an list with their names # put them into an nice dictionary
parsed_data = [ parsed_data["SENSOR_PLOC_HEATSPREADER"] = tm_data[0]
{"SENSOR_PLOC_HEATSPREADER": tm_data[0]}, parsed_data["SENSOR_PLOC_MISSIONBOARD"] = tm_data[1]
{"SENSOR_PLOC_MISSIONBOARD": tm_data[1]}, parsed_data["SENSOR_4K_CAMERA"] = tm_data[2]
{"SENSOR_4K_CAMERA": tm_data[2]}, parsed_data["SENSOR_DAC_HEATSPREADER"] = tm_data[3]
{"SENSOR_DAC_HEATSPREADER": tm_data[3]}, parsed_data["SENSOR_STARTRACKER"] = tm_data[4]
{"SENSOR_STARTRACKER": tm_data[4]}, parsed_data["SENSOR_RW1"] = tm_data[5]
{"SENSOR_RW1": tm_data[5]}, parsed_data["SENSOR_DRO"] = tm_data[6]
{"SENSOR_DRO": tm_data[6]}, parsed_data["SENSOR_SCEX"] = tm_data[7]
{"SENSOR_SCEX": tm_data[7]}, parsed_data["SENSOR_X8"] = tm_data[8]
{"SENSOR_X8": tm_data[8]}, parsed_data["SENSOR_HPA"] = tm_data[9]
{"SENSOR_HPA": tm_data[9]}, parsed_data["SENSOR_TX_MODUL"] = tm_data[10]
{"SENSOR_TX_MODUL": tm_data[10]}, parsed_data["SENSOR_MPA"] = tm_data[11]
{"SENSOR_MPA": tm_data[11]}, parsed_data["SENSOR_ACU"] = tm_data[12]
{"SENSOR_ACU": tm_data[12]}, parsed_data["SENSOR_PLPCDU_HEATSPREADER"] = tm_data[13]
{"SENSOR_PLPCDU_HEATSPREADER": tm_data[13]}, parsed_data["SENSOR_TCS_BOARD"] = tm_data[14]
{"SENSOR_TCS_BOARD": tm_data[14]}, parsed_data["SENSOR_MAGNETTORQUER"] = tm_data[15]
{"SENSOR_MAGNETTORQUER": tm_data[15]},
]
TM_TCP_SERVER.report_parsed_hk_data(object_id, set_id, parsed_data) TM_TCP_SERVER.report_parsed_hk_data(object_id, set_id, parsed_data)

@ -1 +1 @@
Subproject commit 4fbbf129e140e593b1cc54a0361fa20cc8726789 Subproject commit 0e193f9c76973a6105926ed133b179f8ea467981

View File

@ -1,11 +1,18 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
"""TMTC commander for EIVE""" """TMTC commander for EIVE"""
from tmtcc import tmtcc_post_args, tmtcc_pre_args from tmtcc import tmtcc_post_args, tmtcc_pre_args
from tmtccmd.config.args import (
create_default_args_parser,
add_gui_tmtccmd_args,
parse_gui_input_arguments,
)
def main(): def main():
hook_obj = tmtcc_pre_args() hook_obj = tmtcc_pre_args()
tmtcc_post_args(hook_obj=hook_obj, use_gui=True, args=None) arg_parser = create_default_args_parser()
add_gui_tmtccmd_args(arg_parser)
args = parse_gui_input_arguments(arg_parser)
tmtcc_post_args(hook_obj=hook_obj, use_gui=True, args=args)
if __name__ == "__main__": if __name__ == "__main__":