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 2021/10/24 18:01:04 UTC

[plc4x] branch feature/mspec-ng updated: - Continued fixing most remaining issues for the S7 protocol

This is an automated email from the ASF dual-hosted git repository.

cdutz pushed a commit to branch feature/mspec-ng
in repository https://gitbox.apache.org/repos/asf/plc4x.git


The following commit(s) were added to refs/heads/feature/mspec-ng by this push:
     new eda6fe9  - Continued fixing most remaining issues for the S7 protocol
eda6fe9 is described below

commit eda6fe91ddb13e34ede5078548e9c323a4e51a39
Author: cdutz <ch...@c-ware.de>
AuthorDate: Sun Oct 24 20:00:56 2021 +0200

    - Continued fixing most remaining issues for the S7 protocol
---
 .../apache/plc4x/language/java/JavaLanguageTemplateHelper.java    | 3 +++
 .../src/main/resources/templates/java/io-template.java.ftlh       | 4 ----
 plc4j/drivers/s7/src/test/java/S7IoTest.java                      | 7 ++++---
 protocols/s7/src/main/resources/protocols/s7/s7.mspec             | 8 ++++----
 4 files changed, 11 insertions(+), 11 deletions(-)

diff --git a/code-generation/language-java/src/main/java/org/apache/plc4x/language/java/JavaLanguageTemplateHelper.java b/code-generation/language-java/src/main/java/org/apache/plc4x/language/java/JavaLanguageTemplateHelper.java
index 66e6ab0..bf2d0b4 100644
--- a/code-generation/language-java/src/main/java/org/apache/plc4x/language/java/JavaLanguageTemplateHelper.java
+++ b/code-generation/language-java/src/main/java/org/apache/plc4x/language/java/JavaLanguageTemplateHelper.java
@@ -610,6 +610,9 @@ public class JavaLanguageTemplateHelper extends BaseFreemarkerLanguageTemplateHe
         } else if (literal instanceof VariableLiteral) {
             tracer = tracer.dive("variable literal instanceOf");
             VariableLiteral variableLiteral = (VariableLiteral) literal;
+            if ("curPos".equals(((VariableLiteral) literal).getName())) {
+                return "readBuffer.getPos()";
+            }
             // If this literal references an Enum type, then we have to output it differently.
             if (getTypeDefinitions().get(variableLiteral.getName()) instanceof EnumTypeDefinition) {
                 tracer = tracer.dive("enum definition instanceOf");
diff --git a/code-generation/language-java/src/main/resources/templates/java/io-template.java.ftlh b/code-generation/language-java/src/main/resources/templates/java/io-template.java.ftlh
index 50f64bd..c39716d 100644
--- a/code-generation/language-java/src/main/resources/templates/java/io-template.java.ftlh
+++ b/code-generation/language-java/src/main/resources/templates/java/io-template.java.ftlh
@@ -169,10 +169,6 @@ public class ${type.name}IO implements <#if outputFlavor != "passive">MessageIO<
         byte[] ${arrayField.name} = readBuffer.readByteArray("${arrayField.name}", ${numberOfBytesExpression});
         <#else>
         // Array field (${arrayField.name})
-            <#-- Only update curPos if the length expression uses it -->
-            <#if arrayField.loopExpression.contains("curPos")>
-        curPos = readBuffer.getPos() - startPos;
-            </#if>
         <#-- If this is a count array, we can directly initialize an array with the given size -->
             <#if field.isCountArrayField()>
         // Count array
diff --git a/plc4j/drivers/s7/src/test/java/S7IoTest.java b/plc4j/drivers/s7/src/test/java/S7IoTest.java
index 394fae1..af4c135 100644
--- a/plc4j/drivers/s7/src/test/java/S7IoTest.java
+++ b/plc4j/drivers/s7/src/test/java/S7IoTest.java
@@ -29,6 +29,7 @@ import org.apache.plc4x.java.spi.generation.WriteBufferXmlBased;
 import org.junit.jupiter.api.Test;
 
 import java.io.ByteArrayInputStream;
+import java.util.Collections;
 
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.junit.jupiter.api.Assertions.assertEquals;
@@ -222,18 +223,18 @@ public class S7IoTest {
 
         TPKTPacket tpktPacket = new TPKTPacket(
             new COTPPacketData(
-                new COTPParameter[]{new COTPParameterTpduSize(COTPTpduSize.SIZE_4096)},
+                Collections.singletonList(new COTPParameterTpduSize(COTPTpduSize.SIZE_4096)),
                 new S7MessageResponseData(
                     11,
                     new S7ParameterReadVarResponse((short) 1),
                     new S7PayloadReadVarResponse(
-                        new S7VarPayloadDataItem[]{
+                        Collections.singletonList(
                             new S7VarPayloadDataItem(
                                 DataTransportErrorCode.OK,
                                 DataTransportSize.BIT,
                                 new byte[]{0x1}
                             )
-                        }
+                        )
                     ),
                     (short) 0,
                     (short) 0
diff --git a/protocols/s7/src/main/resources/protocols/s7/s7.mspec b/protocols/s7/src/main/resources/protocols/s7/s7.mspec
index 5c10bcf..5909943 100644
--- a/protocols/s7/src/main/resources/protocols/s7/s7.mspec
+++ b/protocols/s7/src/main/resources/protocols/s7/s7.mspec
@@ -223,10 +223,10 @@
 [discriminatedType 'S7Payload' (uint 8 'messageType', S7Parameter 'parameter')
     [typeSwitch 'parameter.parameterType', 'messageType'
         ['0x04','0x03' S7PayloadReadVarResponse(S7Parameter 'parameter')
-            [array S7VarPayloadDataItem('lastItem') 'items' count 'CAST(parameter, S7ParameterReadVarResponse).numItems']
+            [array S7VarPayloadDataItem 'items' count 'CAST(parameter, S7ParameterReadVarResponse).numItems']
         ]
         ['0x05','0x01' S7PayloadWriteVarRequest(S7Parameter 'parameter')
-            [array S7VarPayloadDataItem('lastItem') 'items' count 'COUNT(CAST(parameter, S7ParameterWriteVarRequest).items)']
+            [array S7VarPayloadDataItem 'items' count 'COUNT(CAST(parameter, S7ParameterWriteVarRequest).items)']
         ]
         ['0x05','0x03' S7PayloadWriteVarResponse(S7Parameter 'parameter')
             [array S7VarPayloadStatusItem 'items' count 'CAST(parameter, S7ParameterWriteVarResponse).numItems']
@@ -238,12 +238,12 @@
 ]
 
 // This is actually not quite correct as depending pon the transportSize the length is either defined in bits or bytes.
-[type 'S7VarPayloadDataItem'(bit 'lastItem')
+[type 'S7VarPayloadDataItem'
     [simple   DataTransportErrorCode 'returnCode']
     [simple   DataTransportSize      'transportSize']
     [implicit uint 16                'dataLength' 'COUNT(data) * ((transportSize == DataTransportSize.BIT) ? 1 : (transportSize.sizeInBits ? 8 : 1))']
     [array    byte                   'data'       count 'transportSize.sizeInBits ? CEIL(dataLength / 8.0) : dataLength']
-    [padding  uint 8                 'pad'        '0x00' 'lastItem ? 0 : COUNT(data) % 2']
+    [padding  uint 8                 'pad'        '0x00' 'COUNT(data) % 2']
 ]
 
 [type 'S7VarPayloadStatusItem'