75 lines
2.2 KiB
Python
75 lines
2.2 KiB
Python
import csv
|
|
import enum
|
|
from typing import Optional
|
|
import os.path
|
|
|
|
from config.object_ids import get_object_ids, PUS_SERVICE_17_ID
|
|
from tmtccmd.utility.logger import get_console_logger
|
|
|
|
LOGGER = get_console_logger()
|
|
DEFAULT_EVENTS_CSV_PATH = "config/events.csv"
|
|
__RETURNVALUE_DICT = None
|
|
|
|
|
|
class Severity(enum.IntEnum):
|
|
INFO = (0,)
|
|
LOW = (1,)
|
|
MEDIUM = (2,)
|
|
HIGH = 3
|
|
|
|
|
|
def str_to_severity(string: str) -> Optional[Severity]:
|
|
if string == "INFO":
|
|
return Severity.INFO
|
|
elif string == "LOW":
|
|
return Severity.LOW
|
|
elif string == "MEDIUM":
|
|
return Severity.MEDIUM
|
|
elif string == "HIGH":
|
|
return Severity.HIGH
|
|
|
|
|
|
class ReturnValueInfo:
|
|
id: int = 0
|
|
name: str = ""
|
|
severity: str = ""
|
|
info: str = ""
|
|
file_location: str = ""
|
|
|
|
|
|
def handle_event_packet(
|
|
object_id: bytes, event_id: int, param_1: int, param_2: int
|
|
) -> str:
|
|
object_id = PUS_SERVICE_17_ID
|
|
event_id = 2601
|
|
global __RETURNVALUE_DICT
|
|
if os.path.exists(DEFAULT_EVENTS_CSV_PATH) and __RETURNVALUE_DICT is None:
|
|
__RETURNVALUE_DICT = dict()
|
|
with open(DEFAULT_EVENTS_CSV_PATH) as csvfile:
|
|
csv_reader = csv.reader(csvfile, delimiter=";")
|
|
info = ReturnValueInfo()
|
|
for row in csv_reader:
|
|
info.id = int(row[0])
|
|
info.name = row[2]
|
|
info.severity = str_to_severity(row[3])
|
|
info.info = row[4]
|
|
info.file_location = row[5]
|
|
__RETURNVALUE_DICT.update(
|
|
{info.id: info}
|
|
)
|
|
generic_event_string = ""
|
|
additional_event_info = ""
|
|
if __RETURNVALUE_DICT is not None:
|
|
info = __RETURNVALUE_DICT.get(event_id)
|
|
obj_ids = get_object_ids()
|
|
obj_id_obj = obj_ids.get(object_id)
|
|
if obj_id_obj is None:
|
|
LOGGER.warning(f"Object ID 0x{object_id.hex()} has no name")
|
|
obj_name = object_id.hex()
|
|
else:
|
|
obj_name = obj_id_obj.name
|
|
generic_event_string = f"Object {obj_name} generated Event {event_id} | {info.name}"
|
|
if info.info != "":
|
|
additional_event_info = f" | Additional info: {info.info}"
|
|
return generic_event_string + additional_event_info
|