rework generator modules and remove fsfwgen deps as submodule

This commit is contained in:
2023-02-09 14:49:50 +01:00
parent e527695a33
commit 1cda86ee94
4 changed files with 101 additions and 81 deletions

View File

@ -41,63 +41,79 @@ CPP_H_FILENAME = Path(
f"{os.path.dirname(os.path.realpath(__file__))}/translateEvents.h"
)
BSP_SELECT = BspType.BSP_Q7S
BSP_DIR_NAME = BSP_SELECT.value
# Store this file in the root of the generators folder
CSV_FILENAME = Path(f"{ROOT_DIR}/{BSP_SELECT.value}_events.csv")
CSV_COPY_DEST = Path(f"{OBSW_ROOT_DIR}/tmtc/eive_tmtc/config/events.csv")
if BSP_SELECT == BspType.BSP_Q7S or BSP_SELECT == BspType.BSP_LINUX_BOARD:
FSFW_CONFIG_ROOT = Path(f"{OBSW_ROOT_DIR}/linux/fsfwconfig")
else:
FSFW_CONFIG_ROOT = Path(f"{OBSW_ROOT_DIR}/{BSP_DIR_NAME}/fsfwconfig")
CPP_COPY_DESTINATION = Path(f"{FSFW_CONFIG_ROOT}/events/")
FILE_SEPARATOR = ";"
SUBSYSTEM_DEFINITION_DESTINATIONS = [
f"{FSFW_CONFIG_ROOT}/events/subsystemIdRanges.h",
f"{OBSW_ROOT_DIR}/fsfw/src/fsfw/events/fwSubsystemIdRanges.h",
f"{OBSW_ROOT_DIR}/common/config/eive/eventSubsystemIds.h",
]
SUBSYSTEM_DEFS_DEST_AS_PATH = [Path(x) for x in SUBSYSTEM_DEFINITION_DESTINATIONS]
HEADER_DEFINITION_DESTINATIONS = [
f"{OBSW_ROOT_DIR}/mission/",
f"{OBSW_ROOT_DIR}/fsfw/",
f"{FSFW_CONFIG_ROOT}",
f"{OBSW_ROOT_DIR}/test/",
f"{OBSW_ROOT_DIR}/bsp_q7s/",
f"{OBSW_ROOT_DIR}/linux/",
]
HEADER_DEFINITION_DESTINATIONS_AS_PATH = [
Path(x) for x in HEADER_DEFINITION_DESTINATIONS
]
class BspConfig:
def __init__(self, bsp_select: BspType):
self.bsp_select = bsp_select
self.bsp_dir_name = self.bsp_select.value
# Store this file in the root of the generators folder
self.csv_filename = Path(f"{ROOT_DIR}/{self.bsp_dir_name}_events.csv")
self.csv_copy_dest = Path(f"{OBSW_ROOT_DIR}/tmtc/eive_tmtc/config/events.csv")
if (
self.bsp_select == BspType.BSP_Q7S
or self.bsp_select == BspType.BSP_LINUX_BOARD
):
self.fsfw_config_root = Path(f"{OBSW_ROOT_DIR}/linux/fsfwconfig")
else:
self.fsfw_config_root = Path(
f"{OBSW_ROOT_DIR}/{self.bsp_dir_name}/fsfwconfig"
)
self.cpp_copy_dest = Path(f"{self.fsfw_config_root}/events/")
self.subystem_defs_destinations = [
f"{self.fsfw_config_root}/events/subsystemIdRanges.h",
f"{OBSW_ROOT_DIR}/fsfw/src/fsfw/events/fwSubsystemIdRanges.h",
f"{OBSW_ROOT_DIR}/common/config/eive/eventSubsystemIds.h",
]
self.header_defs_destinations = [
f"{OBSW_ROOT_DIR}/mission/",
f"{OBSW_ROOT_DIR}/fsfw/",
f"{self.fsfw_config_root}",
f"{OBSW_ROOT_DIR}/test/",
f"{OBSW_ROOT_DIR}/bsp_q7s/",
f"{OBSW_ROOT_DIR}/linux/",
]
def subsystem_defs_as_paths(self):
return [Path(x) for x in self.subystem_defs_destinations]
def header_defs_as_paths(self):
return [Path(x) for x in self.header_defs_destinations]
LOGGER = get_console_logger()
def parse_events(
generate_csv: bool = True, generate_cpp: bool = True
bsp_type: BspType, generate_csv: bool = True, generate_cpp: bool = True
):
bsp_cfg = BspConfig(bsp_type)
LOGGER.info("EventParser: Parsing events: ")
# Small delay for clean printout
time.sleep(0.01)
event_list = generate_event_list()
event_list = generate_event_list(bsp_cfg)
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
file_name=bsp_cfg.csv_filename,
event_list=event_list,
file_separator=FILE_SEPARATOR,
)
LOGGER.info(f"Copying CSV file to {CSV_COPY_DEST}")
LOGGER.info(f"Copying CSV file to {bsp_cfg.cpp_copy_dest}")
copy_file(
filename=CSV_FILENAME, destination=CSV_COPY_DEST, delete_existing_file=True
filename=bsp_cfg.csv_filename,
destination=bsp_cfg.csv_copy_dest,
delete_existing_file=True,
)
if generate_cpp:
@ -110,18 +126,18 @@ def parse_events(
)
if COPY_CPP_FILE:
LOGGER.info(
f"EventParser: Copying CPP translation file to {CPP_COPY_DESTINATION}"
f"EventParser: Copying CPP translation file to {bsp_cfg.cpp_copy_dest}"
)
copy_file(CPP_FILENAME, CPP_COPY_DESTINATION)
copy_file(CPP_H_FILENAME, CPP_COPY_DESTINATION)
copy_file(CPP_FILENAME, bsp_cfg.cpp_copy_dest)
copy_file(CPP_H_FILENAME, bsp_cfg.cpp_copy_dest)
def generate_event_list() -> EventDictT:
subsystem_parser = SubsystemDefinitionParser(SUBSYSTEM_DEFS_DEST_AS_PATH)
def generate_event_list(cfg: BspConfig) -> EventDictT:
subsystem_parser = SubsystemDefinitionParser(cfg.subsystem_defs_as_paths())
subsystem_table = subsystem_parser.parse_files()
LOGGER.info(f"Found {len(subsystem_table)} subsystem definitions.")
PrettyPrinter.pprint(subsystem_table)
event_header_parser = FileListParser(HEADER_DEFINITION_DESTINATIONS_AS_PATH)
event_header_parser = FileListParser(cfg.header_defs_as_paths())
event_headers = event_header_parser.parse_header_files(
True, "Parsing event header file list:\n", True
)