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/01/31 09:59:30 UTC
(plc4x) 01/02: feat: Got the RealIdentifitationRequest working for my Adam devices in the new Profinet driver
This is an automated email from the ASF dual-hosted git repository.
cdutz pushed a commit to branch fix/DATE_AND_TIME_2
in repository https://gitbox.apache.org/repos/asf/plc4x.git
commit a7b0a073a04db939e97311bc80f3007de8769211
Author: Christofer Dutz <cd...@apache.org>
AuthorDate: Tue Jan 30 21:19:23 2024 +0100
feat: Got the RealIdentifitationRequest working for my Adam devices in the new Profinet driver
Also tried getting the old driver working with my Adam devices.
---
.../profinet/protocol/ProfinetProtocolLogic.java | 72 ++++++++++++----------
...PN.java => ManualProfinetIoTestAdam6117PN.java} | 23 ++++---
...de.java => ManualProfinetIoTestAdam6150PN.java} | 24 +++++---
...de.java => ManualProfinetIoTestSimocodePN.java} | 15 ++++-
...oupler.java => ManualProfinetIoTestWagoPN.java} | 23 ++++---
.../src/test/resources/logback-test.xml | 2 +-
...etIoTest.java => ManualProfinetIoAdamTest.java} | 9 +--
...Test.java => ManualProfinetIoSimocodeTest.java} | 4 +-
.../java/profinet/ManualProfinetPcapTest.java | 54 +++++++++++-----
9 files changed, 136 insertions(+), 90 deletions(-)
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 142d078e63..169bfca6be 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
@@ -254,17 +254,21 @@ public class ProfinetProtocolLogic extends Plc4xProtocolBase<Ethernet_Frame> imp
submoduleIndex.get(curSlot).put(curSubslot, curSubmodule);
// Replace the text-ids with readable values
- for (ProfinetIoDataInput profinetIoDataInput : curSubmodule.getIoData().getInput()) {
- for (ProfinetDataItem profinetDataItem : profinetIoDataInput.getDataItemList()) {
- if (textMapping.containsKey(profinetDataItem.getTextId())) {
- profinetDataItem.setTextId(textMapping.get(profinetDataItem.getTextId()));
+ if(curSubmodule.getIoData().getInput() != null) {
+ for (ProfinetIoDataInput profinetIoDataInput : curSubmodule.getIoData().getInput()) {
+ for (ProfinetDataItem profinetDataItem : profinetIoDataInput.getDataItemList()) {
+ if (textMapping.containsKey(profinetDataItem.getTextId())) {
+ profinetDataItem.setTextId(textMapping.get(profinetDataItem.getTextId()));
+ }
}
}
}
- for (ProfinetIoDataOutput profinetIoDataOutput : curSubmodule.getIoData().getOutput()) {
- for (ProfinetDataItem profinetDataItem : profinetIoDataOutput.getDataItemList()) {
- if (textMapping.containsKey(profinetDataItem.getTextId())) {
- profinetDataItem.setTextId(textMapping.get(profinetDataItem.getTextId()));
+ if(curSubmodule.getIoData().getOutput() != null) {
+ for (ProfinetIoDataOutput profinetIoDataOutput : curSubmodule.getIoData().getOutput()) {
+ for (ProfinetDataItem profinetDataItem : profinetIoDataOutput.getDataItemList()) {
+ if (textMapping.containsKey(profinetDataItem.getTextId())) {
+ profinetDataItem.setTextId(textMapping.get(profinetDataItem.getTextId()));
+ }
}
}
}
@@ -341,34 +345,38 @@ public class ProfinetProtocolLogic extends Plc4xProtocolBase<Ethernet_Frame> imp
ProfinetVirtualSubmoduleItem subslotModule = subslotEntry.getValue();
// Add all the input tags.
- for (ProfinetIoDataInput profinetIoDataInput : subslotModule.getIoData().getInput()) {
- for (int i = 0; i < profinetIoDataInput.getDataItemList().size(); i++) {
- ProfinetDataItem profinetDataItem = profinetIoDataInput.getDataItemList().get(i);
- ProfinetDataTypeMapper.DataTypeInformation dataTypeInformation =
- ProfinetDataTypeMapper.getPlcValueType(profinetDataItem);
- // The ids have been replaced by real textual values in the connection phase.
- String name = profinetDataItem.getTextId();
- items.add(new DefaultPlcBrowseItem(new ProfinetTag(
- slot, subslot, ProfinetTag.Direction.INPUT,
- i, dataTypeInformation.getPlcValueType(), dataTypeInformation.getNumElements()),
- name, false, true, true,
- Collections.emptyMap(), Collections.emptyMap()));
+ if(subslotModule.getIoData().getInput() != null) {
+ for (ProfinetIoDataInput profinetIoDataInput : subslotModule.getIoData().getInput()) {
+ for (int i = 0; i < profinetIoDataInput.getDataItemList().size(); i++) {
+ ProfinetDataItem profinetDataItem = profinetIoDataInput.getDataItemList().get(i);
+ ProfinetDataTypeMapper.DataTypeInformation dataTypeInformation =
+ ProfinetDataTypeMapper.getPlcValueType(profinetDataItem);
+ // The ids have been replaced by real textual values in the connection phase.
+ String name = profinetDataItem.getTextId();
+ items.add(new DefaultPlcBrowseItem(new ProfinetTag(
+ slot, subslot, ProfinetTag.Direction.INPUT,
+ i, dataTypeInformation.getPlcValueType(), dataTypeInformation.getNumElements()),
+ name, false, true, true,
+ Collections.emptyMap(), Collections.emptyMap()));
+ }
}
}
// Add all the output tags.
- for (ProfinetIoDataOutput profinetIoDataOutput : subslotModule.getIoData().getOutput()) {
- for (int i = 0; i < profinetIoDataOutput.getDataItemList().size(); i++) {
- ProfinetDataItem profinetDataItem = profinetIoDataOutput.getDataItemList().get(i);
- ProfinetDataTypeMapper.DataTypeInformation dataTypeInformation =
- ProfinetDataTypeMapper.getPlcValueType(profinetDataItem);
- // The ids have been replaced by real textual values in the connection phase.
- String name = profinetDataItem.getTextId();
- items.add(new DefaultPlcBrowseItem(new ProfinetTag(
- slot, subslot, ProfinetTag.Direction.OUTPUT,
- i, dataTypeInformation.getPlcValueType(), dataTypeInformation.getNumElements()),
- name, false, true, true,
- Collections.emptyMap(), Collections.emptyMap()));
+ if(subslotModule.getIoData().getOutput() != null) {
+ for (ProfinetIoDataOutput profinetIoDataOutput : subslotModule.getIoData().getOutput()) {
+ for (int i = 0; i < profinetIoDataOutput.getDataItemList().size(); i++) {
+ ProfinetDataItem profinetDataItem = profinetIoDataOutput.getDataItemList().get(i);
+ ProfinetDataTypeMapper.DataTypeInformation dataTypeInformation =
+ ProfinetDataTypeMapper.getPlcValueType(profinetDataItem);
+ // The ids have been replaced by real textual values in the connection phase.
+ String name = profinetDataItem.getTextId();
+ items.add(new DefaultPlcBrowseItem(new ProfinetTag(
+ slot, subslot, ProfinetTag.Direction.OUTPUT,
+ i, dataTypeInformation.getPlcValueType(), dataTypeInformation.getNumElements()),
+ name, false, true, true,
+ Collections.emptyMap(), Collections.emptyMap()));
+ }
}
}
}
diff --git a/plc4j/drivers/profinet-ng/src/test/java/org/apache/plc4x/java/profinet/ManualProfinetIoTestAdamPN.java b/plc4j/drivers/profinet-ng/src/test/java/org/apache/plc4x/java/profinet/ManualProfinetIoTestAdam6117PN.java
similarity index 62%
rename from plc4j/drivers/profinet-ng/src/test/java/org/apache/plc4x/java/profinet/ManualProfinetIoTestAdamPN.java
rename to plc4j/drivers/profinet-ng/src/test/java/org/apache/plc4x/java/profinet/ManualProfinetIoTestAdam6117PN.java
index 8f5352d8eb..6c122538d9 100644
--- a/plc4j/drivers/profinet-ng/src/test/java/org/apache/plc4x/java/profinet/ManualProfinetIoTestAdamPN.java
+++ b/plc4j/drivers/profinet-ng/src/test/java/org/apache/plc4x/java/profinet/ManualProfinetIoTestAdam6117PN.java
@@ -21,24 +21,27 @@ package org.apache.plc4x.java.profinet;
import org.apache.plc4x.java.DefaultPlcDriverManager;
import org.apache.plc4x.java.api.PlcConnection;
-import org.apache.plc4x.java.api.messages.PlcSubscriptionRequest;
-import org.apache.plc4x.java.api.messages.PlcSubscriptionResponse;
+import org.apache.plc4x.java.api.messages.*;
import java.time.Duration;
+import java.util.List;
import java.util.concurrent.TimeUnit;
-public class ManualProfinetIoTestAdamPN {
+public class ManualProfinetIoTestAdam6117PN {
public static void main(String[] args) throws Exception {
+ // Advantech Adam 6150PN (8 chanel 16 bit analog inputs)
// WireShark filter: "eth.addr == 74:fe:48:63:f6:c2"
try(PlcConnection connection = new DefaultPlcDriverManager().getConnection("profinet:raw://192.168.24.41")) {
- // Create and execute the subscription request.
- PlcSubscriptionRequest subscriptionRequest = connection.subscriptionRequestBuilder()
- .addCyclicTagAddress("inputs", "1.1.INPUT.0:BYTE[10]", Duration.ofMillis(400))
- .addCyclicTagAddress("output", "1.1.OUTPUT.0:DWORD", Duration.ofMillis(400))
- .build();
- PlcSubscriptionResponse subscriptionResponse = subscriptionRequest.execute().get(10000, TimeUnit.MILLISECONDS);
- System.out.println(subscriptionResponse);
+ // List up all resources found in the remote device.
+ PlcBrowseRequest browseRequest = connection.browseRequestBuilder().addQuery("all", "*").build();
+ PlcBrowseResponse plcBrowseResponse = browseRequest.execute().get();
+ for (String queryName : plcBrowseResponse.getQueryNames()) {
+ List<PlcBrowseItem> values = plcBrowseResponse.getValues(queryName);
+ for (PlcBrowseItem value : values) {
+ System.out.println(value.getName() + ": " + value.getTag().getAddressString());
+ }
+ }
}
}
diff --git a/plc4j/drivers/profinet-ng/src/test/java/org/apache/plc4x/java/profinet/ManualProfinetIoTestSimocode.java b/plc4j/drivers/profinet-ng/src/test/java/org/apache/plc4x/java/profinet/ManualProfinetIoTestAdam6150PN.java
similarity index 58%
copy from plc4j/drivers/profinet-ng/src/test/java/org/apache/plc4x/java/profinet/ManualProfinetIoTestSimocode.java
copy to plc4j/drivers/profinet-ng/src/test/java/org/apache/plc4x/java/profinet/ManualProfinetIoTestAdam6150PN.java
index 95072070d8..70b65d0587 100644
--- a/plc4j/drivers/profinet-ng/src/test/java/org/apache/plc4x/java/profinet/ManualProfinetIoTestSimocode.java
+++ b/plc4j/drivers/profinet-ng/src/test/java/org/apache/plc4x/java/profinet/ManualProfinetIoTestAdam6150PN.java
@@ -24,20 +24,24 @@ import org.apache.plc4x.java.api.PlcConnection;
import org.apache.plc4x.java.api.messages.*;
import java.time.Duration;
+import java.util.List;
import java.util.concurrent.TimeUnit;
-public class ManualProfinetIoTestSimocode {
+public class ManualProfinetIoTestAdam6150PN {
public static void main(String[] args) throws Exception {
- // WireShark filter: "eth.addr == 88:3f:99:00:06:ef"
- try(PlcConnection connection = new DefaultPlcDriverManager().getConnection("profinet:raw://192.168.24.31")) {
- // Create and execute the subscription request.
- PlcSubscriptionRequest subscriptionRequest = connection.subscriptionRequestBuilder()
- .addCyclicTagAddress("inputs", "1.1.INPUT.0:BYTE[10]", Duration.ofMillis(400))
- .addCyclicTagAddress("output", "1.1.OUTPUT.0:DWORD", Duration.ofMillis(400))
- .build();
- PlcSubscriptionResponse subscriptionResponse = subscriptionRequest.execute().get(100000, TimeUnit.MILLISECONDS);
- System.out.println(subscriptionResponse);
+ // Advantech Adam 6150PN (8 channel digital input, 7 chanel digital output)
+ // WireShark filter: "eth.addr == 74:fe:48:82:4a:7c"
+ try(PlcConnection connection = new DefaultPlcDriverManager().getConnection("profinet:raw://192.168.24.42")) {
+ // List up all resources found in the remote device.
+ PlcBrowseRequest browseRequest = connection.browseRequestBuilder().addQuery("all", "*").build();
+ PlcBrowseResponse plcBrowseResponse = browseRequest.execute().get();
+ for (String queryName : plcBrowseResponse.getQueryNames()) {
+ List<PlcBrowseItem> values = plcBrowseResponse.getValues(queryName);
+ for (PlcBrowseItem value : values) {
+ System.out.println(value.getName() + ": " + value.getTag().getAddressString());
+ }
+ }
}
}
diff --git a/plc4j/drivers/profinet-ng/src/test/java/org/apache/plc4x/java/profinet/ManualProfinetIoTestSimocode.java b/plc4j/drivers/profinet-ng/src/test/java/org/apache/plc4x/java/profinet/ManualProfinetIoTestSimocodePN.java
similarity index 70%
rename from plc4j/drivers/profinet-ng/src/test/java/org/apache/plc4x/java/profinet/ManualProfinetIoTestSimocode.java
rename to plc4j/drivers/profinet-ng/src/test/java/org/apache/plc4x/java/profinet/ManualProfinetIoTestSimocodePN.java
index 95072070d8..7b1c82b1bc 100644
--- a/plc4j/drivers/profinet-ng/src/test/java/org/apache/plc4x/java/profinet/ManualProfinetIoTestSimocode.java
+++ b/plc4j/drivers/profinet-ng/src/test/java/org/apache/plc4x/java/profinet/ManualProfinetIoTestSimocodePN.java
@@ -24,17 +24,28 @@ import org.apache.plc4x.java.api.PlcConnection;
import org.apache.plc4x.java.api.messages.*;
import java.time.Duration;
+import java.util.List;
import java.util.concurrent.TimeUnit;
-public class ManualProfinetIoTestSimocode {
+public class ManualProfinetIoTestSimocodePN {
public static void main(String[] args) throws Exception {
// WireShark filter: "eth.addr == 88:3f:99:00:06:ef"
try(PlcConnection connection = new DefaultPlcDriverManager().getConnection("profinet:raw://192.168.24.31")) {
+ // List up all resources found in the remote device.
+ PlcBrowseRequest browseRequest = connection.browseRequestBuilder().addQuery("all", "*").build();
+ PlcBrowseResponse plcBrowseResponse = browseRequest.execute().get();
+ for (String queryName : plcBrowseResponse.getQueryNames()) {
+ List<PlcBrowseItem> values = plcBrowseResponse.getValues(queryName);
+ for (PlcBrowseItem value : values) {
+ System.out.println(value.getName() + ": " + value.getTag().getAddressString());
+ }
+ }
+
// Create and execute the subscription request.
PlcSubscriptionRequest subscriptionRequest = connection.subscriptionRequestBuilder()
.addCyclicTagAddress("inputs", "1.1.INPUT.0:BYTE[10]", Duration.ofMillis(400))
- .addCyclicTagAddress("output", "1.1.OUTPUT.0:DWORD", Duration.ofMillis(400))
+// .addCyclicTagAddress("output", "1.1.OUTPUT.0:DWORD", Duration.ofMillis(400))
.build();
PlcSubscriptionResponse subscriptionResponse = subscriptionRequest.execute().get(100000, TimeUnit.MILLISECONDS);
System.out.println(subscriptionResponse);
diff --git a/plc4j/drivers/profinet-ng/src/test/java/org/apache/plc4x/java/profinet/ManualProfinetIoTestWagoPNCoupler.java b/plc4j/drivers/profinet-ng/src/test/java/org/apache/plc4x/java/profinet/ManualProfinetIoTestWagoPN.java
similarity index 61%
rename from plc4j/drivers/profinet-ng/src/test/java/org/apache/plc4x/java/profinet/ManualProfinetIoTestWagoPNCoupler.java
rename to plc4j/drivers/profinet-ng/src/test/java/org/apache/plc4x/java/profinet/ManualProfinetIoTestWagoPN.java
index aed2d41140..895f46843d 100644
--- a/plc4j/drivers/profinet-ng/src/test/java/org/apache/plc4x/java/profinet/ManualProfinetIoTestWagoPNCoupler.java
+++ b/plc4j/drivers/profinet-ng/src/test/java/org/apache/plc4x/java/profinet/ManualProfinetIoTestWagoPN.java
@@ -21,24 +21,23 @@ package org.apache.plc4x.java.profinet;
import org.apache.plc4x.java.DefaultPlcDriverManager;
import org.apache.plc4x.java.api.PlcConnection;
-import org.apache.plc4x.java.api.messages.PlcSubscriptionRequest;
-import org.apache.plc4x.java.api.messages.PlcSubscriptionResponse;
+import org.apache.plc4x.java.api.messages.*;
-import java.time.Duration;
-import java.util.concurrent.TimeUnit;
+import java.util.List;
-public class ManualProfinetIoTestWagoPNCoupler {
+public class ManualProfinetIoTestWagoPN {
public static void main(String[] args) throws Exception {
// WireShark filter: "eth.addr == 00:30:de:61:37:79"
try(PlcConnection connection = new DefaultPlcDriverManager().getConnection("profinet:raw://00:30:de:61:37:79?ip-address=192.168.24.51")) {
- // Create and execute the subscription request.
- PlcSubscriptionRequest subscriptionRequest = connection.subscriptionRequestBuilder()
- .addCyclicTagAddress("inputs", "1.1.INPUT.0:BYTE[10]", Duration.ofMillis(400))
- .addCyclicTagAddress("output", "1.1.OUTPUT.0:DWORD", Duration.ofMillis(400))
- .build();
- PlcSubscriptionResponse subscriptionResponse = subscriptionRequest.execute().get(10000, TimeUnit.MILLISECONDS);
- System.out.println(subscriptionResponse);
+ PlcBrowseRequest browseRequest = connection.browseRequestBuilder().addQuery("all", "*").build();
+ PlcBrowseResponse plcBrowseResponse = browseRequest.execute().get();
+ for (String queryName : plcBrowseResponse.getQueryNames()) {
+ List<PlcBrowseItem> values = plcBrowseResponse.getValues(queryName);
+ for (PlcBrowseItem value : values) {
+ System.out.println(value.getName() + ": " + value.getTag().getAddressString());
+ }
+ }
}
}
diff --git a/plc4j/drivers/profinet-ng/src/test/resources/logback-test.xml b/plc4j/drivers/profinet-ng/src/test/resources/logback-test.xml
index d5ea1081e7..7465159b17 100644
--- a/plc4j/drivers/profinet-ng/src/test/resources/logback-test.xml
+++ b/plc4j/drivers/profinet-ng/src/test/resources/logback-test.xml
@@ -29,7 +29,7 @@
</encoder>
</appender>
- <logger name="org.apache.plc4x.java.spi.Plc4xNettyWrapper" level="TRACE"/>
+ <logger name="org.apache.plc4x.java.spi.Plc4xNettyWrapper" level="WARN"/>
<root level="info">
<appender-ref ref="STDOUT" />
diff --git a/plc4j/drivers/profinet/src/test/java/org/apache/plc4x/java/profinet/ManualProfinetIoTest.java b/plc4j/drivers/profinet/src/test/java/org/apache/plc4x/java/profinet/ManualProfinetIoAdamTest.java
similarity index 93%
copy from plc4j/drivers/profinet/src/test/java/org/apache/plc4x/java/profinet/ManualProfinetIoTest.java
copy to plc4j/drivers/profinet/src/test/java/org/apache/plc4x/java/profinet/ManualProfinetIoAdamTest.java
index eac8db3f34..aa89d13262 100644
--- a/plc4j/drivers/profinet/src/test/java/org/apache/plc4x/java/profinet/ManualProfinetIoTest.java
+++ b/plc4j/drivers/profinet/src/test/java/org/apache/plc4x/java/profinet/ManualProfinetIoAdamTest.java
@@ -29,21 +29,18 @@ import org.slf4j.LoggerFactory;
import java.util.concurrent.TimeUnit;
-public class ManualProfinetIoTest {
+public class ManualProfinetIoAdamTest {
- private static final Logger LOGGER = LoggerFactory.getLogger(ManualProfinetIoTest.class);
+ private static final Logger LOGGER = LoggerFactory.getLogger(ManualProfinetIoAdamTest.class);
public static void main(String[] args) throws Exception {
// eth.addr == 88:3f:99:03:ef:b0
- // Zylk device name = simocodexbpn156e
- // Chris device name = cdxb195b3
-
// In this example 192.168.54.2 is the local IP of the computer running PLC4J and 192.168.54.23 is the IP of the PN device.
//final PlcConnection connection = new DefaultPlcDriverManager().getConnection("profinet://192.168.54.2?gsddirectory=~/.gsd&devices=[[simocodexbpn156e,DAP%201,(1,),192.168.54.23]]&reductionratio=16&sendclockfactor=32&dataholdfactor=3&watchdogfactor=3");
// REMARK: The driver would use the local network device with the given IP address and to an auto-discovery, trying to find any devices returned with the matching name.
// If this device is then found and an IP address is provided, it would use PN-DCP to set the IP address of that device to the given value.
- final PlcConnection connection = new DefaultPlcDriverManager().getConnection("profinet://192.168.54.220?gsddirectory=~/.gsd&devices=[[simocodexbpn156e,DAP%201,(1,)]]&reductionratio=128&sendclockfactor=128&dataholdfactor=3&watchdogfactor=3");
+ final PlcConnection connection = new DefaultPlcDriverManager().getConnection("profinet://192.168.54.220?gsddirectory=~/.gsd&devices=[[adam-6117pn,ID_DAP1,(1,)]]&reductionratio=64&sendclockfactor=64&dataholdfactor=3&watchdogfactor=3");
PlcBrowseRequest browseRequest = connection.browseRequestBuilder().addQuery("all", "*").build();
PlcBrowseResponse plcBrowseResponse = browseRequest.execute().get(4000, TimeUnit.MILLISECONDS);
diff --git a/plc4j/drivers/profinet/src/test/java/org/apache/plc4x/java/profinet/ManualProfinetIoTest.java b/plc4j/drivers/profinet/src/test/java/org/apache/plc4x/java/profinet/ManualProfinetIoSimocodeTest.java
similarity index 98%
rename from plc4j/drivers/profinet/src/test/java/org/apache/plc4x/java/profinet/ManualProfinetIoTest.java
rename to plc4j/drivers/profinet/src/test/java/org/apache/plc4x/java/profinet/ManualProfinetIoSimocodeTest.java
index eac8db3f34..e1ba5b5b47 100644
--- a/plc4j/drivers/profinet/src/test/java/org/apache/plc4x/java/profinet/ManualProfinetIoTest.java
+++ b/plc4j/drivers/profinet/src/test/java/org/apache/plc4x/java/profinet/ManualProfinetIoSimocodeTest.java
@@ -29,9 +29,9 @@ import org.slf4j.LoggerFactory;
import java.util.concurrent.TimeUnit;
-public class ManualProfinetIoTest {
+public class ManualProfinetIoSimocodeTest {
- private static final Logger LOGGER = LoggerFactory.getLogger(ManualProfinetIoTest.class);
+ private static final Logger LOGGER = LoggerFactory.getLogger(ManualProfinetIoSimocodeTest.class);
public static void main(String[] args) throws Exception {
// eth.addr == 88:3f:99:03:ef:b0
diff --git a/plc4j/drivers/profinet/src/test/java/org/apache/plc4x/java/profinet/ManualProfinetPcapTest.java b/plc4j/drivers/profinet/src/test/java/org/apache/plc4x/java/profinet/ManualProfinetPcapTest.java
index 684c11ffd0..596114b087 100644
--- a/plc4j/drivers/profinet/src/test/java/org/apache/plc4x/java/profinet/ManualProfinetPcapTest.java
+++ b/plc4j/drivers/profinet/src/test/java/org/apache/plc4x/java/profinet/ManualProfinetPcapTest.java
@@ -30,20 +30,25 @@ import org.pcap4j.packet.Packet;
import org.pcap4j.packet.UnknownPacket;
import java.io.EOFException;
+import java.sql.Timestamp;
import java.util.Arrays;
import java.util.concurrent.TimeoutException;
public class ManualProfinetPcapTest {
public static void main(String[] args) throws Exception {
- try (PcapHandle handle = Pcaps.openOffline("/Users/cdutz/Projects/Apache/PLC4X/profinet-slow.pcapng", PcapHandle.TimestampPrecision.NANO);){
- int lastIncomingCycleTime = 0;
- int lastOutgoingCycleTime = 0;
- int minDelay = 65000;
- int maxDelay = 0;
+ try (PcapHandle handle = Pcaps.openOffline("/Users/cdutz/Projects/Apache/PLC4X/profinet.pcapng", PcapHandle.TimestampPrecision.NANO);){
+ int lastIncomingCycleCounter = 0;
+ double averageIncomingCycleCounter = 0.0;
+ int numberIncomingPackets = 0;
+ Timestamp lastIncomingCycleTime = null;
+ int lastOutgoingCycleCounter = 0;
+ Timestamp lastOutgoingCycleTime = null;
while (true) {
try {
Packet packet = handle.getNextPacketEx();
+ Timestamp timestamp = handle.getTimestamp();
+
EthernetPacket.EthernetHeader packetHeader = (EthernetPacket.EthernetHeader) packet.getHeader();
boolean fromDevice = Arrays.equals(new byte[]{(byte) 0xF8, (byte) 0xE4, (byte) 0x3B, (byte) 0xB6, (byte) 0x9B, (byte) 0xBF}, packetHeader.getSrcAddr().getAddress());
@@ -56,8 +61,24 @@ public class ManualProfinetPcapTest {
PnDcp_Pdu pnDcpPdu = PnDcp_Pdu.staticParse(readBuffer);
if(pnDcpPdu instanceof PnDcp_Pdu_RealTimeCyclic) {
PnDcp_Pdu_RealTimeCyclic pnDcpPdu1 = (PnDcp_Pdu_RealTimeCyclic) pnDcpPdu;
- lastIncomingCycleTime = pnDcpPdu1.getCycleCounter();
- //System.out.printf("--> %d\n", pnDcpPdu1.getCycleCounter());
+
+ if(lastIncomingCycleCounter != 0) {
+ int lastCycles;
+ if(pnDcpPdu1.getCycleCounter() > lastIncomingCycleCounter) {
+ lastCycles = pnDcpPdu1.getCycleCounter() - lastIncomingCycleCounter;
+ } else {
+ lastCycles = (pnDcpPdu1.getCycleCounter() + 0xFFFF) - lastIncomingCycleCounter;
+ }
+ averageIncomingCycleCounter = (numberIncomingPackets * averageIncomingCycleCounter + lastCycles) / (numberIncomingPackets + 1);
+
+ if (lastIncomingCycleTime != null) {
+ System.out.printf("--> %3d %3d %f\n", lastCycles, (timestamp.getNanos() - lastIncomingCycleTime.getNanos()) / 1000000, averageIncomingCycleCounter);
+ }
+ }
+
+ numberIncomingPackets++;
+ lastIncomingCycleCounter = pnDcpPdu1.getCycleCounter();
+ lastIncomingCycleTime = timestamp;
}
} else {
System.out.println("Other packet");
@@ -68,17 +89,20 @@ public class ManualProfinetPcapTest {
PnDcp_Pdu pnDcpPdu = PnDcp_Pdu.staticParse(readBuffer);
if(pnDcpPdu instanceof PnDcp_Pdu_RealTimeCyclic) {
PnDcp_Pdu_RealTimeCyclic pnDcpPdu1 = (PnDcp_Pdu_RealTimeCyclic) pnDcpPdu;
- int difference = (pnDcpPdu1.getCycleCounter() < lastIncomingCycleTime) ? lastIncomingCycleTime - pnDcpPdu1.getCycleCounter() : pnDcpPdu1.getCycleCounter() - lastIncomingCycleTime;
- if(difference < 60000 && difference > 100) {
- if (difference < minDelay) {
- minDelay = difference;
+ if(lastOutgoingCycleCounter != 0) {
+ int lastCycles;
+ if(pnDcpPdu1.getCycleCounter() > lastOutgoingCycleCounter) {
+ lastCycles = pnDcpPdu1.getCycleCounter() - lastOutgoingCycleCounter;
+ } else {
+ lastCycles = (pnDcpPdu1.getCycleCounter() + 0xFFFF) - lastOutgoingCycleCounter;
}
- if (difference > maxDelay) {
- maxDelay = difference;
+
+ if (lastOutgoingCycleTime != null) {
+ System.out.printf("<-- %3d %3d\n", lastCycles, (timestamp.getNanos() - lastOutgoingCycleTime.getNanos()) / 1000000);
}
- System.out.printf("<-- %10d %10d %10d-%10d\n", difference, pnDcpPdu1.getCycleCounter() - lastOutgoingCycleTime, minDelay, maxDelay);
}
- lastOutgoingCycleTime = pnDcpPdu1.getCycleCounter();
+ lastOutgoingCycleCounter = pnDcpPdu1.getCycleCounter();
+ lastOutgoingCycleTime = timestamp;
}
} else {
System.out.println("Other packet");