|
@@ -2,19 +2,23 @@ package com.judong.chuanyiserver.util;
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.judong.chuanyiserver.entity.DataSource;
|
|
|
+import com.judong.chuanyiserver.entity.Item;
|
|
|
import com.judong.chuanyiserver.enums.ResultEnum;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.eclipse.milo.opcua.sdk.client.OpcUaClient;
|
|
|
import org.eclipse.milo.opcua.sdk.client.api.config.OpcUaClientConfig;
|
|
|
import org.eclipse.milo.opcua.sdk.client.api.identity.AnonymousProvider;
|
|
|
import org.eclipse.milo.opcua.sdk.client.api.identity.UsernameProvider;
|
|
|
+import org.eclipse.milo.opcua.sdk.client.model.nodes.variables.PropertyTypeNode;
|
|
|
import org.eclipse.milo.opcua.sdk.client.nodes.UaNode;
|
|
|
import org.eclipse.milo.opcua.stack.client.DiscoveryClient;
|
|
|
import org.eclipse.milo.opcua.stack.core.Identifiers;
|
|
|
import org.eclipse.milo.opcua.stack.core.UaException;
|
|
|
import org.eclipse.milo.opcua.stack.core.security.SecurityPolicy;
|
|
|
-import org.eclipse.milo.opcua.stack.core.types.builtin.LocalizedText;
|
|
|
+import org.eclipse.milo.opcua.stack.core.types.builtin.*;
|
|
|
+import org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.UShort;
|
|
|
import org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.Unsigned;
|
|
|
+import org.eclipse.milo.opcua.stack.core.types.enumerated.TimestampsToReturn;
|
|
|
import org.eclipse.milo.opcua.stack.core.types.structured.EndpointDescription;
|
|
|
|
|
|
import java.nio.file.Files;
|
|
@@ -23,6 +27,7 @@ import java.nio.file.Paths;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
import java.util.Objects;
|
|
|
+import java.util.Optional;
|
|
|
import java.util.concurrent.ExecutionException;
|
|
|
import java.util.function.Predicate;
|
|
|
|
|
@@ -105,7 +110,7 @@ public class OpcUaUtil {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public static Result opcUaGetTree(DataSource dataSource){
|
|
|
+ public static Result opcUaGetTree(DataSource dataSource) {
|
|
|
OpcUaClient opcUaClient = null;
|
|
|
try {
|
|
|
opcUaClient = createClient(dataSource);
|
|
@@ -145,10 +150,40 @@ public class OpcUaUtil {
|
|
|
}
|
|
|
JSONObject jsonObject = new JSONObject();
|
|
|
jsonObject.put("label", nd.getBrowseName().getName());
|
|
|
+// jsonObject.put("nodeId", nd.getNodeId());
|
|
|
+ jsonObject.put("nodeIndex", nd.getNodeId().getNamespaceIndex());
|
|
|
+ jsonObject.put("nodeIndentifier", nd.getNodeId().getIdentifier());
|
|
|
+ jsonObject.put("description", nd.getDescription());
|
|
|
+// PropertyTypeNode nd1 = (PropertyTypeNode) nd;
|
|
|
+// nd1.getMinimumSamplingInterval();
|
|
|
+// DataValue dataValue = client.readValue(0.0, TimestampsToReturn.Neither, nd.getNodeId()).get();
|
|
|
+// Variant value = dataValue.getValue();
|
|
|
+// Object value1 = value.getValue();
|
|
|
+// Optional<ExpandedNodeId> dataType = value.getDataType();
|
|
|
+// int value2 = dataType.get().getType().getValue();
|
|
|
+// UShort serverPicoseconds = dataValue.getServerPicoseconds();
|
|
|
+// DateTime serverTime = dataValue.getServerTime();
|
|
|
+// UShort sourcePicoseconds = dataValue.getSourcePicoseconds();
|
|
|
+// DateTime sourceTime = dataValue.getSourceTime();
|
|
|
+// StatusCode statusCode = dataValue.getStatusCode();
|
|
|
+// jsonObject.put("value",client.readValue(0.0, TimestampsToReturn.Neither, nd.getNodeId()).get());
|
|
|
+// jsonObject.put("nodeId",nd.);
|
|
|
// jsonObject.put("value",client.readValue(0.0, TimestampsToReturn.Neither, nd.getNodeId()).get());
|
|
|
jsonObject.put("children", generOpcUaTree(client, nd));
|
|
|
jsonList.add(jsonObject);
|
|
|
}
|
|
|
return jsonList;
|
|
|
}
|
|
|
+
|
|
|
+ public static List<NodeId> genNodeId(List<Item> itemList) {
|
|
|
+ if (Blank.isEmpty(itemList)) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ List<NodeId> nodeIdList = new ArrayList<>();
|
|
|
+ for (Item item : itemList) {
|
|
|
+ NodeId nodeId = new NodeId(item.getNodeIndex(), item.getNodeIndentifier());
|
|
|
+ nodeIdList.add(nodeId);
|
|
|
+ }
|
|
|
+ return nodeIdList;
|
|
|
+ }
|
|
|
}
|