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 dcdad3137d4a5b2a42e15af6fd45dfe6c491dcc8
Author: Ben Hutcheson <[email protected]>
AuthorDate: Sun Sep 11 13:38:47 2022 -0600

    feat(plc4j/profinet): Fixed a few minor issues and added the Application 
Ready packet
---
 .../apache/plc4x/java/profinet/ProfinetDriver.java |  7 ++-
 .../profinet/discovery/ProfinetPlcDiscoverer.java  |  2 +-
 .../profinet/protocol/ProfinetProtocolLogic.java   | 51 +++++++++++++++++++++-
 .../resources/protocols/profinet/profinet.mspec    | 44 +++++++++++++------
 4 files changed, 88 insertions(+), 16 deletions(-)

diff --git 
a/plc4j/drivers/profinet/src/main/java/org/apache/plc4x/java/profinet/ProfinetDriver.java
 
b/plc4j/drivers/profinet/src/main/java/org/apache/plc4x/java/profinet/ProfinetDriver.java
index 1fec4f741..05d96d8b4 100644
--- 
a/plc4j/drivers/profinet/src/main/java/org/apache/plc4x/java/profinet/ProfinetDriver.java
+++ 
b/plc4j/drivers/profinet/src/main/java/org/apache/plc4x/java/profinet/ProfinetDriver.java
@@ -99,11 +99,16 @@ public class ProfinetDriver extends 
GeneratedDriverBase<Ethernet_Frame> {
 
     @Override
     protected boolean canRead() {
-        return true;
+        return false;
     }
 
     @Override
     protected boolean canWrite() {
+        return false;
+    }
+
+    @Override
+    protected boolean canSubscribe() {
         return true;
     }
 
diff --git 
a/plc4j/drivers/profinet/src/main/java/org/apache/plc4x/java/profinet/discovery/ProfinetPlcDiscoverer.java
 
b/plc4j/drivers/profinet/src/main/java/org/apache/plc4x/java/profinet/discovery/ProfinetPlcDiscoverer.java
index 35681f795..f4066d098 100644
--- 
a/plc4j/drivers/profinet/src/main/java/org/apache/plc4x/java/profinet/discovery/ProfinetPlcDiscoverer.java
+++ 
b/plc4j/drivers/profinet/src/main/java/org/apache/plc4x/java/profinet/discovery/ProfinetPlcDiscoverer.java
@@ -410,7 +410,7 @@ public class ProfinetPlcDiscoverer implements PlcDiscoverer 
{
                                                     new TlvManagementAddress(
                                                         12,
                                                         
ManagementAddressSubType.IPV4,
-                                                        new 
IpAddress(Hex.decodeHex("c0a8006e")),
+                                                        new 
IpAddress(Hex.decodeHex("c0a85a6e")),
                                                         (short) 0x03,
                                                         0x01L,
                                                         (short) 0x00
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 d3c1d1024..3801c1dfa 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
@@ -208,6 +208,23 @@ public class ProfinetProtocolLogic extends 
Plc4xProtocolBase<Ethernet_Frame> {
             connectResponsePacket = new DatagramPacket(resultBuffer, 
resultBuffer.length);
             udpSocket.receive(connectResponsePacket);
 
+            // Create the packet
+            final DceRpc_Packet profinetAdvancedConnectionApplicationReady = 
createProfinetAdvancedConnectionApplicationReady();
+            // Serialize it to a byte-payload
+            writeBuffer = new 
WriteBufferByteBased(profinetAdvancedConnectionApplicationReady.getLengthInBytes());
+            profinetAdvancedConnectionApplicationReady.serialize(writeBuffer);
+            // Create a udp packet.
+            connectRequestPacket = new DatagramPacket(writeBuffer.getData(), 
writeBuffer.getData().length);
+            connectRequestPacket.setAddress(remoteAddress.getAddress());
+            connectRequestPacket.setPort(remoteAddress.getPort());
+            // Send it.
+
+            udpSocket.send(connectRequestPacket);
+
+            // Receive the response.
+            resultBuffer = new 
byte[profinetAdvancedConnectionApplicationReady.getLengthInBytes()];
+            connectResponsePacket = new DatagramPacket(resultBuffer, 
resultBuffer.length);
+            udpSocket.receive(connectResponsePacket);
 
         } catch (SerializationException | IOException | PlcException | 
ParseException e) {
             logger.error("Error", e);
@@ -233,6 +250,13 @@ public class ProfinetProtocolLogic extends 
Plc4xProtocolBase<Ethernet_Frame> {
         return future;
     }
 
+    @Override
+    public CompletableFuture<PlcSubscriptionResponse> 
subscribe(PlcSubscriptionRequest subscriptionRequest) {
+        CompletableFuture<PlcSubscriptionResponse> future = new 
CompletableFuture<>();
+        future.completeExceptionally(new NotImplementedException());
+        return future;
+    }
+
     @Override
     protected void decode(ConversationContext<Ethernet_Frame> context, 
Ethernet_Frame msg) throws Exception {
         super.decode(context, msg);
@@ -386,7 +410,7 @@ public class ProfinetProtocolLogic extends 
Plc4xProtocolBase<Ethernet_Frame> {
                     new PDInterfaceAdjust(
                         (short) 1,
                         (short) 0,
-                        MultipleInterfaceModeNameOfDevice.PORT_PROVIDED_BY_LLDP
+                        MultipleInterfaceModeNameOfDevice.NAME_PROVIDED_BY_LLDP
                     ),
                     new IODWriteRequestHeader(
                         (short) 1,
@@ -437,6 +461,31 @@ public class ProfinetProtocolLogic extends 
Plc4xProtocolBase<Ethernet_Frame> {
         );
     }
 
+
+
+    private DceRpc_Packet createProfinetAdvancedConnectionApplicationReady() 
throws PlcException {
+
+        return new DceRpc_Packet(
+            DceRpc_PacketType.REQUEST, true, false, false,
+            IntegerEncoding.BIG_ENDIAN, CharacterEncoding.ASCII, 
FloatingPointEncoding.IEEE,
+            new DceRpc_ObjectUuid((byte) 0x00, 0x0001, 0x0904, 0x002A),
+            new DceRpc_InterfaceUuid_DeviceInterface(),
+            profinetDriverContext.getDceRpcActivityUuid(),
+            0, 1, DceRpc_Operation.CONTROL,
+            new PnIoCm_Packet_Req(16696, 16696, 0, 244,
+                Arrays.asList(
+                    new PnIoCM_Block_Request(
+                        (short) 1,
+                        (short) 0,
+                        ARUUID,
+                        0x0001,
+                        0x0002,
+                        0x0000
+                    )
+                ))
+        );
+    }
+
     protected static DceRpc_ActivityUuid generateActivityUuid() {
         UUID number = UUID.randomUUID();
         try {
diff --git 
a/protocols/profinet/src/main/resources/protocols/profinet/profinet.mspec 
b/protocols/profinet/src/main/resources/protocols/profinet/profinet.mspec
index 57f3ced3a..2cabb832f 100644
--- a/protocols/profinet/src/main/resources/protocols/profinet/profinet.mspec
+++ b/protocols/profinet/src/main/resources/protocols/profinet/profinet.mspec
@@ -823,27 +823,43 @@
             [simple   vstring 'stationNameLength * 8' cmInitiatorStationName   
                              ]
         ]
         ['AR_BLOCK_RES' PnIoCm_Block_ArRes
-            [simple   PnIoCm_ArType          arType                            
                     ]
-            [simple   Uuid                   arUuid                            
                     ]
-            [simple   uint 16                sessionKey                        
                     ]
-            [simple   MacAddress             cmResponderMacAddr                
                     ]
-            [simple   uint 16                responderUDPRTPort                
                     ]
+            [simple   PnIoCm_ArType          arType                            
                              ]
+            [simple   Uuid                   arUuid                            
                              ]
+            [simple   uint 16                sessionKey                        
                              ]
+            [simple   MacAddress             cmResponderMacAddr                
                              ]
+            [simple   uint 16                responderUDPRTPort                
                              ]
         ]
         ['IOD_CONTROL_REQ' PnIoCm_Control_Request
-            [reserved uint 16                         '0x0000'                 
                        ]
+            [reserved uint 16                         '0x0000'                 
                              ]
             [simple   Uuid                            arUuid                   
                              ]
             [simple   uint 16                         sessionKey               
                              ]
-            [reserved uint 16                         '0x0000'                 
                        ]
+            [reserved uint 16                         '0x0000'                 
                              ]
             [simple   uint 16                         controlCommand           
                              ]
-            [reserved uint 16                         '0x0000'                 
                        ]
+            [reserved uint 16                         '0x0000'                 
                              ]
+        ]
+        ['IOX_BLOCK_REQ'    PnIoCM_Block_Request
+            [reserved uint 16                         '0x0000'                 
                              ]
+            [simple   Uuid                            arUuid                   
                              ]
+            [simple   uint 16                         sessionKey               
                              ]
+            [reserved uint 16                         '0x0000'                 
                              ]
+            [simple   uint 16                         controlCommand           
                              ]
+            [simple   uint 16                         controlBlockProperties   
                              ]
+        ]
+        ['IOX_BLOCK_RES'    PnIoCM_Block_Response
+            [reserved uint 16                         '0x0000'                 
                              ]
+            [simple   Uuid                            arUuid                   
                              ]
+            [simple   uint 16                         sessionKey               
                              ]
+            [reserved uint 16                         '0x0000'                 
                              ]
+            [simple   uint 16                         controlCommand           
                              ]
+            [simple   uint 16                         controlBlockProperties   
                              ]
         ]
         ['IOD_CONTROL_RES' PnIoCm_Control_Response
-            [reserved uint 16                         '0x0000'                 
                        ]
+            [reserved uint 16                         '0x0000'                 
                              ]
             [simple   Uuid                            arUuid                   
                              ]
             [simple   uint 16                         sessionKey               
                              ]
-            [reserved uint 16                         '0x0000'                 
                        ]
+            [reserved uint 16                         '0x0000'                 
                              ]
             [simple   uint 16                         controlCommand           
                              ]
-            [reserved uint 16                         '0x0000'                 
                        ]
+            [reserved uint 16                         '0x0000'                 
                              ]
         ]
         ['IO_CR_BLOCK_REQ' PnIoCm_Block_IoCrReq
             [simple PnIoCm_IoCrType          ioCrType                          
                     ]
@@ -913,9 +929,9 @@
 ]
 
 [type PascalString
-    [implicit int 16 sLength          'stringValue.length == 0 ? -1 : 
stringValue.length']
+    [implicit int 8 sLength          'stringValue.length == 0 ? -1 : 
stringValue.length']
     [simple vstring 'sLength == -1 ? 0 : sLength * 8' stringValue]
-    [virtual  int 16 stringLength     'stringValue.length == -1 ? 0 : 
stringValue.length']
+    [virtual  int 8 stringLength     'stringValue.length == -1 ? 0 : 
stringValue.length']
 ]
 
 [type PnIoCm_IoCrBlockReqApi
@@ -1016,6 +1032,7 @@
     ['0x0103' ALARM_CR_BLOCK_REQ          ]
     ['0x0104' EXPECTED_SUBMODULE_BLOCK_REQ]
     ['0x0110' IOD_CONTROL_REQ             ]
+    ['0x0112' IOX_BLOCK_REQ               ]
     ['0x0200' PD_PORT_DATA_CHECK          ]
     ['0x020a' CHECK_PEERS                 ]
     ['0x0250' PD_INTERFACE_ADJUST         ]
@@ -1025,6 +1042,7 @@
     ['0x8104' MODULE_DIFF_BLOCK           ]
     ['0x8106' AR_SERVER_BLOCK             ]
     ['0x8110' IOD_CONTROL_RES             ]
+    ['0x8112' IOX_BLOCK_RES               ]
 ]
 
 [enum uint 16 PnIoCm_ArType

Reply via email to