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 2019/02/13 18:57:29 UTC
[incubator-plc4x] branch develop updated: - Fixed a bug only
inserting a fill byte by 1 byte payloads,
but it must have been in case of an uneven number of bytes.
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 9688502 - Fixed a bug only inserting a fill byte by 1 byte payloads, but it must have been in case of an uneven number of bytes.
9688502 is described below
commit 9688502a725eee026f1f505d160198bcf5e6ecc7
Author: Christofer Dutz <ch...@c-ware.de>
AuthorDate: Wed Feb 13 19:57:23 2019 +0100
- Fixed a bug only inserting a fill byte by 1 byte payloads, but it must have been in case of an uneven number of bytes.
---
.../apache/plc4x/protocols/s7/protocol.dfdl.xsd | 13 ++--
.../org/apache/plc4x/protocols/s7/protocol.tdml | 79 ++++++++++++++++++++++
2 files changed, 84 insertions(+), 8 deletions(-)
diff --git a/protocols/s7/src/main/resources/org/apache/plc4x/protocols/s7/protocol.dfdl.xsd b/protocols/s7/src/main/resources/org/apache/plc4x/protocols/s7/protocol.dfdl.xsd
index b0ec9f8..cff8ea0 100644
--- a/protocols/s7/src/main/resources/org/apache/plc4x/protocols/s7/protocol.dfdl.xsd
+++ b/protocols/s7/src/main/resources/org/apache/plc4x/protocols/s7/protocol.dfdl.xsd
@@ -471,7 +471,7 @@
<xs:element name="payloads" minOccurs="0"
dfdl:lengthKind="explicit" dfdl:lengthUnits="bytes" dfdl:length="{../payloadsLength}"
dfdl:occursCountKind="expression"
- dfdl:occursCount="{if(../parametersLength gt 0) then 1 else 0}">
+ dfdl:occursCount="{if(../payloadsLength gt 0) then 1 else 0}">
<xs:complexType>
<xs:sequence>
<!--
@@ -834,7 +834,7 @@
-->
<xs:element name="fillByte" type="s7:byte" minOccurs="0"
dfdl:occursCountKind="expression" dfdl:occursCount="{
- if((../lengthInBytes eq 1) and
+ if(((../lengthInBytes mod 2) eq 1) and
(dfdl:occursIndex() ne ../../numItems)) then 1 else 0}"/>
</xs:sequence>
</xs:complexType>
@@ -870,15 +870,12 @@
dfdl:byteOrder="bigEndian" dfdl:lengthUnits="bytes" dfdl:lengthKind="explicit"
dfdl:length="{../lengthInBytes}"/>
<!--
- Transport sizes: BIT, BYTE_WORD_DWORD and OCTET_STRING require a blank byte.
- However only if this is not the last item in the result.
-
- Actually the S7 device will never process data that contains more
- than one item in a write request, so this is rather a cosmetic fine-tuning.
+ It seems that the item payload must always be an even number of bytes. So if it's
+ not an even number, add a fill byte.
-->
<xs:element name="fillByte" type="s7:byte" minOccurs="0"
dfdl:occursCountKind="expression" dfdl:occursCount="{
- if((../lengthInBytes eq 1) and
+ if(((../lengthInBytes mod 2) eq 1) and
(dfdl:occursIndex() ne ../../numItems)) then 1 else 0}"/>
</xs:sequence>
</xs:complexType>
diff --git a/protocols/s7/src/test/resources/org/apache/plc4x/protocols/s7/protocol.tdml b/protocols/s7/src/test/resources/org/apache/plc4x/protocols/s7/protocol.tdml
index c418628..5efa67d 100644
--- a/protocols/s7/src/test/resources/org/apache/plc4x/protocols/s7/protocol.tdml
+++ b/protocols/s7/src/test/resources/org/apache/plc4x/protocols/s7/protocol.tdml
@@ -1426,6 +1426,85 @@
</tdml:infoset>
</tdml:parserTestCase>
+ <tdml:parserTestCase name="S7: Read Var Response (Mixed Items with odd number of bytes)"
+ root="tpktMessage"
+ model="s7Schema">
+ <!-- Define the input -->
+ <tdml:document>
+ <tdml:documentPart type="byte">
+ 0300002802f0803203000000010002001300000403ff040018AABBCC00ff0400080000ff03000100
+ </tdml:documentPart>
+ </tdml:document>
+
+ <tdml:infoset>
+ <tdml:dfdlInfoset>
+ <test:tpktMessage>
+ <magicByte>3</magicByte>
+ <reserved>0</reserved>
+ <length>40</length>
+ <userData>
+ <headerLength>2</headerLength>
+ <type>240</type>
+ <CotpTpduData>
+ <endOfTransmission>1</endOfTransmission>
+ <tpduRef>0</tpduRef>
+ </CotpTpduData>
+ <userData>
+ <magicByte>50</magicByte>
+ <type>3</type>
+ <S7ResponseMessage>
+ <reserved>0</reserved>
+ <tpduReference>1</tpduReference>
+ <parametersLength>2</parametersLength>
+ <payloadsLength>19</payloadsLength>
+ <errorClass>0</errorClass>
+ <errorCode>0</errorCode>
+ <parameters>
+ <parameter>
+ <type>4</type>
+ <S7ResponseParameterReadVar>
+ <numItems>3</numItems>
+ </S7ResponseParameterReadVar>
+ </parameter>
+ </parameters>
+ <payloads>
+ <payload>
+ <S7ResponsePayloadReadVar>
+ <numItems>3</numItems>
+ <item>
+ <returnCode>255</returnCode>
+ <transportSize>4</transportSize>
+ <rawLength>24</rawLength>
+ <lengthInBytes>3</lengthInBytes>
+ <data>AABBCC</data>
+ <fillByte>0</fillByte>
+ </item>
+ <item>
+ <returnCode>255</returnCode>
+ <transportSize>4</transportSize>
+ <rawLength>8</rawLength>
+ <lengthInBytes>1</lengthInBytes>
+ <data>00</data>
+ <fillByte>0</fillByte>
+ </item>
+ <item>
+ <returnCode>255</returnCode>
+ <transportSize>3</transportSize>
+ <rawLength>1</rawLength>
+ <lengthInBytes>1</lengthInBytes>
+ <data>00</data>
+ </item>
+ </S7ResponsePayloadReadVar>
+ </payload>
+ </payloads>
+ </S7ResponseMessage>
+ </userData>
+ </userData>
+ </test:tpktMessage>
+ </tdml:dfdlInfoset>
+ </tdml:infoset>
+ </tdml:parserTestCase>
+
<tdml:parserTestCase name="S7: Read Var Request (No Filling Bytes)"
root="tpktMessage"
model="s7Schema">