Init Commit
This commit is contained in:
@@ -0,0 +1,140 @@
|
||||
#! /usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
"""Part of the MIB export tools for the EIVE project by.
|
||||
Returnvalue exporter.
|
||||
"""
|
||||
import logging
|
||||
from pathlib import Path
|
||||
|
||||
from fsfwgen.utility.file_management import copy_file
|
||||
from fsfwgen.parserbase.file_list_parser import FileListParser
|
||||
from fsfwgen.returnvalues.returnvalues_parser import (
|
||||
InterfaceParser,
|
||||
ReturnValueParser,
|
||||
RetvalDictT,
|
||||
)
|
||||
from fsfwgen.utility.sql_writer import SqlWriter
|
||||
|
||||
from definitions import BspType, DATABASE_NAME, ROOT_DIR, OBSW_ROOT_DIR
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
EXPORT_TO_FILE = True
|
||||
COPY_CSV_FILE = True
|
||||
EXPORT_TO_SQL = True
|
||||
PRINT_TABLES = False
|
||||
|
||||
|
||||
FILE_SEPARATOR = ";"
|
||||
MAX_STRING_LENGTH = 32
|
||||
|
||||
|
||||
CSV_COPY_DEST = Path(f"{OBSW_ROOT_DIR}/tmtc/eive_tmtc/config/returnvalues.csv")
|
||||
|
||||
|
||||
SQL_DELETE_RETURNVALUES_CMD = """
|
||||
DROP TABLE IF EXISTS Returnvalues
|
||||
"""
|
||||
|
||||
SQL_CREATE_RETURNVALUES_CMD = """
|
||||
CREATE TABLE IF NOT EXISTS Returnvalues (
|
||||
id INTEGER PRIMARY KEY,
|
||||
code TEXT,
|
||||
name TEXT,
|
||||
interface TEXT,
|
||||
file TEXT,
|
||||
description TEXT
|
||||
)
|
||||
"""
|
||||
|
||||
SQL_INSERT_RETURNVALUES_CMD = """
|
||||
INSERT INTO Returnvalues(code,name,interface,file,description)
|
||||
VALUES(?,?,?,?,?)
|
||||
"""
|
||||
|
||||
|
||||
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]
|
||||
|
||||
|
||||
def parse_returnvalues(bsp_select: BspType, copy_to_eive_tmtc: bool):
|
||||
cfg = BspConfig(bsp_select)
|
||||
returnvalue_table = generate_returnvalue_table(cfg)
|
||||
if EXPORT_TO_FILE:
|
||||
ReturnValueParser.export_to_csv(
|
||||
cfg.csv_retval_filename, returnvalue_table, FILE_SEPARATOR
|
||||
)
|
||||
if COPY_CSV_FILE:
|
||||
if copy_to_eive_tmtc:
|
||||
_LOGGER.info(f"Copying CSV to {CSV_COPY_DEST}")
|
||||
copy_file(
|
||||
filename=cfg.csv_retval_filename,
|
||||
destination=CSV_COPY_DEST,
|
||||
delete_existing_file=True,
|
||||
)
|
||||
if EXPORT_TO_SQL:
|
||||
_LOGGER.info("ReturnvalueParser: Exporting to SQL")
|
||||
sql_retval_exporter(
|
||||
returnvalue_table, db_filename=f"{ROOT_DIR}/{DATABASE_NAME}"
|
||||
)
|
||||
|
||||
|
||||
def generate_returnvalue_table(cfg: BspConfig):
|
||||
"""Core function to parse for the return values"""
|
||||
interface_parser = InterfaceParser(
|
||||
file_list=cfg.if_definition_files(), print_table=PRINT_TABLES
|
||||
)
|
||||
interfaces = interface_parser.parse_files()
|
||||
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
|
||||
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")
|
||||
return returnvalue_table
|
||||
|
||||
|
||||
def sql_retval_exporter(returnvalue_table: RetvalDictT, db_filename: str):
|
||||
sql_writer = SqlWriter(db_filename=db_filename)
|
||||
sql_writer.open(SQL_CREATE_RETURNVALUES_CMD)
|
||||
for entry in returnvalue_table.items():
|
||||
sql_writer.write_entries(
|
||||
SQL_INSERT_RETURNVALUES_CMD,
|
||||
(
|
||||
entry[0],
|
||||
entry[1].name,
|
||||
entry[1].description,
|
||||
entry[1].unique_id,
|
||||
entry[1].subsystem_name,
|
||||
),
|
||||
)
|
||||
sql_writer.commit()
|
||||
sql_writer.close()
|
||||
Reference in New Issue
Block a user