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/22 11:16:25 UTC

[plc4x] branch feature/mspec-ng updated (75aa3cb -> 8248318)

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

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


    from 75aa3cb  feat(plc4j/codgen): small code cleanup
     new 6e1b8ba  - Fixed the problem with enum fields and simplified the code generated for complex types
     new 8248318  - Fixed the problem with enum fields and simplified the code generated for complex types

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../language/java/JavaLanguageTemplateHelper.java  |  2 +-
 .../resources/templates/java/io-template.java.ftlh | 16 ++++-----
 .../s7/src/main/resources/protocols/s7/s7.mspec    | 38 +++++++++++-----------
 3 files changed, 28 insertions(+), 28 deletions(-)

[plc4x] 01/02: - Fixed the problem with enum fields and simplified the code generated for complex types

Posted by cd...@apache.org.
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

commit 6e1b8ba4df10755d05802aa9b3624bd2112f8390
Author: cdutz <ch...@c-ware.de>
AuthorDate: Wed Oct 20 22:31:24 2021 +0200

    - Fixed the problem with enum fields and simplified the code generated for complex types
---
 .../language/java/JavaLanguageTemplateHelper.java  |  2 +-
 .../s7/src/main/resources/protocols/s7/s7.mspec    | 38 +++++++++++-----------
 2 files changed, 20 insertions(+), 20 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 24f538f..cac5ea2 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
