2021-08-02 11:43:49 +02:00
|
|
|
"""Part of the Mission Operation Database Exporter for the EVIE project.
|
2021-05-17 19:39:35 +02:00
|
|
|
Event exporter.
|
|
|
|
"""
|
|
|
|
import datetime
|
2021-08-02 11:43:49 +02:00
|
|
|
import time
|
2022-03-01 18:03:50 +01:00
|
|
|
import os
|
2022-06-20 18:05:05 +02:00
|
|
|
from pathlib import Path
|
2022-03-01 18:03:50 +01:00
|
|
|
|
|
|
|
from fsfwgen.events.event_parser import (
|
|
|
|
handle_csv_export,
|
|
|
|
handle_cpp_export,
|
|
|
|
SubsystemDefinitionParser,
|
|
|
|
EventParser,
|
2022-06-21 00:58:59 +02:00
|
|
|
EventDictT,
|
2022-03-01 18:03:50 +01:00
|
|
|
)
|
2021-06-08 17:10:47 +02:00
|
|
|
from fsfwgen.parserbase.file_list_parser import FileListParser
|
|
|
|
from fsfwgen.utility.printer import PrettyPrinter
|
2022-03-01 18:03:50 +01:00
|
|
|
from fsfwgen.utility.file_management import copy_file
|
2022-06-21 00:58:59 +02:00
|
|
|
from fsfwgen.logging import get_console_logger
|
2021-08-02 11:43:49 +02:00
|
|
|
from definitions import BspType, ROOT_DIR, OBSW_ROOT_DIR
|
2021-05-17 19:39:35 +02:00
|
|
|
|
2021-08-02 11:43:49 +02:00
|
|
|
LOGGER = get_console_logger()
|
2021-05-17 19:39:35 +02:00
|
|
|
DATE_TODAY = datetime.datetime.now()
|
|
|
|
DATE_STRING_FULL = DATE_TODAY.strftime("%Y-%m-%d %H:%M:%S")
|
|
|
|
|
|
|
|
GENERATE_CPP = True
|
|
|
|
GENERATE_CPP_H = True
|
|
|
|
GENERATE_CSV = True
|
|
|
|
COPY_CPP_FILE = True
|
|
|
|
COPY_CPP_H_FILE = True
|
|
|
|
MOVE_CSV_FILE = True
|
|
|
|
|
|
|
|
PARSE_HOST_BSP = True
|
|
|
|
|
2022-03-01 18:03:50 +01:00
|
|
|
# Store these files relative to the events folder
|
2022-06-21 00:58:59 +02:00
|
|
|
CPP_FILENAME = Path(
|
|
|
|
f"{os.path.dirname(os.path.realpath(__file__))}/translateEvents.cpp"
|
|
|
|
)
|
|
|
|
CPP_H_FILENAME = Path(
|
|
|
|
f"{os.path.dirname(os.path.realpath(__file__))}/translateEvents.h"
|
|
|
|
)
|
2021-05-17 19:39:35 +02:00
|
|
|
|
2021-05-17 19:50:24 +02:00
|
|
|
BSP_SELECT = BspType.BSP_Q7S
|
2021-05-17 19:39:35 +02:00
|
|
|
|
|
|
|
BSP_DIR_NAME = BSP_SELECT.value
|
|
|
|
|
2022-03-01 18:03:50 +01:00
|
|
|
# Store this file in the root of the generators folder
|
2022-06-20 18:05:05 +02:00
|
|
|
CSV_FILENAME = Path(f"{ROOT_DIR}/{BSP_SELECT.value}_events.csv")
|
2022-11-29 16:55:55 +01:00
|
|
|
CSV_COPY_DEST = Path(f"{OBSW_ROOT_DIR}/tmtc/eive_tmtc/config/events.csv")
|
2021-05-18 16:16:02 +02:00
|
|
|
|
2021-05-17 19:39:35 +02:00
|
|
|
if BSP_SELECT == BspType.BSP_Q7S or BSP_SELECT == BspType.BSP_LINUX_BOARD:
|
2022-06-20 18:05:05 +02:00
|
|
|
FSFW_CONFIG_ROOT = Path(f"{OBSW_ROOT_DIR}/linux/fsfwconfig")
|
2021-05-17 19:39:35 +02:00
|
|
|
|
|
|
|
else:
|
2022-06-20 18:05:05 +02:00
|
|
|
FSFW_CONFIG_ROOT = Path(f"{OBSW_ROOT_DIR}/{BSP_DIR_NAME}/fsfwconfig")
|
2021-05-17 19:39:35 +02:00
|
|
|
|
2022-06-20 18:05:05 +02:00
|
|
|
CPP_COPY_DESTINATION = Path(f"{FSFW_CONFIG_ROOT}/events/")
|
2021-05-17 19:39:35 +02:00
|
|
|
|
|
|
|
FILE_SEPARATOR = ";"
|
|
|
|
SUBSYSTEM_DEFINITION_DESTINATIONS = [
|
|
|
|
f"{FSFW_CONFIG_ROOT}/events/subsystemIdRanges.h",
|
2021-08-02 11:43:49 +02:00
|
|
|
f"{OBSW_ROOT_DIR}/fsfw/src/fsfw/events/fwSubsystemIdRanges.h",
|
2022-09-27 09:33:34 +02:00
|
|
|
f"{OBSW_ROOT_DIR}/common/config/eive/eventSubsystemIds.h",
|
2021-08-02 11:43:49 +02:00
|
|
|
]
|
2022-06-20 18:05:05 +02:00
|
|
|
SUBSYSTEM_DEFS_DEST_AS_PATH = [Path(x) for x in SUBSYSTEM_DEFINITION_DESTINATIONS]
|
|
|
|
|
2021-08-02 11:43:49 +02:00
|
|
|
HEADER_DEFINITION_DESTINATIONS = [
|
2022-03-01 18:03:50 +01:00
|
|
|
f"{OBSW_ROOT_DIR}/mission/",
|
|
|
|
f"{OBSW_ROOT_DIR}/fsfw/",
|
|
|
|
f"{FSFW_CONFIG_ROOT}",
|
|
|
|
f"{OBSW_ROOT_DIR}/test/",
|
2022-06-20 18:05:05 +02:00
|
|
|
f"{OBSW_ROOT_DIR}/bsp_q7s/",
|
2022-03-01 18:03:50 +01:00
|
|
|
f"{OBSW_ROOT_DIR}/linux/",
|
2021-05-17 19:39:35 +02:00
|
|
|
]
|
2022-06-20 18:05:05 +02:00
|
|
|
HEADER_DEFINITION_DESTINATIONS_AS_PATH = [
|
|
|
|
Path(x) for x in HEADER_DEFINITION_DESTINATIONS
|
|
|
|
]
|
2021-05-17 19:39:35 +02:00
|
|
|
|
2022-06-21 00:58:59 +02:00
|
|
|
LOGGER = get_console_logger()
|
|
|
|
|
2021-05-17 19:39:35 +02:00
|
|
|
|
2021-08-02 11:43:49 +02:00
|
|
|
def parse_events(
|
2022-03-01 18:03:50 +01:00
|
|
|
generate_csv: bool = True, generate_cpp: bool = True, print_events: bool = True
|
2021-08-02 11:43:49 +02:00
|
|
|
):
|
|
|
|
LOGGER.info("EventParser: Parsing events: ")
|
|
|
|
# Small delay for clean printout
|
|
|
|
time.sleep(0.01)
|
|
|
|
event_list = generate_event_list()
|
|
|
|
if print_events:
|
|
|
|
PrettyPrinter.pprint(event_list)
|
|
|
|
# Delay for clean printout
|
|
|
|
time.sleep(0.1)
|
|
|
|
if generate_csv:
|
|
|
|
handle_csv_export(
|
|
|
|
file_name=CSV_FILENAME, event_list=event_list, file_separator=FILE_SEPARATOR
|
|
|
|
)
|
2022-03-07 13:20:17 +01:00
|
|
|
LOGGER.info(f"Copying CSV file to {CSV_COPY_DEST}")
|
|
|
|
copy_file(
|
|
|
|
filename=CSV_FILENAME, destination=CSV_COPY_DEST, delete_existing_file=True
|
|
|
|
)
|
2022-03-04 15:14:02 +01:00
|
|
|
|
2021-08-02 11:43:49 +02:00
|
|
|
if generate_cpp:
|
2021-05-17 19:39:35 +02:00
|
|
|
handle_cpp_export(
|
2022-03-01 18:03:50 +01:00
|
|
|
event_list=event_list,
|
|
|
|
date_string=DATE_STRING_FULL,
|
|
|
|
file_name=CPP_FILENAME,
|
|
|
|
generate_header=GENERATE_CPP_H,
|
|
|
|
header_file_name=CPP_H_FILENAME,
|
2021-05-17 19:39:35 +02:00
|
|
|
)
|
|
|
|
if COPY_CPP_FILE:
|
2022-06-20 18:05:05 +02:00
|
|
|
LOGGER.info(
|
|
|
|
f"EventParser: Copying CPP translation file to {CPP_COPY_DESTINATION}"
|
|
|
|
)
|
2021-05-17 19:39:35 +02:00
|
|
|
copy_file(CPP_FILENAME, CPP_COPY_DESTINATION)
|
|
|
|
copy_file(CPP_H_FILENAME, CPP_COPY_DESTINATION)
|
|
|
|
|
|
|
|
|
2022-06-21 00:58:59 +02:00
|
|
|
def generate_event_list() -> EventDictT:
|
2022-06-20 18:05:05 +02:00
|
|
|
subsystem_parser = SubsystemDefinitionParser(SUBSYSTEM_DEFS_DEST_AS_PATH)
|
2021-05-17 19:39:35 +02:00
|
|
|
subsystem_table = subsystem_parser.parse_files()
|
2022-03-01 18:03:50 +01:00
|
|
|
LOGGER.info(f"Found {len(subsystem_table)} subsystem definitions.")
|
2021-05-17 19:39:35 +02:00
|
|
|
PrettyPrinter.pprint(subsystem_table)
|
2022-06-20 18:05:05 +02:00
|
|
|
event_header_parser = FileListParser(HEADER_DEFINITION_DESTINATIONS_AS_PATH)
|
2021-05-17 19:39:35 +02:00
|
|
|
event_headers = event_header_parser.parse_header_files(
|
|
|
|
True, "Parsing event header file list:\n", True
|
|
|
|
)
|
|
|
|
# PrettyPrinter.pprint(event_headers)
|
|
|
|
# myEventList = parseHeaderFiles(subsystem_table, event_headers)
|
|
|
|
event_parser = EventParser(event_headers, subsystem_table)
|
2022-03-01 18:03:50 +01:00
|
|
|
event_parser.obsw_root_path = OBSW_ROOT_DIR
|
2021-05-17 19:39:35 +02:00
|
|
|
event_parser.set_moving_window_mode(moving_window_size=7)
|
|
|
|
event_table = event_parser.parse_files()
|
2022-06-21 00:58:59 +02:00
|
|
|
events_sorted = dict(sorted(event_table.items()))
|
|
|
|
LOGGER.info(f"Found {len(events_sorted)} entries")
|
|
|
|
return events_sorted
|