Skip to content

Commit 4468010

Browse files
committedJul 12, 2024·
feat: Extended the browse item with array-information.
1 parent fdd99de commit 4468010

File tree

7 files changed

+98
-9
lines changed

7 files changed

+98
-9
lines changed
 

‎plc4go/assets/testing/protocols/eip/DriverTestsuite.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
<driver-name>eip</driver-name>
2929
<driver-parameters>
3030
<parameter>
31-
<name>bigEndian</name>
31+
<name>big-endian</name>
3232
<value>false</value>
3333
</parameter>
3434
</driver-parameters>

‎plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/PlcBrowseItem.java

+8
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import org.apache.plc4x.java.api.model.PlcTag;
2222
import org.apache.plc4x.java.api.value.PlcValue;
2323

24+
import java.util.List;
2425
import java.util.Map;
2526

2627
public interface PlcBrowseItem {
@@ -50,6 +51,13 @@ public interface PlcBrowseItem {
5051
*/
5152
boolean isSubscribable();
5253

54+
boolean isArray();
55+
56+
/**
57+
* @return list of elements providing information about the array dimensions of this item.
58+
*/
59+
List<PlcBrowseItemArrayInfo> getArrayInformation();
60+
5361
/**
5462
* @return returns any children this item might have
5563
*/

‎plc4j/drivers/ads/src/main/java/org/apache/plc4x/java/ads/protocol/AdsProtocolLogic.java

+15-6
Original file line numberDiff line numberDiff line change
@@ -505,13 +505,16 @@ public CompletableFuture<PlcBrowseResponse> browseWithInterceptor(PlcBrowseReque
505505
options.put("size-in-bytes", new PlcUDINT(symbol.getSize()));
506506

507507
if (plc4xPlcValueType == org.apache.plc4x.java.api.types.PlcValueType.List) {
508-
List<ArrayInfo> arrayInfo = new ArrayList<>();
508+
List<ArrayInfo> arrayInfo = new ArrayList<>(dataType.getArrayInfo().size());
509+
List<PlcBrowseItemArrayInfo> itemArrayInfo = new ArrayList<>(dataType.getArrayInfo().size());
509510
for (AdsDataTypeArrayInfo adsDataTypeArrayInfo : dataType.getArrayInfo()) {
510511
arrayInfo.add(new DefaultArrayInfo(
511512
(int) adsDataTypeArrayInfo.getLowerBound(), (int) adsDataTypeArrayInfo.getUpperBound()));
513+
itemArrayInfo.add(new DefaultPlcBrowseItemArrayInfo(
514+
adsDataTypeArrayInfo.getLowerBound(), adsDataTypeArrayInfo.getUpperBound()));
512515
}
513516
DefaultListPlcBrowseItem item = new DefaultListPlcBrowseItem(new SymbolicAdsTag(symbol.getName(), plc4xPlcValueType, arrayInfo), itemName,
514-
true, !symbol.getFlagReadOnly(), true, childMap, options);
517+
true, !symbol.getFlagReadOnly(), true, childMap, options, itemArrayInfo);
515518

516519
// Check if this item should be added to the result
517520
if (interceptor.intercept(item)) {
@@ -571,17 +574,23 @@ protected List<PlcBrowseItem> getBrowseItems(String basePath, long baseGroupId,
571574
options.put("size-in-bytes", new PlcUDINT(childDataType.getSize()));
572575

573576
if (plc4xPlcValueType == org.apache.plc4x.java.api.types.PlcValueType.List) {
574-
List<ArrayInfo> arrayInfo = new ArrayList<>();
577+
List<ArrayInfo> arrayInfo = new ArrayList<>(childDataType.getArrayInfo().size());
578+
List<PlcBrowseItemArrayInfo> itemArrayInfo = new ArrayList<>(childDataType.getArrayInfo().size());
575579
for (AdsDataTypeArrayInfo adsDataTypeArrayInfo : childDataType.getArrayInfo()) {
576580
arrayInfo.add(new DefaultArrayInfo(
577581
(int) adsDataTypeArrayInfo.getLowerBound(), (int) adsDataTypeArrayInfo.getUpperBound()));
582+
itemArrayInfo.add(new DefaultPlcBrowseItemArrayInfo(
583+
adsDataTypeArrayInfo.getLowerBound(), adsDataTypeArrayInfo.getUpperBound()));
578584
}
579585
// Add the type itself.
580-
values.add(new DefaultListPlcBrowseItem(new SymbolicAdsTag(basePath + "." + child.getPropertyName(), plc4xPlcValueType, arrayInfo), itemName,
581-
true, parentWritable, true, childMap, options));
586+
values.add(new DefaultListPlcBrowseItem(new SymbolicAdsTag(
587+
basePath + "." + child.getPropertyName(), plc4xPlcValueType, arrayInfo), itemName,
588+
true, parentWritable, true, childMap, options, itemArrayInfo));
582589
} else {
583590
// Add the type itself.
584-
values.add(new DefaultPlcBrowseItem(new SymbolicAdsTag(basePath + "." + child.getPropertyName(), plc4xPlcValueType, Collections.emptyList()), itemName,
591+
values.add(new DefaultPlcBrowseItem(new SymbolicAdsTag(
592+
basePath + "." + child.getPropertyName(), plc4xPlcValueType,
593+
Collections.emptyList()), itemName,
585594
true, parentWritable, true, childMap, options));
586595
}
587596
}

‎plc4j/drivers/ctrlx/src/main/java/org/apache/plc4x/java/ctrlx/readwrite/connection/CtrlXConnection.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ public CompletableFuture<PlcBrowseResponse> browseWithInterceptor(PlcBrowseReque
261261
new DefaultListPlcBrowseItem(
262262
new CtrlXTag(curNode, PlcValueType.BOOL, Collections.emptyList()),
263263
curNode, true, true, true,
264-
Collections.emptyMap(), Collections.emptyMap())));
264+
Collections.emptyMap(), Collections.emptyMap(), Collections.emptyList())));
265265
}
266266
}
267267
// If this node has children, then it's branch, and we need to add its children to the queue.

