From fdb14cbdc57d8ddd2e6a90deb19430c7bccb0ccc Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 10 Jul 2023 16:07:01 +0200 Subject: [PATCH] HK level is a CLI argument now --- CHANGELOG.md | 4 ++++ eive_tmtc/pus_tm/hk_handling.py | 7 +++---- eive_tmtc/pus_tm/pus_demux.py | 3 ++- eive_tmtc/tmtc/tcs/defs.py | 1 + pyproject.toml | 4 ++-- tmtcc.py | 23 ++++++++++++++++------- 6 files changed, 28 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e3dbd2e..df9fb14 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,10 @@ list yields a list of all related PRs for each release. - New TCS controller events +## Changed + +- HK level can be specified as CLI argument now. + # [v5.1.0] 2023-06-28 ## Added diff --git a/eive_tmtc/pus_tm/hk_handling.py b/eive_tmtc/pus_tm/hk_handling.py index 68cf432..fcc7e97 100644 --- a/eive_tmtc/pus_tm/hk_handling.py +++ b/eive_tmtc/pus_tm/hk_handling.py @@ -45,14 +45,13 @@ _LOGGER = logging.getLogger(__name__) FORWARD_SENSOR_TEMPS = False -# TODO: Transform this into a CLI argument -HK_OUTPUT_LEVEL = 1 def handle_hk_packet( raw_tm: bytes, obj_id_dict: ObjectIdDictT, printer: FsfwTmTcPrinter, + hk_level: int ): tm_packet = Service3FsfwTm.unpack(raw_telemetry=raw_tm, custom_hk_handling=False) named_obj_id = obj_id_dict.get(tm_packet.object_id.as_bytes) @@ -73,9 +72,9 @@ def handle_hk_packet( hk_data=hk_data, ) try: - if HK_OUTPUT_LEVEL == 1: + if hk_level == 1: pass - elif HK_OUTPUT_LEVEL > 1: + elif hk_level > 1: handle_regular_hk_print( printer=printer, object_id=named_obj_id, diff --git a/eive_tmtc/pus_tm/pus_demux.py b/eive_tmtc/pus_tm/pus_demux.py index 89ccb11..66de46f 100644 --- a/eive_tmtc/pus_tm/pus_demux.py +++ b/eive_tmtc/pus_tm/pus_demux.py @@ -29,6 +29,7 @@ def pus_factory_hook( # noqa C901 : Complexity okay here verif_wrapper: VerificationWrapper, printer: FsfwTmTcPrinter, raw_logger: RawTmtcTimedLogWrapper, + hk_level: int ): if len(packet) < 8: _LOGGER.warning("Detected packet shorter than 8 bytes!") @@ -48,7 +49,7 @@ def pus_factory_hook( # noqa C901 : Complexity okay here if service == 1: handle_service_1_fsfw_packet(wrapper=verif_wrapper, raw_tm=packet) elif service == 3: - handle_hk_packet(printer=printer, raw_tm=packet, obj_id_dict=obj_id_dict) + handle_hk_packet(printer=printer, raw_tm=packet, obj_id_dict=obj_id_dict, hk_level=hk_level) elif service == 5: handle_event_packet(raw_tm=packet, pw=pw) elif service == 8: diff --git a/eive_tmtc/tmtc/tcs/defs.py b/eive_tmtc/tmtc/tcs/defs.py index 6ec5a0a..8eb631a 100644 --- a/eive_tmtc/tmtc/tcs/defs.py +++ b/eive_tmtc/tmtc/tcs/defs.py @@ -6,6 +6,7 @@ class CtrlSetId(enum.IntEnum): DEVICE_SENSORS = 1 SUS_TEMP_SENSORS = 2 HEATER_INFO = 4 + TCS_CTRL_INFO = 5 class TcsSubmode(enum.IntEnum): diff --git a/pyproject.toml b/pyproject.toml index 5915d1b..7abd90a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -29,9 +29,9 @@ classifiers = [ "Topic :: Scientific/Engineering" ] dependencies = [ - "tmtccmd ~= 5.0.0rc0", + # "tmtccmd ~= 5.0.0rc0", "python-dateutil ~= 2.8", - # tmtccmd @ git+https://github.com/robamu-org/tmtccmd@#egg=tmtccmd + tmtccmd @ git+https://github.com/robamu-org/tmtccmd@1b110d321ef85#egg=tmtccmd ] [project.urls] diff --git a/tmtcc.py b/tmtcc.py index 94a8d84..473aeb3 100755 --- a/tmtcc.py +++ b/tmtcc.py @@ -166,16 +166,18 @@ class PusHandler(SpecificApidHandlerBase): wrapper: VerificationWrapper, printer: FsfwTmTcPrinter, raw_logger: RawTmtcTimedLogWrapper, + hk_level: int ): super().__init__(PUS_APID, None) self.printer = printer self.verif_wrapper = wrapper self.raw_logger = raw_logger + self.hk_level = hk_level def handle_tm(self, packet: bytes, _user_args: any): # with open("tc.bin", "wb") as of: # of.write(packet) - pus_factory_hook(packet, self.verif_wrapper, self.printer, self.raw_logger) + pus_factory_hook(packet, self.verif_wrapper, self.printer, self.raw_logger, self.hk_level) class UnknownApidHandler(GenericApidHandlerBase): @@ -335,13 +337,18 @@ class TcHandler(TcHandlerBase): _LOGGER.info("Finished CFDP queue") -def setup_params() -> SetupWrapper: +def setup_params() -> (SetupWrapper, int): hook_obj = EiveHookObject(default_json_path()) params = SetupParams() parser_wrapper = PreArgsParsingWrapper() parser_wrapper.create_default_parent_parser() parser_wrapper.create_default_parser() - parser_wrapper.add_def_proc_and_cfdp_as_subparsers() + tmtc_parser, cfdp_parser = parser_wrapper.add_def_proc_and_cfdp_as_subparsers() + tmtc_parser.add_argument( + "--hk", + help="HK output level", + default=2, + ) post_arg_parsing_wrapper = parser_wrapper.parse( setup_params=params, hook_obj=hook_obj ) @@ -352,13 +359,14 @@ def setup_params() -> SetupWrapper: post_arg_parsing_wrapper.set_params_with_prompts(proc_param_wrapper) else: post_arg_parsing_wrapper.set_params_without_prompts(proc_param_wrapper) + hk_level = int(post_arg_parsing_wrapper.args_raw.hk) params.apid = PUS_APID if params.com_if is None: raise ValueError("could not determine a COM interface.") setup_wrapper = SetupWrapper( hook_obj=hook_obj, setup_params=params, proc_param_wrapper=proc_param_wrapper ) - return setup_wrapper + return setup_wrapper, hk_level def setup_cfdp_handler() -> CfdpInCcsdsWrapper: @@ -400,12 +408,13 @@ def setup_tmtc_handlers( printer: FsfwTmTcPrinter, raw_logger: RawTmtcTimedLogWrapper, gui: bool, + hk_level: int ) -> (CcsdsTmHandler, TcHandler): cfdp_in_ccsds_wrapper = setup_cfdp_handler() verification_wrapper = VerificationWrapper( verificator, _LOGGER, printer.file_logger ) - pus_handler = PusHandler(verification_wrapper, printer, raw_logger) + pus_handler = PusHandler(verification_wrapper, printer, raw_logger, hk_level) ccsds_handler = CustomCcsdsTmHandler(generic_handler=UnknownApidHandler(None)) ccsds_handler.add_apid_handler(pus_handler) ccsds_handler.add_apid_handler(cfdp_in_ccsds_wrapper) @@ -444,7 +453,7 @@ def main(): # noqa C901: Complexity okay here. # TODO: -V CLI argument to enable this? _LOGGER.setLevel(_LOG_LEVEL) try: - setup_wrapper = setup_params() + setup_wrapper, hk_level = setup_params() except KeyboardInterrupt as e: _LOGGER.info(f"{e}. Exiting") sys.exit(0) @@ -457,7 +466,7 @@ def main(): # noqa C901: Complexity okay here. ) pus_verificator = PusVerificator() ccsds_handler, tc_handler = setup_tmtc_handlers( - pus_verificator, printer, raw_logger, setup_wrapper.params.use_gui + pus_verificator, printer, raw_logger, setup_wrapper.params.use_gui, hk_level ) tmtccmd.setup(setup_wrapper)