Skip to content

Commit

Permalink
WIP adding new Node attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinherron committed Mar 26, 2022
1 parent ac667b6 commit 0fc226a
Show file tree
Hide file tree
Showing 24 changed files with 2,613 additions and 1,568 deletions.
Expand Up @@ -10,8 +10,11 @@

package org.eclipse.milo.opcua.sdk.client;

import java.util.Arrays;
import java.util.EnumSet;
import java.util.List;
import java.util.concurrent.ExecutionException;
import java.util.stream.Collectors;

import org.eclipse.milo.opcua.sdk.client.AddressSpace.BrowseOptions;
import org.eclipse.milo.opcua.sdk.client.model.nodes.objects.ServerTypeNode;
Expand All @@ -26,7 +29,10 @@
import org.eclipse.milo.opcua.stack.core.types.builtin.QualifiedName;
import org.eclipse.milo.opcua.stack.core.types.builtin.StatusCode;
import org.eclipse.milo.opcua.stack.core.types.builtin.Variant;
import org.eclipse.milo.opcua.stack.core.types.enumerated.TimestampsToReturn;
import org.eclipse.milo.opcua.stack.core.types.structured.BuildInfo;
import org.eclipse.milo.opcua.stack.core.types.structured.ReadResponse;
import org.eclipse.milo.opcua.stack.core.types.structured.ReadValueId;
import org.eclipse.milo.opcua.stack.core.types.structured.ReferenceDescription;
import org.junit.jupiter.api.Test;

Expand Down Expand Up @@ -95,6 +101,37 @@ public void read() throws UaException {
assertNotNull(descriptionValue);
}

@Test
public void readBaseNodeAttributes() throws ExecutionException, InterruptedException {
NodeId nodeId = new NodeId(2, "TestInt32");

List<ReadValueId> readValueIds = AttributeId.BASE_ATTRIBUTES.stream()
.map(
aid ->
new ReadValueId(nodeId, aid.uid(), null, QualifiedName.NULL_VALUE)
)
.collect(Collectors.toList());

ReadResponse response = client.read(
0.0,
TimestampsToReturn.Both,
readValueIds
).get();

Arrays.stream(response.getResults()).forEach(v -> System.out.println(v.getValue().getValue()));
}

@Test
public void readBaseNodeAttributes2() throws UaException {
NodeId nodeId = new NodeId(2, "TestInt32");

UaNode node = client.getAddressSpace().getNode(nodeId);

assertNotNull(node.getRolePermissions());
assertNotNull(node.getUserRolePermissions());
assertNotNull(node.getAccessRestrictions());
}

