You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@plc4x.apache.org by cd...@apache.org on 2020/03/07 11:26:33 UTC
[plc4x] branch develop updated: - Added a PacketSizeEstimator for
the AbETH protocol.
This is an automated email from the ASF dual-hosted git repository.
cdutz pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/plc4x.git
The following commit(s) were added to refs/heads/develop by this push:
new f0dd5f5 - Added a PacketSizeEstimator for the AbETH protocol.
f0dd5f5 is described below
commit f0dd5f53be061674ea0dba45467d1978e6bf5e77
Author: Christofer Dutz <ch...@c-ware.de>
AuthorDate: Sat Mar 7 12:26:26 2020 +0100
- Added a PacketSizeEstimator for the AbETH protocol.
---
.../java/org/apache/plc4x/java/abeth/AbEthDriver.java | 16 ++++++++++++++++
1 file changed, 16 insertions(+)
diff --git a/plc4j/drivers/ab-eth/src/main/java/org/apache/plc4x/java/abeth/AbEthDriver.java b/plc4j/drivers/ab-eth/src/main/java/org/apache/plc4x/java/abeth/AbEthDriver.java
index 6d87e7a..de74374 100644
--- a/plc4j/drivers/ab-eth/src/main/java/org/apache/plc4x/java/abeth/AbEthDriver.java
+++ b/plc4j/drivers/ab-eth/src/main/java/org/apache/plc4x/java/abeth/AbEthDriver.java
@@ -18,6 +18,7 @@ under the License.
*/
package org.apache.plc4x.java.abeth;
+import io.netty.buffer.ByteBuf;
import org.apache.plc4x.java.abeth.configuration.AbEthConfiguration;
import org.apache.plc4x.java.abeth.field.AbEthFieldHandler;
import org.apache.plc4x.java.abeth.protocol.AbEthProtocolLogic;
@@ -30,6 +31,8 @@ import org.apache.plc4x.java.spi.connection.ProtocolStackConfigurer;
import org.apache.plc4x.java.spi.connection.SingleProtocolStackConfigurer;
import org.osgi.service.component.annotations.Component;
+import java.util.function.ToIntFunction;
+
@Component(service = PlcDriver.class, immediate = true)
public class AbEthDriver extends GeneratedDriverBase<CIPEncapsulationPacket> {
@@ -65,7 +68,20 @@ public class AbEthDriver extends GeneratedDriverBase<CIPEncapsulationPacket> {
protected ProtocolStackConfigurer<CIPEncapsulationPacket> getStackConfigurer() {
return SingleProtocolStackConfigurer.builder(CIPEncapsulationPacket.class, CIPEncapsulationPacketIO.class)
.withProtocol(AbEthProtocolLogic.class)
+ .withPacketSizeEstimator(ByteLengthEstimator.class)
.build();
}
+ /** Estimate the Length of a Packet */
+ public static class ByteLengthEstimator implements ToIntFunction<ByteBuf> {
+ @Override
+ public int applyAsInt(ByteBuf byteBuf) {
+ if (byteBuf.readableBytes() >= 4) {
+ // In the mspec we subtract 28 from the full size ... so here we gotta add it back.
+ return byteBuf.getUnsignedShort(byteBuf.readerIndex() + 2) + 28;
+ }
+ return -1;
+ }
+ }
+
}