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/06/13 06:39:37 UTC

[incubator-plc4x] branch master updated: move ack to postaction as we only ack a valid (crc) packet

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 929162b  move ack to postaction as we only ack a valid (crc) packet
929162b is described below

commit 929162becc4f9b533b422fa67f3d208d5695f375
Author: Sebastian Rühl <sr...@apache.org>
AuthorDate: Wed Jun 13 08:39:27 2018 +0200

    move ack to postaction as we only ack a valid (crc) packet
---
 .../java/ads/protocol/Payload2SerialProtocol.java      | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)

diff --git a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/protocol/Payload2SerialProtocol.java b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/protocol/Payload2SerialProtocol.java
index 45edf8a..d03331b 100644
--- a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/protocol/Payload2SerialProtocol.java
+++ b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/protocol/Payload2SerialProtocol.java
@@ -29,6 +29,7 @@ import org.apache.plc4x.java.ads.api.serial.AmsSerialResetFrame;
 import org.apache.plc4x.java.ads.api.serial.types.*;
 import org.apache.plc4x.java.ads.protocol.util.DigestUtil;
 import org.apache.plc4x.java.api.exceptions.PlcProtocolException;
+import org.apache.plc4x.java.api.exceptions.PlcRuntimeException;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -86,11 +87,18 @@ public class Payload2SerialProtocol extends MessageToMessageCodec<ByteBuf, ByteB
             case AmsSerialFrame.ID:
                 AmsSerialFrame amsSerialFrame = AmsSerialFrame.of(magicCookie, transmitterAddress, receiverAddress, fragmentNumber, userDataLength, userData, crc);
                 LOGGER.debug("Ams Serial Frame received {}", amsSerialFrame);
-                // TODO: check if this is the right way to ack a package.
-                ChannelFuture channelFuture = channelHandlerContext.writeAndFlush(AmsSerialAcknowledgeFrame.of(transmitterAddress, receiverAddress, fragmentNumber).getByteBuf());
-                // waiting for the ack-frame to be transmitted before we forward the package
-                channelFuture.await();
-                postAction = () -> out.add(userData.getByteBuf());
+                postAction = () -> {
+                    // TODO: check if this is the right way to ack a package.
+                    ChannelFuture channelFuture = channelHandlerContext.writeAndFlush(AmsSerialAcknowledgeFrame.of(transmitterAddress, receiverAddress, fragmentNumber).getByteBuf());
+                    // waiting for the ack-frame to be transmitted before we forward the package
+                    try {
+                        channelFuture.await();
+                    } catch (InterruptedException e) {
+                        Thread.currentThread().interrupt();
+                        throw new PlcRuntimeException(e);
+                    }
+                    out.add(userData.getByteBuf());
+                };
                 break;
             case AmsSerialAcknowledgeFrame.ID:
                 AmsSerialAcknowledgeFrame amsSerialAcknowledgeFrame = AmsSerialAcknowledgeFrame.of(magicCookie, transmitterAddress, receiverAddress, fragmentNumber, userDataLength, crc);

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