You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@plc4x.apache.org by sr...@apache.org on 2019/12/18 14:43:16 UTC

[plc4x] branch feature/reply-request-builder updated (80fbddd -> 7487316)

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

sruehl pushed a change to branch feature/reply-request-builder
in repository https://gitbox.apache.org/repos/asf/plc4x.git.


 discard 80fbddd  Pushed my shit
     add 8dbed5c  - Updated the build after the moving of packages
     new 7487316  Pushed my shit

This update added new revisions after undoing existing revisions.
That is to say, some revisions that were in the old version of the
branch are not in the new version.  This situation occurs
when a user --force pushes a change and generates a repository
containing something like this:

 * -- * -- B -- O -- O -- O   (80fbddd)
            \
             N -- N -- N   refs/heads/feature/reply-request-builder (7487316)

You should already have received notification emails for all of the O
revisions, and so the following emails describe only the N revisions
from the common base, B.

Any revisions marked "omit" are not gone; other references still
refer to them.  Any revisions marked "discard" are gone forever.

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 plc4j/drivers/ethernet-ip/pom.xml | 5 +++++
 plc4j/protocols/pom.xml           | 2 +-
 2 files changed, 6 insertions(+), 1 deletion(-)


[plc4x] 01/01: Pushed my shit

Posted by sr...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

sruehl pushed a commit to branch feature/reply-request-builder
in repository https://gitbox.apache.org/repos/asf/plc4x.git

commit 7487316b6b2720ad40d1f3f408d05c3fd0dce97c
Author: Julian Feinauer <j....@pragmaticminds.de>
AuthorDate: Wed Dec 18 15:40:03 2019 +0100

    Pushed my shit
---
 .../apache/plc4x/java/spi/ConversationContext.java |   4 +-
 .../apache/plc4x/java/spi/request/PlcRequest.java  |   4 +-
 .../s7/readwrite/protocol/Plc4xS7Protocol.java     | 154 ++++++++++++++++-----
 3 files changed, 129 insertions(+), 33 deletions(-)

diff --git a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/ConversationContext.java b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/ConversationContext.java
index 973d9a3..07895e8 100644
--- a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/ConversationContext.java
+++ b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/ConversationContext.java
@@ -19,9 +19,11 @@
 
 package org.apache.plc4x.java.spi;
 
