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/03 21:14:11 UTC

[plc4x] branch feature/mspec-ng updated: Finished updating the mspecs and the build

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 f5df8f3  Finished updating the mspecs and the build
f5df8f3 is described below

commit f5df8f37031c287859bd1e6f64818596303e0cfc
Author: cdutz <ch...@c-ware.de>
AuthorDate: Sun Oct 3 23:13:48 2021 +0200

    Finished updating the mspecs and the build
---
 code-generation/language-java/pom.xml                   | 17 +++++++++--------
 .../main/resources/templates/java/io-template.java.ftlh |  9 ++-------
 .../apache/plc4x/java/spi/generation/StaticHelper.java  |  9 +++++++--
 .../ads/src/main/resources/protocols/ads/ads.mspec      |  8 ++++----
 .../src/main/resources/protocols/can/canopen.mspec      |  6 +++---
 protocols/s7/src/main/resources/protocols/s7/s7.mspec   | 10 +++++-----
 .../main/resources/protocols/simulated/simulated.mspec  |  4 ++--
 7 files changed, 32 insertions(+), 31 deletions(-)

diff --git a/code-generation/language-java/pom.xml b/code-generation/language-java/pom.xml
index 6c621ba..1f73cb6 100644
--- a/code-generation/language-java/pom.xml
+++ b/code-generation/language-java/pom.xml
@@ -50,14 +50,15 @@
               <goal>verify</goal>
             </goals>
             <configuration>
-              <!-- These option allow that openjdk >16 can run the google-code-format -->
-              <mavenOpts>
-                --add-exports jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED
-                --add-exports jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED
-                --add-exports jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED
-                --add-exports jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED
-                --add-exports jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED
-              </mavenOpts>
+              <!-- These option allow that openjdk >=16 can run the google-code-format -->
+              <!-- TODO: Add this to a self-activating maven profile -->
+              <!--mavenOpts>
+                - -add-exports jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED
+                - -add-exports jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED
+                - -add-exports jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED
+                - -add-exports jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED
+                - -add-exports jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED
+              </mavenOpts-->
               <debug>true</debug>
               <localRepositoryPath>${project.build.directory}/local-repo</localRepositoryPath>
               <projectsDirectory>src/test/resources</projectsDirectory>
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 3305725..928d570 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
@@ -443,16 +443,13 @@ public class ${type.name}IO implements <#if outputFlavor != "passive">MessageIO<
         <#assign optionalField = field.asOptionalField().orElseThrow()>
 
         // Optional Field (${optionalField.name}) (Can be skipped, if a given expression evaluates to false)
-        <#if !optionalField.conditionExpression.present>
+        ${helper.getLanguageTypeNameForField(optionalField)} ${optionalField.name} = null;
         <#-- TODO: we need to initalize base types-->
-        ${helper.getLanguageTypeNameForField(simpleField)} ${simpleField.name} = null;
         curPos = readBuffer.getPos();
         try {
-        </#if>
         <#if optionalField.conditionExpression.present && optionalField.conditionExpression.orElseThrow().contains("curPos")>
         curPos = readBuffer.getPos();
         </#if>
-        ${helper.getLanguageTypeNameForField(field)} ${optionalField.name} = null;
         <#if optionalField.conditionExpression.present>
         if(${helper.toParseExpression(optionalField, optionalField.conditionExpression.get(), parserArguments)}) {
         </#if>
@@ -500,11 +497,9 @@ public class ${type.name}IO implements <#if outputFlavor != "passive">MessageIO<
         <#if optionalField.conditionExpression.present>
         }
         </#if>
-        <#if !optionalField.conditionExpression.present>
         } catch(ParseAssertException ignore){
-        readBuffer.reset(curPos);
+            readBuffer.reset(curPos);
         }
-        </#if>
         <#break>
     <#case "assert">
         <#assign assertField = field.asAssertField().orElseThrow()>
diff --git a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/generation/StaticHelper.java b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/generation/StaticHelper.java
index 6de232a..1e6f73d 100644
--- a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/generation/StaticHelper.java
+++ b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/generation/StaticHelper.java
@@ -19,6 +19,7 @@
 package org.apache.plc4x.java.spi.generation;
 
 import org.apache.plc4x.java.api.exceptions.PlcRuntimeException;
+import org.apache.plc4x.java.api.value.PlcValue;
 
 import java.util.Collection;
 
@@ -86,11 +87,15 @@ public class StaticHelper {
         throw new PlcRuntimeException("Unable to count object of type " + obj.getClass().getName());
     }
 
