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
The following commit(s) were added to refs/heads/develop by this push:
new 08dcb7221f refactor: Updated the discovery example to not list every
device for every local device that could reach it.
08dcb7221f is described below
commit 08dcb7221fa35fe7c48c542e4bcb2c2238b11eb6
Author: Christofer Dutz <[email protected]>
AuthorDate: Mon Dec 4 07:47:58 2023 +0100
refactor: Updated the discovery example to not list every device for every
local device that could reach it.
---
.../plc4x/java/profinet/ManualProfinetIoDiscoveryTest.java | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git
a/plc4j/drivers/profinet-ng/src/test/java/org/apache/plc4x/java/profinet/ManualProfinetIoDiscoveryTest.java
b/plc4j/drivers/profinet-ng/src/test/java/org/apache/plc4x/java/profinet/ManualProfinetIoDiscoveryTest.java
index 8a5c41e137..5ef5115f0d 100644
---
a/plc4j/drivers/profinet-ng/src/test/java/org/apache/plc4x/java/profinet/ManualProfinetIoDiscoveryTest.java
+++
b/plc4j/drivers/profinet-ng/src/test/java/org/apache/plc4x/java/profinet/ManualProfinetIoDiscoveryTest.java
@@ -23,12 +23,22 @@ import org.apache.plc4x.java.api.PlcDriver;
import org.apache.plc4x.java.api.messages.PlcDiscoveryItem;
import org.apache.plc4x.java.api.messages.PlcDiscoveryResponse;
+import java.util.Map;
+import java.util.TreeMap;
+
public class ManualProfinetIoDiscoveryTest {
public static void main(String[] args) throws Exception {
final PlcDriver profinetDriver = new
DefaultPlcDriverManager().getDriver("profinet");
final PlcDiscoveryResponse plcDiscoveryResponse =
profinetDriver.discoveryRequestBuilder().build().execute().get();
+ // As we can reach some devices from multiple network devices,
aggregate them by connection url
+ Map<String, PlcDiscoveryItem> items = new TreeMap<>();
for (PlcDiscoveryItem responseValue :
plcDiscoveryResponse.getValues()) {
+ items.put(responseValue.getConnectionUrl(), responseValue);
+ }
+ // Output the aggregated values.
+ for (Map.Entry<String, PlcDiscoveryItem> stringPlcDiscoveryItemEntry :
items.entrySet()) {
+ PlcDiscoveryItem responseValue =
stringPlcDiscoveryItemEntry.getValue();
System.out.println(responseValue.getName() + ": " +
responseValue.getConnectionUrl());
}
}