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 2024/10/20 11:50:29 UTC
(plc4x) 02/03: refactor: Cleaned up the array handling in browse-items.
This is an automated email from the ASF dual-hosted git repository.
cdutz pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/plc4x.git
commit ccf6ebebab36e1bf8d0bd568aa26ffab33a1546b
Author: Christofer Dutz <cd...@apache.org>
AuthorDate: Sun Oct 20 13:49:50 2024 +0200
refactor: Cleaned up the array handling in browse-items.
---
.../plc4x/java/api/messages/PlcBrowseItem.java | 3 +-
.../plc4x/java/ads/protocol/AdsProtocolLogic.java | 20 ++--
.../readwrite/connection/CtrlXConnection.java | 4 +-
.../profinet/protocol/ProfinetProtocolLogic.java | 4 +-
.../java/profinet/device/ProfinetModuleImpl.java | 10 +-
.../java/spi/messages/DefaultPlcBrowseItem.java | 12 ++-
.../messages/DefaultPlcBrowseItemArrayInfo.java | 44 --------
.../spi/messages/DefaultPlcBrowseItemList.java | 117 ---------------------
8 files changed, 28 insertions(+), 186 deletions(-)
diff --git a/plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/PlcBrowseItem.java b/plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/PlcBrowseItem.java
index fdc147332a..2de156b74b 100644
--- a/plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/PlcBrowseItem.java
+++ b/plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/PlcBrowseItem.java
@@ -18,6 +18,7 @@
*/
package org.apache.plc4x.java.api.messages;
+import org.apache.plc4x.java.api.model.ArrayInfo;
import org.apache.plc4x.java.api.model.PlcTag;
import org.apache.plc4x.java.api.value.PlcValue;
@@ -61,7 +62,7 @@ public interface PlcBrowseItem {
/**
* @return list of elements providing information about the array dimensions of this item.
*/
- List<PlcBrowseItemArrayInfo> getArrayInformation();
+ List<ArrayInfo> getArrayInformation();
/**
* @return returns any children this item might have
diff --git a/plc4j/drivers/ads/src/main/java/org/apache/plc4x/java/ads/protocol/AdsProtocolLogic.java b/plc4j/drivers/ads/src/main/java/org/apache/plc4x/java/ads/protocol/AdsProtocolLogic.java
index e4edbe1ccc..08eaa141d0 100644
--- a/plc4j/drivers/ads/src/main/java/org/apache/plc4x/java/ads/protocol/AdsProtocolLogic.java
+++ b/plc4j/drivers/ads/src/main/java/org/apache/plc4x/java/ads/protocol/AdsProtocolLogic.java
@@ -523,15 +523,15 @@ public class AdsProtocolLogic extends Plc4xProtocolBase<AmsTCPPacket> implements
options.put("size-in-bytes", new PlcUDINT(symbol.getSize()));
List<ArrayInfo> arrayInfo = new ArrayList<>(dataType.getArrayInfo().size());
- List<PlcBrowseItemArrayInfo> itemArrayInfo = new ArrayList<>(dataType.getArrayInfo().size());
+ List<ArrayInfo> itemArrayInfo = new ArrayList<>(dataType.getArrayInfo().size());
for (AdsDataTypeArrayInfo adsDataTypeArrayInfo : dataType.getArrayInfo()) {
arrayInfo.add(new DefaultArrayInfo(
(int) adsDataTypeArrayInfo.getLowerBound(), (int) adsDataTypeArrayInfo.getUpperBound()));
- itemArrayInfo.add(new DefaultPlcBrowseItemArrayInfo(
- adsDataTypeArrayInfo.getLowerBound(), adsDataTypeArrayInfo.getUpperBound()));
+ itemArrayInfo.add(new DefaultArrayInfo(
+ (int) adsDataTypeArrayInfo.getLowerBound(), (int) adsDataTypeArrayInfo.getUpperBound()));
}
- DefaultPlcBrowseItemList item = new DefaultPlcBrowseItemList(new SymbolicAdsTag(symbol.getName(), plcValueType, arrayInfo), symbol.getName(),
- true, !symbol.getFlagReadOnly(), true, false, childMap, options, itemArrayInfo);
+ DefaultPlcBrowseItem item = new DefaultPlcBrowseItem(new SymbolicAdsTag(symbol.getName(), plcValueType, arrayInfo), symbol.getName(),
+ true, !symbol.getFlagReadOnly(), true, false, itemArrayInfo, childMap, options);
// Check if this item should be added to the result
if (interceptor.intercept(item)) {
@@ -585,17 +585,17 @@ public class AdsProtocolLogic extends Plc4xProtocolBase<AmsTCPPacket> implements
options.put("size-in-bytes", new PlcUDINT(childDataType.getSize()));
List<ArrayInfo> arrayInfo = new ArrayList<>(childDataType.getArrayInfo().size());
- List<PlcBrowseItemArrayInfo> itemArrayInfo = new ArrayList<>(childDataType.getArrayInfo().size());
+ List<ArrayInfo> itemArrayInfo = new ArrayList<>(childDataType.getArrayInfo().size());
for (AdsDataTypeArrayInfo adsDataTypeArrayInfo : childDataType.getArrayInfo()) {
arrayInfo.add(new DefaultArrayInfo(
(int) adsDataTypeArrayInfo.getLowerBound(), (int) adsDataTypeArrayInfo.getUpperBound()));
- itemArrayInfo.add(new DefaultPlcBrowseItemArrayInfo(
- adsDataTypeArrayInfo.getLowerBound(), adsDataTypeArrayInfo.getUpperBound()));
+ itemArrayInfo.add(new DefaultArrayInfo(
+ (int) adsDataTypeArrayInfo.getLowerBound(), (int) adsDataTypeArrayInfo.getUpperBound()));
}
// Add the type itself.
- values.add(new DefaultPlcBrowseItemList(new SymbolicAdsTag(
+ values.add(new DefaultPlcBrowseItem(new SymbolicAdsTag(
basePath + "." + child.getPropertyName(), plc4xPlcValueType, arrayInfo), child.getPropertyName(),
- true, parentWritable, true, false, childMap, options, itemArrayInfo));
+ true, parentWritable, true, false, itemArrayInfo, childMap, options));
}
return values;
}
diff --git a/plc4j/drivers/ctrlx/src/main/java/org/apache/plc4x/java/ctrlx/readwrite/connection/CtrlXConnection.java b/plc4j/drivers/ctrlx/src/main/java/org/apache/plc4x/java/ctrlx/readwrite/connection/CtrlXConnection.java
index dfff73c39b..454fdb2f72 100644
--- a/plc4j/drivers/ctrlx/src/main/java/org/apache/plc4x/java/ctrlx/readwrite/connection/CtrlXConnection.java
+++ b/plc4j/drivers/ctrlx/src/main/java/org/apache/plc4x/java/ctrlx/readwrite/connection/CtrlXConnection.java
@@ -274,10 +274,10 @@ public class CtrlXConnection implements PlcConnection, PlcPinger, PlcBrowser {
e.printStackTrace();
}*/
matchingQueryNames.forEach(queryName -> responseItems.get(queryName).add(
- new DefaultPlcBrowseItemList(
+ new DefaultPlcBrowseItem(
new CtrlXTag(curNode, PlcValueType.BOOL, Collections.emptyList()),
curNode, true, true, true, false,
- Collections.emptyMap(), Collections.emptyMap(), Collections.emptyList())));
+ Collections.emptyList(), Collections.emptyMap(), Collections.emptyMap())));
}
}
// If this node has children, then it's branch, and we need to add its children to the queue.
diff --git a/plc4j/drivers/profinet-ng/src/main/java/org/apache/plc4x/java/profinet/protocol/ProfinetProtocolLogic.java b/plc4j/drivers/profinet-ng/src/main/java/org/apache/plc4x/java/profinet/protocol/ProfinetProtocolLogic.java
index 68f1c39353..2999014978 100644
--- a/plc4j/drivers/profinet-ng/src/main/java/org/apache/plc4x/java/profinet/protocol/ProfinetProtocolLogic.java
+++ b/plc4j/drivers/profinet-ng/src/main/java/org/apache/plc4x/java/profinet/protocol/ProfinetProtocolLogic.java
@@ -364,7 +364,7 @@ public class ProfinetProtocolLogic extends Plc4xProtocolBase<Ethernet_Frame> imp
slot, subslot, ProfinetTag.Direction.INPUT,
i, dataTypeInformation.getPlcValueType(), dataTypeInformation.getNumElements()),
name, false, true, true, false,
- Collections.emptyMap(), Collections.emptyMap()));
+ Collections.emptyList(), Collections.emptyMap(), Collections.emptyMap()));
}
}
}
@@ -382,7 +382,7 @@ public class ProfinetProtocolLogic extends Plc4xProtocolBase<Ethernet_Frame> imp
slot, subslot, ProfinetTag.Direction.OUTPUT,
i, dataTypeInformation.getPlcValueType(), dataTypeInformation.getNumElements()),
name, false, true, true, false,
- Collections.emptyMap(), Collections.emptyMap()));
+ Collections.emptyList(), Collections.emptyMap(), Collections.emptyMap()));
}
}
}
diff --git a/plc4j/drivers/profinet/src/main/java/org/apache/plc4x/java/profinet/device/ProfinetModuleImpl.java b/plc4j/drivers/profinet/src/main/java/org/apache/plc4x/java/profinet/device/ProfinetModuleImpl.java
index 63a6f8d431..808117c479 100644
--- a/plc4j/drivers/profinet/src/main/java/org/apache/plc4x/java/profinet/device/ProfinetModuleImpl.java
+++ b/plc4j/drivers/profinet/src/main/java/org/apache/plc4x/java/profinet/device/ProfinetModuleImpl.java
@@ -264,19 +264,19 @@ public class ProfinetModuleImpl implements ProfinetModule {
}
String statusName = addressSpace + "." + this.slot + "." + block.getSubSlotNumber() + "." + virtual.getId() + ".Status";
- browseItems.add(new DefaultPlcBrowseItem(ProfinetTag.of(statusName + ":INT"), statusName, false, false, true, false, new HashMap<>(), options));
+ browseItems.add(new DefaultPlcBrowseItem(ProfinetTag.of(statusName + ":INT"), statusName, false, false, true, false, Collections.emptyList(), new HashMap<>(), options));
if (virtual.getIoData() != null && virtual.getIoData().getInput() != null) {
for (ProfinetIoDataInput input : virtual.getIoData().getInput()) {
for (ProfinetDataItem item : input.getDataItemList()) {
if (item.isUseAsBits()) {
for (int i = 0; i < ProfinetDataType.firstEnumForFieldConversion(item.getDataType().toUpperCase()).getDataTypeSize() * 8; i++) {
String tagName = addressSpace + "." + this.slot + "." + block.getSubSlotNumber() + "." + item.getTextId() + "." + i;
- browseItems.add(new DefaultPlcBrowseItem(ProfinetTag.of(tagName + ":BOOL"), tagName, false, false, true, false, new HashMap<>(), options));
+ browseItems.add(new DefaultPlcBrowseItem(ProfinetTag.of(tagName + ":BOOL"), tagName, false, false, true, false, Collections.emptyList(), new HashMap<>(), options));
}
} else {
String tagName = addressSpace + "." + this.slot + "." + block.getSubSlotNumber() + "." + item.getTextId();
String datatype = ProfinetDataType.firstEnumForFieldConversion(item.getDataType().toUpperCase()).toString();
- browseItems.add(new DefaultPlcBrowseItem(ProfinetTag.of(tagName + ":" + datatype), tagName, false, false, true, false, new HashMap<>(), options));
+ browseItems.add(new DefaultPlcBrowseItem(ProfinetTag.of(tagName + ":" + datatype), tagName, false, false, true, false, Collections.emptyList(), new HashMap<>(), options));
}
}
}
@@ -287,13 +287,13 @@ public class ProfinetModuleImpl implements ProfinetModule {
for (ProfinetInterfaceSubmoduleItem systemInterface : module.getSystemDefinedSubmoduleList().getInterfaceSubmodules()) {
if (identNumber == systemInterface.getSubslotNumber()) {
String statusName = addressSpace + "." + this.slot + "." + block.getSubSlotNumber() + "." + systemInterface.getId() + ".Status";
- browseItems.add(new DefaultPlcBrowseItem(ProfinetTag.of(statusName + ":INT"), statusName, false, false, true, false, new HashMap<>(), options));
+ browseItems.add(new DefaultPlcBrowseItem(ProfinetTag.of(statusName + ":INT"), statusName, false, false, true, false, Collections.emptyList(), new HashMap<>(), options));
}
}
for (ProfinetPortSubmoduleItem systemPort : module.getSystemDefinedSubmoduleList().getPortSubmodules()) {
if (identNumber == systemPort.getSubslotNumber()) {
String statusName = addressSpace + "." + this.slot + "." + block.getSubSlotNumber() + "." + systemPort.getId() + ".Status";
- browseItems.add(new DefaultPlcBrowseItem(ProfinetTag.of(statusName + ":INT"), statusName, false, false, true, false, new HashMap<>(), options));
+ browseItems.add(new DefaultPlcBrowseItem(ProfinetTag.of(statusName + ":INT"), statusName, false, false, true, false, Collections.emptyList(), new HashMap<>(), options));
}
}
}
diff --git a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/messages/DefaultPlcBrowseItem.java b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/messages/DefaultPlcBrowseItem.java
index 304737b5aa..57df37bd3c 100644
--- a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/messages/DefaultPlcBrowseItem.java
+++ b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/messages/DefaultPlcBrowseItem.java
@@ -19,7 +19,7 @@
package org.apache.plc4x.java.spi.messages;
import org.apache.plc4x.java.api.messages.PlcBrowseItem;
-import org.apache.plc4x.java.api.messages.PlcBrowseItemArrayInfo;
+import org.apache.plc4x.java.api.model.ArrayInfo;
import org.apache.plc4x.java.api.model.PlcTag;
import org.apache.plc4x.java.api.value.PlcValue;
import org.apache.plc4x.java.spi.codegen.WithOption;
@@ -28,7 +28,6 @@ import org.apache.plc4x.java.spi.generation.WriteBuffer;
import org.apache.plc4x.java.spi.utils.Serializable;
import java.nio.charset.StandardCharsets;
-import java.util.Collections;
import java.util.List;
import java.util.Map;
@@ -43,8 +42,8 @@ public class DefaultPlcBrowseItem implements PlcBrowseItem, Serializable {
private final boolean subscribable;
private final boolean publishable;
+ private final List<ArrayInfo> arrayInformation;
private final Map<String, PlcBrowseItem> children;
-
private final Map<String, PlcValue> options;
public DefaultPlcBrowseItem(PlcTag tag,
@@ -53,6 +52,7 @@ public class DefaultPlcBrowseItem implements PlcBrowseItem, Serializable {
boolean writable,
boolean subscribable,
boolean publishable,
+ List<ArrayInfo> arrayInformation,
Map<String, PlcBrowseItem> children,
Map<String, PlcValue> options) {
this.tag = tag;
@@ -61,6 +61,7 @@ public class DefaultPlcBrowseItem implements PlcBrowseItem, Serializable {
this.writable = writable;
this.subscribable = subscribable;
this.publishable = publishable;
+ this.arrayInformation = arrayInformation;
this.children = children;
this.options = options;
}
@@ -72,6 +73,7 @@ public class DefaultPlcBrowseItem implements PlcBrowseItem, Serializable {
this.writable = original.isWritable();
this.subscribable = original.isSubscribable();
this.publishable = original.isPublishable();
+ this.arrayInformation = original.getArrayInformation();
this.options = original.getOptions();
this.children = children;
}
@@ -112,8 +114,8 @@ public class DefaultPlcBrowseItem implements PlcBrowseItem, Serializable {
}
@Override
- public List<PlcBrowseItemArrayInfo> getArrayInformation() {
- return Collections.emptyList();
+ public List<ArrayInfo> getArrayInformation() {
+ return arrayInformation;
}
@Override
diff --git a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/messages/DefaultPlcBrowseItemArrayInfo.java b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/messages/DefaultPlcBrowseItemArrayInfo.java
deleted file mode 100644
index 5be3aae609..0000000000
--- a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/messages/DefaultPlcBrowseItemArrayInfo.java
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * 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.messages;
-
-import org.apache.plc4x.java.api.messages.PlcBrowseItemArrayInfo;
-
-public class DefaultPlcBrowseItemArrayInfo implements PlcBrowseItemArrayInfo {
-
- private final long lowerBound;
- private final long upperBound;
-
- public DefaultPlcBrowseItemArrayInfo(long lowerBound, long upperBound) {
- this.lowerBound = lowerBound;
- this.upperBound = upperBound;
- }
-
- @Override
- public long getLowerBound() {
- return lowerBound;
- }
-
- @Override
- public long getUpperBound() {
- return upperBound;
- }
-
-}
diff --git a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/messages/DefaultPlcBrowseItemList.java b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/messages/DefaultPlcBrowseItemList.java
deleted file mode 100644
index 50ad9363a4..0000000000
--- a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/messages/DefaultPlcBrowseItemList.java
+++ /dev/null
@@ -1,117 +0,0 @@
-/*
- * 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
- *
- * https://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.messages;
-
-import org.apache.plc4x.java.api.messages.PlcBrowseItem;
-import org.apache.plc4x.java.api.messages.PlcBrowseItemArrayInfo;
-import org.apache.plc4x.java.api.model.PlcTag;
-import org.apache.plc4x.java.api.value.PlcValue;
-import org.apache.plc4x.java.spi.codegen.WithOption;
-import org.apache.plc4x.java.spi.generation.SerializationException;
-import org.apache.plc4x.java.spi.generation.WriteBuffer;
-
-import java.nio.charset.StandardCharsets;
-import java.util.List;
-import java.util.Map;
-
-public class DefaultPlcBrowseItemList extends DefaultPlcBrowseItem {
-
- private final List<PlcBrowseItemArrayInfo> arrayInformation;
-
- public DefaultPlcBrowseItemList(PlcTag tag,
- String name,
- boolean readable,
- boolean writable,
- boolean subscribable,
- boolean publishable,
- Map<String, PlcBrowseItem> children,
- Map<String, PlcValue> options,
- List<PlcBrowseItemArrayInfo> arrayInformation) {
- super(tag, name, readable, writable, subscribable, publishable, children, options);
- this.arrayInformation = arrayInformation;
- }
-
- @Override
- public boolean isArray() {
- return (arrayInformation != null) && !arrayInformation.isEmpty();
- }
-
- @Override
- public List<PlcBrowseItemArrayInfo> getArrayInformation() {
- return arrayInformation;
- }
-
- /*@Override
- public PlcBrowseItem resolveArrayItems() {
- if((arrayInformation == null) || (arrayInformation.isEmpty())) {
- return super.resolveArrayItems();
- }
- return resolveInternal(getTag() ,arrayInformation);
- }
-
- protected PlcBrowseItem resolveInternal(PlcTag tag, List<PlcBrowseItemArrayInfo> arrayInformation) {
- if(arrayInformation.isEmpty()) {
-
- }
- for (PlcBrowseItemArrayInfo arrayInfo : arrayInformation) {
- for(long i = arrayInfo.getLowerBound(); i <= arrayInfo.getUpperBound(); i++) {
-
- }
- }
- return this;
- }*/
-
- @Override
- public void serialize(WriteBuffer writeBuffer) throws SerializationException {
- writeBuffer.pushContext("PlcBrowseItemList");
- writeBuffer.writeString("address",
- getTag().getAddressString().getBytes(StandardCharsets.UTF_8).length * 8,
- getTag().getAddressString(), WithOption.WithEncoding(StandardCharsets.UTF_8.name()));
- writeBuffer.writeString("name",
- getName().getBytes(StandardCharsets.UTF_8).length * 8,
- getName(), WithOption.WithEncoding(StandardCharsets.UTF_8.name()));
- // TODO: Find out how to serialize an enum.
- //writeBuffer.writeString("dataType", dataType.getBytes(StandardCharsets.UTF_8).length * 8, StandardCharsets.UTF_8.name(), dataType);
- if(getChildren() != null && !getChildren().isEmpty()) {
- writeBuffer.pushContext("children");
- for (PlcBrowseItem child : getChildren().values()) {
- writeBuffer.pushContext("child");
- ((DefaultPlcBrowseItemList) child).serialize(writeBuffer);
- writeBuffer.popContext("child");
- }
- writeBuffer.popContext("children");
- }
- if(getOptions() != null && !getOptions().isEmpty()) {
- writeBuffer.pushContext("options");
- for (Map.Entry<String, PlcValue> optionEntry : getOptions().entrySet()) {
- writeBuffer.pushContext("option");
- writeBuffer.writeString("name",
- optionEntry.getKey().getBytes(StandardCharsets.UTF_8).length * 8,
- optionEntry.getKey(), WithOption.WithEncoding(StandardCharsets.UTF_8.name()));
- // TODO: Find out how to serialize a PlcValue
- //writeBuffer.writeString("value", optionEntry.getValue().getBytes(StandardCharsets.UTF_8).length * 8, StandardCharsets.UTF_8.name(), optionEntry.getValue());
- ((DefaultPlcBrowseItemList) optionEntry).serialize(writeBuffer);
- writeBuffer.popContext("option");
- }
- writeBuffer.popContext("options");
- }
- writeBuffer.popContext("PlcBrowseItemList");
- }
-
-}