@@ -370,7 +370,7 @@ public class JavaLanguageTemplateHelper extends BaseFreemarkerLanguageTemplateHe
         if (isEnumTypeReference(typeReference)) {
             final String languageTypeName = getLanguageTypeNameForTypeReference(typeReference);
             final SimpleTypeReference enumBaseTypeReference = getEnumBaseTypeReference(typeReference);
-            return "new DataReaderEnumDefault(" + languageTypeName + "::enumForValue, " + getDataReaderCall(enumBaseTypeReference) + ")";
+            return "new DataReaderEnumDefault<>(" + languageTypeName + "::enumForValue, " + getDataReaderCall(enumBaseTypeReference) + ")";
         } else if (typeReference.isSimpleTypeReference()) {
             SimpleTypeReference simpleTypeReference = typeReference.asSimpleTypeReference().orElseThrow(IllegalStateException::new);
             return getDataReaderCall(simpleTypeReference);
diff --git a/protocols/s7/src/main/resources/protocols/s7/s7.mspec b/protocols/s7/src/main/resources/protocols/s7/s7.mspec
index 4249c7b..e478bb2 100644
--- a/protocols/s7/src/main/resources/protocols/s7/s7.mspec
+++ b/protocols/s7/src/main/resources/protocols/s7/s7.mspec
@@ -22,10 +22,10 @@
 ////////////////////////////////////////////////////////////////
 
 [type 'TPKTPacket' byteOrder='"BIG_ENDIAN"'
-    [const    uint 8                 'protocolId' '0x03'                     ]
-    [reserved uint 8                 '0x00'                                  ]
-    [implicit uint 16                'len'        'payload.lengthInBytes + 4']
-    [simple   COTPPacket ['len - 4'] 'payload'                               ]
+    [const    uint 8                 'protocolId' '0x03']
+    [reserved uint 8                 '0x00']
+    [implicit uint 16                'len'       'payload.lengthInBytes + 4']
+    [simple   COTPPacket ['len - 4'] 'payload']
 ]
 
 ////////////////////////////////////////////////////////////////
@@ -37,31 +37,31 @@
     [discriminator uint 8 'tpduCode']
     [typeSwitch 'tpduCode'
         ['0xF0' COTPPacketData
-            [simple bit    'eot'                            ]
-            [simple uint 7 'tpduRef'                        ]
+            [simple bit    'eot']
+            [simple uint 7 'tpduRef']
         ]
         ['0xE0' COTPPacketConnectionRequest
             [simple uint 16           'destinationReference']
-            [simple uint 16           'sourceReference'     ]
-            [simple COTPProtocolClass 'protocolClass'       ]
+            [simple uint 16           'sourceReference']
+            [simple COTPProtocolClass 'protocolClass']
         ]
         ['0xD0' COTPPacketConnectionResponse
             [simple uint 16           'destinationReference']
-            [simple uint 16           'sourceReference'     ]
-            [simple COTPProtocolClass 'protocolClass'       ]
+            [simple uint 16           'sourceReference']
+            [simple COTPProtocolClass 'protocolClass']
         ]
         ['0x80' COTPPacketDisconnectRequest
             [simple uint 16           'destinationReference']
-            [simple uint 16           'sourceReference'     ]
-            [simple COTPProtocolClass 'protocolClass'       ]
+            [simple uint 16           'sourceReference']
+            [simple COTPProtocolClass 'protocolClass']
         ]
         ['0xC0' COTPPacketDisconnectResponse
-            [simple uint 16 'destinationReference'          ]
-            [simple uint 16 'sourceReference'               ]
+            [simple uint 16 'destinationReference']
+            [simple uint 16 'sourceReference']
         ]
         ['0x70' COTPPacketTpduError
-            [simple uint 16 'destinationReference'          ]
-            [simple uint 8  'rejectCause'                   ]
+            [simple uint 16 'destinationReference']
+            [simple uint 8  'rejectCause']
         ]
     ]
     [array    COTPParameter ['(headerLength + 1) - curPos'] 'parameters' length '(headerLength + 1) - curPos']
@@ -223,16 +223,16 @@
 [discriminatedType 'S7Payload' [uint 8 'messageType', S7Parameter 'parameter']
     [typeSwitch 'parameter.parameterType', 'messageType'
         ['0x04','0x03' S7PayloadReadVarResponse [S7Parameter 'parameter']
-            [array S7VarPayloadDataItem 'items' count 'CAST(parameter, S7ParameterReadVarResponse).numItems' ['lastItem']]
+            [array S7VarPayloadDataItem ['lastItem'] 'items' count 'CAST(parameter, S7ParameterReadVarResponse).numItems']
         ]
         ['0x05','0x01' S7PayloadWriteVarRequest [S7Parameter 'parameter']
-            [array S7VarPayloadDataItem 'items' count 'COUNT(CAST(parameter, S7ParameterWriteVarRequest).items)' ['lastItem']]
+            [array S7VarPayloadDataItem ['lastItem'] 'items' count 'COUNT(CAST(parameter, S7ParameterWriteVarRequest).items)']
         ]
         ['0x05','0x03' S7PayloadWriteVarResponse [S7Parameter 'parameter']
             [array S7VarPayloadStatusItem 'items' count 'CAST(parameter, S7ParameterWriteVarResponse).numItems']
         ]
         ['0x00','0x07' S7PayloadUserData [S7Parameter 'parameter']
-            [array S7PayloadUserDataItem 'items' count 'COUNT(CAST(parameter, S7ParameterUserData).items)' ['CAST(CAST(parameter, S7ParameterUserData).items[0], S7ParameterUserDataItemCPUFunctions).cpuFunctionType', 'CAST(CAST(parameter, S7ParameterUserData).items[0], S7ParameterUserDataItemCPUFunctions).cpuSubfunction']]
+            [array S7PayloadUserDataItem ['CAST(CAST(parameter, S7ParameterUserData).items[0], S7ParameterUserDataItemCPUFunctions).cpuFunctionType', 'CAST(CAST(parameter, S7ParameterUserData).items[0], S7ParameterUserDataItemCPUFunctions).cpuSubfunction'] 'items' count 'COUNT(CAST(parameter, S7ParameterUserData).items)']
         ]
     ]
 ]

[plc4x] 02/02: - Fixed the problem with enum fields and simplified the code generated for complex types

Posted by cd...@apache.org.
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

commit 824831803e8b5998cb9d1723436fb0bb16770b85
Author: cdutz <ch...@c-ware.de>
AuthorDate: Fri Oct 22 13:14:41 2021 +0200

    - Fixed the problem with enum fields and simplified the code generated for complex types
---
 .../main/resources/templates/java/io-template.java.ftlh  | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

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 0df71d7..bdb25da 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
@@ -303,6 +303,14 @@ public class ${type.name}IO implements <#if outputFlavor != "passive">MessageIO<
             readBuffer.closeContext("${arrayField.name}", WithReaderWriterArgs.WithRenderAsList(true));
         </#if>
         <#break>
+    <#case "assert">
+        <#assign assertField = field.asAssertField().orElseThrow()>
+        <#assign typedField = field.asTypedField().orElseThrow()>
+        <#assign namedField = field.asNamedField().orElseThrow()>
+
+        // ${field.typeName?cap_first} Field (${namedField.name})
+        ${helper.getLanguageTypeNameForField(field)} ${namedField.name} = read${field.typeName?cap_first}Field("${namedField.name}", ${helper.getDataReaderCall(typedField.type)}, ${type.name}.${namedField.name?upper_case});
+        <#break>
     <#-- TODO: Port this -->
     <#case "checksum">
         <#assign checksumField = field.asChecksumField().orElseThrow()>
@@ -455,14 +463,6 @@ public class ${type.name}IO implements <#if outputFlavor != "passive">MessageIO<
         </#if>
         ${helper.getLanguageTypeNameForField(field)} ${namedField.name} = read${field.typeName?cap_first}Field("${namedField.name}", ${helper.getDataReaderCall(typedField.type)}<#if optionalField.conditionExpression.present>, ${helper.toParseExpression(optionalField, optionalField.conditionExpression.get(), parserArguments)}</#if>);
         <#break>
-    <#case "assert">
-        <#assign assertField = field.asAssertField().orElseThrow()>
-        <#assign typedField = field.asTypedField().orElseThrow()>
-        <#assign namedField = field.asNamedField().orElseThrow()>
-
-        // ${field.typeName?cap_first} Field (${namedField.name})
-        ${helper.getLanguageTypeNameForField(field)} ${namedField.name} = read${field.typeName?cap_first}Field("${namedField.name}", ${helper.getDataReaderCall(typedField.type)}, ${type.name}.${namedField.name?upper_case});
-        <#break>
     <#case "padding">
         <#assign paddingField = field.asPaddingField().orElseThrow()>
         <#assign typedField = field.asTypedField().orElseThrow()>