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;
}
}
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);
}
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);
}
Aggregations