Skip to content

Commit

Permalink
Merge pull request #36 from PrediktorAS/bugfix/fix-value-validator
Browse files Browse the repository at this point in the history
Bugfix/fix value validator
  • Loading branch information
DawidMakar-acaisoft authored Jan 17, 2024
2 parents 5947910 + ac5a8ae commit 5f448ad
Show file tree
Hide file tree
Showing 7 changed files with 132 additions and 5,013 deletions.
57 changes: 57 additions & 0 deletions opcua_tools/constants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
from opcua_tools.ua_data_types import (
UABoolean,
UAByte,
UAByteString,
UADataValue,
UADateTime,
UADiagnosticInfo,
UADouble,
UAExpandedNodeId,
UAExtensionObject,
UAFloat,
UAGuid,
UAInt16,
UAInt32,
UAInt64,
UALocalizedText,
UANodeId,
UAQualifiedName,
UASByte,
UAStatusCode,
UAString,
UAUInt16,
UAUInt32,
UAUInt64,
UAVariant,
UAXMLElement,
VariantType,
)


DATA_TYPES_MAPPING = {
VariantType.Boolean.name: UABoolean,
VariantType.SByte.name: UASByte,
VariantType.Byte.name: UAByte,
VariantType.Int16.name: UAInt16,
VariantType.UInt16.name: UAUInt16,
VariantType.Int32.name: UAInt32,
VariantType.UInt32.name: UAUInt32,
VariantType.Int64.name: UAInt64,
VariantType.UInt64.name: UAUInt64,
VariantType.Float.name: UAFloat,
VariantType.Double.name: UADouble,
VariantType.String.name: UAString,
VariantType.DateTime.name: UADateTime,
VariantType.Guid.name: UAGuid,
VariantType.ByteString.name: UAByteString,
VariantType.XmlElement.name: UAXMLElement,
VariantType.NodeId.name: UANodeId,
VariantType.ExpandedNodeId.name: UAExpandedNodeId,
VariantType.StatusCode.name: UAStatusCode,
VariantType.QualifiedName.name: UAQualifiedName,
VariantType.LocalizedText.name: UALocalizedText,
VariantType.ExtensionObject.name: UAExtensionObject,
VariantType.DataValue.name: UADataValue,
VariantType.Variant.name: UAVariant,
VariantType.DiagnosticInfo.name: UADiagnosticInfo,
}
11 changes: 7 additions & 4 deletions opcua_tools/nodeset_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,10 @@ def encode_values(nodes):


def generate_nodes_xml(
nodes: pd.DataFrame, references: pd.DataFrame, lookup_df: pd.DataFrame
nodes: pd.DataFrame,
references: pd.DataFrame,
lookup_df: pd.DataFrame,
original_nodes: pd.DataFrame,
):
assert (
nodes["BrowseNameNamespace"].isna().sum() == 0
Expand All @@ -178,6 +181,7 @@ def generate_nodes_xml(
nodes["Description"] = replacer(nodes["Description"])
nodes["NodeId"] = replacer(nodes["NodeId"].map(str))

nodes = value_validator.validate_values_in_df(nodes, original_nodes)
nodes = denormalize_nodes_nodeids(nodes, lookup_df=lookup_df)
references = denormalize_references_nodeids(references, lookup_df=lookup_df)

Expand All @@ -186,7 +190,6 @@ def generate_nodes_xml(
references["ReferenceType"] = replacer(references["ReferenceType"].map(str))

nodes = nodes.copy()
nodes = value_validator.validate_values_in_df(nodes)

encode_values(nodes)
encode_definitions(nodes)
Expand Down Expand Up @@ -302,6 +305,7 @@ def create_nodeset2_file(
nodes=nodes, references=references, namespace_index=serialize_namespace
)
namespaces_in_use.sort()
original_nodes = nodes.copy()
nodes = nodes[nodes["ns"].map(lambda x: x in (namespaces_in_use))].copy()
serialize_namespace_uri = namespaces[serialize_namespace]
original_namespaces = namespaces
Expand All @@ -323,8 +327,7 @@ def create_nodeset2_file(

nodes = nodes[nodes["ns"] == serialize_namespace].copy()
# References restrict themselves

nodes_df = generate_nodes_xml(nodes, references, lookup_df)
nodes_df = generate_nodes_xml(nodes, references, lookup_df, original_nodes)
end_time = time.time()
logger.info(f"Creating nodeset2xml-string took {str(end_time - start_time)}")
logger.info("Writing nodeset2xml")
Expand Down
Loading

0 comments on commit 5f448ad

Please sign in to comment.