Search in sources :

Example 1 with UaServerNode

use of org.eclipse.milo.opcua.sdk.server.nodes.UaServerNode in project milo by eclipse.

the class AttributeReader method getEncodingId.

@Nullable
private static NodeId getEncodingId(AttributeContext context, UaServerNode node, QualifiedName encodingName) {
    // TODO avoid dynamic lookup by registering codecs with their associated DataType and Encoding name
    NodeId dataTypeId;
    if (node instanceof VariableNode) {
        dataTypeId = ((VariableNode) node).getDataType();
    } else if (node instanceof VariableTypeNode) {
        dataTypeId = ((VariableTypeNode) node).getDataType();
    } else {
        return null;
    }
    AddressSpaceManager addressSpaceManager = context.getServer().getAddressSpaceManager();
    UaNode dataTypeNode = addressSpaceManager.getManagedNode(dataTypeId).orElse(null);
    if (dataTypeNode != null) {
        return dataTypeNode.getReferences().stream().filter(r -> r.isForward() && Identifiers.HasEncoding.equals(r.getReferenceTypeId())).flatMap(r -> opt2stream(addressSpaceManager.getManagedNode(r.getTargetNodeId()))).filter(n -> encodingName.equals(n.getBrowseName())).map(Node::getNodeId).findFirst().orElse(null);
    } else {
        return null;
    }
}
Also used : DataTypeEncoding(org.eclipse.milo.opcua.stack.core.types.DataTypeEncoding) OpcUaDefaultBinaryEncoding(org.eclipse.milo.opcua.stack.core.types.OpcUaDefaultBinaryEncoding) VariableNode(org.eclipse.milo.opcua.sdk.core.nodes.VariableNode) DataValue(org.eclipse.milo.opcua.stack.core.types.builtin.DataValue) VariableTypeNode(org.eclipse.milo.opcua.sdk.core.nodes.VariableTypeNode) ExtensionObject(org.eclipse.milo.opcua.stack.core.types.builtin.ExtensionObject) AccessLevel(org.eclipse.milo.opcua.sdk.core.AccessLevel) QualifiedName(org.eclipse.milo.opcua.stack.core.types.builtin.QualifiedName) AttributeUtil.getAccessLevels(org.eclipse.milo.opcua.sdk.server.util.AttributeUtil.getAccessLevels) AttributeId(org.eclipse.milo.opcua.stack.core.AttributeId) OpcUaDefaultXmlEncoding(org.eclipse.milo.opcua.stack.core.types.OpcUaDefaultXmlEncoding) StatusCodes(org.eclipse.milo.opcua.stack.core.StatusCodes) TimestampsToReturn(org.eclipse.milo.opcua.stack.core.types.enumerated.TimestampsToReturn) NodeId(org.eclipse.milo.opcua.stack.core.types.builtin.NodeId) ArrayUtil(org.eclipse.milo.opcua.stack.core.util.ArrayUtil) Set(java.util.Set) NumericRange(org.eclipse.milo.opcua.sdk.core.NumericRange) UaNode(org.eclipse.milo.opcua.sdk.server.nodes.UaNode) OpcUaServer(org.eclipse.milo.opcua.sdk.server.OpcUaServer) Nullable(org.jetbrains.annotations.Nullable) AttributeUtil.getUserAccessLevels(org.eclipse.milo.opcua.sdk.server.util.AttributeUtil.getUserAccessLevels) AddressSpaceManager(org.eclipse.milo.opcua.sdk.server.api.AddressSpaceManager) AttributeContext(org.eclipse.milo.opcua.sdk.server.nodes.AttributeContext) Variant(org.eclipse.milo.opcua.stack.core.types.builtin.Variant) NodeClass(org.eclipse.milo.opcua.stack.core.types.enumerated.NodeClass) UaException(org.eclipse.milo.opcua.stack.core.UaException) Optional(java.util.Optional) Node(org.eclipse.milo.opcua.sdk.core.nodes.Node) UaServerNode(org.eclipse.milo.opcua.sdk.server.nodes.UaServerNode) StreamUtil.opt2stream(org.eclipse.milo.opcua.sdk.core.util.StreamUtil.opt2stream) ArrayUtil.transformArray(org.eclipse.milo.opcua.stack.core.util.ArrayUtil.transformArray) Identifiers(org.eclipse.milo.opcua.stack.core.Identifiers) VariableNode(org.eclipse.milo.opcua.sdk.core.nodes.VariableNode) VariableNode(org.eclipse.milo.opcua.sdk.core.nodes.VariableNode) VariableTypeNode(org.eclipse.milo.opcua.sdk.core.nodes.VariableTypeNode) UaNode(org.eclipse.milo.opcua.sdk.server.nodes.UaNode) Node(org.eclipse.milo.opcua.sdk.core.nodes.Node) UaServerNode(org.eclipse.milo.opcua.sdk.server.nodes.UaServerNode) NodeId(org.eclipse.milo.opcua.stack.core.types.builtin.NodeId) UaNode(org.eclipse.milo.opcua.sdk.server.nodes.UaNode) VariableTypeNode(org.eclipse.milo.opcua.sdk.core.nodes.VariableTypeNode) AddressSpaceManager(org.eclipse.milo.opcua.sdk.server.api.AddressSpaceManager) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with UaServerNode

