Compare commits
4 Commits
update-eve
...
main
Author | SHA1 | Date | |
---|---|---|---|
7eb6a6f7a8 | |||
bb7886f063 | |||
2d7a2a09b8 | |||
76139f3934 |
@ -8,6 +8,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
|
|||||||
|
|
||||||
# [unreleased]
|
# [unreleased]
|
||||||
|
|
||||||
|
# [v0.4.0]
|
||||||
|
|
||||||
|
- Update event handling for new `constexpr` templated arguments
|
||||||
|
|
||||||
# [v0.3.4]
|
# [v0.3.4]
|
||||||
|
|
||||||
- Hotfixes for pyproject.toml file
|
- Hotfixes for pyproject.toml file
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
import re
|
import re
|
||||||
import enum
|
|
||||||
import logging
|
import logging
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import List, Optional, Dict
|
from typing import List, Optional, Dict
|
||||||
@ -16,25 +15,6 @@ SUBSYSTEM_ID_NAMESPACE = "SUBSYSTEM_ID"
|
|||||||
EVENT_NAME_IDX = 1
|
EVENT_NAME_IDX = 1
|
||||||
|
|
||||||
|
|
||||||
class Severity(enum.IntEnum):
|
|
||||||
INFO = 0
|
|
||||||
LOW = 1
|
|
||||||
MEDIUM = 2
|
|
||||||
HIGH = 3
|
|
||||||
|
|
||||||
|
|
||||||
def severity_str_to_enum(severity: str) -> Severity | None:
|
|
||||||
if severity == "INFO":
|
|
||||||
return Severity.INFO
|
|
||||||
if severity == "LOW":
|
|
||||||
return Severity.LOW
|
|
||||||
if severity == "MEDIUM":
|
|
||||||
return Severity.MEDIUM
|
|
||||||
if severity == "HIGH":
|
|
||||||
return Severity.HIGH
|
|
||||||
return None
|
|
||||||
|
|
||||||
|
|
||||||
class SubsystemDefinitionParser(FileParser):
|
class SubsystemDefinitionParser(FileParser):
|
||||||
def __init__(self, file_list):
|
def __init__(self, file_list):
|
||||||
super().__init__(file_list)
|
super().__init__(file_list)
|
||||||
@ -89,8 +69,8 @@ class EventParser(FileParser):
|
|||||||
self.set_moving_window_mode(moving_window_size)
|
self.set_moving_window_mode(moving_window_size)
|
||||||
self.interfaces = interface_list
|
self.interfaces = interface_list
|
||||||
self.count = 0
|
self.count = 0
|
||||||
self.current_group_id = 0
|
self.my_id = 0
|
||||||
self.current_unique_id = 0
|
self.current_id = 0
|
||||||
self.mib_table: EventDictT = dict()
|
self.mib_table: EventDictT = dict()
|
||||||
self.obsw_root_path: Optional[Path] = None
|
self.obsw_root_path: Optional[Path] = None
|
||||||
self.last_lines = ["", "", ""]
|
self.last_lines = ["", "", ""]
|
||||||
@ -116,8 +96,8 @@ class EventParser(FileParser):
|
|||||||
# For now, it is assumed that there is only going to be one subsystem ID per
|
# For now, it is assumed that there is only going to be one subsystem ID per
|
||||||
# class / source file
|
# class / source file
|
||||||
try:
|
try:
|
||||||
self.current_group_id = self.interfaces[subsystem_id_assignment_match.group(1)][0]
|
self.current_id = self.interfaces[subsystem_id_assignment_match.group(1)][0]
|
||||||
self.current_group_id = self.return_number_from_string(self.current_group_id)
|
self.my_id = self.return_number_from_string(self.current_id)
|
||||||
except KeyError as e:
|
except KeyError as e:
|
||||||
print(f"Key not found: {e}")
|
print(f"Key not found: {e}")
|
||||||
# Now try to look for event definitions. Moving windows allows multi line event definitions
|
# Now try to look for event definitions. Moving windows allows multi line event definitions
|
||||||
@ -176,28 +156,17 @@ class EventParser(FileParser):
|
|||||||
if event_full_match:
|
if event_full_match:
|
||||||
name = event_match.group(EVENT_NAME_IDX)
|
name = event_match.group(EVENT_NAME_IDX)
|
||||||
if macro_api_match:
|
if macro_api_match:
|
||||||
severity = event_full_match.group(3)
|
full_id = (self.my_id * 100) + self.return_number_from_string(
|
||||||
severity_num = severity_str_to_enum(severity)
|
event_full_match.group(2)
|
||||||
if severity_num is None:
|
|
||||||
raise ValueError(f"Unknown severity: {severity}")
|
|
||||||
full_id = (
|
|
||||||
(severity_num << 30)
|
|
||||||
| (self.current_group_id << 16)
|
|
||||||
| self.return_number_from_string(event_full_match.group(2))
|
|
||||||
)
|
)
|
||||||
|
severity = event_full_match.group(3)
|
||||||
else:
|
else:
|
||||||
severity = event_full_match.group(4)
|
|
||||||
severity_num = severity_str_to_enum(severity)
|
|
||||||
if severity_num is None:
|
|
||||||
raise ValueError(f"Unknown severity: {severity}")
|
|
||||||
if event_full_match.group(1) == "EV_REPLY_INVALID_SIZE":
|
if event_full_match.group(1) == "EV_REPLY_INVALID_SIZE":
|
||||||
print(f"Group 3: {event_full_match.group(3)}")
|
print(f"Group 3: {event_full_match.group(3)}")
|
||||||
full_id = (
|
full_id = (self.my_id * 100) + self.return_number_from_string(
|
||||||
(severity_num << 30)
|
event_full_match.group(3)
|
||||||
| (self.current_group_id << 16)
|
|
||||||
| self.return_number_from_string(event_full_match.group(3))
|
|
||||||
)
|
)
|
||||||
|
severity = event_full_match.group(4)
|
||||||
if self.obsw_root_path is not None:
|
if self.obsw_root_path is not None:
|
||||||
file_name = file_name.relative_to(self.obsw_root_path)
|
file_name = file_name.relative_to(self.obsw_root_path)
|
||||||
if self.mib_table.get(full_id) is not None:
|
if self.mib_table.get(full_id) is not None:
|
||||||
@ -217,9 +186,20 @@ class EventParser(FileParser):
|
|||||||
r"static const(?:expr)? Event[\s]*([\w]*)[\s]*=[\s]*"
|
r"static const(?:expr)? Event[\s]*([\w]*)[\s]*=[\s]*"
|
||||||
r"MAKE_EVENT\((0x[0-9a-fA-F]+|[0-9]{1,3}),[\s]*severity::([A-Z]*)\)[\s]*;"
|
r"MAKE_EVENT\((0x[0-9a-fA-F]+|[0-9]{1,3}),[\s]*severity::([A-Z]*)\)[\s]*;"
|
||||||
)
|
)
|
||||||
else:
|
return re.search(regex_string, full_string)
|
||||||
regex_string = r"static const(?:expr)? Event\s*([\w]+)\s*=\s*event::makeEvent\(([\w:]+),\s*(0x[0-9a-fA-F]+|[0-9]{1,3})\s*,\s*severity::([A-Z]+)\)\s*;"
|
|
||||||
|
# Non compiletime const version kept for backwards compatibility
|
||||||
|
regex_string = r"static const(?:expr)? Event\s*([\w]+)\s*=\s*event::makeEvent\(([\w:]+),\s*(0x[0-9a-fA-F]+|[0-9]{1,3})\s*,\s*severity::([A-Z]+)\)\s*;"
|
||||||
event_full_match = re.search(regex_string, full_string)
|
event_full_match = re.search(regex_string, full_string)
|
||||||
|
|
||||||
|
# Using old, non compiletime const version
|
||||||
|
if event_full_match:
|
||||||
|
return event_full_match
|
||||||
|
|
||||||
|
# Using compiletime const version
|
||||||
|
regex_string = r"static const(?:expr)? Event\s*([\w]+)\s*=\s*event::makeEvent<([\w:]+),\s*(0x[0-9a-fA-F]+|[0-9]{1,3})\s*,\s*severity::([A-Z]+)>\(\)\s*;"
|
||||||
|
event_full_match = re.search(regex_string, full_string)
|
||||||
|
|
||||||
return event_full_match
|
return event_full_match
|
||||||
|
|
||||||
def __build_multi_line_event_string(self, first_line: str, moving_window: List[str]) -> str:
|
def __build_multi_line_event_string(self, first_line: str, moving_window: List[str]) -> str:
|
||||||
@ -285,15 +265,13 @@ def export_to_csv(filename: Path, event_list: EventDictT, col_sep: str):
|
|||||||
|
|
||||||
|
|
||||||
def write_translation_source_file(
|
def write_translation_source_file(
|
||||||
event_list: EventDictT,
|
event_list: EventDictT, date_string: str, filename: Path = "translateEvents.cpp"
|
||||||
date_string: str,
|
|
||||||
filename: Path = Path("translateEvents.cpp"),
|
|
||||||
):
|
):
|
||||||
with open(filename, "w") as out:
|
with open(filename, "w") as out:
|
||||||
definitions = ""
|
definitions = ""
|
||||||
# Look up table to avoid duplicate events
|
# Look up table to avoid duplicate events
|
||||||
lut = dict()
|
lut = dict()
|
||||||
function = "const char *translateEvents(Event event) {\n switch (event) {\n"
|
function = "const char *translateEvents(Event event) {\n switch ((event & 0xFFFF)) {\n"
|
||||||
for entry in event_list.items():
|
for entry in event_list.items():
|
||||||
event_id = entry[0]
|
event_id = entry[0]
|
||||||
event_value = entry[1]
|
event_value = entry[1]
|
||||||
@ -305,8 +283,8 @@ def write_translation_source_file(
|
|||||||
_LOGGER.warning(f"Name: {name}, Event Entry: {event_value}")
|
_LOGGER.warning(f"Name: {name}, Event Entry: {event_value}")
|
||||||
name = f"{name}_{event_id}"
|
name = f"{name}_{event_id}"
|
||||||
_LOGGER.info(f"Created unique name {name}")
|
_LOGGER.info(f"Created unique name {name}")
|
||||||
definitions += f'const char *{name}_STRING = "{name}";\n'
|
definitions += f"const char *{name}_STRING " f'= "{name}";\n'
|
||||||
function += f" case ({event_id}):\n return {name}_STRING;\n"
|
function += f" case ({event_id}):\n " f"return {name}_STRING;\n"
|
||||||
lut.update({name: event_value})
|
lut.update({name: event_value})
|
||||||
function += ' default:\n return "UNKNOWN_EVENT";\n'
|
function += ' default:\n return "UNKNOWN_EVENT";\n'
|
||||||
out.write(
|
out.write(
|
||||||
@ -319,7 +297,7 @@ def write_translation_source_file(
|
|||||||
out.write(definitions + "\n" + function + " }\n return 0;\n}\n")
|
out.write(definitions + "\n" + function + " }\n return 0;\n}\n")
|
||||||
|
|
||||||
|
|
||||||
def write_translation_header_file(filename: Path = Path("translateEvents.h")):
|
def write_translation_header_file(filename: Path = "translateEvents.h"):
|
||||||
with open(filename, "w") as out:
|
with open(filename, "w") as out:
|
||||||
out.write(
|
out.write(
|
||||||
f"#ifndef FSFWCONFIG_EVENTS_TRANSLATEEVENTS_H_\n"
|
f"#ifndef FSFWCONFIG_EVENTS_TRANSLATEEVENTS_H_\n"
|
||||||
|
@ -8,7 +8,7 @@ build-backend = "setuptools.build_meta"
|
|||||||
[project]
|
[project]
|
||||||
name = "fsfwgen"
|
name = "fsfwgen"
|
||||||
description = "FSFW Generator Core"
|
description = "FSFW Generator Core"
|
||||||
version = "0.3.4"
|
version = "0.4.0"
|
||||||
license = { text = "Apache-2.0" }
|
license = { text = "Apache-2.0" }
|
||||||
authors = [
|
authors = [
|
||||||
{name = "Robin Mueller", email = "robin.mueller.m@gmail.com"}
|
{name = "Robin Mueller", email = "robin.mueller.m@gmail.com"}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user