Skip to content

Commit

Permalink
feat: accept Organizes tag set container nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
cailloumajor committed Sep 13, 2023
1 parent 486e147 commit 9aed8ea
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 22 deletions.
5 changes: 5 additions & 0 deletions integration/config-api/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@
"namespaceUri": "http://opcfoundation.org/UA/",
"nodeIdentifier": 2256
},
{
"type": "container",
"namespaceUri": "http://microsoft.com/Opc/OpcPlc/",
"nodeIdentifier": "Basic"
},
{
"type": "tag",
"name": "slowNumberOfUpdates",
Expand Down
16 changes: 11 additions & 5 deletions integration/tests.mongodb
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,22 @@ result = db.data.findOne(
{
state: "$val.State",
slowNumberOfUpdates: "$val.slowNumberOfUpdates",
alternatingBoolean: "$val.AlternatingBoolean",
randomUnsignedInt32: "$val.RandomUnsignedInt32",
timeDiff: {
$abs: {
$subtract: [
{ $dateFromString: { dateString: "$val.CurrentTime" } },
{ $dateFromString: { dateString: "$val.StartTime" } }
]
}
{ $dateFromString: { dateString: "$val.StartTime" } },
],
},
},
timestampDiff: {
$dateDiff: {
startDate: "$ts.State",
endDate: "$$NOW",
unit: "millisecond"
}
unit: "millisecond",
},
},
}
);
Expand All @@ -33,6 +35,10 @@ assert.equal(result.state, 0);

assert.equal(result.slowNumberOfUpdates, -1);

assert.equal(typeof result.alternatingBoolean, "boolean");

assert.ok(result.randomUnsignedInt32 > 0);

assert.ok(result.timeDiff > 0);

assert.ok(result.timestampDiff > 0);
50 changes: 33 additions & 17 deletions src/opcua/tag_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,16 @@ impl TagSet {
.get(&namespace_uri)
.with_context(|| format!("namespace `{namespace_uri}` not found"))?;
let node_id = NodeId::new(*namespace, node_identifier);
let result_mask = (BrowseDescriptionResultMask::RESULT_MASK_DISPLAY_NAME
| BrowseDescriptionResultMask::RESULT_MASK_REFERENCE_TYPE)
.bits();
let browse_description = BrowseDescription {
node_id: node_id.clone(),
browse_direction: BrowseDirection::Forward,
reference_type_id: ReferenceTypeId::HasComponent.into(),
include_subtypes: false,
reference_type_id: ReferenceTypeId::HierarchicalReferences.into(),
include_subtypes: true,
node_class_mask: NodeClassMask::VARIABLE.bits(),
result_mask: BrowseDescriptionResultMask::RESULT_MASK_DISPLAY_NAME.bits(),
result_mask,
};
let browse_result = session
.browse(&[browse_description])
Expand All @@ -85,8 +88,13 @@ impl TagSet {
node_id,
display_name,
..
} in references
{
} in references.into_iter().filter(|ref_description| {
use ReferenceTypeId::*;
matches!(
ref_description.reference_type_id.as_reference_type_id(),
Ok(HasComponent | Organizes)
)
}) {
tag_set.push(Tag {
name: display_name.to_string(),
node_id: node_id.node_id,
Expand Down Expand Up @@ -303,18 +311,25 @@ mod tests {
},
];
let namespaces = HashMap::from([("urn:ns".to_string(), 1), ("urn:ns2".to_string(), 2)]);
let references = [VariableId::LocalTime, VariableId::Server_ServiceLevel]
.iter()
.map(|var| ReferenceDescription {
reference_type_id: NodeId::null(),
is_forward: true,
node_id: NodeId::from(var).into(),
browse_name: QualifiedName::null(),
display_name: format!("{var:?}").into(),
node_class: NodeClass::Unspecified,
type_definition: ExpandedNodeId::null(),
})
.collect();
let references = [
(VariableId::LocalTime, ReferenceTypeId::HasComponent),
(VariableId::Server_ServiceLevel, ReferenceTypeId::Organizes),
(
VariableId::Server_ServerStatus,
ReferenceTypeId::HasEventSource,
),
]
.iter()
.map(|(variable_id, reference_type)| ReferenceDescription {
reference_type_id: reference_type.into(),
is_forward: true,
node_id: NodeId::from(variable_id).into(),
browse_name: QualifiedName::null(),
display_name: format!("{variable_id:?}").into(),
node_class: NodeClass::Unspecified,
type_definition: ExpandedNodeId::null(),
})
.collect();
let session = ViewServiceMock {
browse_outcome: Ok(Some(vec![BrowseResult {
status_code: StatusCode::Good,
Expand All @@ -326,6 +341,7 @@ mod tests {
let result = TagSet::from_config(config, &namespaces, &session)
.expect("result should not be an error");

assert_eq!(result.0.len(), 3);
assert_eq!(result.0[0].name, "LocalTime");
assert_eq!(result.0[0].node_id, VariableId::LocalTime.into());
assert_eq!(result.0[1].name, "Server_ServiceLevel");
Expand Down

0 comments on commit 9aed8ea

Please sign in to comment.