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/05/26 21:53:21 UTC

[plc4x] branch logix_develop updated: Got the Connection Manager to connect.

This is an automated email from the ASF dual-hosted git repository.

hutcheb pushed a commit to branch logix_develop
in repository https://gitbox.apache.org/repos/asf/plc4x.git


The following commit(s) were added to refs/heads/logix_develop by this push:
     new 8da23206c2 Got the Connection Manager to connect.
8da23206c2 is described below

commit 8da23206c2dbf70cf203634d1d99982fc914448c
Author: Ben Hutcheson <be...@gmail.com>
AuthorDate: Fri May 27 07:52:43 2022 +1000

    Got the Connection Manager to connect.
---
 .../plc4x/java/logix/readwrite/LogixDriver.java    |  4 +-
 .../readwrite/protocol/LogixProtocolLogic.java     | 91 ++++++++++++++++++++--
 .../src/main/resources/logback.xml                 |  2 +-
 plc4j/examples/pom.xml                             |  7 ++
 .../src/main/resources/protocols/logix/logix.mspec | 50 ++++++++----
 5 files changed, 129 insertions(+), 25 deletions(-)

diff --git a/plc4j/drivers/logix/src/main/java/org/apache/plc4x/java/logix/readwrite/LogixDriver.java b/plc4j/drivers/logix/src/main/java/org/apache/plc4x/java/logix/readwrite/LogixDriver.java
index 9a25486f41..56fc13f014 100644
--- a/plc4j/drivers/logix/src/main/java/org/apache/plc4x/java/logix/readwrite/LogixDriver.java
+++ b/plc4j/drivers/logix/src/main/java/org/apache/plc4x/java/logix/readwrite/LogixDriver.java
@@ -38,12 +38,12 @@ public class LogixDriver extends GeneratedDriverBase<EipPacket> {
     public static final int PORT = 44818;
     @Override
     public String getProtocolCode() {
-        return "eip";
+        return "logix";
     }
 
     @Override
     public String getProtocolName() {
-        return "EthernetIP";
+        return "Allen Bradley Logix";
     }
 
     @Override
diff --git a/plc4j/drivers/logix/src/main/java/org/apache/plc4x/java/logix/readwrite/protocol/LogixProtocolLogic.java b/plc4j/drivers/logix/src/main/java/org/apache/plc4x/java/logix/readwrite/protocol/LogixProtocolLogic.java
index 33232f7504..1ba27b8de2 100644
--- a/plc4j/drivers/logix/src/main/java/org/apache/plc4x/java/logix/readwrite/protocol/LogixProtocolLogic.java
+++ b/plc4j/drivers/logix/src/main/java/org/apache/plc4x/java/logix/readwrite/protocol/LogixProtocolLogic.java
@@ -31,9 +31,7 @@ import org.apache.plc4x.java.logix.readwrite.field.LogixField;
 import org.apache.plc4x.java.spi.ConversationContext;
 import org.apache.plc4x.java.spi.Plc4xProtocolBase;
 import org.apache.plc4x.java.spi.configuration.HasConfiguration;
-import org.apache.plc4x.java.spi.generation.ParseException;
-import org.apache.plc4x.java.spi.generation.ReadBuffer;
-import org.apache.plc4x.java.spi.generation.ReadBufferByteBased;
+import org.apache.plc4x.java.spi.generation.*;
 import org.apache.plc4x.java.spi.messages.*;
 import org.apache.plc4x.java.spi.messages.utils.ResponseItem;
 import org.apache.plc4x.java.spi.transaction.RequestTransactionManager;
@@ -78,6 +76,82 @@ public class LogixProtocolLogic extends Plc4xProtocolBase<EipPacket> implements
         context.sendRequest(connectionRequest)
             .expectResponse(EipPacket.class, REQUEST_TIMEOUT).unwrap(p -> p)
             .check(p -> p instanceof EipConnectionRequest)
+            .handle(p -> {
+                if (p.getStatus() == 0L) {
+                    sessionHandle = p.getSessionHandle();
+                    senderContext = p.getSenderContext();
+                    logger.debug("Got assigned with Session {}", sessionHandle);
+                    // Send an event that connection setup is complete.
+                    onConnectOpenConnectionManager(context, p);
+
+                } else {
+                    logger.warn("Got status code [{}]", p.getStatus());
+                }
+
+            });
+    }
+
+    public void onConnectOpenConnectionManager(ConversationContext<EipPacket> context, EipPacket response) {
+        logger.debug("Sending Open Connection Manager EIP Package");
+
+        PathSegment classSegment = new LogicalSegment(new ClassID((byte) 0, (short) 6));
+        PathSegment instanceSegment = new LogicalSegment(new InstanceID((byte) 0, (short) 1));
+
+        CipExchange exchange = new CipExchange(
+            new CipConnectionManagerRequest(
+                (byte) 2,
+                classSegment,
+                instanceSegment,
+                (byte) 0,
+                (byte) 10,
+                (short) 14,
+                (long) 536870914,
+                (long) 33944,
+                (int) 8592,
+                (int) 4919,
+                (long) 42,
+                (short) 3,
+                (long) 2101812,
+                new NetworkConnectionParameters(
+                    (int) 4002,
+                    false,
+                    (byte) 2,
+                    (byte) 0,
+                    true
+                ),
+                (long) 2113537,
+                new NetworkConnectionParameters(
+                    (int) 4002,
+                    false,
+                    (byte) 2,
+                    (byte) 0,
+                    true
+                ),
+                new TransportType(true, (byte) 2, (byte) 3),
+                (short) 3,
+                new PortSegment(false, (byte) 1, (short) 0),
+                new LogicalSegment(new ClassID((byte) 0, (short) 2)),
+                new LogicalSegment(new InstanceID((byte) 0, (short) 1)),
+                (int) 0
+            ),
+            -1
+        );
+
+        CipRRData eipWrapper = new CipRRData(
+            sessionHandle,
+            response.getStatus(),
+            senderContext,
+            0L,
+            0,
+            2,
+            exchange,
+            -1
+        );
+
+
+        context.sendRequest(eipWrapper)
+            .expectResponse(EipPacket.class, REQUEST_TIMEOUT).unwrap(p -> p)
+            .check(p -> p instanceof CipRRData)
             .handle(p -> {
                 if (p.getStatus() == 0L) {
                     sessionHandle = p.getSessionHandle();
@@ -85,6 +159,7 @@ public class LogixProtocolLogic extends Plc4xProtocolBase<EipPacket> implements
                     logger.debug("Got assigned with Session {}", sessionHandle);
                     // Send an event that connection setup is complete.
                     context.fireConnected();
+
                 } else {
                     logger.warn("Got status code [{}]", p.getStatus());
                 }
@@ -92,6 +167,8 @@ public class LogixProtocolLogic extends Plc4xProtocolBase<EipPacket> implements
             });
     }
 
