From 734a9018d480d8b71d3e3998bd338b557d07760e Mon Sep 17 00:00:00 2001 From: BjoernAtBosch Date: Fri, 20 Dec 2024 16:18:35 +0100 Subject: [PATCH] Extend cpp model with node type and small int types (#58) --- NOTICE-3RD-PARTY-CONTENT.md | 27 +++++++++---------- README.md | 8 +++--- .../model_generator/cpp/cpp_generator.py | 9 ++++--- .../model_generator/python/vss_collection.py | 1 + 4 files changed, 24 insertions(+), 21 deletions(-) diff --git a/NOTICE-3RD-PARTY-CONTENT.md b/NOTICE-3RD-PARTY-CONTENT.md index fce4863..57b963b 100644 --- a/NOTICE-3RD-PARTY-CONTENT.md +++ b/NOTICE-3RD-PARTY-CONTENT.md @@ -6,22 +6,21 @@ |anytree|2.12.1|Apache 2.0| |cfgv|3.4.0|MIT| |deprecation|2.1.0|Apache 2.0| -|distlib|0.3.8|Python Software Foundation License| -|filelock|3.14.0|The Unlicense (Unlicense)| -|graphql-core|3.2.3|MIT| -|identify|2.5.36|MIT| -|mypy|1.10.0|MIT| +|distlib|0.3.9|Python Software Foundation License| +|filelock|3.16.1|The Unlicense (Unlicense)| +|graphql-core|3.2.5|MIT| +|identify|2.6.2|MIT| +|mypy|1.13.0|MIT| |mypy-extensions|1.0.0|MIT| -|nodeenv|1.8.0|BSD| -|packaging|24.0|Apache 2.0
BSD| -|platformdirs|4.2.2|MIT| -|pre-commit|3.7.1|MIT| -|PyYAML|6.0.1|MIT| -|setuptools|58.1.0|MIT| +|nodeenv|1.9.1|BSD| +|packaging|24.2|Apache 2.0
BSD| +|platformdirs|4.3.6|MIT| +|pre-commit|4.0.1|MIT| +|PyYAML|6.0.2|MIT| |six|1.16.0|MIT| -|tomli|2.0.1|MIT| -|typing-extensions|4.11.0|Python Software Foundation License| -|virtualenv|20.26.2|MIT| +|tomli|2.1.0|MIT| +|typing-extensions|4.12.2|Python Software Foundation License| +|virtualenv|20.27.1|MIT| |vss-tools|4.0|Mozilla Public License 2.0| ## Workflows | Dependency | Version | License | diff --git a/README.md b/README.md index da2aa6f..3d3d4d9 100644 --- a/README.md +++ b/README.md @@ -10,11 +10,11 @@ This generator creates a vehicle model from the given vspec specification for th * Python 3 * C++ +**HINT**: C++ model generated by model generator versions >= 0.8.0 require C++ SDK versions >= 0.5.5 ! + ## Supported VSS versions -* 3.0 -* 3.1 -* 3.1.1 -* 4.0 +* 3.x +* 4.x ## Usage diff --git a/src/velocitas/model_generator/cpp/cpp_generator.py b/src/velocitas/model_generator/cpp/cpp_generator.py index 90bdd4d..45a4297 100644 --- a/src/velocitas/model_generator/cpp/cpp_generator.py +++ b/src/velocitas/model_generator/cpp/cpp_generator.py @@ -172,6 +172,7 @@ def __gen_model_docstring(self, node: VSSNode): def __document_member(self, node: VSSNode): self.ctx_header.write("/**\n") if node.type.value == "attribute": + assert node.datatype is not None self.ctx_header.write( f"* {node.name}: {node.type.value} ({node.datatype.value})\n" ) @@ -378,7 +379,10 @@ def __gen_model(self, node: VSSNode, namespace_list: List[str], is_root=False): header_public.write( f"velocitas::DataPoint{data_type} {child.name};\n\n" ) - member += ",\n\t\t" + f'{child.name}("{child.name}", this)' + member += ( + ",\n\t\t" + + f'{child.name}("{child.name}", Type::{child.type.value.upper()}, this)' + ) if child.type == VSSType.BRANCH: if child.instances: @@ -410,6 +414,7 @@ def __gen_model(self, node: VSSNode, namespace_list: List[str], is_root=False): self.ctx_header.reset() def __gen_instances(self, node: VSSNode) -> list[tuple[str, list]]: + assert node.instances is not None instances = node.instances reg_ex = r"\w+\[\d+,(\d+)\]" @@ -448,8 +453,6 @@ def __parse_instances(self, reg_ex, i) -> tuple[str, list]: raise ValueError("", "", f"is of type {type(i)} which is unsupported") def __get_data_type(self, data_type: str) -> str: - # there are no 8bit or 16bit types in grpc... - data_type = data_type.replace("8", "32").replace("16", "32") if data_type[-1] == "]": return data_type[0].upper() + data_type[1:-2] + "Array" return data_type[0].upper() + data_type[1:] diff --git a/src/velocitas/model_generator/python/vss_collection.py b/src/velocitas/model_generator/python/vss_collection.py index 16ea22b..ea81d47 100644 --- a/src/velocitas/model_generator/python/vss_collection.py +++ b/src/velocitas/model_generator/python/vss_collection.py @@ -58,6 +58,7 @@ def __init__(self, node: VSSNode): def __gen_collection(self, node: VSSNode): print(f"- {self.name:30}{node.instances}") + assert node.instances is not None self.ctx.write(self.ctx.line_break) self.ctx.write(f"class {self.name}(Model):\n") with self.ctx as def_ctx: