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 07:16:01 UTC
[incubator-plc4x] branch master updated: ADS/AMS serial protocol.
Throw error if user data exceeds 255 bytes.
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 d06dd30 ADS/AMS serial protocol. Throw error if user data exceeds 255 bytes.
d06dd30 is described below
commit d06dd305c26af3e8a1cdf60a919aeb2e4b0cf416
Author: Sebastian Rühl <sr...@apache.org>
AuthorDate: Wed Jun 13 09:15:52 2018 +0200
ADS/AMS serial protocol. Throw error if user data exceeds 255 bytes.
---
.../plc4x/java/ads/protocol/Payload2SerialProtocol.java | 11 +++++++----
1 file changed, 7 insertions(+), 4 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 d03331b..70a7932 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.PlcProtocolPayloadTooBigException;
import org.apache.plc4x.java.api.exceptions.PlcRuntimeException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -43,7 +44,7 @@ public class Payload2SerialProtocol extends MessageToMessageCodec<ByteBuf, ByteB
private final AtomicInteger fragmentCounter = new AtomicInteger(0);
@Override
- protected void encode(ChannelHandlerContext channelHandlerContext, ByteBuf amsPacket, List<Object> out) {
+ protected void encode(ChannelHandlerContext channelHandlerContext, ByteBuf amsPacket, List<Object> out) throws PlcProtocolPayloadTooBigException {
LOGGER.trace("(<--OUT): {}, {}, {}", channelHandlerContext, amsPacket, out);
int fragmentNumber = fragmentCounter.getAndIncrement();
if (fragmentNumber > 255) {
@@ -51,9 +52,11 @@ public class Payload2SerialProtocol extends MessageToMessageCodec<ByteBuf, ByteB
fragmentCounter.set(fragmentNumber);
}
LOGGER.debug("Using fragmentNumber {} for {}", fragmentNumber, amsPacket);
- // TODO: we need to remember the fragment and maybe even need to spilt up the package
- // TODO: if we exceed 255 byte
- AmsSerialFrame amsSerialFrame = AmsSerialFrame.of(FragmentNumber.of((byte) fragmentNumber), UserData.of(amsPacket));
+ UserData userData = UserData.of(amsPacket);
+ if (userData.getCalculatedLength() > 255) {
+ throw new PlcProtocolPayloadTooBigException("ADS/AMS", 255, (int) userData.getCalculatedLength(), amsPacket);
+ }
+ AmsSerialFrame amsSerialFrame = AmsSerialFrame.of(FragmentNumber.of((byte) fragmentNumber), userData);
out.add(amsSerialFrame.getByteBuf());
}
--
To stop receiving notification emails like this one, please contact
sruehl@apache.org.