‎plc4j/spi/src/main/java/org/apache/plc4x/java/spi/messages/DefaultListPlcBrowseItem.java

+17-1
Original file line numberDiff line numberDiff line change
@@ -19,25 +19,41 @@
1919
package org.apache.plc4x.java.spi.messages;
2020

2121
import org.apache.plc4x.java.api.messages.PlcBrowseItem;
22+
import org.apache.plc4x.java.api.messages.PlcBrowseItemArrayInfo;
2223
import org.apache.plc4x.java.api.model.PlcTag;
2324
import org.apache.plc4x.java.api.value.PlcValue;
2425
import org.apache.plc4x.java.spi.codegen.WithOption;
2526
import org.apache.plc4x.java.spi.generation.SerializationException;
2627
import org.apache.plc4x.java.spi.generation.WriteBuffer;
2728

2829
import java.nio.charset.StandardCharsets;
30+
import java.util.List;
2931
import java.util.Map;
3032

3133
public class DefaultListPlcBrowseItem extends DefaultPlcBrowseItem {
3234

35+
private final List<PlcBrowseItemArrayInfo> arrayInformation;
36+
3337
public DefaultListPlcBrowseItem(PlcTag tag,
3438
String name,
3539
boolean readable,
3640
boolean writable,
3741
boolean subscribable,
3842
Map<String, PlcBrowseItem> children,
39-
Map<String, PlcValue> options) {
43+
Map<String, PlcValue> options,
44+
List<PlcBrowseItemArrayInfo> arrayInformation) {
4045
super(tag, name, readable, writable, subscribable, children, options);
46+
this.arrayInformation = arrayInformation;
47+
}
48+
49+
@Override
50+
public boolean isArray() {
51+
return (arrayInformation != null) && !arrayInformation.isEmpty();
52+
}
53+
54+
@Override
55+
public List<PlcBrowseItemArrayInfo> getArrayInformation() {
56+
return arrayInformation;
4157
}
4258

4359
@Override

‎plc4j/spi/src/main/java/org/apache/plc4x/java/spi/messages/DefaultPlcBrowseItem.java

+12
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
package org.apache.plc4x.java.spi.messages;
2020

2121
import org.apache.plc4x.java.api.messages.PlcBrowseItem;
22+
import org.apache.plc4x.java.api.messages.PlcBrowseItemArrayInfo;
2223
import org.apache.plc4x.java.api.model.PlcTag;
2324
import org.apache.plc4x.java.api.value.PlcValue;
2425
import org.apache.plc4x.java.spi.codegen.WithOption;
@@ -27,6 +28,8 @@
2728
import org.apache.plc4x.java.spi.utils.Serializable;
2829

2930
import java.nio.charset.StandardCharsets;
31+
import java.util.Collections;
32+
import java.util.List;
3033
import java.util.Map;
3134

3235
public class DefaultPlcBrowseItem implements PlcBrowseItem, Serializable {
@@ -81,6 +84,15 @@ public boolean isSubscribable() {
8184
return subscribable;
8285
}
8386

87+
@Override
88+
public boolean isArray() {
89+
return false;
90+
}
91+
92+
public List<PlcBrowseItemArrayInfo> getArrayInformation() {
93+
return Collections.emptyList();
94+
}
95+
8496
@Override
8597
public Map<String, PlcBrowseItem> getChildren() {
8698
return children;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
package org.apache.plc4x.java.spi.messages;
21+
22+
import org.apache.plc4x.java.api.messages.PlcBrowseItemArrayInfo;
23+
24+
public class DefaultPlcBrowseItemArrayInfo implements PlcBrowseItemArrayInfo {
25+
26+
private final long lowerBound;
27+
private final long upperBound;
28+
29+
public DefaultPlcBrowseItemArrayInfo(long lowerBound, long upperBound) {
30+
this.lowerBound = lowerBound;
31+
this.upperBound = upperBound;
32+
}
33+
34+
@Override
35+
public long getLowerBound() {
36+
return lowerBound;
37+
}
38+
39+
@Override
40+
public long getUpperBound() {
41+
return upperBound;
42+
}
43+
44+
}

0 commit comments

Comments
 (0)
Please sign in to comment.