You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@plc4x.apache.org by cd...@apache.org on 2021/10/30 13:10:48 UTC
[plc4x] branch feature/mspec-ng updated: - Got most of the opc-ua
tests working
This is an automated email from the ASF dual-hosted git repository.
cdutz pushed a commit to branch feature/mspec-ng
in repository https://gitbox.apache.org/repos/asf/plc4x.git
The following commit(s) were added to refs/heads/feature/mspec-ng by this push:
new 57f6cd4 - Got most of the opc-ua tests working
57f6cd4 is described below
commit 57f6cd454d79114fce5dafcb473e9461c6de3ef0
Author: cdutz <ch...@c-ware.de>
AuthorDate: Sat Oct 30 15:10:33 2021 +0200
- Got most of the opc-ua tests working
---
.../java/opcua/protocol/OpcuaProtocolLogic.java | 6 +--
.../opcua/protocol/OpcuaSubscriptionHandle.java | 2 +-
.../plc4x/java/spi/optimizer/BaseOptimizer.java | 1 -
.../java/spi/values/IEC61131ValueHandler.java | 8 +++
.../apache/plc4x/java/spi/values/PlcByteArray.java | 61 ++++++++++++++++++++++
5 files changed, 72 insertions(+), 6 deletions(-)
diff --git a/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/protocol/OpcuaProtocolLogic.java b/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/protocol/OpcuaProtocolLogic.java
index 03b38df..d43ec1f 100644
--- a/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/protocol/OpcuaProtocolLogic.java
+++ b/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/protocol/OpcuaProtocolLogic.java
@@ -611,14 +611,12 @@ public class OpcuaProtocolLogic extends Plc4xProtocolBase<OpcuaAPU> implements H
NULL_EXTENSION_OBJECT);
List<ExtensionObjectDefinition> writeValueList = new ArrayList<>(request.getFieldNames().size());
- Iterator<String> iterator = request.getFieldNames().iterator();
- for (int i = 0; i < request.getFieldNames().size(); i++ ) {
- String fieldName = iterator.next();
+ for (String fieldName : request.getFieldNames()) {
OpcuaField field = (OpcuaField) request.getField(fieldName);
NodeId nodeId = generateNodeId(field);
- writeValueList.set(i, new WriteValue(nodeId,
+ writeValueList.add(new WriteValue(nodeId,
0xD,
NULL_STRING,
new DataValue(
diff --git a/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/protocol/OpcuaSubscriptionHandle.java b/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/protocol/OpcuaSubscriptionHandle.java
index 6c27ff7..e0333bc 100644
--- a/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/protocol/OpcuaSubscriptionHandle.java
+++ b/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/protocol/OpcuaSubscriptionHandle.java
@@ -126,7 +126,7 @@ public class OpcuaSubscriptionHandle extends DefaultPlcSubscriptionHandle {
MonitoredItemCreateRequest request = new MonitoredItemCreateRequest(
readValueId, monitoringMode, parameters);
- requestList.set(i, request);
+ requestList.add(request);
}
CompletableFuture<CreateMonitoredItemsResponse> future = new CompletableFuture<>();
diff --git a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/optimizer/BaseOptimizer.java b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/optimizer/BaseOptimizer.java
index 8d32056..dcc91a4 100644
--- a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/optimizer/BaseOptimizer.java
+++ b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/optimizer/BaseOptimizer.java
@@ -30,7 +30,6 @@ import org.apache.plc4x.java.spi.messages.utils.ResponseItem;
import java.util.*;
import java.util.concurrent.CompletableFuture;
-import java.util.concurrent.ExecutionException;
import java.util.function.Function;
public abstract class BaseOptimizer {
diff --git a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/values/IEC61131ValueHandler.java b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/values/IEC61131ValueHandler.java
index da9a8cd..5ee14ba 100644
--- a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/values/IEC61131ValueHandler.java
+++ b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/values/IEC61131ValueHandler.java
@@ -29,6 +29,7 @@ import java.time.Duration;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
+import java.util.List;
public class IEC61131ValueHandler implements PlcValueHandler {
@@ -53,6 +54,10 @@ public class IEC61131ValueHandler implements PlcValueHandler {
return of(new Object[]{value});
}
+ public static PlcValue of(List<?> value) {
+ return of(value.toArray());
+ }
+
public static PlcValue of(Object[] values) {
if (values.length != 1) {
PlcList list = new PlcList();
@@ -68,6 +73,9 @@ public class IEC61131ValueHandler implements PlcValueHandler {
if (value instanceof Byte) {
return PlcSINT.of(value);
}
+ if (value instanceof byte[]) {
+ return PlcByteArray.of(value);
+ }
if (value instanceof Short) {
return PlcINT.of(value);
}
diff --git a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/values/PlcByteArray.java b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/values/PlcByteArray.java
new file mode 100644
index 0000000..f6da107
--- /dev/null
+++ b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/values/PlcByteArray.java
@@ -0,0 +1,61 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.plc4x.java.spi.values;
+
+import com.fasterxml.jackson.annotation.JsonCreator;
+import com.fasterxml.jackson.annotation.JsonIgnore;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.annotation.JsonTypeInfo;
+import org.apache.commons.codec.binary.Hex;
+import org.apache.plc4x.java.spi.generation.ParseException;
+import org.apache.plc4x.java.spi.generation.WriteBuffer;
+
+@JsonTypeInfo(use = JsonTypeInfo.Id.CLASS, property = "className")
+public class PlcByteArray extends PlcIECValue<byte[]> {
+
+ public static PlcByteArray of(Object value) {
+ if (value instanceof byte[]) {
+ return new PlcByteArray((byte[]) value);
+ }
+ throw new IllegalArgumentException("Only byte[] supported here");
+ }
+
+ @JsonCreator(mode = JsonCreator.Mode.PROPERTIES)
+ public PlcByteArray(@JsonProperty("value")byte[] value) {
+ this.value = value;
+ this.isNullable = false;
+ }
+
+ @Override
+ @JsonIgnore
+ public String toString() {
+ return Hex.encodeHexString(value);
+ }
+
+ @JsonIgnore
+ public byte[] getBytes() {
+ return value;
+ }
+
+ @Override
+ public void serialize(WriteBuffer writeBuffer) throws ParseException {
+ writeBuffer.writeByteArray(getClass().getSimpleName(), value);
+ }
+
+}