-    public static int STR_LEN(String str) {
+    public static int STR_LEN(Object str) {
         if (str == null) {
             return 0;
         }
-        return str.length();
+        if (str instanceof PlcValue) {
+            PlcValue plcValue = (PlcValue) str;
+            return plcValue.getString().length();
+        }
+        return str.toString().length();
     }
 
     public static <T> T CAST(Object obj, Class<T> clazz) {
diff --git a/protocols/ads/src/main/resources/protocols/ads/ads.mspec b/protocols/ads/src/main/resources/protocols/ads/ads.mspec
index 58961d0..bf5c9ae 100644
--- a/protocols/ads/src/main/resources/protocols/ads/ads.mspec
+++ b/protocols/ads/src/main/resources/protocols/ads/ads.mspec
@@ -458,18 +458,18 @@
         // Characters & Strings
         // -----------------------------------------
         ['IEC61131_CHAR' STRING
-//            [simple string 8 'value' encoding='UTF-8']
+//            [simple string 8 'value']
         ]
         ['IEC61131_WCHAR' STRING
-//            [simple string 16 'value' encoding='UTF-16']
+//            [simple string 16 'value' encoding='"UTF-16"']
         ]
         ['IEC61131_STRING' STRING
             // TODO: Fix this length
-            [manual   string 8 'value' 'STATIC_CALL("org.apache.plc4x.java.ads.utils.StaticHelper.parseAmsString", readBuffer, stringLength, _type.encoding)' 'STATIC_CALL("org.apache.plc4x.java.ads.utils.StaticHelper.serializeAmsString", writeBuffer, _value, stringLength, _type.encoding)' 'stringLength + 1' encoding='UTF-8']
+            [manual   string 8 'value' 'STATIC_CALL("org.apache.plc4x.java.ads.utils.StaticHelper.parseAmsString", readBuffer, stringLength, _type.encoding)' 'STATIC_CALL("org.apache.plc4x.java.ads.utils.StaticHelper.serializeAmsString", writeBuffer, _value, stringLength, _type.encoding)' 'stringLength + 1']
         ]
         ['IEC61131_WSTRING' STRING
             // TODO: Fix this length
-            [manual string 8 'value' 'STATIC_CALL("org.apache.plc4x.java.ads.utils.StaticHelper.parseAmsString", readBuffer, stringLength, _type.encoding)' 'STATIC_CALL("org.apache.plc4x.java.ads.utils.StaticHelper.serializeAmsString", writeBuffer, _value, stringLength, _type.encoding)' '(stringLength * 2) + 2' encoding='UTF-16']
+            [manual string 8 'value' 'STATIC_CALL("org.apache.plc4x.java.ads.utils.StaticHelper.parseAmsString", readBuffer, stringLength, _type.encoding)' 'STATIC_CALL("org.apache.plc4x.java.ads.utils.StaticHelper.serializeAmsString", writeBuffer, _value, stringLength, _type.encoding)' '(stringLength * 2) + 2' encoding='"UTF-16"']
         ]
 
         // -----------------------------------------
diff --git a/protocols/canopen/src/main/resources/protocols/can/canopen.mspec b/protocols/canopen/src/main/resources/protocols/can/canopen.mspec
index 6479f6b..07b52f2 100644
--- a/protocols/canopen/src/main/resources/protocols/can/canopen.mspec
+++ b/protocols/canopen/src/main/resources/protocols/can/canopen.mspec
@@ -333,15 +333,15 @@
             [array int 8 'value' length 'size']
         ]
         ['OCTET_STRING' STRING
-           [simple vstring 'size' 'test' encoding='UTF-8']
+           [simple vstring 'size' 'test']
         ]
         ['VISIBLE_STRING' STRING
-            [simple vstring 'size' 'value' encoding='UTF-8']
+            [simple vstring 'size' 'value']
         ]
         //CANOpenDataType.TIME_OF_DAY' CANOpenTime
         //CANOpenDataType.TIME_DIFFERENCE' CANOpenTime
         ['UNICODE_STRING' STRING
-            [simple vstring 'size/8' 'value' encoding='UTF-8']
+            [simple vstring 'size/8' 'value']
         ]
     ]
 ]
diff --git a/protocols/s7/src/main/resources/protocols/s7/s7.mspec b/protocols/s7/src/main/resources/protocols/s7/s7.mspec
index bdbb90d..8544d08 100644
--- a/protocols/s7/src/main/resources/protocols/s7/s7.mspec
+++ b/protocols/s7/src/main/resources/protocols/s7/s7.mspec
@@ -469,7 +469,7 @@
         ['0x04', '0x02' S7PayloadUserDataItemCpuFunctionMsgSubscription
             [simple   uint 8         'Subscription']
             [reserved uint 8         '0x00']
-            [simple   string         64             'magicKey'            encoding='UTF-8']
+            [simple   string         64             'magicKey'           ]
             [optional AlarmStateType 'Alarmtype'    'Subscription >= 128']
             [optional uint 8         'Reserve'      'Subscription >= 128']
         ]