+
+
     @Override
     public CompletableFuture<PlcReadResponse> read(PlcReadRequest readRequest) {
         DefaultPlcReadRequest request = (DefaultPlcReadRequest) readRequest;
@@ -210,7 +287,7 @@ public class LogixProtocolLogic extends Plc4xProtocolBase<EipPacket> implements
             Services data = new Services(nb, offsets, serviceArr, -1);
             //Encapsulate the data
 
-            PathSegment pathSegment0 = new AnsiExtendedSymbolSegment("test");
+            PathSegment pathSegment0 = new AnsiExtendedSymbolSegment((short) 4,"test");
 
             CipRRData pkt = new CipRRData(sessionHandle, 0L, emptySenderContext, 0L, 0, 2,
                 new CipExchange(
@@ -244,7 +321,7 @@ public class LogixProtocolLogic extends Plc4xProtocolBase<EipPacket> implements
                 }));
         } else if (request.size() == 1) {
 
-            PathSegment pathSegment0 = new AnsiExtendedSymbolSegment("test");
+            PathSegment pathSegment0 = new AnsiExtendedSymbolSegment((short) 4,"test");
 
             CipExchange exchange = new CipExchange(
                 new CipUnconnectedRequest(
@@ -434,7 +511,7 @@ public class LogixProtocolLogic extends Plc4xProtocolBase<EipPacket> implements
         RequestTransactionManager.RequestTransaction transaction = tm.startRequest();
         if (items.size() == 1) {
             tm.startRequest();
-            PathSegment pathSegment0 = new AnsiExtendedSymbolSegment("test");
+            PathSegment pathSegment0 = new AnsiExtendedSymbolSegment((short) 4,"test");
             CipRRData rrdata = new CipRRData(sessionHandle, 0L, senderContext, 0L, 0, 2,
                 new CipExchange(
                     new CipUnconnectedRequest(
@@ -478,7 +555,7 @@ public class LogixProtocolLogic extends Plc4xProtocolBase<EipPacket> implements
             Services data = new Services(nb, offsets, serviceArr, -1);
             //Encapsulate the data
 
-            PathSegment pathSegment0 = new AnsiExtendedSymbolSegment("test");
+            PathSegment pathSegment0 = new AnsiExtendedSymbolSegment((short) 4,"test");
 
             CipRRData pkt = new CipRRData(sessionHandle, 0L, emptySenderContext, 0L, 0, 2,
                 new CipExchange(
diff --git a/plc4j/examples/hello-world-plc4x/src/main/resources/logback.xml b/plc4j/examples/hello-world-plc4x/src/main/resources/logback.xml
index ca1c35dfd8..f5922f3e2b 100644
--- a/plc4j/examples/hello-world-plc4x/src/main/resources/logback.xml
+++ b/plc4j/examples/hello-world-plc4x/src/main/resources/logback.xml
@@ -27,7 +27,7 @@
     </encoder>
   </appender>
 
-  <root level="info">
+  <root level="trace">
     <appender-ref ref="STDOUT" />
   </root>
 
diff --git a/plc4j/examples/pom.xml b/plc4j/examples/pom.xml
index e24f218914..18b81bd0d4 100644
--- a/plc4j/examples/pom.xml
+++ b/plc4j/examples/pom.xml
@@ -109,6 +109,7 @@
             <usedDependency>org.apache.plc4x:plc4j-driver-eip</usedDependency>
             <usedDependency>org.apache.plc4x:plc4j-driver-firmata</usedDependency>
             <usedDependency>org.apache.plc4x:plc4j-driver-knxnetip</usedDependency>
+            <usedDependency>org.apache.plc4x:plc4j-driver-logix</usedDependency>
             <usedDependency>org.apache.plc4x:plc4j-driver-modbus</usedDependency>
             <usedDependency>org.apache.plc4x:plc4j-driver-opcua</usedDependency>
             <usedDependency>org.apache.plc4x:plc4j-driver-profinet</usedDependency>
@@ -189,6 +190,12 @@
       <version>0.10.0-SNAPSHOT</version>
       <scope>runtime</scope>
     </dependency>
+    <dependency>
+      <groupId>org.apache.plc4x</groupId>
+      <artifactId>plc4j-driver-logix</artifactId>
+      <version>0.10.0-SNAPSHOT</version>
+      <scope>runtime</scope>
+    </dependency>
     <dependency>
       <groupId>org.apache.plc4x</groupId>
       <artifactId>plc4j-driver-modbus</artifactId>
diff --git a/protocols/logix/src/main/resources/protocols/logix/logix.mspec b/protocols/logix/src/main/resources/protocols/logix/logix.mspec
index 742bc123c8..a9712cfa15 100644
--- a/protocols/logix/src/main/resources/protocols/logix/logix.mspec
+++ b/protocols/logix/src/main/resources/protocols/logix/logix.mspec
@@ -68,7 +68,7 @@
 [type  CipExchange (uint 16 exchangeLen)  //We pass then length down to evey sub-type to be able to provide the remaining data size
     [const          uint 32                         nullPtr             0x0                   ]  //NullPointerAddress
     [const          uint 16                         unconnectedData     0x00B2                ]  //Connection Manager
-    [implicit       uint 16                         size                'lengthInBytes - 8 - 2' ]  //remove fields above and routing
+    [implicit       uint 16                         size                'lengthInBytes - 8' ]  //remove fields above and routing
     [simple         CipService('exchangeLen - 10')  service                                     ]
 ]
 
@@ -120,12 +120,11 @@
         ]
         ['0x5B','false'     CipConnectionManagerRequest
                [simple      int     8           requestPathSize]
-               [simple      ClassSegment        classSegment]
-               [simple      InstanceSegment     instanceSegment]
+               [simple      PathSegment         classSegment]
+               [simple      PathSegment         instanceSegment]
                [simple      uint    4           priority]
                [simple      uint    4           tickTime]
                [simple      uint    8           timeoutTicks]
-               [simple      uint    16          actualTimeout]
                [simple      uint    32          otConnectionId]
                [simple      uint    32          toConnectionId]
                [simple      uint    16          connectionSerialNumber]
@@ -139,7 +138,9 @@
                [simple      NetworkConnectionParameters toConnectionParameters]
                [simple      TransportType       transportType]
                [simple      uint    8           connectionPathSize]
-               [simple      PortSegment         portSegment]
+               [simple      PathSegment         connectionPathPortSegment]
+               [simple      PathSegment         connectionPathClassSegment]
+               [simple      PathSegment         connectionPathInstanceSegment]
 
         ]
         ['0x5B','true'     CipConnectionManagerResponse
@@ -159,15 +160,37 @@
 
 [discriminatedType PathSegment
     [discriminator  uint    3   pathSegment]
-    [discriminator  uint    5   dataSegment]
-    [typeSwitch pathSegment,dataSegment
-        ['0x04','0x11'      AnsiExtendedSymbolSegment
+    [typeSwitch pathSegment
+        ['0x00'      PortSegment
+            [simple bit extendedLinkAddress]
+            [simple uint 4  port]
+            [simple uint    8   linkAddress]
+        ]
+        ['0x01'      LogicalSegment
+            [simple LogicalSegmentType  segmentType]
+        ]
+        ['0x04'      AnsiExtendedSymbolSegment
+            [simple  uint    5   dataSegment]
             [implicit   uint    8   dataSize    'symbol.length']
             [simple     vstring 'dataSize'  symbol]
         ]
     ]
 ]
 
+[discriminatedType LogicalSegmentType
+    [discriminator  uint    3   logicalSegmentType]
+    [typeSwitch logicalSegmentType
+        ['0x00' ClassID
+            [simple uint    2   format]
+            [simple uint    8   segmentClass]
+        ]
+        ['0x01' InstanceID
+            [simple uint    2   format]
+            [simple uint    8   instance]
+        ]
+    ]
+]
+
 [type   InstanceSegment
     [simple     uint    3   pathSegmentType]
     [simple     uint    3   logicalSegmentType]
@@ -182,19 +205,16 @@
     [simple     uint    8   classSegment]
 ]
 
-[type   PortSegment
-    [simple     uint    3   portSegmentType]
-    [simple     bit         extendedLinkAddress]
-    [simple     uint    4   port]
-    [simple     uint    8   linkAddress]
-]
 
 [type   NetworkConnectionParameters
+   [simple      uint    16  connectionSize]
+   [reserved    uint    8   '0x00']
    [simple      bit         owner]
    [simple      uint    2   connectionType]
+   [reserved    bit         'false']
    [simple      uint    2   priority]
    [simple      bit         connectionSizeType]
-   [simple      uint    16  connectionSize]
+   [reserved    bit         'false']
 ]
 
 [type   TransportType