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 2018/04/19 14:01:02 UTC

[incubator-plc4x] branch master updated: several smaller fixes on ads protocol: + fixed message mixup on ads return code + fixed rendering on ams net id + fixed type missuse on tcp implementation + ...and some more smaller fixes...

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

sruehl pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-plc4x.git


The following commit(s) were added to refs/heads/master by this push:
     new 88e4e92  several smaller fixes on ads protocol: + fixed message mixup on ads return code + fixed rendering on ams net id + fixed type missuse on tcp implementation + ...and some more smaller fixes...
88e4e92 is described below

commit 88e4e9211f8b4c129898ebf63c78bad074941a22
Author: Sebastian Rühl <sr...@apache.org>
AuthorDate: Thu Apr 19 16:00:58 2018 +0200

    several smaller fixes on ads protocol:
    + fixed message mixup on ads return code
    + fixed rendering on ams net id
    + fixed type missuse on tcp implementation
    + ...and some more smaller fixes...
---
 .../plc4x/java/ads/api/commands/types/AdsReturnCode.java |  2 +-
 .../plc4x/java/ads/api/generic/types/AmsNetId.java       |  2 +-
 .../org/apache/plc4x/java/ads/api/tcp/AmsTCPPacket.java  |  2 +-
 .../plc4x/java/ads/connection/AdsTcpPlcConnection.java   | 11 +++++++++++
 .../plc4x/java/ads/protocol/Payload2TcpProtocol.java     |  3 +--
 .../test/java/org/apache/plc4x/java/ads/AdsDumper.java   | 16 ++++++++++------
 .../plc4x/java/ads/protocol/Payload2TcpProtocolTest.java |  2 +-
 7 files changed, 26 insertions(+), 12 deletions(-)

