From 1cda86ee94fbdbd284f0d69884fb2f02b1d9451c Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Thu, 9 Feb 2023 14:49:50 +0100 Subject: [PATCH] rework generator modules and remove fsfwgen deps as submodule --- .gitmodules | 3 - generators/deps/fsfwgen | 1 - generators/events/event_parser.py | 104 ++++++++++-------- .../returnvalues/returnvalues_parser.py | 74 +++++++------ 4 files changed, 101 insertions(+), 81 deletions(-) delete mode 160000 generators/deps/fsfwgen diff --git a/.gitmodules b/.gitmodules index 50e2e6e1..76fb8527 100644 --- a/.gitmodules +++ b/.gitmodules @@ -10,9 +10,6 @@ [submodule "thirdparty/lwgps"] path = thirdparty/lwgps url = https://github.com/rmspacefish/lwgps.git -[submodule "generators/fsfwgen"] - path = generators/deps/fsfwgen - url = https://egit.irs.uni-stuttgart.de/fsfw/fsfw-gen.git [submodule "thirdparty/arcsec_star_tracker"] path = thirdparty/arcsec_star_tracker url = https://egit.irs.uni-stuttgart.de/eive/arcsec_star_tracker.git diff --git a/generators/deps/fsfwgen b/generators/deps/fsfwgen deleted file mode 160000 index b1e5a2d4..00000000 --- a/generators/deps/fsfwgen +++ /dev/null @@ -1 +0,0 @@ -Subproject commit b1e5a2d40a5f41b9020f2beb0b976035f91c6343 diff --git a/generators/events/event_parser.py b/generators/events/event_parser.py index 8dd4952b..284b13a4 100644 --- a/generators/events/event_parser.py +++ b/generators/events/event_parser.py @@ -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 ) diff --git a/generators/returnvalues/returnvalues_parser.py b/generators/returnvalues/returnvalues_parser.py index 6ad893d1..f4da066c 100644 --- a/generators/returnvalues/returnvalues_parser.py +++ b/generators/returnvalues/returnvalues_parser.py @@ -14,7 +14,6 @@ from fsfwgen.returnvalues.returnvalues_parser import ( RetvalDictT, ) from fsfwgen.utility.sql_writer import SqlWriter -from fsfwgen.utility.printer import PrettyPrinter from definitions import BspType, DATABASE_NAME, ROOT_DIR, OBSW_ROOT_DIR @@ -28,33 +27,41 @@ PRINT_TABLES = False FILE_SEPARATOR = ";" MAX_STRING_LENGTH = 32 -BSP_SELECT = BspType.BSP_Q7S -BSP_DIR_NAME = BSP_SELECT.value -CSV_RETVAL_FILENAME = Path(f"{ROOT_DIR}/{BSP_SELECT.value}_returnvalues.csv") + +class BspConfig: + def __init__(self, bps_select: BspType): + self.bsp_dir_name = bps_select.value + self.csv_retval_filename = Path( + f"{ROOT_DIR}/{self.bsp_dir_name}_returnvalues.csv" + ) + self.add_linux_folder = False + if bps_select == BspType.BSP_Q7S or bps_select == BspType.BSP_LINUX_BOARD: + self.fsfw_config_root = f"{OBSW_ROOT_DIR}/linux/fsfwconfig" + self.add_linux_folder = True + else: + self.fsfw_config_root = f"{OBSW_ROOT_DIR}/{self.bsp_dir_name}/fsfwconfig" + self.bsp_path = f"{OBSW_ROOT_DIR}/{self.bsp_dir_name}" + self.retval_sources = [ + f"{OBSW_ROOT_DIR}/mission/", + f"{OBSW_ROOT_DIR}/fsfw/", + f"{self.bsp_path}", + ] + if self.add_linux_folder: + self.retval_sources.append(f"{OBSW_ROOT_DIR}/linux") + + def if_definition_files(self): + return [ + f"{OBSW_ROOT_DIR}/fsfw/src/fsfw/returnvalues/FwClassIds.h", + f"{OBSW_ROOT_DIR}/common/config/eive/resultClassIds.h", + f"{self.fsfw_config_root}/returnvalues/classIds.h", + ] + + def retval_sources_as_path(self): + return [Path(x) for x in self.retval_sources] + + CSV_COPY_DEST = Path(f"{OBSW_ROOT_DIR}/tmtc/eive_tmtc/config/returnvalues.csv") -ADD_LINUX_FOLDER = False -if BSP_SELECT == BspType.BSP_Q7S or BSP_SELECT == BspType.BSP_LINUX_BOARD: - FSFW_CONFIG_ROOT = f"{OBSW_ROOT_DIR}/linux/fsfwconfig" - ADD_LINUX_FOLDER = True -else: - FSFW_CONFIG_ROOT = f"{OBSW_ROOT_DIR}/{BSP_DIR_NAME}/fsfwconfig" -BSP_PATH = f"{OBSW_ROOT_DIR}/{BSP_DIR_NAME}" - -INTERFACE_DEFINITION_FILES = [ - f"{OBSW_ROOT_DIR}/fsfw/src/fsfw/returnvalues/FwClassIds.h", - f"{OBSW_ROOT_DIR}/common/config/eive/resultClassIds.h", - f"{FSFW_CONFIG_ROOT}/returnvalues/classIds.h", -] -RETURNVALUE_SOURCES = [ - f"{OBSW_ROOT_DIR}/mission/", - f"{OBSW_ROOT_DIR}/fsfw/", - f"{BSP_PATH}", -] -RETVAL_SRCS_AS_PATH = [Path(x) for x in RETURNVALUE_SOURCES] - -if ADD_LINUX_FOLDER: - RETURNVALUE_SOURCES.append(f"{OBSW_ROOT_DIR}/linux") SQL_DELETE_RETURNVALUES_CMD = """ DROP TABLE IF EXISTS Returnvalues @@ -77,15 +84,16 @@ VALUES(?,?,?,?,?) """ -def parse_returnvalues(): - returnvalue_table = generate_returnvalue_table() +def parse_returnvalues(bsp_select: BspType): + cfg = BspConfig(bsp_select) + returnvalue_table = generate_returnvalue_table(cfg) if EXPORT_TO_FILE: ReturnValueParser.export_to_csv( - CSV_RETVAL_FILENAME, returnvalue_table, FILE_SEPARATOR + cfg.csv_retval_filename, returnvalue_table, FILE_SEPARATOR ) if COPY_CSV_FILE: copy_file( - filename=CSV_RETVAL_FILENAME, + filename=cfg.csv_retval_filename, destination=CSV_COPY_DEST, delete_existing_file=True, ) @@ -96,13 +104,13 @@ def parse_returnvalues(): ) -def generate_returnvalue_table(): +def generate_returnvalue_table(cfg: BspConfig): """Core function to parse for the return values""" interface_parser = InterfaceParser( - file_list=INTERFACE_DEFINITION_FILES, print_table=PRINT_TABLES + file_list=cfg.if_definition_files(), print_table=PRINT_TABLES ) interfaces = interface_parser.parse_files() - header_parser = FileListParser(RETVAL_SRCS_AS_PATH) + header_parser = FileListParser(cfg.retval_sources_as_path()) header_list = header_parser.parse_header_files(True, "Parsing header file list: ") returnvalue_parser = ReturnValueParser(interfaces, header_list, PRINT_TABLES) returnvalue_parser.obsw_root_path = OBSW_ROOT_DIR