You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@plc4x.apache.org by hu...@apache.org on 2022/10/06 15:23:47 UTC
[plc4x] 02/13: fix(plc4j(profinet): Connections are working for my setup
This is an automated email from the ASF dual-hosted git repository.
hutcheb pushed a commit to branch plc4j/profinet
in repository https://gitbox.apache.org/repos/asf/plc4x.git
commit b55c5d22550f970cbd34a73fdf0c3292ad674ecd
Author: Ben Hutcheson <be...@gmail.com>
AuthorDate: Thu Sep 8 07:03:32 2022 -0600
fix(plc4j(profinet): Connections are working for my setup
---
.../profinet/protocol/ProfinetProtocolLogic.java | 46 ++++++----------------
.../apache/plc4x/java/profinet/ProfinetPoc.java | 2 +-
.../resources/protocols/profinet/profinet.mspec | 2 +-
3 files changed, 13 insertions(+), 37 deletions(-)
diff --git a/plc4j/drivers/profinet/src/main/java/org/apache/plc4x/java/profinet/protocol/ProfinetProtocolLogic.java b/plc4j/drivers/profinet/src/main/java/org/apache/plc4x/java/profinet/protocol/ProfinetProtocolLogic.java
index 62b209c10..836732954 100644
--- a/plc4j/drivers/profinet/src/main/java/org/apache/plc4x/java/profinet/protocol/ProfinetProtocolLogic.java
+++ b/plc4j/drivers/profinet/src/main/java/org/apache/plc4x/java/profinet/protocol/ProfinetProtocolLogic.java
@@ -40,10 +40,7 @@ import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.net.*;
import java.time.Duration;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.Optional;
-import java.util.UUID;
+import java.util.*;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.atomic.AtomicInteger;
@@ -133,6 +130,7 @@ public class ProfinetProtocolLogic extends Plc4xProtocolBase<Ethernet_Frame> {
connectRequestPacket.setAddress(remoteAddress.getAddress());
connectRequestPacket.setPort(remoteAddress.getPort());
// Send it.
+
udpSocket.send(connectRequestPacket);
// Receive the response.
@@ -221,14 +219,14 @@ public class ProfinetProtocolLogic extends Plc4xProtocolBase<Ethernet_Frame> {
new DceRpc_InterfaceUuid_DeviceInterface(),
profinetDriverContext.getDceRpcActivityUuid(),
0, 0, DceRpc_Operation.CONNECT,
- new PnIoCm_Packet_Req(404, 404, 404, 0, 404,
+ new PnIoCm_Packet_Req(16696, 16696, 0, 0,
Arrays.asList(
new PnIoCm_Block_ArReq((short) 1, (short) 0, PnIoCm_ArType.IO_CONTROLLER,
new Uuid(Hex.decodeHex("654519352df3b6428f874371217c2b51")),
profinetDriverContext.getSessionKey(),
profinetDriverContext.getLocalMacAddress(),
new Uuid(Hex.decodeHex("dea000006c9711d1827100640008002a")),
- false, false, false,
+ false, true, false,
false, PnIoCm_CompanionArType.SINGLE_AR, false,
true, false, PnIoCm_State.ACTIVE,
600,
@@ -249,31 +247,23 @@ public class ProfinetProtocolLogic extends Plc4xProtocolBase<Ethernet_Frame> {
Arrays.asList(
new PnIoCm_IoDataObject(0, 0x0001, 0),
new PnIoCm_IoDataObject(0, 0x8000, 1),
- new PnIoCm_IoDataObject(0, 0x8001, 2),
- new PnIoCm_IoDataObject(0, 0x8002, 3),
- new PnIoCm_IoDataObject(1, 0x0001, 4)
+ new PnIoCm_IoDataObject(0, 0x8001, 2)
),
- Collections.singletonList(
- new PnIoCm_IoCs(0x0001, 0x0001, 0x0019)
- ))
+ new ArrayList<PnIoCm_IoCs>(0))
)),
new PnIoCm_Block_IoCrReq((short) 1, (short) 0, PnIoCm_IoCrType.OUTPUT_CR,
0x0002, 0x8892, false, false,
false, false, PnIoCm_RtClass.RT_CLASS_2, 40,
- 0x8000, 128, 8, 1, 0, 0xffffffff,
+ 0xFFFF, 128, 8, 1, 0, 0xffffffff,
3, 3, 0xC000,
new MacAddress(Hex.decodeHex("000000000000")),
Collections.singletonList(
new PnIoCm_IoCrBlockReqApi(
- Collections.singletonList(
- new PnIoCm_IoDataObject(0x0001, 0x0001, 0x0005)
- ),
+ new ArrayList<PnIoCm_IoDataObject>(0),
Arrays.asList(
new PnIoCm_IoCs(0, 0x0001, 0),
new PnIoCm_IoCs(0, 0x8000, 1),
- new PnIoCm_IoCs(0, 0x8001, 2),
- new PnIoCm_IoCs(0, 0x8002, 3),
- new PnIoCm_IoCs(1, 0x0001, 4)
+ new PnIoCm_IoCs(0, 0x8001, 2)
)
)
)
@@ -287,29 +277,15 @@ public class ProfinetProtocolLogic extends Plc4xProtocolBase<Ethernet_Frame> {
0x00000001, false, false,
false, false),
new PnIoCm_Submodule_NoInputNoOutputData(0x8000,
- 0x00000002, false, false,
+ 0x00008000, false, false,
false, false),
new PnIoCm_Submodule_NoInputNoOutputData(0x8001,
- 0x00000003, false, false,
- false, false),
- new PnIoCm_Submodule_NoInputNoOutputData(0x8002,
- 0x00000003, false, false,
+ 0x00008001, false, false,
false, false)
)
)
)
),
- new PnIoCm_Block_ExpectedSubmoduleReq((short) 1, (short) 0,
- Collections.singletonList(
- new PnIoCm_ExpectedSubmoduleBlockReqApi(1,
- 0x00000022, 0x00000000, Collections.singletonList(
- new PnIoCm_Submodule_InputAndOutputData(0x0001, 0x00000010,
- false, false, false,
- false, 20, (short) 1, (short) 1,
- 6, (short) 1, (short) 1))
- )
- )
- ),
new PnIoCm_Block_AlarmCrReq((short) 1, (short) 0,
PnIoCm_AlarmCrType.ALARM_CR, 0x8892, false, false, 1, 3,
0x0000, 200, 0xC000, 0xA000)
diff --git a/plc4j/drivers/profinet/src/test/java/org/apache/plc4x/java/profinet/ProfinetPoc.java b/plc4j/drivers/profinet/src/test/java/org/apache/plc4x/java/profinet/ProfinetPoc.java
index 401258f04..90ccefbc3 100644
--- a/plc4j/drivers/profinet/src/test/java/org/apache/plc4x/java/profinet/ProfinetPoc.java
+++ b/plc4j/drivers/profinet/src/test/java/org/apache/plc4x/java/profinet/ProfinetPoc.java
@@ -40,7 +40,7 @@ public class ProfinetPoc {
new DceRpc_ObjectUuid((byte) 0x00, 0x0001, 0x0904, 0x002A),
new DceRpc_InterfaceUuid_DeviceInterface(), generateActivityUuid(),
0, 0, DceRpc_Operation.CONNECT,
- new PnIoCm_Packet_Req(404, 404, 404, 0, 404,
+ new PnIoCm_Packet_Req(404, 404, 0, 404,
Arrays.asList(
new PnIoCm_Block_ArReq((short) 1, (short) 0, PnIoCm_ArType.IO_CONTROLLER,
new Uuid(Hex.decodeHex("654519352df3b6428f874371217c2b51")), 2,
diff --git a/protocols/profinet/src/main/resources/protocols/profinet/profinet.mspec b/protocols/profinet/src/main/resources/protocols/profinet/profinet.mspec
index b6d05a84a..35bdaf24c 100644
--- a/protocols/profinet/src/main/resources/protocols/profinet/profinet.mspec
+++ b/protocols/profinet/src/main/resources/protocols/profinet/profinet.mspec
@@ -651,7 +651,7 @@
[typeSwitch packetType
['REQUEST' PnIoCm_Packet_Req
[simple uint 32 argsMaximum ]
- [simple uint 32 argsLength ]
+ [implicit uint 32 argsLength 'lengthInBytes - 20']
[simple uint 32 arrayMaximumCount ]
[simple uint 32 arrayOffset ]
[simple uint 32 arrayActualCount ]