Skip to content

Commit

Permalink
Extend cpp model with node type and small int types (#58)
Browse files Browse the repository at this point in the history
  • Loading branch information
BjoernAtBosch authored Dec 20, 2024
1 parent 84c3107 commit 734a901
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 21 deletions.
27 changes: 13 additions & 14 deletions NOTICE-3RD-PARTY-CONTENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<br/>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<br/>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 |
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
9 changes: 6 additions & 3 deletions src/velocitas/model_generator/cpp/cpp_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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+)\]"
Expand Down Expand Up @@ -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:]
1 change: 1 addition & 0 deletions src/velocitas/model_generator/python/vss_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 734a901

Please sign in to comment.