@Test
public void write() throws UaException {
AddressSpace addressSpace = client.getAddressSpace();
Expand Down
Expand Up @@ -44,12 +44,16 @@
import org.eclipse.milo.opcua.stack.core.types.builtin.QualifiedName;
import org.eclipse.milo.opcua.stack.core.types.builtin.StatusCode;
import org.eclipse.milo.opcua.stack.core.types.builtin.Variant;
import org.eclipse.milo.opcua.stack.core.types.structured.AccessRestrictionType;
import org.eclipse.milo.opcua.stack.core.types.structured.Argument;
import org.eclipse.milo.opcua.stack.core.types.structured.PermissionType;
import org.eclipse.milo.opcua.stack.core.types.structured.Range;
import org.eclipse.milo.opcua.stack.core.types.structured.RolePermissionType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import static org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.Unsigned.ubyte;
import static org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.Unsigned.uint;
import static org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.Unsigned.ushort;

public class TestNamespace extends ManagedNamespaceWithLifecycle {
Expand Down Expand Up @@ -91,6 +95,13 @@ public void shutdown() {
.setDisplayName(LocalizedText.english("TestInt32"))
.setDataType(Identifiers.Int32)
.setTypeDefinition(Identifiers.BaseDataVariableType)
.setRolePermissions(new RolePermissionType[] {
new RolePermissionType(newNodeId("roleId"), new PermissionType(uint(0)))
})
.setUserRolePermissions(new RolePermissionType[] {
new RolePermissionType(newNodeId("roleId"), new PermissionType(uint(0)))
})
.setAccessRestrictions(new AccessRestrictionType(uint(0)))
.build();

testInt32Node.setValue(new DataValue(new Variant(0)));
Expand Down
Expand Up @@ -50,11 +50,14 @@
import org.eclipse.milo.opcua.stack.core.types.enumerated.BrowseResultMask;
import org.eclipse.milo.opcua.stack.core.types.enumerated.NodeClass;
import org.eclipse.milo.opcua.stack.core.types.enumerated.TimestampsToReturn;
import org.eclipse.milo.opcua.stack.core.types.structured.AccessLevelExType;
import org.eclipse.milo.opcua.stack.core.types.structured.AccessRestrictionType;
import org.eclipse.milo.opcua.stack.core.types.structured.BrowseDescription;
import org.eclipse.milo.opcua.stack.core.types.structured.BrowseResult;
import org.eclipse.milo.opcua.stack.core.types.structured.ReadResponse;
import org.eclipse.milo.opcua.stack.core.types.structured.ReadValueId;
import org.eclipse.milo.opcua.stack.core.types.structured.ReferenceDescription;
import org.eclipse.milo.opcua.stack.core.types.structured.RolePermissionType;
import org.jetbrains.annotations.Nullable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -1339,34 +1342,51 @@ private UaVariableNode newVariableNode(
List<DataValue> attributeValues
) throws UaException {

DataValue nodeIdDataValue = attributeValues.get(0);
int ai = 0;
DataValue nodeIdDataValue = attributeValues.get(ai++);
StatusCode nodeIdStatusCode = nodeIdDataValue.getStatusCode();
if (nodeIdStatusCode != null && nodeIdStatusCode.isBad()) {
throw new UaException(nodeIdStatusCode);
}

try {
NodeClass nodeClass = NodeClass.from((Integer) attributeValues.get(1).getValue().getValue());
NodeClass nodeClass = NodeClass.from((Integer) attributeValues.get(ai++).getValue().getValue());

Preconditions.checkArgument(
nodeClass == NodeClass.Variable,
"expected NodeClass.Variable, got NodeClass." + nodeClass
);

QualifiedName browseName = (QualifiedName) attributeValues.get(2).getValue().getValue();
LocalizedText displayName = (LocalizedText) attributeValues.get(3).getValue().getValue();
LocalizedText description = getAttributeOrNull(attributeValues.get(4), LocalizedText.class);
UInteger writeMask = getAttributeOrNull(attributeValues.get(5), UInteger.class);
UInteger userWriteMask = getAttributeOrNull(attributeValues.get(6), UInteger.class);
QualifiedName browseName = (QualifiedName) attributeValues.get(ai++).getValue().getValue();
LocalizedText displayName = (LocalizedText) attributeValues.get(ai++).getValue().getValue();
LocalizedText description = getAttributeOrNull(attributeValues.get(ai++), LocalizedText.class);
UInteger writeMask = getAttributeOrNull(attributeValues.get(ai++), UInteger.class);
UInteger userWriteMask = getAttributeOrNull(attributeValues.get(ai++), UInteger.class);
RolePermissionType[] rolePermissions = getAttributeOrNull(
attributeValues.get(ai++),
RolePermissionType[].class
);
RolePermissionType[] userRolePermissions = getAttributeOrNull(
attributeValues.get(ai++),
RolePermissionType[].class
);
AccessRestrictionType accessRestrictions = getAttributeOrNull(
attributeValues.get(ai++),
AccessRestrictionType.class
);

DataValue value = attributeValues.get(7);
NodeId dataType = (NodeId) attributeValues.get(8).getValue().getValue();
Integer valueRank = (Integer) attributeValues.get(9).getValue().getValue();
UInteger[] arrayDimensions = getAttributeOrNull(attributeValues.get(10), UInteger[].class);
UByte accessLevel = (UByte) attributeValues.get(11).getValue().getValue();
UByte userAccessLevel = (UByte) attributeValues.get(12).getValue().getValue();
Double minimumSamplingInterval = getAttributeOrNull(attributeValues.get(13), Double.class);
Boolean historizing = (Boolean) attributeValues.get(14).getValue().getValue();
DataValue value = attributeValues.get(ai++);
NodeId dataType = (NodeId) attributeValues.get(ai++).getValue().getValue();
Integer valueRank = (Integer) attributeValues.get(ai++).getValue().getValue();
UInteger[] arrayDimensions = getAttributeOrNull(attributeValues.get(ai++), UInteger[].class);
UByte accessLevel = (UByte) attributeValues.get(ai++).getValue().getValue();
UByte userAccessLevel = (UByte) attributeValues.get(ai++).getValue().getValue();
Double minimumSamplingInterval = getAttributeOrNull(attributeValues.get(ai++), Double.class);
Boolean historizing = (Boolean) attributeValues.get(ai++).getValue().getValue();
AccessLevelExType accessLevelEx = getAttributeOrNull(
attributeValues.get(ai),
AccessLevelExType.class
);

VariableTypeManager.VariableNodeConstructor constructor = client.getVariableTypeManager()
.getNodeConstructor(typeDefinitionId)
Expand All @@ -1381,14 +1401,18 @@ private UaVariableNode newVariableNode(
description,
writeMask,
userWriteMask,
rolePermissions,
userRolePermissions,
accessRestrictions,
value,
dataType,
valueRank,
arrayDimensions,
accessLevel,
userAccessLevel,
minimumSamplingInterval,
historizing
historizing,
accessLevelEx
);
} catch (Throwable t) {
throw UaException.extract(t)
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019 the Eclipse Milo Authors
* Copyright (c) 2021 the Eclipse Milo Authors
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
Expand All @@ -22,6 +22,9 @@
import org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.UByte;
import org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.UInteger;
import org.eclipse.milo.opcua.stack.core.types.enumerated.NodeClass;
import org.eclipse.milo.opcua.stack.core.types.structured.AccessLevelExType;
import org.eclipse.milo.opcua.stack.core.types.structured.AccessRestrictionType;
import org.eclipse.milo.opcua.stack.core.types.structured.RolePermissionType;

public class VariableTypeManager {

Expand Down Expand Up @@ -67,14 +70,18 @@ UaVariableNode apply(
LocalizedText description,
UInteger writeMask,
UInteger userWriteMask,
RolePermissionType[] rolePermissions,
RolePermissionType[] userRolePermissions,
AccessRestrictionType accessRestrictions,
DataValue value,
NodeId dataType,
Integer valueRank,
UInteger[] arrayDimensions,
UByte accessLevel,
UByte userAccessLevel,
Double minimumSamplingInterval,
Boolean historizing
Boolean historizing,
AccessLevelExType accessLevelEx
);

}
Expand Down

0 comments on commit 0fc226a

Please sign in to comment.