diff --git a/gui/obsw_tmtc_gui.py b/gui/obsw_tmtc_gui.py index adc571c7735b82d9f2ff9c4d23018f7c90863817..240af41886df222fa2d4de1250d990e117cc4bb4 100644 --- a/gui/obsw_tmtc_gui.py +++ b/gui/obsw_tmtc_gui.py @@ -13,8 +13,10 @@ @author: R. Mueller """ +from PyQt5 import QtCore from PyQt5.QtWidgets import * +from core.tmtc_backend import TmTcHandler from tmtc_core.tc.obsw_pus_tc_base import PusTelecommand from tmtc_core.utility.obsw_logger import get_logger from config import obsw_config @@ -33,21 +35,9 @@ LOGGER = get_logger() # Step 1: Huge Mission Badge in Tkinter window because that is cool. # Step 2: Simple buttons to run servce tests around the badge. -class TmTcGUI: - def __init__(self): - pass - # super(TmTcGUI, self).__init__() - - def run(self): - application = Application() - # init the backend - application.init_tmtc_handler() - # init the frontend - application.init_ui() - - def close(self): - pass - # self.window.quit() +def initialize_frontend(tmtc_backend: TmTcHandler): + tmtc_frontend = TmTcFrontend(tmtc_backend) + tmtc_frontend.init_ui() class SingleCommandTable(QTableWidget): def __init__(self): @@ -64,7 +54,7 @@ class SingleCommandTable(QTableWidget): self.setItem(0, 2, QTableWidgetItem("20")) -class Application: +class TmTcFrontend: from core.tmtc_client_core import TmTcHandler tmtc_handler: TmTcHandler @@ -87,54 +77,10 @@ class Application: obsw_config.G_SERVICE = 17 obsw_config.G_COM_IF = obsw_config.ComIF.QEMU - def init_tmtc_handler(self): - from core.tmtc_client_core import TmTcHandler - self.tmtc_handler = TmTcHandler() - - def com_if_index_changed(self, index: int): - obsw_config.G_COM_IF = obsw_config.ComIF(index) - LOGGER.info("com if updated: " + str(obsw_config.G_COM_IF)) - def service_index_changed(self, index: int): obsw_config.G_SERVICE = self.serviceList[index] LOGGER.info("service_test_mode_selection updated: " + str(self.serviceList[index])) - def checkbox_console_print(self, state: int): - LOGGER.info(["enabled", "disabled"][state == 0] + " console print") - obsw_config.G_PRINT_TM = state == 0 - - def checkbox_log_print(self, state: int): - LOGGER.info(["enabled", "disabled"][state == 0] + " print to log") - obsw_config.G_PRINT_TO_FILE = state == 0 - - def checkbox_print_raw_data(self, state: int): - LOGGER.info(["enabled", "disabled"][state == 0] + " printing of raw data") - obsw_config.G_PRINT_RAW_TM = state == 0 - - def checkbox_print_hk_data(self, state: int): - LOGGER.info(["enabled", "disabled"][state == 0] + " printing of hk data") - obsw_config.G_PRINT_HK_DATA = state == 0 - - def checkbox_short_display_mode(self, state: int): - LOGGER.info(["enabled", "disabled"][state == 0] + " short display mode") - obsw_config.G_DISPLAY_MODE = ["short", "long"][state == 0] - - def number_timeout(self, value: float): - LOGGER.info("tm timeout changed to: " + str(value)) - obsw_config.G_TM_TIMEOUT = value - - def number_timeout_factor(self, value: float): - LOGGER.info("tm timeout factor changed to: " + str(value)) - obsw_config.G_TC_SEND_TIMEOUT_FACTOR = value - - def ip_change_client(self, value): - LOGGER.info("client ip changed: " + value) - obsw_config.G_REC_ADDRESS = (value, 2008) - - def ip_change_board(self, value): - LOGGER.info("board ip changed: " + value) - obsw_config.G_SEND_ADDRESS = (value, 7) - def single_command_set_service(self, value): self.singleCommandService = value @@ -149,7 +95,7 @@ class Application: LOGGER.info("start testing service: " + str(obsw_config.G_SERVICE)) self.tmtc_handler.mode = obsw_config.ModeList.ServiceTestMode # start the action in a new process - p = threading.Thread(target=self.handleTmTcAction) + p = threading.Thread(target=self.handle_tm_tc_action) p.start() def send_single_command_clicked(self, table): @@ -175,19 +121,19 @@ class Application: self.tmtc_handler.mode = obsw_config.ModeList.SingleCommandMode # start the action in a new process - p = threading.Thread(target=self.handleTmTcAction) + p = threading.Thread(target=self.handle_tm_tc_action) p.start() - def handleTmTcAction(self): + def handle_tm_tc_action(self): LOGGER.info("start tmtc_handler.handle_action") self.isBusy = True - self.setSendButtons(False) + self.set_send_buttons(False) self.tmtc_handler.handle_action() self.isBusy = False - self.setSendButtons(True) + self.set_send_buttons(True) LOGGER.info("finished tmtc_handler.handle_action") - def setSendButtons(self, state: bool): + def set_send_buttons(self, state: bool): self.serviceTest_button.setEnabled(state) self.singleCommand_button.setEnabled(state) @@ -203,23 +149,23 @@ class Application: checkbox_console = QCheckBox("print output to console") checkbox_console.setChecked(obsw_config.G_PRINT_TM) - checkbox_console.stateChanged.connect(self.checkbox_console_print) + checkbox_console.stateChanged.connect(checkbox_console_print) checkbox_log = QCheckBox("print output to log file") checkbox_log.setChecked(obsw_config.G_PRINT_TO_FILE) - checkbox_log.stateChanged.connect(self.checkbox_log_print) + checkbox_log.stateChanged.connect(checkbox_log_print) checkbox_raw_tm = QCheckBox("print all raw TM data directly") checkbox_raw_tm.setChecked(obsw_config.G_PRINT_RAW_TM) - checkbox_raw_tm.stateChanged.connect(self.checkbox_print_raw_data) + checkbox_raw_tm.stateChanged.connect(checkbox_print_raw_data) checkbox_hk = QCheckBox("print hk data") checkbox_hk.setChecked(obsw_config.G_PRINT_HK_DATA) - checkbox_hk.stateChanged.connect(self.checkbox_print_hk_data) + checkbox_hk.stateChanged.connect(checkbox_print_hk_data) checkbox_short = QCheckBox("short display mode") checkbox_short.setChecked(obsw_config.G_DISPLAY_MODE == "short") - checkbox_short.stateChanged.connect(self.checkbox_short_display_mode) + checkbox_short.stateChanged.connect(checkbox_short_display_mode) grid.addWidget(checkbox_log, row, 0, 1, 1) grid.addWidget(checkbox_console, row, 1, 1, 1) @@ -240,7 +186,7 @@ class Application: spin_timeout.setSingleStep(0.1) spin_timeout.setMinimum(0.25) spin_timeout.setMaximum(60) - spin_timeout.valueChanged.connect(self.number_timeout) + spin_timeout.valueChanged.connect(number_timeout) grid.addWidget(spin_timeout, row, 0, 1, 1) spin_timeout_factor = QDoubleSpinBox() @@ -249,7 +195,7 @@ class Application: spin_timeout_factor.setSingleStep(0.1) spin_timeout_factor.setMinimum(0.25) spin_timeout_factor.setMaximum(10) - spin_timeout_factor.valueChanged.connect(self.number_timeout_factor) + spin_timeout_factor.valueChanged.connect(number_timeout_factor) grid.addWidget(spin_timeout_factor, row, 1, 1, 1) row += 1 @@ -260,13 +206,13 @@ class Application: spin_client_ip = QLineEdit() # TODO: set sensible min/max values spin_client_ip.setInputMask("000.000.000.000;_") - spin_client_ip.textChanged.connect(self.ip_change_client) + spin_client_ip.textChanged.connect(ip_change_client) grid.addWidget(spin_client_ip, row, 0, 1, 1) spin_board_ip = QLineEdit() # TODO: set sensible min/max values spin_board_ip.setInputMask("000.000.000.000;_") - spin_board_ip.textChanged.connect(self.ip_change_board) + spin_board_ip.textChanged.connect(ip_change_board) #spin_board_ip.setText(obsw_config.G_SEND_ADDRESS[0]) grid.addWidget(spin_board_ip, row, 1, 1, 1) @@ -279,7 +225,7 @@ class Application: for comIf in obsw_config.ComIF: com_if_comboBox.addItem(comIf.name) com_if_comboBox.setCurrentIndex(obsw_config.G_COM_IF.value) - com_if_comboBox.currentIndexChanged.connect(self.com_if_index_changed) + com_if_comboBox.currentIndexChanged.connect(com_if_index_changed) grid.addWidget(com_if_comboBox, row, 1, 1, 1) row += 1 @@ -368,4 +314,55 @@ class Application: #for i in range(0, 5): # self.commandTable.setColumnWidth(i, int(self.commandTable.width() / 5) - 3) - app.exec_() \ No newline at end of file + app.exec_() + + + +def com_if_index_changed(index: int): + obsw_config.G_COM_IF = obsw_config.ComIF(index) + LOGGER.info("com if updated: " + str(obsw_config.G_COM_IF)) + + +def checkbox_console_print(state: int): + LOGGER.info(["enabled", "disabled"][state == 0] + " console print") + obsw_config.G_PRINT_TM = state == 0 + + +def checkbox_log_print(state: int): + LOGGER.info(["enabled", "disabled"][state == 0] + " print to log") + obsw_config.G_PRINT_TO_FILE = state == 0 + + +def checkbox_print_raw_data(state: int): + LOGGER.info(["enabled", "disabled"][state == 0] + " printing of raw data") + obsw_config.G_PRINT_RAW_TM = state == 0 + + +def checkbox_print_hk_data(state: int): + LOGGER.info(["enabled", "disabled"][state == 0] + " printing of hk data") + obsw_config.G_PRINT_HK_DATA = state == 0 + + +def checkbox_short_display_mode(state: int): + LOGGER.info(["enabled", "disabled"][state == 0] + " short display mode") + obsw_config.G_DISPLAY_MODE = ["short", "long"][state == 0] + + +def number_timeout(value: float): + LOGGER.info("tm timeout changed to: " + str(value)) + obsw_config.G_TM_TIMEOUT = value + + +def number_timeout_factor(value: float): + LOGGER.info("tm timeout factor changed to: " + str(value)) + obsw_config.G_TC_SEND_TIMEOUT_FACTOR = value + + +def ip_change_client(value): + LOGGER.info("client ip changed: " + value) + obsw_config.G_REC_ADDRESS = (value, 2008) + + +def ip_change_board(value): + LOGGER.info("board ip changed: " + value) + obsw_config.G_SEND_ADDRESS = (value, 7) \ No newline at end of file