use of org.eclipse.milo.opcua.sdk.server.nodes.UaServerNode in project milo by eclipse.

the class ManagedAddressSpace method write.

@Override
public void write(WriteContext context, List<WriteValue> writeValues) {
    List<StatusCode> results = Lists.newArrayListWithCapacity(writeValues.size());
    for (WriteValue writeValue : writeValues) {
        UaServerNode node = nodeManager.get(writeValue.getNodeId());
        if (node != null) {
            try {
                node.writeAttribute(new AttributeContext(context), writeValue.getAttributeId(), writeValue.getValue(), writeValue.getIndexRange());
                results.add(StatusCode.GOOD);
                logger.debug("Wrote value {} to {} attribute of {}", writeValue.getValue().getValue(), AttributeId.from(writeValue.getAttributeId()).map(Object::toString).orElse("unknown"), node.getNodeId());
            } catch (UaException e) {
                logger.error("Unable to write value={}", writeValue.getValue(), e);
                results.add(e.getStatusCode());
            }
        } else {
            results.add(new StatusCode(StatusCodes.Bad_NodeIdUnknown));
        }
    }
    context.success(results);
}
Also used : WriteValue(org.eclipse.milo.opcua.stack.core.types.structured.WriteValue) AttributeContext(org.eclipse.milo.opcua.sdk.server.nodes.AttributeContext) UaException(org.eclipse.milo.opcua.stack.core.UaException) UaServerNode(org.eclipse.milo.opcua.sdk.server.nodes.UaServerNode) StatusCode(org.eclipse.milo.opcua.stack.core.types.builtin.StatusCode)

Example 3 with UaServerNode

use of org.eclipse.milo.opcua.sdk.server.nodes.UaServerNode in project milo by eclipse.

the class ManagedAddressSpace method read.

@Override
public void read(ReadContext context, Double maxAge, TimestampsToReturn timestamps, List<ReadValueId> readValueIds) {
    List<DataValue> results = Lists.newArrayListWithCapacity(readValueIds.size());
    for (ReadValueId readValueId : readValueIds) {
        UaServerNode node = nodeManager.get(readValueId.getNodeId());
        if (node != null) {
            DataValue value = node.readAttribute(new AttributeContext(context), readValueId.getAttributeId(), timestamps, readValueId.getIndexRange(), readValueId.getDataEncoding());
            logger.debug("Read value {} from attribute {} of {}", value.getValue().getValue(), AttributeId.from(readValueId.getAttributeId()).map(Object::toString).orElse("unknown"), node.getNodeId());
            results.add(value);
        } else {
            results.add(new DataValue(StatusCodes.Bad_NodeIdUnknown));
        }
    }
    context.success(results);
}
Also used : ReadValueId(org.eclipse.milo.opcua.stack.core.types.structured.ReadValueId) AttributeContext(org.eclipse.milo.opcua.sdk.server.nodes.AttributeContext) DataValue(org.eclipse.milo.opcua.stack.core.types.builtin.DataValue) UaServerNode(org.eclipse.milo.opcua.sdk.server.nodes.UaServerNode)

Aggregations

AttributeContext (org.eclipse.milo.opcua.sdk.server.nodes.AttributeContext)3 UaServerNode (org.eclipse.milo.opcua.sdk.server.nodes.UaServerNode)3 UaException (org.eclipse.milo.opcua.stack.core.UaException)2 DataValue (org.eclipse.milo.opcua.stack.core.types.builtin.DataValue)2 Optional (java.util.Optional)1 Set (java.util.Set)1 AccessLevel (org.eclipse.milo.opcua.sdk.core.AccessLevel)1 NumericRange (org.eclipse.milo.opcua.sdk.core.NumericRange)1 Node (org.eclipse.milo.opcua.sdk.core.nodes.Node)1 VariableNode (org.eclipse.milo.opcua.sdk.core.nodes.VariableNode)1 VariableTypeNode (org.eclipse.milo.opcua.sdk.core.nodes.VariableTypeNode)1 StreamUtil.opt2stream (org.eclipse.milo.opcua.sdk.core.util.StreamUtil.opt2stream)1 OpcUaServer (org.eclipse.milo.opcua.sdk.server.OpcUaServer)1 AddressSpaceManager (org.eclipse.milo.opcua.sdk.server.api.AddressSpaceManager)1 UaNode (org.eclipse.milo.opcua.sdk.server.nodes.UaNode)1 AttributeUtil.getAccessLevels (org.eclipse.milo.opcua.sdk.server.util.AttributeUtil.getAccessLevels)1 AttributeUtil.getUserAccessLevels (org.eclipse.milo.opcua.sdk.server.util.AttributeUtil.getUserAccessLevels)1 AttributeId (org.eclipse.milo.opcua.stack.core.AttributeId)1 Identifiers (org.eclipse.milo.opcua.stack.core.Identifiers)1 StatusCodes (org.eclipse.milo.opcua.stack.core.StatusCodes)1