diff --git a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/types/AdsReturnCode.java b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/types/AdsReturnCode.java
index fa6cbaf..6c6c982 100644
--- a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/types/AdsReturnCode.java
+++ b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/types/AdsReturnCode.java
@@ -119,7 +119,7 @@ public enum AdsReturnCode {
     ADS_CODE_1858(0x742, 1858, "polling list is empty"),
     ADS_CODE_1859(0x743, 1859, "var connection already in use"),
     ADS_CODE_1860(0x744, 1860, "invoke ID in use"),
-    ADS_CODE_1861(0x745, 1861, "timeout elapsedCheck ADS routes of sender and receiver and your  firewall setting"),
+    ADS_CODE_1861(0x745, 1861, "timeout elapsed", "", "Check ADS routes of sender and receiver and your firewall setting"),
     ADS_CODE_1862(0x746, 1862, "error in win32 subsystem"),
     ADS_CODE_1863(0x747, 1863, "Invalid client timeout value"),
     ADS_CODE_1864(0x748, 1864, "ads-port not opened"),
diff --git a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/generic/types/AmsNetId.java b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/generic/types/AmsNetId.java
index c6e7aff..4dbe76e 100644
--- a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/generic/types/AmsNetId.java
+++ b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/generic/types/AmsNetId.java
@@ -85,6 +85,6 @@ public class AmsNetId extends ByteValue {
     @Override
     public String toString() {
         byte[] bytes = getBytes();
-        return bytes[0] + "." + bytes[1] + "." + bytes[2] + "." + bytes[3] + "." + bytes[4] + "." + bytes[5];
+        return (bytes[0] & 0xff) + "." + (bytes[1] & 0xff) + "." + (bytes[2] & 0xff) + "." + (bytes[3] & 0xff) + "." + (bytes[4] & 0xff) + "." + (bytes[5] & 0xff);
     }
 }
diff --git a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/tcp/AmsTCPPacket.java b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/tcp/AmsTCPPacket.java
index 2cfc60b..5c34f79 100644
--- a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/tcp/AmsTCPPacket.java
+++ b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/tcp/AmsTCPPacket.java
@@ -19,7 +19,7 @@
 package org.apache.plc4x.java.ads.api.tcp;
 
 import io.netty.buffer.ByteBuf;
-import org.apache.plc4x.java.ads.api.serial.types.UserData;
+import org.apache.plc4x.java.ads.api.tcp.types.UserData;
 import org.apache.plc4x.java.ads.api.util.ByteReadable;
 
 import static java.util.Objects.requireNonNull;
diff --git a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/connection/AdsTcpPlcConnection.java b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/connection/AdsTcpPlcConnection.java
index 49ee16e..ce96675 100644
--- a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/connection/AdsTcpPlcConnection.java
+++ b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/connection/AdsTcpPlcConnection.java
@@ -27,9 +27,12 @@ import org.apache.plc4x.java.ads.api.generic.types.AmsPort;
 import org.apache.plc4x.java.ads.protocol.Ads2PayloadProtocol;
 import org.apache.plc4x.java.ads.protocol.Payload2TcpProtocol;
 import org.apache.plc4x.java.ads.protocol.Plc4x2AdsProtocol;
+import org.apache.plc4x.java.api.exceptions.PlcRuntimeException;
 import org.apache.plc4x.java.base.connection.TcpSocketChannelFactory;
 
+import java.net.Inet4Address;
 import java.net.InetAddress;
+import java.net.UnknownHostException;
 import java.util.concurrent.CompletableFuture;
 
 public class AdsTcpPlcConnection extends AdsAbstractPlcConnection {
@@ -82,6 +85,14 @@ public class AdsTcpPlcConnection extends AdsAbstractPlcConnection {
         };
     }
 
+    protected static AmsNetId generateAMSNetId() {
+        try {
+            return AmsNetId.of(Inet4Address.getLocalHost().getHostAddress() + ".1.1");
+        } catch (UnknownHostException e) {
+            throw new PlcRuntimeException(e);
+        }
+    }
+
     protected static AmsPort generateAMSPort() {
         return AmsPort.of(TCP_PORT);
     }
diff --git a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/protocol/Payload2TcpProtocol.java b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/protocol/Payload2TcpProtocol.java
index a12c867..b164368 100644
--- a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/protocol/Payload2TcpProtocol.java
+++ b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/protocol/Payload2TcpProtocol.java
@@ -21,10 +21,10 @@ package org.apache.plc4x.java.ads.protocol;
 import io.netty.buffer.ByteBuf;
 import io.netty.channel.ChannelHandlerContext;
 import io.netty.handler.codec.MessageToMessageCodec;
-import org.apache.plc4x.java.ads.api.serial.types.UserData;
 import org.apache.plc4x.java.ads.api.tcp.AmsTCPPacket;
 import org.apache.plc4x.java.ads.api.tcp.AmsTcpHeader;
 import org.apache.plc4x.java.ads.api.tcp.types.TcpLength;
+import org.apache.plc4x.java.ads.api.tcp.types.UserData;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -37,7 +37,6 @@ public class Payload2TcpProtocol extends MessageToMessageCodec<ByteBuf, ByteBuf>
     @Override
     protected void encode(ChannelHandlerContext channelHandlerContext, ByteBuf amsPacket, List<Object> out) throws Exception {
         out.add(AmsTCPPacket.of(UserData.of(amsPacket)).getByteBuf());
-        amsPacket.release();
     }
 
     @SuppressWarnings("unchecked")
diff --git a/plc4j/protocols/ads/src/test/java/org/apache/plc4x/java/ads/AdsDumper.java b/plc4j/protocols/ads/src/test/java/org/apache/plc4x/java/ads/AdsDumper.java
index 9690d48..8cb1890 100644
--- a/plc4j/protocols/ads/src/test/java/org/apache/plc4x/java/ads/AdsDumper.java
+++ b/plc4j/protocols/ads/src/test/java/org/apache/plc4x/java/ads/AdsDumper.java
@@ -26,6 +26,8 @@ import org.apache.plc4x.java.ads.api.commands.types.IndexOffset;
 import org.apache.plc4x.java.ads.api.generic.types.AmsNetId;
 import org.apache.plc4x.java.ads.api.generic.types.AmsPort;
 import org.apache.plc4x.java.ads.api.generic.types.Invoke;
+import org.apache.plc4x.java.ads.api.tcp.AmsTCPPacket;
+import org.apache.plc4x.java.ads.api.tcp.types.UserData;
 import org.apache.plc4x.java.ads.util.TcpHexDumper;
 import org.pcap4j.core.PcapDumper;
 import org.pcap4j.core.PcapHandle;
@@ -55,22 +57,24 @@ public class AdsDumper {
             String randomString = RandomStringUtils.randomAscii(1024);
 
             AdsWriteRequest adsWriteRequest = AdsWriteRequest.of(
-                AmsNetId.of("192.168.0.70.1.2"),
-                AmsPort.of(12),
-                AmsNetId.of("192.168.0.70.1.1"),
+                AmsNetId.of("192.168.99.101.1.1"),
+                AmsPort.of(851),
+                AmsNetId.of("192.168.99.1.1.1"),
                 AmsPort.of(14),
                 Invoke.of(0),
                 IndexGroup.of(1),
                 IndexOffset.of(3),
                 Data.of(randomString.getBytes())
             );
+            AmsTCPPacket amsTCPPacket = AmsTCPPacket.of(UserData.of(adsWriteRequest.getBytes()));
 
-            try (TcpHexDumper tcpHexDumper = TcpHexDumper.runOn(55862); Socket localhost = new Socket("localhost", tcpHexDumper.getPort())) {
-                localhost.getOutputStream().write(adsWriteRequest.getBytes());
+            //try (TcpHexDumper tcpHexDumper = TcpHexDumper.runOn(55862); Socket localhost = new Socket("localhost", tcpHexDumper.getPort())) {
+            try (TcpHexDumper tcpHexDumper = TcpHexDumper.runOn(55862); Socket localhost = new Socket("192.168.99.100", 48898)) {
+                localhost.getOutputStream().write(amsTCPPacket.getBytes());
             }
 
             UnknownPacket.Builder amsPacket = new UnknownPacket.Builder();
-            amsPacket.rawData(adsWriteRequest.getBytes());
+            amsPacket.rawData(amsTCPPacket.getBytes());
 
             TcpPacket.Builder tcpPacketBuilder = new TcpPacket.Builder();
             tcpPacketBuilder
diff --git a/plc4j/protocols/ads/src/test/java/org/apache/plc4x/java/ads/protocol/Payload2TcpProtocolTest.java b/plc4j/protocols/ads/src/test/java/org/apache/plc4x/java/ads/protocol/Payload2TcpProtocolTest.java
index 336253e..49b015f 100644
--- a/plc4j/protocols/ads/src/test/java/org/apache/plc4x/java/ads/protocol/Payload2TcpProtocolTest.java
+++ b/plc4j/protocols/ads/src/test/java/org/apache/plc4x/java/ads/protocol/Payload2TcpProtocolTest.java
@@ -21,8 +21,8 @@ package org.apache.plc4x.java.ads.protocol;
 import io.netty.buffer.ByteBuf;
 import io.netty.buffer.Unpooled;
 import io.netty.channel.ChannelHandlerContext;
-import org.apache.plc4x.java.ads.api.serial.types.UserData;
 import org.apache.plc4x.java.ads.api.tcp.AmsTCPPacket;
+import org.apache.plc4x.java.ads.api.tcp.types.UserData;
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;

-- 
To stop receiving notification emails like this one, please contact
sruehl@apache.org.