This is an automated email from the ASF dual-hosted git repository.
justinchen pushed a commit to branch new_opc_server
in repository https://gitbox.apache.org/repos/asf/iotdb.git
The following commit(s) were added to refs/heads/new_opc_server by this push:
new ae2a493047a object
ae2a493047a is described below
commit ae2a493047ab97f7ab4bb4edf595d2b303db8baf
Author: Caideyipi <[email protected]>
AuthorDate: Thu Dec 4 15:57:16 2025 +0800
object
---
.../java/org/apache/iotdb/opcua/ClientTest.java | 39 ++++++++++++----------
.../pipe/sink/protocol/opcua/OpcUaNameSpace.java | 16 ++++++++-
2 files changed, 36 insertions(+), 19 deletions(-)
diff --git
a/example/pipe-opc-ua-sink/src/main/java/org/apache/iotdb/opcua/ClientTest.java
b/example/pipe-opc-ua-sink/src/main/java/org/apache/iotdb/opcua/ClientTest.java
index f5a8314f9cc..a1aa1ef2521 100644
---
a/example/pipe-opc-ua-sink/src/main/java/org/apache/iotdb/opcua/ClientTest.java
+++
b/example/pipe-opc-ua-sink/src/main/java/org/apache/iotdb/opcua/ClientTest.java
@@ -19,12 +19,10 @@
package org.apache.iotdb.opcua;
-import io.netty.buffer.ByteBuf;
import org.eclipse.milo.opcua.sdk.client.OpcUaClient;
import org.eclipse.milo.opcua.sdk.core.AccessLevel;
import org.eclipse.milo.opcua.sdk.core.ValueRanks;
import org.eclipse.milo.opcua.stack.core.Identifiers;
-import org.eclipse.milo.opcua.stack.core.types.builtin.ByteString;
import org.eclipse.milo.opcua.stack.core.types.builtin.DataValue;
import org.eclipse.milo.opcua.stack.core.types.builtin.DateTime;
import org.eclipse.milo.opcua.stack.core.types.builtin.ExtensionObject;
@@ -39,8 +37,10 @@ import
org.eclipse.milo.opcua.stack.core.types.enumerated.TimestampsToReturn;
import org.eclipse.milo.opcua.stack.core.types.structured.AddNodesItem;
import org.eclipse.milo.opcua.stack.core.types.structured.AddNodesResponse;
import org.eclipse.milo.opcua.stack.core.types.structured.DeleteNodesItem;
+import org.eclipse.milo.opcua.stack.core.types.structured.ObjectAttributes;
import org.eclipse.milo.opcua.stack.core.types.structured.VariableAttributes;
+import java.util.Arrays;
import java.util.Collections;
import java.util.concurrent.CompletableFuture;
@@ -80,7 +80,16 @@ public class ClientTest implements ClientExample {
AddNodesResponse addStatus =
client
.addNodes(
- Collections.singletonList(
+ Arrays.asList(
+ new AddNodesItem(
+ new NodeId(2, "root/sg").expanded(),
+ Identifiers.Organizes,
+ new NodeId(2, "root/sg/d2").expanded(),
+ new QualifiedName(2, "d2"),
+ NodeClass.Object,
+ ExtensionObject.encode(
+ client.getStaticSerializationContext(),
createFolderAttributes()),
+ Identifiers.ObjectsFolder.expanded()),
new AddNodesItem(
new NodeId(2, "root/sg/d1").expanded(),
Identifiers.Organizes,
@@ -114,20 +123,14 @@ public class ClientTest implements ClientExample {
);
}
- // 方法1:将 ByteBuf 转换为 ByteString
- public static ByteString convertByteBufToByteString(ByteBuf byteBuf) {
- // 确保 ByteBuf 可读
- if (byteBuf == null || byteBuf.readableBytes() == 0) {
- return ByteString.NULL_VALUE; // 返回空 ByteString
- }
-
- // 创建与 ByteBuf 可读字节数相同的字节数组
- byte[] bytes = new byte[byteBuf.readableBytes()];
-
- // 将 ByteBuf 数据读取到字节数组
- byteBuf.readBytes(bytes);
-
- // 使用 ByteString.of() 创建 ByteString
- return ByteString.of(bytes);
+ public static ObjectAttributes createFolderAttributes() {
+ return new ObjectAttributes(
+ Unsigned.uint(0xFFFF), // specifiedAttributes
+ LocalizedText.english("d2"),
+ LocalizedText.english("反应釜压力传感器"),
+ Unsigned.uint(0), // writeMask
+ Unsigned.uint(0), // userWriteMask
+ null // 启用历史记录
+ );
}
}
diff --git
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/sink/protocol/opcua/OpcUaNameSpace.java
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/sink/protocol/opcua/OpcUaNameSpace.java
index 0386c59decf..8209a44a876 100644
---
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/sink/protocol/opcua/OpcUaNameSpace.java
+++
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/sink/protocol/opcua/OpcUaNameSpace.java
@@ -45,6 +45,7 @@ import org.eclipse.milo.opcua.sdk.server.api.MonitoredItem;
import org.eclipse.milo.opcua.sdk.server.model.nodes.objects.BaseEventTypeNode;
import org.eclipse.milo.opcua.sdk.server.nodes.UaFolderNode;
import org.eclipse.milo.opcua.sdk.server.nodes.UaNode;
+import org.eclipse.milo.opcua.sdk.server.nodes.UaObjectNode;
import org.eclipse.milo.opcua.sdk.server.nodes.UaVariableNode;
import org.eclipse.milo.opcua.sdk.server.util.SubscriptionModel;
import org.eclipse.milo.opcua.stack.core.Identifiers;
@@ -59,6 +60,7 @@ 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.AddNodesItem;
import org.eclipse.milo.opcua.stack.core.types.structured.AddNodesResult;
+import org.eclipse.milo.opcua.stack.core.types.structured.ObjectAttributes;
import org.eclipse.milo.opcua.stack.core.types.structured.VariableAttributes;
import java.nio.file.Paths;
@@ -526,7 +528,7 @@ public class OpcUaNameSpace extends
ManagedNamespaceWithLifecycle {
}
// Construct node
- UaNode newNode = null;
+ final UaNode newNode;
switch (item.getNodeClass()) {
case Variable:
final VariableAttributes variableAttributes =
@@ -555,6 +557,18 @@ public class OpcUaNameSpace extends
ManagedNamespaceWithLifecycle {
new DateTime()));
break;
case Object:
+ final ObjectAttributes objectAttributes =
+ (ObjectAttributes)
+
item.getNodeAttributes().decode(getServer().getSerializationContext());
+ newNode =
+ new UaObjectNode.UaObjectNodeBuilder(getNodeContext())
+ .setNodeId(nodeId.get())
+ .setBrowseName(item.getBrowseName())
+ .setDisplayName(objectAttributes.getDisplayName())
+ .setTypeDefinition(typeDefinition.get())
+ .setWriteMask(objectAttributes.getWriteMask())
+ .setUserWriteMask(objectAttributes.getUserWriteMask())
+ .build();
break;
default:
results.add(