+import org.apache.plc4x.java.spi.request.PlcRequest;
+
 public interface ConversationContext<T> {
 
-    void sendToWire(T msg);
+    PlcRequest sendToWire(T msg);
 
     void fireConnected();
 
diff --git a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/request/PlcRequest.java b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/request/PlcRequest.java
index 5c36894..42d0850 100644
--- a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/request/PlcRequest.java
+++ b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/request/PlcRequest.java
@@ -24,5 +24,7 @@ package org.apache.plc4x.java.spi.request;
 
 public class PlcRequest {
 
-    // void expectResponse();
+    void expectResponse() {
+
+    }
 }
diff --git a/sandbox/test-java-s7-driver/src/main/java/org/apache/plc4x/java/s7/readwrite/protocol/Plc4xS7Protocol.java b/sandbox/test-java-s7-driver/src/main/java/org/apache/plc4x/java/s7/readwrite/protocol/Plc4xS7Protocol.java
index 93e3b9a..1d2d85d 100644
--- a/sandbox/test-java-s7-driver/src/main/java/org/apache/plc4x/java/s7/readwrite/protocol/Plc4xS7Protocol.java
+++ b/sandbox/test-java-s7-driver/src/main/java/org/apache/plc4x/java/s7/readwrite/protocol/Plc4xS7Protocol.java
@@ -27,8 +27,47 @@ import org.apache.plc4x.java.api.exceptions.PlcRuntimeException;
 import org.apache.plc4x.java.api.messages.PlcResponse;
 import org.apache.plc4x.java.api.model.PlcField;
 import org.apache.plc4x.java.api.types.PlcResponseCode;
-import org.apache.plc4x.java.s7.readwrite.*;
-import org.apache.plc4x.java.s7.readwrite.types.*;
+import org.apache.plc4x.java.s7.readwrite.COTPPacketConnectionRequest;
+import org.apache.plc4x.java.s7.readwrite.COTPPacketConnectionResponse;
+import org.apache.plc4x.java.s7.readwrite.COTPPacketData;
+import org.apache.plc4x.java.s7.readwrite.COTPParameter;
+import org.apache.plc4x.java.s7.readwrite.COTPParameterCalledTsap;
+import org.apache.plc4x.java.s7.readwrite.COTPParameterCallingTsap;
+import org.apache.plc4x.java.s7.readwrite.COTPParameterTpduSize;
+import org.apache.plc4x.java.s7.readwrite.S7Address;
+import org.apache.plc4x.java.s7.readwrite.S7AddressAny;
+import org.apache.plc4x.java.s7.readwrite.S7Message;
+import org.apache.plc4x.java.s7.readwrite.S7MessageRequest;
+import org.apache.plc4x.java.s7.readwrite.S7MessageResponse;
+import org.apache.plc4x.java.s7.readwrite.S7MessageUserData;
+import org.apache.plc4x.java.s7.readwrite.S7Parameter;
+import org.apache.plc4x.java.s7.readwrite.S7ParameterReadVarRequest;
+import org.apache.plc4x.java.s7.readwrite.S7ParameterReadVarResponse;
+import org.apache.plc4x.java.s7.readwrite.S7ParameterSetupCommunication;
+import org.apache.plc4x.java.s7.readwrite.S7ParameterUserData;
+import org.apache.plc4x.java.s7.readwrite.S7ParameterUserDataItem;
+import org.apache.plc4x.java.s7.readwrite.S7ParameterUserDataItemCPUFunctions;
+import org.apache.plc4x.java.s7.readwrite.S7ParameterWriteVarResponse;
+import org.apache.plc4x.java.s7.readwrite.S7PayloadReadVarRequest;
+import org.apache.plc4x.java.s7.readwrite.S7PayloadReadVarResponse;
+import org.apache.plc4x.java.s7.readwrite.S7PayloadSetupCommunication;
+import org.apache.plc4x.java.s7.readwrite.S7PayloadUserData;
+import org.apache.plc4x.java.s7.readwrite.S7PayloadUserDataItem;
+import org.apache.plc4x.java.s7.readwrite.S7PayloadUserDataItemCpuFunctionReadSzlRequest;
+import org.apache.plc4x.java.s7.readwrite.S7PayloadUserDataItemCpuFunctionReadSzlResponse;
+import org.apache.plc4x.java.s7.readwrite.S7VarPayloadDataItem;
+import org.apache.plc4x.java.s7.readwrite.S7VarRequestParameterItem;
+import org.apache.plc4x.java.s7.readwrite.S7VarRequestParameterItemAddress;
+import org.apache.plc4x.java.s7.readwrite.SzlDataTreeItem;
+import org.apache.plc4x.java.s7.readwrite.SzlId;
+import org.apache.plc4x.java.s7.readwrite.TPKTPacket;
+import org.apache.plc4x.java.s7.readwrite.types.COTPProtocolClass;
+import org.apache.plc4x.java.s7.readwrite.types.COTPTpduSize;
+import org.apache.plc4x.java.s7.readwrite.types.DataTransportErrorCode;
+import org.apache.plc4x.java.s7.readwrite.types.DataTransportSize;
+import org.apache.plc4x.java.s7.readwrite.types.S7ControllerType;
+import org.apache.plc4x.java.s7.readwrite.types.SzlModuleTypeClass;
+import org.apache.plc4x.java.s7.readwrite.types.SzlSublist;
 import org.apache.plc4x.java.s7.readwrite.utils.S7Field;
 import org.apache.plc4x.java.spi.ConversationContext;
 import org.apache.plc4x.java.spi.Plc4xProtocolBase;
@@ -59,7 +98,12 @@ import java.time.LocalDate;
 import java.time.LocalDateTime;
 import java.time.LocalTime;
 import java.time.temporal.ChronoUnit;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.BitSet;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicInteger;
 import java.util.function.Function;
 import java.util.stream.Collectors;
@@ -96,7 +140,9 @@ public class Plc4xS7Protocol extends Plc4xProtocolBase<TPKTPacket> {
     }
 
     @Override
-    public void onConnect(ConversationContext<TPKTPacket> context) {
+    public void onConnect(
+        // Special COntext
+        ConversationContext<TPKTPacket> context) {
         logger.debug("ISO Transport Protocol Sending Connection Request");
         // Open the session on ISO Transport Protocol first.
         COTPPacketConnectionRequest connectionRequest = new COTPPacketConnectionRequest(
@@ -106,7 +152,38 @@ public class Plc4xS7Protocol extends Plc4xProtocolBase<TPKTPacket> {
                 new COTPParameterTpduSize(cotpTpduSize)
             }, null, (short) 0x0000, (short) 0x000F, COTPProtocolClass.CLASS_0);
         TPKTPacket packet = new TPKTPacket(connectionRequest);
-        context.sendToWire(packet);
+        context.sendRequest(packet)
+            .expectResponse(TPKTPacket.class, 1000, TimeUnit.MILLISECONDS)
+            .check(packet -> packet.getTpid == 0x0000)
+            .handle((packet -> {
+                COTPPacketConnectionResponse cotpPacketConnectionResponse = (COTPPacketConnectionResponse) msg.getPayload();
+                for (COTPParameter parameter : cotpPacketConnectionResponse.getParameters()) {
+                    if(parameter instanceof COTPParameterCalledTsap) {
+                        COTPParameterCalledTsap cotpParameterCalledTsap = (COTPParameterCalledTsap) parameter;
+                        calledTsapId = cotpParameterCalledTsap.getTsapId();
+                    } else if(parameter instanceof COTPParameterTpduSize) {
+                        COTPParameterTpduSize cotpParameterTpduSize = (COTPParameterTpduSize) parameter;
+                        cotpTpduSize = cotpParameterTpduSize.getTpduSize();
+                    } else if(parameter instanceof COTPParameterCallingTsap) {
+                        // Ignore this ...
+                    } else {
+                        logger.warn("Got unknown parameter type '" + parameter.getClass().getName() + "'");
+                    }
+                }
+
+                // Send an S7 login message.
+                S7ParameterSetupCommunication s7ParameterSetupCommunication =
+                    new S7ParameterSetupCommunication(maxAmqCaller, maxAmqCallee, pduSize);
+                S7Message s7Message = new S7MessageRequest(0, s7ParameterSetupCommunication,
+                    new S7PayloadSetupCommunication());
+                COTPPacketData cotpPacketData = new COTPPacketData(null, s7Message, true, (short) 1);
+                TPKTPacket tpktPacket = new TPK Packet(cotpPacketData);
+
+                context.sendRequest(tpktPacket)
+
+
+                    context.fireConnectionEstablished();
+            });
     }
 
     @Override
@@ -118,11 +195,50 @@ public class Plc4xS7Protocol extends Plc4xProtocolBase<TPKTPacket> {
                 requestItems.add(new S7VarRequestParameterItemAddress(toS7Address(field)));
             }
             final int tpduId = tpduGenerator.getAndIncrement();
-            context.sendToWire(new TPKTPacket(new COTPPacketData(null,
+            context.sendRequest(new TPKTPacket(new COTPPacketData(null,
                 new S7MessageRequest(tpduId,
                     new S7ParameterReadVarRequest(requestItems.toArray(new S7VarRequestParameterItem[0])),
                     new S7PayloadReadVarRequest()),
-                true, (short) tpduId)));
+                true, (short) tpduId)))
+                .expectResponse(TPKTPacket.class, 1000, TimeUnit.MILLISECONDS)
+                .check(packet -> packet.getTpid == tpduId)
+                .handle((packet -> {
+                    COTPPacketData packetData = (COTPPacketData) packet.getPayload();
+                    assert packetData.getPayload() instanceof S7MessageResponse;
+                    S7MessageResponse s7MessageResponse = (S7MessageResponse) packetData.getPayload();
+                    final S7Parameter parameter = s7MessageResponse.getParameter();
+                    assert parameter instanceof S7ParameterReadVarResponse;
+                    final PlcResponse response = decodeReadResponse(s7MessageResponse, msg);
+                    msg.getResponseFuture().complete(response);
+                })
+                .onTimeout(packet, e -> {
+                    COTPPacketConnectionResponse cotpPacketConnectionResponse = (COTPPacketConnectionResponse) msg.getPayload();
+                    for (COTPParameter parameter : cotpPacketConnectionResponse.getParameters()) {
+                        if(parameter instanceof COTPParameterCalledTsap) {
+                            COTPParameterCalledTsap cotpParameterCalledTsap = (COTPParameterCalledTsap) parameter;
+                            calledTsapId = cotpParameterCalledTsap.getTsapId();
+                        } else if(parameter instanceof COTPParameterTpduSize) {
+                            COTPParameterTpduSize cotpParameterTpduSize = (COTPParameterTpduSize) parameter;
+                            cotpTpduSize = cotpParameterTpduSize.getTpduSize();
+                        } else if(parameter instanceof COTPParameterCallingTsap) {
+                            // Ignore this ...
+                        } else {
+                            logger.warn("Got unknown parameter type '" + parameter.getClass().getName() + "'");
+                        }
+                    }
+
+                    // Send an S7 login message.
+                    S7ParameterSetupCommunication s7ParameterSetupCommunication =
+                        new S7ParameterSetupCommunication(maxAmqCaller, maxAmqCallee, pduSize);
+                    S7Message s7Message = new S7MessageRequest(0, s7ParameterSetupCommunication,
+                        new S7PayloadSetupCommunication());
+                    COTPPacketData cotpPacketData = new COTPPacketData(null, s7Message, true, (short) 1);
+                    TPKTPacket tpktPacket = new TPKTPacket(cotpPacketData);
+                    context.sendToWire(tpktPacket);
+                })
+                // TODO: optional this on default behavior
+                .defaultHandling(msg);
+            ;
             requests.put(tpduId, msg);
         }
     }
@@ -135,31 +251,7 @@ public class Plc4xS7Protocol extends Plc4xProtocolBase<TPKTPacket> {
 
         // When getting a response to the connection request on COTP layer, extract some
         // data and continue logging in on the S7 protocol.
-        if(msg.getPayload() instanceof COTPPacketConnectionResponse) {
-            COTPPacketConnectionResponse cotpPacketConnectionResponse = (COTPPacketConnectionResponse) msg.getPayload();
-            for (COTPParameter parameter : cotpPacketConnectionResponse.getParameters()) {
-                if(parameter instanceof COTPParameterCalledTsap) {
-                    COTPParameterCalledTsap cotpParameterCalledTsap = (COTPParameterCalledTsap) parameter;
-                    calledTsapId = cotpParameterCalledTsap.getTsapId();
-                } else if(parameter instanceof COTPParameterTpduSize) {
-                    COTPParameterTpduSize cotpParameterTpduSize = (COTPParameterTpduSize) parameter;
-                    cotpTpduSize = cotpParameterTpduSize.getTpduSize();
-                } else if(parameter instanceof COTPParameterCallingTsap) {
-                    // Ignore this ...
-                } else {
-                    logger.warn("Got unknown parameter type '" + parameter.getClass().getName() + "'");
-                }
-            }
 
-            // Send an S7 login message.
-            S7ParameterSetupCommunication s7ParameterSetupCommunication =
-                new S7ParameterSetupCommunication(maxAmqCaller, maxAmqCallee, pduSize);
-            S7Message s7Message = new S7MessageRequest(0, s7ParameterSetupCommunication,
-                new S7PayloadSetupCommunication());
-            COTPPacketData cotpPacketData = new COTPPacketData(null, s7Message, true, (short) 1);
-            TPKTPacket tpktPacket = new TPKTPacket(cotpPacketData);
-            context.sendToWire(tpktPacket);
-        }
 
         else if(msg.getPayload() instanceof COTPPacketData) {
             COTPPacketData packetData = (COTPPacketData) msg.getPayload();