continuing rework of generators
All checks were successful
EIVE/eive-obsw/pipeline/head This commit looks good
All checks were successful
EIVE/eive-obsw/pipeline/head This commit looks good
This commit is contained in:
parent
8a88695409
commit
59689f2af6
@ -2,6 +2,7 @@
|
||||
Event exporter.
|
||||
"""
|
||||
import datetime
|
||||
import logging
|
||||
import time
|
||||
import os
|
||||
from pathlib import Path
|
||||
@ -16,10 +17,9 @@ from fsfwgen.events.event_parser import (
|
||||
from fsfwgen.parserbase.file_list_parser import FileListParser
|
||||
from fsfwgen.utility.printer import PrettyPrinter
|
||||
from fsfwgen.utility.file_management import copy_file
|
||||
from fsfwgen.logging import get_console_logger
|
||||
from definitions import BspType, ROOT_DIR, OBSW_ROOT_DIR
|
||||
|
||||
LOGGER = get_console_logger()
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
DATE_TODAY = datetime.datetime.now()
|
||||
DATE_STRING_FULL = DATE_TODAY.strftime("%Y-%m-%d %H:%M:%S")
|
||||
|
||||
@ -88,14 +88,11 @@ class BspConfig:
|
||||
return [Path(x) for x in self.header_defs_destinations]
|
||||
|
||||
|
||||
LOGGER = get_console_logger()
|
||||
|
||||
|
||||
def parse_events(
|
||||
bsp_type: BspType, generate_csv: bool = True, generate_cpp: bool = True
|
||||
):
|
||||
bsp_cfg = BspConfig(bsp_type)
|
||||
LOGGER.info("EventParser: Parsing events: ")
|
||||
_LOGGER.info("EventParser: Parsing events: ")
|
||||
# Small delay for clean printout
|
||||
time.sleep(0.01)
|
||||
event_list = generate_event_list(bsp_cfg)
|
||||
@ -109,7 +106,7 @@ def parse_events(
|
||||
event_list=event_list,
|
||||
file_separator=FILE_SEPARATOR,
|
||||
)
|
||||
LOGGER.info(f"Copying CSV file to {bsp_cfg.cpp_copy_dest}")
|
||||
_LOGGER.info(f"Copying CSV file to {bsp_cfg.cpp_copy_dest}")
|
||||
copy_file(
|
||||
filename=bsp_cfg.csv_filename,
|
||||
destination=bsp_cfg.csv_copy_dest,
|
||||
@ -125,7 +122,7 @@ def parse_events(
|
||||
header_file_name=CPP_H_FILENAME,
|
||||
)
|
||||
if COPY_CPP_FILE:
|
||||
LOGGER.info(
|
||||
_LOGGER.info(
|
||||
f"EventParser: Copying CPP translation file to {bsp_cfg.cpp_copy_dest}"
|
||||
)
|
||||
copy_file(CPP_FILENAME, bsp_cfg.cpp_copy_dest)
|
||||
@ -135,7 +132,7 @@ def parse_events(
|
||||
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.")
|
||||
_LOGGER.info(f"Found {len(subsystem_table)} subsystem definitions.")
|
||||
PrettyPrinter.pprint(subsystem_table)
|
||||
event_header_parser = FileListParser(cfg.header_defs_as_paths())
|
||||
event_headers = event_header_parser.parse_header_files(
|
||||
@ -148,5 +145,5 @@ def generate_event_list(cfg: BspConfig) -> EventDictT:
|
||||
event_parser.set_moving_window_mode(moving_window_size=7)
|
||||
event_table = event_parser.parse_files()
|
||||
events_sorted = dict(sorted(event_table.items()))
|
||||
LOGGER.info(f"Found {len(events_sorted)} entries")
|
||||
_LOGGER.info(f"Found {len(events_sorted)} entries")
|
||||
return events_sorted
|
||||
|
@ -1,6 +1,7 @@
|
||||
#!/usr/bin/env python3
|
||||
import time
|
||||
import logging
|
||||
|
||||
from definitions import BspType
|
||||
from objects.objects import parse_objects
|
||||
from events.event_parser import parse_events
|
||||
from returnvalues.returnvalues_parser import parse_returnvalues
|
||||
@ -8,32 +9,29 @@ from fsfwgen.core import (
|
||||
return_generic_args_parser,
|
||||
init_printout,
|
||||
)
|
||||
from fsfwgen.logging import get_console_logger
|
||||
|
||||
LOGGER = get_console_logger()
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def main():
|
||||
init_printout(project_string="EIVE")
|
||||
parser = return_generic_args_parser()
|
||||
args = parser.parse_args()
|
||||
bsp_select = BspType.BSP_Q7S
|
||||
if args.type == "objects":
|
||||
LOGGER.info(f"Generating objects data")
|
||||
time.sleep(0.05)
|
||||
parse_objects()
|
||||
_LOGGER.info(f"Generating objects data")
|
||||
parse_objects(bsp_select)
|
||||
elif args.type == "events":
|
||||
LOGGER.info(f"Generating event data")
|
||||
time.sleep(0.05)
|
||||
parse_events()
|
||||
_LOGGER.info(f"Generating event data")
|
||||
parse_events(bsp_select)
|
||||
elif args.type == "returnvalues":
|
||||
LOGGER.info("Generating returnvalue data")
|
||||
time.sleep(0.05)
|
||||
parse_returnvalues()
|
||||
_LOGGER.info("Generating returnvalue data")
|
||||
parse_returnvalues(bsp_select)
|
||||
elif args.type == "all":
|
||||
LOGGER.info("Generating all data")
|
||||
parse_objects()
|
||||
parse_events()
|
||||
parse_returnvalues()
|
||||
_LOGGER.info("Generating all data")
|
||||
parse_objects(bsp_select)
|
||||
parse_events(bsp_select)
|
||||
parse_returnvalues(bsp_select)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
@ -2,10 +2,10 @@
|
||||
Object exporter.
|
||||
"""
|
||||
import datetime
|
||||
import logging
|
||||
import os
|
||||
from pathlib import Path
|
||||
|
||||
from fsfwgen.logging import get_console_logger
|
||||
from fsfwgen.objects.objects import (
|
||||
sql_object_exporter,
|
||||
ObjectDefinitionParser,
|
||||
@ -18,7 +18,7 @@ from fsfwgen.utility.file_management import copy_file
|
||||
|
||||
from definitions import BspType, DATABASE_NAME, OBSW_ROOT_DIR, ROOT_DIR
|
||||
|
||||
LOGGER = get_console_logger()
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
DATE_TODAY = datetime.datetime.now()
|
||||
DATE_STRING_FULL = DATE_TODAY.strftime("%Y-%m-%d %H:%M:%S")
|
||||
|
||||
@ -30,29 +30,40 @@ COPY_CPP = True
|
||||
|
||||
GENERATE_HEADER = True
|
||||
|
||||
BSP_SELECT = BspType.BSP_Q7S
|
||||
BSP_DIR_NAME = BSP_SELECT.value
|
||||
if BSP_SELECT == BspType.BSP_Q7S or BSP_SELECT == BspType.BSP_LINUX_BOARD:
|
||||
FSFW_CONFIG_ROOT = f"{OBSW_ROOT_DIR}/linux/fsfwconfig"
|
||||
|
||||
class BspConfig:
|
||||
def __init__(self, bsp_select: BspType):
|
||||
self.bsp_select = bsp_select
|
||||
self.bsp_dir_name = bsp_select.value
|
||||
if (
|
||||
self.bsp_select == BspType.BSP_Q7S
|
||||
or self.bsp_select == BspType.BSP_LINUX_BOARD
|
||||
):
|
||||
self.fsfw_config_root = f"{OBSW_ROOT_DIR}/linux/fsfwconfig"
|
||||
else:
|
||||
FSFW_CONFIG_ROOT = f"{OBSW_ROOT_DIR}/{BSP_DIR_NAME}/fsfwconfig"
|
||||
self.fsfw_config_root = f"{OBSW_ROOT_DIR}/{self.bsp_dir_name}/fsfwconfig"
|
||||
self.cpp_copy_dest = Path(f"{self.fsfw_config_root}/objects/")
|
||||
self.csv_obj_filename = f"{ROOT_DIR}/{self.bsp_dir_name}_objects.csv"
|
||||
self.objects_path = Path(f"{self.fsfw_config_root}/objects/systemObjectList.h")
|
||||
self.objects_defs = [
|
||||
self.objects_path,
|
||||
FRAMEWORK_OBJECT_PATH,
|
||||
COMMON_OBJECTS_PATH,
|
||||
]
|
||||
|
||||
|
||||
EXPORT_TO_SQL = True
|
||||
|
||||
CPP_COPY_DESTINATION = f"{FSFW_CONFIG_ROOT}/objects/"
|
||||
CPP_FILENAME = f"{os.path.dirname(os.path.realpath(__file__))}//translateObjects.cpp"
|
||||
CPP_H_FILENAME = f"{os.path.dirname(os.path.realpath(__file__))}//translateObjects.h"
|
||||
CSV_OBJECT_FILENAME = f"{ROOT_DIR}/{BSP_SELECT.value}_objects.csv"
|
||||
CSV_COPY_DEST = f"{OBSW_ROOT_DIR}/tmtc/eive_tmtc/config/objects.csv"
|
||||
FILE_SEPARATOR = ";"
|
||||
|
||||
|
||||
OBJECTS_PATH = Path(f"{FSFW_CONFIG_ROOT}/objects/systemObjectList.h")
|
||||
FRAMEWORK_OBJECT_PATH = Path(
|
||||
f"{OBSW_ROOT_DIR}/fsfw/src/fsfw/objectmanager/frameworkObjects.h"
|
||||
)
|
||||
COMMON_OBJECTS_PATH = Path(f"{OBSW_ROOT_DIR}/common/config/eive/objects.h")
|
||||
OBJECTS_DEFINITIONS = [OBJECTS_PATH, FRAMEWORK_OBJECT_PATH, COMMON_OBJECTS_PATH]
|
||||
|
||||
SQL_DELETE_OBJECTS_CMD = """
|
||||
DROP TABLE IF EXISTS Objects
|
||||
@ -72,20 +83,21 @@ VALUES(?,?)
|
||||
"""
|
||||
|
||||
|
||||
def parse_objects(print_object_list: bool = True):
|
||||
def parse_objects(bsp_select: BspType, print_object_list: bool = True):
|
||||
cfg = BspConfig(bsp_select)
|
||||
# fetch objects
|
||||
object_parser = ObjectDefinitionParser(OBJECTS_DEFINITIONS)
|
||||
object_parser = ObjectDefinitionParser(cfg.objects_defs)
|
||||
subsystem_definitions = object_parser.parse_files()
|
||||
# id_subsystem_definitions.update(framework_subsystem_definitions)
|
||||
list_items = sorted(subsystem_definitions.items())
|
||||
LOGGER.info(f"ObjectParser: Number of objects: {len(list_items)}")
|
||||
_LOGGER.info(f"ObjectParser: Number of objects: {len(list_items)}")
|
||||
|
||||
if print_object_list:
|
||||
PrettyPrinter.pprint(list_items)
|
||||
|
||||
handle_file_export(list_items)
|
||||
handle_file_export(cfg, list_items)
|
||||
if EXPORT_TO_SQL:
|
||||
LOGGER.info("ObjectParser: Exporting to SQL")
|
||||
_LOGGER.info("ObjectParser: Exporting to SQL")
|
||||
sql_object_exporter(
|
||||
object_table=list_items,
|
||||
delete_cmd=SQL_DELETE_OBJECTS_CMD,
|
||||
@ -95,29 +107,31 @@ def parse_objects(print_object_list: bool = True):
|
||||
)
|
||||
|
||||
|
||||
def handle_file_export(list_items):
|
||||
def handle_file_export(cfg: BspConfig, list_items):
|
||||
if GENERATE_CPP:
|
||||
LOGGER.info("ObjectParser: Generating C++ translation file")
|
||||
_LOGGER.info("ObjectParser: Generating C++ translation file")
|
||||
write_translation_file(
|
||||
filename=CPP_FILENAME,
|
||||
list_of_entries=list_items,
|
||||
date_string_full=DATE_STRING_FULL,
|
||||
)
|
||||
if COPY_CPP:
|
||||
LOGGER.info("ObjectParser: Copying object file to " + CPP_COPY_DESTINATION)
|
||||
copy_file(CPP_FILENAME, CPP_COPY_DESTINATION)
|
||||
_LOGGER.info(
|
||||
"ObjectParser: Copying object file to " + str(cfg.cpp_copy_dest)
|
||||
)
|
||||
copy_file(Path(CPP_FILENAME), cfg.cpp_copy_dest)
|
||||
if GENERATE_HEADER:
|
||||
write_translation_header_file(filename=CPP_H_FILENAME)
|
||||
copy_file(filename=CPP_H_FILENAME, destination=CPP_COPY_DESTINATION)
|
||||
copy_file(filename=Path(CPP_H_FILENAME), destination=cfg.cpp_copy_dest)
|
||||
if GENERATE_CSV:
|
||||
LOGGER.info("ObjectParser: Generating text export")
|
||||
_LOGGER.info("ObjectParser: Generating text export")
|
||||
export_object_file(
|
||||
filename=CSV_OBJECT_FILENAME,
|
||||
filename=cfg.csv_obj_filename,
|
||||
object_list=list_items,
|
||||
file_separator=FILE_SEPARATOR,
|
||||
)
|
||||
copy_file(
|
||||
filename=CSV_OBJECT_FILENAME,
|
||||
destination=CSV_COPY_DEST,
|
||||
filename=Path(cfg.csv_obj_filename),
|
||||
destination=Path(CSV_COPY_DEST),
|
||||
delete_existing_file=True,
|
||||
)
|
||||
|
@ -3,9 +3,9 @@
|
||||
"""Part of the MIB export tools for the EIVE project by.
|
||||
Returnvalue exporter.
|
||||
"""
|
||||
import logging
|
||||
from pathlib import Path
|
||||
|
||||
from fsfwgen.logging import get_console_logger
|
||||
from fsfwgen.utility.file_management import copy_file
|
||||
from fsfwgen.parserbase.file_list_parser import FileListParser
|
||||
from fsfwgen.returnvalues.returnvalues_parser import (
|
||||
@ -17,7 +17,7 @@ from fsfwgen.utility.sql_writer import SqlWriter
|
||||
|
||||
from definitions import BspType, DATABASE_NAME, ROOT_DIR, OBSW_ROOT_DIR
|
||||
|
||||
LOGGER = get_console_logger()
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
EXPORT_TO_FILE = True
|
||||
COPY_CSV_FILE = True
|
||||
EXPORT_TO_SQL = True
|
||||
@ -98,7 +98,7 @@ def parse_returnvalues(bsp_select: BspType):
|
||||
delete_existing_file=True,
|
||||
)
|
||||
if EXPORT_TO_SQL:
|
||||
LOGGER.info("ReturnvalueParser: Exporting to SQL")
|
||||
_LOGGER.info("ReturnvalueParser: Exporting to SQL")
|
||||
sql_retval_exporter(
|
||||
returnvalue_table, db_filename=f"{ROOT_DIR}/{DATABASE_NAME}"
|
||||
)
|
||||
@ -116,7 +116,7 @@ def generate_returnvalue_table(cfg: BspConfig):
|
||||
returnvalue_parser.obsw_root_path = OBSW_ROOT_DIR
|
||||
returnvalue_parser.set_moving_window_mode(moving_window_size=7)
|
||||
returnvalue_table = returnvalue_parser.parse_files(True)
|
||||
LOGGER.info(f"ReturnvalueParser: Found {len(returnvalue_table)} returnvalues")
|
||||
_LOGGER.info(f"ReturnvalueParser: Found {len(returnvalue_table)} returnvalues")
|
||||
return returnvalue_table
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user