continuing refactoring of printouts
This commit is contained in:
@ -1,7 +1,9 @@
|
||||
import logging
|
||||
import os.path
|
||||
|
||||
from datetime import datetime
|
||||
from config.object_ids import get_object_ids
|
||||
|
||||
from tmtccmd.tm import Service5Tm
|
||||
from tmtccmd.logging import get_console_logger
|
||||
from tmtccmd.fsfw import parse_fsfw_events_csv, EventDictT, EventInfo
|
||||
|
||||
@ -22,26 +24,33 @@ def get_event_dict() -> EventDictT:
|
||||
return __EVENT_DICT
|
||||
|
||||
|
||||
def handle_event_packet(
|
||||
object_id: bytes, event_id: int, param_1: int, param_2: int
|
||||
) -> str:
|
||||
def handle_event_packet(file_logger: logging.Logger, tm: Service5Tm) -> str:
|
||||
additional_event_info = ""
|
||||
event_dict = get_event_dict()
|
||||
info = event_dict.get(event_id)
|
||||
info = event_dict.get(tm.event_id)
|
||||
if info is None:
|
||||
LOGGER.warning(f"Event ID {event_id} has no information")
|
||||
LOGGER.warning(f"Event ID {tm.event_id} has no information")
|
||||
info = EventInfo()
|
||||
info.name = "Unknown event"
|
||||
obj_ids = get_object_ids()
|
||||
obj_id_obj = obj_ids.get(bytes(object_id))
|
||||
obj_id_obj = obj_ids.get(tm.reporter_id.as_bytes)
|
||||
if obj_id_obj is None:
|
||||
LOGGER.warning(f"Object ID 0x{object_id.hex()} has no name")
|
||||
obj_name = object_id.hex()
|
||||
LOGGER.warning(f"Object ID 0x{tm.reporter_id.as_string} has no name")
|
||||
obj_name = tm.reporter_id.as_string
|
||||
else:
|
||||
obj_name = obj_id_obj.name
|
||||
generic_event_string = f"Object {obj_name} generated Event {event_id} | {info.name}"
|
||||
generic_event_string = (
|
||||
f"Object {obj_name} generated Event {tm.event_id} | {info.name}"
|
||||
)
|
||||
if info.info != "":
|
||||
additional_event_info = (
|
||||
f" | Additional info: {info.info} | P1: {param_1} | P2: {param_2}"
|
||||
f"Additional info: {info.info} | P1: {tm.param_1} | P2: {tm.param_2}"
|
||||
)
|
||||
return generic_event_string + additional_event_info
|
||||
file_logger.info(
|
||||
f"{datetime.now().strftime('%Y-%m-%d %H:%M:%S')}: {generic_event_string}"
|
||||
)
|
||||
LOGGER.info(generic_event_string)
|
||||
if additional_event_info != "":
|
||||
file_logger.info(additional_event_info)
|
||||
print(additional_event_info)
|
||||
return generic_event_string + " | " + additional_event_info
|
||||
|
Reference in New Issue
Block a user