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/incubator-plc4x.git
The following commit(s) were added to refs/heads/develop by this push: new d95081a - Fixed a problem with the S7 not correctly handling fill-bytes in multi-item read-responses and write-requests. d95081a is described below commit d95081a490913f952ca3a16fb9fffcb8334e941f Author: Christofer Dutz <christofer.d...@c-ware.de> AuthorDate: Fri Jan 25 17:14:36 2019 +0100 - Fixed a problem with the S7 not correctly handling fill-bytes in multi-item read-responses and write-requests. --- RELEASE_NOTES | 18 +++++++++++++++++- .../org/apache/plc4x/java/s7/netty/S7Protocol.java | 17 +++++++++++------ .../s7/netty/model/types/DataTransportSize.java | 22 ++++++++-------------- 3 files changed, 36 insertions(+), 21 deletions(-) diff --git a/RELEASE_NOTES b/RELEASE_NOTES index 89a02fc..05abffb 100644 --- a/RELEASE_NOTES +++ b/RELEASE_NOTES @@ -1,5 +1,21 @@ ============================================================== -(Unreleased) Apache PLC4X (incubating) 0.3.0-SNAPSHOT +(Unreleased) Apache PLC4X (incubating) 0.4.0-SNAPSHOT +============================================================== + +New Features +------------ + +Incompatible changes +-------------------- + +Bug Fixes +--------- +- The S7 driver didn't correctly handle "fill-bytes" in multi- +item read-responses and multi-item write-requests + + +============================================================== +Apache PLC4X (incubating) 0.3.0 ============================================================== This is the third official release of Apache PLC4X. diff --git a/plc4j/protocols/s7/src/main/java/org/apache/plc4x/java/s7/netty/S7Protocol.java b/plc4j/protocols/s7/src/main/java/org/apache/plc4x/java/s7/netty/S7Protocol.java index d52d4cc..12759e2 100644 --- a/plc4j/protocols/s7/src/main/java/org/apache/plc4x/java/s7/netty/S7Protocol.java +++ b/plc4j/protocols/s7/src/main/java/org/apache/plc4x/java/s7/netty/S7Protocol.java @@ -221,10 +221,12 @@ public class S7Protocol extends ChannelDuplexHandler { private void encodePayloads(S7Message in, ByteBuf buf) throws PlcProtocolException { if(in.getPayloads() != null) { - for (S7Payload payload : in.getPayloads()) { + Iterator<S7Payload> payloadIterator = in.getPayloads().iterator(); + while(payloadIterator.hasNext()) { + S7Payload payload = payloadIterator.next(); switch (payload.getType()) { case WRITE_VAR: - encodeWriteVarPayload((VarPayload) payload, buf); + encodeWriteVarPayload((VarPayload) payload, buf, !payloadIterator.hasNext()); break; case CPU_SERVICES: encodeCpuServicesPayload((CpuServicesPayload) payload, buf); @@ -237,14 +239,17 @@ public class S7Protocol extends ChannelDuplexHandler { } } - private void encodeWriteVarPayload(VarPayload varPayload, ByteBuf buf) { + private void encodeWriteVarPayload(VarPayload varPayload, ByteBuf buf, boolean lastItem) { for (VarPayloadItem payloadItem : varPayload.getItems()) { buf.writeByte(payloadItem.getReturnCode().getCode()); buf.writeByte(payloadItem.getDataTransportSize().getCode()); // TODO: Check if this is correct?!?! Might be problems with sizeInBits = true/false buf.writeShort(payloadItem.getData().length); buf.writeBytes(payloadItem.getData()); - // TODO: It looks as if BIT type reads require a 0x00 fill byte at the end ... + // if this is not the last item and it's payload is exactly one byte, we need to output a fill-byte. + if((payloadItem.getData().length == 1) && !lastItem) { + buf.writeByte(0x00); + } } } @@ -613,9 +618,9 @@ public class S7Protocol extends ChannelDuplexHandler { VarPayloadItem payload = new VarPayloadItem(dataTransportErrorCode, dataTransportSize, data); payloadItems.add(payload); i += S7SizeHelper.getPayloadLength(payload); - // It seems that datatype BIT reads an additional byte, if it's not the last. - if(dataTransportSize.isHasBlankByte() && (userData.readableBytes() > 0)) { + // It seems that one-byte payloads require a fill byte, but only if it's not the last item. + if((length == 1) && (userData.readableBytes() > 0)) { userData.readByte(); i++; } diff --git a/plc4j/protocols/s7/src/main/java/org/apache/plc4x/java/s7/netty/model/types/DataTransportSize.java b/plc4j/protocols/s7/src/main/java/org/apache/plc4x/java/s7/netty/model/types/DataTransportSize.java index d571015..e93a34e 100644 --- a/plc4j/protocols/s7/src/main/java/org/apache/plc4x/java/s7/netty/model/types/DataTransportSize.java +++ b/plc4j/protocols/s7/src/main/java/org/apache/plc4x/java/s7/netty/model/types/DataTransportSize.java @@ -25,13 +25,13 @@ import java.util.Map; * (Values determined by evaluating generated ".pcap" files) */ public enum DataTransportSize { - NULL((byte) 0x00, false, false), - BIT((byte) 0x03, true, true), - BYTE_WORD_DWORD((byte) 0x04, true, false), - INTEGER((byte) 0x05, true, false), - DINTEGER((byte) 0x06, false, false), - REAL((byte) 0x07, false, false), - OCTET_STRING((byte) 0x09, false, false); + NULL((byte) 0x00, false), + BIT((byte) 0x03, true), + BYTE_WORD_DWORD((byte) 0x04, true), + INTEGER((byte) 0x05, true), + DINTEGER((byte) 0x06, false), + REAL((byte) 0x07, false), + OCTET_STRING((byte) 0x09, false); private static final Map<Byte, DataTransportSize> map; static { @@ -43,12 +43,10 @@ public enum DataTransportSize { private final byte code; private final boolean sizeInBits; - private final boolean hasBlankByte; - DataTransportSize(byte code, boolean sizeInBits, boolean hasBlankByte) { + DataTransportSize(byte code, boolean sizeInBits) { this.code = code; this.sizeInBits = sizeInBits; - this.hasBlankByte = hasBlankByte; } public byte getCode() { @@ -59,10 +57,6 @@ public enum DataTransportSize { return sizeInBits; } - public boolean isHasBlankByte() { - return hasBlankByte; - } - public static DataTransportSize valueOf(byte code) { return map.get(code); }