Skip to content

Commit 1565f34

Browse files
committed
Generate OPC UA node set
We generate an OPC UA node set so that the model instances can be transferred through OPC UA as channel. The mapping to OPC UA information model is kept minimal and as simple as possible to avoid maintenance issues in the future.
1 parent 4433d09 commit 1565f34

File tree

57 files changed

+14603
-2
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+14603
-2
lines changed

README.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ Call the generator with the appropriate target:
139139
140140
usage: aas-core-codegen [-h] --model_path MODEL_PATH --snippets_dir
141141
SNIPPETS_DIR --output_dir OUTPUT_DIR --target
142-
{csharp,cpp,golang,java,jsonschema,python,typescript,rdf_shacl,xsd,jsonld_context,protobuf,python_protobuf}
142+
{csharp,cpp,golang,java,jsonschema,python,typescript,rdf_shacl,xsd,jsonld_context,protobuf,python_protobuf,opcua}
143143
[--version]
144144
145145
Generate implementations and schemas based on an AAS meta-model.
@@ -153,7 +153,7 @@ Call the generator with the appropriate target:
153153
specific code snippets
154154
--output_dir OUTPUT_DIR
155155
path to the generated code
156-
--target {csharp,cpp,golang,java,jsonschema,python,typescript,rdf_shacl,xsd,jsonld_context,protobuf,python_protobuf}
156+
--target {csharp,cpp,golang,java,jsonschema,python,typescript,rdf_shacl,xsd,jsonld_context,protobuf,python_protobuf,opcua}
157157
target language or schema
158158
--version show the current version and exit
159159

aas_core_codegen/intermediate/_translate.py

+50
Original file line numberDiff line numberDiff line change
@@ -4437,6 +4437,54 @@ def _verify_only_simple_type_patterns(symbol_table: SymbolTable) -> List[Error]:
44374437
return errors
44384438

44394439

4440+
def _verify_invariant_descriptions_unique(symbol_table: SymbolTable) -> List[Error]:
4441+
"""Check that no two invariants share the same description."""
4442+
errors = [] # type: List[Error]
4443+
for something_with_invariants in itertools.chain(
4444+
symbol_table.classes, symbol_table.constrained_primitives
4445+
):
4446+
description_map = dict() # type: MutableMapping[str, Invariant]
4447+
4448+
for invariant in something_with_invariants.invariants:
4449+
conflicting_invariant = description_map.get(invariant.description, None)
4450+
if conflicting_invariant is not None:
4451+
what: str
4452+
if isinstance(something_with_invariants, Class):
4453+
what = "class"
4454+
elif isinstance(something_with_invariants, ConstrainedPrimitive):
4455+
what = "constrained primitive"
4456+
else:
4457+
assert_never(something_with_invariants)
4458+
raise AssertionError("Unexpected execution path")
4459+
4460+
if conflicting_invariant.specified_for is invariant.specified_for:
4461+
errors.append(
4462+
Error(
4463+
invariant.parsed.node,
4464+
f"The invariants' descriptions need to be unique, "
4465+
f"but they conflict "
4466+
f"in the {what} {invariant.specified_for.name!r} "
4467+
f"for the description: {invariant.description!r}",
4468+
)
4469+
)
4470+
else:
4471+
errors.append(
4472+
Error(
4473+
invariant.parsed.node,
4474+
f"The invariants' descriptions need to be unique, "
4475+
f"but an invariant from "
4476+
f"the {what} {invariant.specified_for.name!r} "
4477+
f"and from "
4478+
f"the {what} {conflicting_invariant.specified_for.name!r} "
4479+
f"conflict for the description: {invariant.description!r}",
4480+
)
4481+
)
4482+
else:
4483+
description_map[invariant.description] = invariant
4484+
4485+
return errors
4486+
4487+
44404488
def _verify_patterns_anchored_at_start_and_end(
44414489
symbol_table: SymbolTable,
44424490
) -> List[Error]:
@@ -4622,6 +4670,8 @@ def _verify(symbol_table: SymbolTable, ontology: _hierarchy.Ontology) -> List[Er
46224670

46234671
errors.extend(_verify_patterns_anchored_at_start_and_end(symbol_table=symbol_table))
46244672

4673+
errors.extend(_verify_invariant_descriptions_unique(symbol_table=symbol_table))
4674+
46254675
if len(errors) > 0:
46264676
return errors
46274677

aas_core_codegen/main.py

+5
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import aas_core_codegen.jsonld.main as jsonld_main
2020
import aas_core_codegen.protobuf.main as protobuf_main
2121
import aas_core_codegen.python_protobuf.main as python_protobuf_main
22+
import aas_core_codegen.opcua.main as opcua_main
2223
from aas_core_codegen import run, specific_implementations
2324
from aas_core_codegen.common import LinenoColumner, assert_never
2425

@@ -40,6 +41,7 @@ class Target(enum.Enum):
4041
JSONLD_CONTEXT = "jsonld_context"
4142
PROTOBUF = "protobuf"
4243
PYTHON_PROTOBUF = "python_protobuf"
44+
OPCUA = "opcua"
4345

4446

4547
class Parameters:
@@ -174,6 +176,9 @@ def execute(params: Parameters, stdout: TextIO, stderr: TextIO) -> int:
174176
elif params.target is Target.PYTHON_PROTOBUF:
175177
return python_protobuf_main.execute(run_context, stdout=stdout, stderr=stderr)
176178

179+
elif params.target is Target.OPCUA:
180+
return opcua_main.execute(run_context, stdout=stdout, stderr=stderr)
181+
177182
else:
178183
assert_never(params.target)
179184

aas_core_codegen/opcua/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"""Generate the OPC UA Schema node set corresponding to the meta-model."""

0 commit comments

Comments
 (0)