@@ -597,18 +597,18 @@
         // Characters & Strings
         // -----------------------------------------
         ['IEC61131_CHAR' CHAR
-            [manual string 8 'value'  'STATIC_CALL("org.apache.plc4x.java.s7.utils.StaticHelper.parseS7Char", readBuffer, _type.encoding)' 'STATIC_CALL("org.apache.plc4x.java.s7.utils.StaticHelper.serializeS7Char", writeBuffer, _value, _type.encoding)' '1' encoding='UTF-8']
+            [manual string 8 'value'  'STATIC_CALL("org.apache.plc4x.java.s7.utils.StaticHelper.parseS7Char", readBuffer, _type.encoding)' 'STATIC_CALL("org.apache.plc4x.java.s7.utils.StaticHelper.serializeS7Char", writeBuffer, _value, _type.encoding)' '1']
         ]
         ['IEC61131_WCHAR' CHAR
-            [manual string 16 'value' 'STATIC_CALL("org.apache.plc4x.java.s7.utils.StaticHelper.parseS7Char", readBuffer, _type.encoding)' 'STATIC_CALL("org.apache.plc4x.java.s7.utils.StaticHelper.serializeS7Char", writeBuffer, _value, _type.encoding)' '2' encoding='UTF-16']
+            [manual string 16 'value' 'STATIC_CALL("org.apache.plc4x.java.s7.utils.StaticHelper.parseS7Char", readBuffer, _type.encoding)' 'STATIC_CALL("org.apache.plc4x.java.s7.utils.StaticHelper.serializeS7Char", writeBuffer, _value, _type.encoding)' '2' encoding='"UTF-16"']
         ]
         ['IEC61131_STRING' STRING
             // TODO: Fix this length
-            [manual string 8 'value'  'STATIC_CALL("org.apache.plc4x.java.s7.utils.StaticHelper.parseS7String", readBuffer, stringLength, _type.encoding)' 'STATIC_CALL("org.apache.plc4x.java.s7.utils.StaticHelper.serializeS7String", writeBuffer, _value, stringLength, _type.encoding)' 'STR_LEN(_value.string) + 2' encoding='UTF-8']
+            [manual string 8 'value'  'STATIC_CALL("org.apache.plc4x.java.s7.utils.StaticHelper.parseS7String", readBuffer, stringLength, _type.encoding)' 'STATIC_CALL("org.apache.plc4x.java.s7.utils.StaticHelper.serializeS7String", writeBuffer, _value, stringLength, _type.encoding)' 'STR_LEN(_value) + 2']
         ]
         ['IEC61131_WSTRING' STRING
             // TODO: Fix this length
-            [manual string 16 'value' 'STATIC_CALL("org.apache.plc4x.java.s7.utils.StaticHelper.parseS7String", readBuffer, stringLength, _type.encoding)' 'STATIC_CALL("org.apache.plc4x.java.s7.utils.StaticHelper.serializeS7String", writeBuffer, _value, stringLength, _type.encoding)' '(STR_LEN(_value.string) * 2) + 2' encoding='UTF-16']
+            [manual string 16 'value' 'STATIC_CALL("org.apache.plc4x.java.s7.utils.StaticHelper.parseS7String", readBuffer, stringLength, _type.encoding)' 'STATIC_CALL("org.apache.plc4x.java.s7.utils.StaticHelper.serializeS7String", writeBuffer, _value, stringLength, _type.encoding)' '(STR_LEN(_value) * 2) + 2' encoding='"UTF-16"']
         ]
 
         // -----------------------------------------
diff --git a/protocols/simulated/src/main/resources/protocols/simulated/simulated.mspec b/protocols/simulated/src/main/resources/protocols/simulated/simulated.mspec
index 4ca6259..b3c44f3 100644
--- a/protocols/simulated/src/main/resources/protocols/simulated/simulated.mspec
+++ b/protocols/simulated/src/main/resources/protocols/simulated/simulated.mspec
@@ -128,10 +128,10 @@
             [array uint 16 'value' count 'numberOfValues']
         ]
         ['STRING' STRING
-            [simple string 255 'value' encoding='UTF-8']
+            [simple string 255 'value']
         ]
         ['WSTRING' STRING
-            [simple string 255 'value' encoding='UTF-8']
+            [simple string 255 'value']
         ]
     ]
 ]