from spacepackets.ecss.pus_1_verification import UnpackParams from tmtccmd.logging import get_console_logger from tmtccmd.pus import VerificationWrapper from tmtccmd.tm.pus_1_verification import Service1TmExtended from config.retvals import get_retval_dict LOGGER = get_console_logger() def handle_service_1_packet(wrapper: VerificationWrapper, raw_tm: bytes): if wrapper.console_logger is None or wrapper.file_logger is None: raise ValueError( "Console logger or file logger not valid. Please set a valid one" ) tm_packet = Service1TmExtended.unpack(data=raw_tm, params=UnpackParams(1, 1)) res = wrapper.verificator.add_tm(tm_packet) if res is None: LOGGER.info( f"Received Verification TM[{tm_packet.service}, {tm_packet.subservice}] " f"with Request ID {tm_packet.tc_req_id.as_u32():#08x}" ) LOGGER.warning(f"No matching telecommand found for {tm_packet.tc_req_id}") else: wrapper.log_to_console(tm_packet, res) wrapper.log_to_file(tm_packet, res) retval_dict = get_retval_dict() if tm_packet.has_failure_notice: retval_info = retval_dict.get(tm_packet.error_code.val) if retval_info is None: LOGGER.info( f"No returnvalue information found for error code {tm_packet.error_code}" ) else: retval_string = ( f"Error Code information for code {tm_packet.error_code} | " f"Name: {retval_info.name} | Info: {retval_info.info}" ) wrapper.console_logger.info(retval_string) wrapper.file_logger.info(retval_string)