From ee38f83ec1c44885dde7a1f401a2d4a5b888a17d Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Wed, 1 Feb 2023 20:11:47 +0100 Subject: [PATCH] i am happy with this output format --- eive_tmtc/config/definitions.py | 1 + eive_tmtc/pus_tm/defs.py | 6 +++++ eive_tmtc/pus_tm/event_handler.py | 6 ++++- eive_tmtc/tmtc/__init__.py | 1 + eive_tmtc/tmtc/core.py | 1 - eive_tmtc/tmtc/health.py | 43 +++++++++++++++++++++++++++++++ eive_tmtc/tmtc/tcs/heater.py | 8 +++--- 7 files changed, 60 insertions(+), 6 deletions(-) create mode 100644 eive_tmtc/tmtc/health.py diff --git a/eive_tmtc/config/definitions.py b/eive_tmtc/config/definitions.py index 570b6fa..2b0b538 100644 --- a/eive_tmtc/config/definitions.py +++ b/eive_tmtc/config/definitions.py @@ -29,6 +29,7 @@ class CustomServiceList(str, enum.Enum): value: str TEST_DEVICE = "test" + HEALTH = "health" P60DOCK = "p60dock" PDU1 = "pdu1" PDU2 = "pdu2" diff --git a/eive_tmtc/pus_tm/defs.py b/eive_tmtc/pus_tm/defs.py index e5e6d14..ad43cdb 100644 --- a/eive_tmtc/pus_tm/defs.py +++ b/eive_tmtc/pus_tm/defs.py @@ -1,3 +1,5 @@ +import logging + from tmtccmd.util.tmtc_printer import FsfwTmTcPrinter @@ -9,6 +11,10 @@ class PrintWrapper: print(string) self.printer.file_logger.info(string) + def ilog(self, logger: logging.Logger, string: str): + logger.info(string) + self.printer.file_logger.info(string) + def log_to_both(printer: FsfwTmTcPrinter, string: str): print(string) diff --git a/eive_tmtc/pus_tm/event_handler.py b/eive_tmtc/pus_tm/event_handler.py index 0452c4f..1fc8a02 100644 --- a/eive_tmtc/pus_tm/event_handler.py +++ b/eive_tmtc/pus_tm/event_handler.py @@ -7,6 +7,7 @@ from eive_tmtc.pus_tm.defs import PrintWrapper from eive_tmtc.pus_tm.verification_handler import generic_retval_printout from eive_tmtc.tmtc.acs.subsystem import AcsMode from tmtccmd.tc.pus_200_fsfw_mode import Mode +from tmtccmd.tc.pus_201_fsfw_health import FsfwHealth from tmtccmd.tm import Service5Tm from tmtccmd.util.tmtc_printer import FsfwTmTcPrinter @@ -37,7 +38,7 @@ def handle_event_packet(raw_tm: bytes, printer: FsfwTmTcPrinter): pw.printer.file_logger.info( f"{datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')}: {generic_event_string}" ) - _LOGGER.info(generic_event_string) + pw.ilog(_LOGGER, generic_event_string) specific_handler = True if info.name == "MODE_TRANSITION_FAILED": reason = generic_retval_printout(event_def.param1) @@ -88,6 +89,9 @@ def handle_event_packet(raw_tm: bytes, printer: FsfwTmTcPrinter): time = event_def.param1 + event_def.param2 / 1000.0 time_dt = datetime.datetime.fromtimestamp(time, datetime.timezone.utc) pw.dlog(f"Current time: {time_dt}") + elif info.name == "HEALTH_INFO": + health = FsfwHealth(event_def.param1) + pw.dlog(f"{obj_name}: {health!r}") else: specific_handler = False if info.info != "": diff --git a/eive_tmtc/tmtc/__init__.py b/eive_tmtc/tmtc/__init__.py index 311de35..4ec6c35 100644 --- a/eive_tmtc/tmtc/__init__.py +++ b/eive_tmtc/tmtc/__init__.py @@ -2,3 +2,4 @@ from .payload.subsystem import add_payload_subsystem_cmds from .solar_array_deployment import add_sa_depl_cmds from .test import add_test_defs from .time import add_time_cmds +from .health import add_health_cmd_defs diff --git a/eive_tmtc/tmtc/core.py b/eive_tmtc/tmtc/core.py index 0f45600..98d4739 100644 --- a/eive_tmtc/tmtc/core.py +++ b/eive_tmtc/tmtc/core.py @@ -10,7 +10,6 @@ from tmtccmd.config import TmtcDefinitionWrapper from tmtccmd.tc import DefaultPusQueueHelper from tmtccmd.pus.s8_fsfw_funccmd import create_action_cmd -from tmtccmd.logging import get_console_logger from tmtccmd.tc.pus_3_fsfw_hk import make_sid, generate_one_hk_command from tmtccmd.config.tmtc import OpCodeEntry, tmtc_definitions_provider from eive_tmtc.config.object_ids import CORE_CONTROLLER_ID diff --git a/eive_tmtc/tmtc/health.py b/eive_tmtc/tmtc/health.py new file mode 100644 index 0000000..4195004 --- /dev/null +++ b/eive_tmtc/tmtc/health.py @@ -0,0 +1,43 @@ +from eive_tmtc.config.definitions import CustomServiceList +from spacepackets.ecss import PusTelecommand +from tmtccmd.config.tmtc import ( + tmtc_definitions_provider, + TmtcDefinitionWrapper, + OpCodeEntry, +) +from tmtccmd.tc import service_provider +from tmtccmd.pus.s201_fsfw_health import Subservice +from tmtccmd.tc.decorator import ServiceProviderParams + + +class OpCode: + ANNOUNCE_HEALTH_ALL = "read_health_all" + ANNOUNCE_HEALTH = "read_health" + + +class Info: + ANNOUNCE_HEALTH_ALL = "Read all health states" + ANNOUNCE_HEALTH = "Read health state of one object" + + +@service_provider(CustomServiceList.HEALTH) +def pack_test_command(p: ServiceProviderParams): + o = p.op_code + q = p.queue_helper + if o == OpCode.ANNOUNCE_HEALTH: + raise NotImplementedError() + elif o == OpCode.ANNOUNCE_HEALTH_ALL: + q.add_log_cmd(Info.ANNOUNCE_HEALTH_ALL) + q.add_pus_tc( + PusTelecommand(service=201, subservice=Subservice.TC_ANNOUNCE_HEALTH_ALL) + ) + return + raise ValueError(f"unknown op code {o} for service {CustomServiceList.HEALTH}") + + +@tmtc_definitions_provider +def add_health_cmd_defs(defs: TmtcDefinitionWrapper): + oce = OpCodeEntry() + oce.add(OpCode.ANNOUNCE_HEALTH_ALL, Info.ANNOUNCE_HEALTH_ALL) + oce.add(OpCode.ANNOUNCE_HEALTH, Info.ANNOUNCE_HEALTH) + defs.add_service(CustomServiceList.HEALTH, info="Health Service", op_code_entry=oce) diff --git a/eive_tmtc/tmtc/tcs/heater.py b/eive_tmtc/tmtc/tcs/heater.py index fc7ad3e..b3f1d8e 100644 --- a/eive_tmtc/tmtc/tcs/heater.py +++ b/eive_tmtc/tmtc/tcs/heater.py @@ -33,10 +33,10 @@ class Heater(enum.IntEnum): class OpCode: - HEATER_CMD = ["0", "switch-cmd"] - HEATER_EXT_CTRL = ["1", "set-ext-ctrl"] - HEATER_FAULTY_CMD = ["2", "set-faulty"] - HEATER_HEALTHY_CMD = ["3", "set-healthy"] + HEATER_CMD = ["switch_cmd"] + HEATER_EXT_CTRL = ["set_ext_ctrl"] + HEATER_FAULTY_CMD = ["set_faulty"] + HEATER_HEALTHY_CMD = ["set_healthy"] class Info: