eive-tmtc/eive_tmtc/pus_tm/verification_handler.py

67 lines
2.5 KiB
Python
Raw Normal View History

2023-02-01 11:17:04 +01:00
import logging
2022-10-11 15:08:00 +02:00
from typing import List, Optional
2023-01-16 17:45:46 +01:00
from spacepackets.ccsds import CdsShortTimestamp
from spacepackets.ecss.pus_1_verification import UnpackParams, Service1Tm
2022-07-04 15:22:53 +02:00
from tmtccmd.pus import VerificationWrapper
2023-11-10 19:23:06 +01:00
from tmtccmd.pus.s1_verification import Service1FsfwWrapper
2022-11-29 16:53:29 +01:00
from eive_tmtc.config.retvals import get_retval_dict
2022-04-05 17:05:11 +02:00
2023-02-01 11:17:04 +01:00
_LOGGER = logging.getLogger(__name__)
2022-04-05 17:05:11 +02:00
def handle_service_1_fsfw_packet(wrapper: VerificationWrapper, raw_tm: bytes):
2022-07-04 15:22:53 +02:00
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"
)
# Error code with length 2 is FSFW specific
2023-01-16 17:45:46 +01:00
tm_packet = Service1Tm.unpack(
data=raw_tm, params=UnpackParams(CdsShortTimestamp.empty(), 1, 2)
)
fsfw_wrapper = Service1FsfwWrapper(tm_packet)
2022-07-04 15:22:53 +02:00
res = wrapper.verificator.add_tm(tm_packet)
if res is None:
2023-02-01 11:17:04 +01:00
_LOGGER.info(
2022-07-04 15:22:53 +02:00
f"Received Verification TM[{tm_packet.service}, {tm_packet.subservice}] "
f"with Request ID {tm_packet.tc_req_id.as_u32():#08x}"
)
2023-02-01 11:17:04 +01:00
_LOGGER.warning(f"No matching telecommand found for {tm_packet.tc_req_id}")
2022-07-04 15:22:53 +02:00
else:
wrapper.log_to_console(tm_packet, res)
wrapper.log_to_file(tm_packet, res)
if tm_packet.has_failure_notice:
2022-10-11 15:08:00 +02:00
str_list = generic_retval_printout(
tm_packet.error_code.val,
fsfw_wrapper.error_param_1,
fsfw_wrapper.error_param_2,
)
for string in str_list:
wrapper.dlog(string)
def generic_retval_printout(
retval: int, p1: Optional[int] = None, p2: Optional[int] = None
) -> List[str]:
retval_dict = get_retval_dict()
retval_info = retval_dict.get(retval)
if retval_info is None:
raw_err = retval
return [
2023-09-12 13:48:38 +02:00
"No returnvalue information found for error code with "
2022-10-11 15:08:00 +02:00
f"subsystem ID {(raw_err >> 8) & 0xff} and unique ID {raw_err & 0xff}"
]
else:
retval_string = (
f"Error Code information for code {retval:#06x} | "
f"Name: {retval_info.name} | Info: {retval_info.info}"
)
string_list = [retval_string]
if p1:
2023-09-12 13:48:38 +02:00
error_param_1_str = f"Error Parameter 1: hex {p1:#010x} dec {p1} "
2022-10-11 15:08:00 +02:00
string_list.append(error_param_1_str)
if p2:
2023-09-12 13:48:38 +02:00
error_param_2_str = f"Error Parameter 2: hex {p2:#010x} dec {p2}"
2022-10-11 15:08:00 +02:00
string_list.append(error_param_2_str)
return string_list