some minor updates and bugfixes
This commit is contained in:
parent
8c51049821
commit
bd76760052
6
core.py
6
core.py
@ -68,16 +68,16 @@ class ParserTypes(enum.Enum):
|
|||||||
def init_printout(project_string: str):
|
def init_printout(project_string: str):
|
||||||
global LOGGER_INSTANCE
|
global LOGGER_INSTANCE
|
||||||
LOGGER_INSTANCE = get_console_logger()
|
LOGGER_INSTANCE = get_console_logger()
|
||||||
print(f"-- {project_string} MOD Generator --")
|
print(f"-- {project_string} MIB Generator --")
|
||||||
|
|
||||||
|
|
||||||
def return_generic_args_parser() -> argparse.ArgumentParser:
|
def return_generic_args_parser() -> argparse.ArgumentParser:
|
||||||
parser = argparse.ArgumentParser("Arguments for FSFW MOD generation")
|
parser = argparse.ArgumentParser("Arguments for FSFW MIB generation")
|
||||||
choices = ("events", "objects", "returnvalues", "subservices")
|
choices = ("events", "objects", "returnvalues", "subservices")
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"type",
|
"type",
|
||||||
metavar="type",
|
metavar="type",
|
||||||
choices=choices,
|
choices=choices,
|
||||||
help=f"Type of MOD data to generate. Choices: {choices}",
|
help=f"Type of MIB data to generate. Choices: {choices}",
|
||||||
)
|
)
|
||||||
return parser
|
return parser
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import re
|
import re
|
||||||
|
import os
|
||||||
from typing import List
|
from typing import List
|
||||||
|
|
||||||
from fsfwgen.parserbase.parser import FileParser
|
from fsfwgen.parserbase.parser import FileParser
|
||||||
@ -49,12 +50,13 @@ class SubsystemDefinitionParser(FileParser):
|
|||||||
|
|
||||||
|
|
||||||
class EventParser(FileParser):
|
class EventParser(FileParser):
|
||||||
def __init__(self, file_list, interface_list):
|
def __init__(self, file_list: List[str], interface_list):
|
||||||
super().__init__(file_list)
|
super().__init__(file_list)
|
||||||
self.interfaces = interface_list
|
self.interfaces = interface_list
|
||||||
self.count = 0
|
self.count = 0
|
||||||
self.my_id = 0
|
self.my_id = 0
|
||||||
self.current_id = 0
|
self.current_id = 0
|
||||||
|
self.obsw_root_path = None
|
||||||
self.last_lines = ["", "", ""]
|
self.last_lines = ["", "", ""]
|
||||||
self.moving_window_center_idx = 3
|
self.moving_window_center_idx = 3
|
||||||
|
|
||||||
@ -180,7 +182,7 @@ class EventParser(FileParser):
|
|||||||
def _post_parsing_operation(self):
|
def _post_parsing_operation(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def __handle_line_reading(self, line, file_name):
|
def __handle_line_reading(self, line, file_name: str):
|
||||||
if not self.last_lines[0] == "\n":
|
if not self.last_lines[0] == "\n":
|
||||||
twolines = self.last_lines[0] + " " + line.strip()
|
twolines = self.last_lines[0] + " " + line.strip()
|
||||||
else:
|
else:
|
||||||
@ -213,6 +215,8 @@ class EventParser(FileParser):
|
|||||||
# print("EventParser: Duplicate Event " + hex(full_id) + " from " + file_name +
|
# print("EventParser: Duplicate Event " + hex(full_id) + " from " + file_name +
|
||||||
# " was already in " + self.mib_table[full_id][3])
|
# " was already in " + self.mib_table[full_id][3])
|
||||||
pass
|
pass
|
||||||
|
if self.obsw_root_path is not None:
|
||||||
|
file_name = os.path.relpath(file_name, self.obsw_root_path)
|
||||||
self.mib_table.update(
|
self.mib_table.update(
|
||||||
{full_id: (string_to_add, severity, description, file_name)}
|
{full_id: (string_to_add, severity, description, file_name)}
|
||||||
)
|
)
|
||||||
@ -285,7 +289,7 @@ def write_translation_source_file(
|
|||||||
definitions = ""
|
definitions = ""
|
||||||
|
|
||||||
function = (
|
function = (
|
||||||
"const char* translateEvents(Event event) {\n switch( (event & 0xFFFF) ) {\n"
|
"const char *translateEvents(Event event) {\n switch((event & 0xFFFF)) {\n"
|
||||||
)
|
)
|
||||||
for entry in event_list:
|
for entry in event_list:
|
||||||
event_id = entry[0]
|
event_id = entry[0]
|
||||||
@ -294,8 +298,11 @@ def write_translation_source_file(
|
|||||||
f"const char *{event_value[EVENT_ENTRY_NAME_IDX]}_STRING "
|
f"const char *{event_value[EVENT_ENTRY_NAME_IDX]}_STRING "
|
||||||
f'= "{event_value[EVENT_ENTRY_NAME_IDX]}";\n'
|
f'= "{event_value[EVENT_ENTRY_NAME_IDX]}";\n'
|
||||||
)
|
)
|
||||||
function += f" case({event_id}):\n return {event_value[EVENT_ENTRY_NAME_IDX]}_STRING;\n"
|
function += (
|
||||||
function += ' default:\n return "UNKNOWN_EVENT";\n'
|
f" case ({event_id}):\n "
|
||||||
|
f"return {event_value[EVENT_ENTRY_NAME_IDX]}_STRING;\n"
|
||||||
|
)
|
||||||
|
function += ' default:\n return "UNKNOWN_EVENT";\n'
|
||||||
outputfile.write(
|
outputfile.write(
|
||||||
f"/**\n * @brief Auto-generated event translation file. "
|
f"/**\n * @brief Auto-generated event translation file. "
|
||||||
f"Contains {len(event_list)} translations.\n"
|
f"Contains {len(event_list)} translations.\n"
|
||||||
@ -313,7 +320,7 @@ def write_translation_header_file(filename: str = "translateEvents.h"):
|
|||||||
f"#ifndef FSFWCONFIG_EVENTS_TRANSLATEEVENTS_H_\n"
|
f"#ifndef FSFWCONFIG_EVENTS_TRANSLATEEVENTS_H_\n"
|
||||||
f"#define FSFWCONFIG_EVENTS_TRANSLATEEVENTS_H_\n\n"
|
f"#define FSFWCONFIG_EVENTS_TRANSLATEEVENTS_H_\n\n"
|
||||||
f"{FSFW_EVENT_HEADER_INCLUDE}\n\n"
|
f"{FSFW_EVENT_HEADER_INCLUDE}\n\n"
|
||||||
f"const char * translateEvents(Event event);\n\n"
|
f"const char *translateEvents(Event event);\n\n"
|
||||||
f"#endif /* FSFWCONFIG_EVENTS_TRANSLATEEVENTS_H_ */\n"
|
f"#endif /* FSFWCONFIG_EVENTS_TRANSLATEEVENTS_H_ */\n"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -46,23 +46,23 @@ def write_translation_file(filename: str, list_of_entries, date_string_full: str
|
|||||||
LOGGER.info("ObjectParser: Writing translation file " + filename)
|
LOGGER.info("ObjectParser: Writing translation file " + filename)
|
||||||
definitions = ""
|
definitions = ""
|
||||||
function = (
|
function = (
|
||||||
"const char* translateObject(object_id_t object) "
|
"const char *translateObject(object_id_t object) "
|
||||||
"{\n\tswitch( (object & 0xFFFFFFFF) ) {\n"
|
"{\n switch ((object & 0xFFFFFFFF)) {\n"
|
||||||
)
|
)
|
||||||
for entry in list_of_entries:
|
for entry in list_of_entries:
|
||||||
# first part of translate file
|
# first part of translate file
|
||||||
definitions += f'const char *{entry[1][0]}_STRING = "{entry[1][0]}";\n'
|
definitions += f'const char *{entry[1][0]}_STRING = "{entry[1][0]}";\n'
|
||||||
# second part of translate file. entry[i] contains 32 bit hexadecimal numbers
|
# second part of translate file. entry[i] contains 32 bit hexadecimal numbers
|
||||||
function += f"\tcase {entry[0]}:\n\t\treturn {entry[1][0]}_STRING;\n"
|
function += f" case {entry[0]}:\n return {entry[1][0]}_STRING;\n"
|
||||||
function += '\tdefault:\n\t\treturn "UNKNOWN_OBJECT";\n'
|
function += ' default:\n return "UNKNOWN_OBJECT";\n }\n'
|
||||||
outputfile.write(
|
outputfile.write(
|
||||||
f"/**\n * @brief\tAuto-generated object translation file.\n"
|
f"/**\n * @brief Auto-generated object translation file.\n"
|
||||||
f" * @details\n"
|
f" * @details\n"
|
||||||
f" * Contains {len(list_of_entries)} translations.\n"
|
f" * Contains {len(list_of_entries)} translations.\n"
|
||||||
f" * Generated on: {date_string_full}\n */\n"
|
f" * Generated on: {date_string_full}\n */\n"
|
||||||
)
|
)
|
||||||
outputfile.write('#include "translateObjects.h"\n\n')
|
outputfile.write('#include "translateObjects.h"\n\n')
|
||||||
outputfile.write(definitions + "\n" + function + "\t}\n\treturn 0;\n}\n")
|
outputfile.write(definitions + "\n" + function + " return 0;\n}\n")
|
||||||
outputfile.close()
|
outputfile.close()
|
||||||
|
|
||||||
|
|
||||||
@ -72,7 +72,7 @@ def write_translation_header_file(filename: str = "translateObjects.h"):
|
|||||||
f"#ifndef FSFWCONFIG_OBJECTS_TRANSLATEOBJECTS_H_\n"
|
f"#ifndef FSFWCONFIG_OBJECTS_TRANSLATEOBJECTS_H_\n"
|
||||||
f"#define FSFWCONFIG_OBJECTS_TRANSLATEOBJECTS_H_\n\n"
|
f"#define FSFWCONFIG_OBJECTS_TRANSLATEOBJECTS_H_\n\n"
|
||||||
f"#include <fsfw/objectmanager/SystemObjectIF.h>\n\n"
|
f"#include <fsfw/objectmanager/SystemObjectIF.h>\n\n"
|
||||||
f"const char* translateObject(object_id_t object);\n\n"
|
f"const char *translateObject(object_id_t object);\n\n"
|
||||||
f"#endif /* FSFWCONFIG_OBJECTS_TRANSLATEOBJECTS_H_ */\n"
|
f"#endif /* FSFWCONFIG_OBJECTS_TRANSLATEOBJECTS_H_ */\n"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -18,8 +18,8 @@ from typing import Dict, List
|
|||||||
|
|
||||||
|
|
||||||
class VerbosityLevels(enum.Enum):
|
class VerbosityLevels(enum.Enum):
|
||||||
REDUCED = (0,)
|
REDUCED = 0
|
||||||
REGULAR = (1,)
|
REGULAR = 1
|
||||||
DEBUG = 2
|
DEBUG = 2
|
||||||
|
|
||||||
|
|
||||||
@ -280,4 +280,6 @@ class FileParser:
|
|||||||
resulting_description = re.search(
|
resulting_description = re.search(
|
||||||
r"\[EXPORT][\s]*:[\s]*\[COMMENT][\s](.*)", descrip_string
|
r"\[EXPORT][\s]*:[\s]*\[COMMENT][\s](.*)", descrip_string
|
||||||
)
|
)
|
||||||
return resulting_description.group(1)
|
if resulting_description:
|
||||||
|
return resulting_description.group(1)
|
||||||
|
return ""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user