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/31 21:44:05 UTC

[plc4x] 01/02: - Adjusted PLC4X to the latest changes

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 2cf33a164db47e5fed02d59481d5804113baa181
Author: cdutz <ch...@c-ware.de>
AuthorDate: Sun Oct 31 14:06:13 2021 +0100

    - Adjusted PLC4X to the latest changes
---
 code-generation/language-c/pom.xml                 | 39 -----------------
 .../plc4x/language/c/CLanguageTemplateHelper.java  | 51 ++++++++++++++++------
 code-generation/language-java/pom.xml              | 48 ++++++++++++++++++++
 .../modbus_pdu_read_file_record_response_item.c    |  8 ++--
 sandbox/test-java-bacnetip-driver/pom.xml          |  2 +-
 sandbox/test-java-df1-driver/pom.xml               |  2 +-
 6 files changed, 91 insertions(+), 59 deletions(-)

diff --git a/code-generation/language-c/pom.xml b/code-generation/language-c/pom.xml
index 2a8f589..8838984 100644
--- a/code-generation/language-c/pom.xml
+++ b/code-generation/language-c/pom.xml
@@ -34,45 +34,6 @@
 
   <build>
     <plugins>
-      <plugin>
-        <groupId>org.apache.maven.plugins</groupId>
-        <artifactId>maven-invoker-plugin</artifactId>
-        <version>3.2.2</version>
-        <executions>
-          <execution>
-            <id>integration-test</id>
-            <goals>
-              <!-- Install the current project artifacts into the maven local repo, so they can be used in the test -->
-              <goal>install</goal>
-              <!-- Execute the maven builds defines in src/test/resources -->
-              <goal>integration-test</goal>
-              <!-- Checks the results of the maven builds -->
-              <goal>verify</goal>
-            </goals>
-            <configuration>
-              <debug>true</debug>
-              <localRepositoryPath>${project.build.directory}/local-repo</localRepositoryPath>
-              <projectsDirectory>src/test/resources</projectsDirectory>
-              <cloneProjectsTo>${project.build.directory}/integration-tests</cloneProjectsTo>
-              <settingsFile>src/test/resources/settings.xml</settingsFile>
-              <extraArtifacts>
-                <extraArtifact>org.apache.plc4x.plugins:plc4x-code-generation-language-base:${plc4x-code-generation.version}</extraArtifact>
-                <extraArtifact>org.apache.plc4x.plugins:plc4x-maven-plugin:${plc4x-code-generation.version}</extraArtifact>
-                <extraArtifact>org.apache.plc4x.plugins:plc4x-code-generation-protocol-base:${plc4x-code-generation.version}</extraArtifact>
-                <extraArtifact>org.apache.plc4x.plugins:plc4x-code-generation-types-base:${plc4x-code-generation.version}</extraArtifact>
-                <extraArtifact>org.apache.plc4x.plugins:plc4x-code-generation-types-base:${plc4x-code-generation.version}</extraArtifact>
-              </extraArtifacts>
-              <pomIncludes>
-                <pomInclude>*/pom.xml</pomInclude>
-              </pomIncludes>
-              <!-- The goals we will be executing in the test-projects -->
-              <goals>
-                <goal>test</goal>
-              </goals>
-            </configuration>
-          </execution>
-        </executions>
-      </plugin>
     </plugins>
   </build>
 
diff --git a/code-generation/language-c/src/main/java/org/apache/plc4x/language/c/CLanguageTemplateHelper.java b/code-generation/language-c/src/main/java/org/apache/plc4x/language/c/CLanguageTemplateHelper.java
index c95d4c2..73a5e38 100644
--- a/code-generation/language-c/src/main/java/org/apache/plc4x/language/c/CLanguageTemplateHelper.java
+++ b/code-generation/language-c/src/main/java/org/apache/plc4x/language/c/CLanguageTemplateHelper.java
@@ -409,9 +409,14 @@ public class CLanguageTemplateHelper extends BaseFreemarkerLanguageTemplateHelpe
                 throw new FreemarkerException("Unsupported float type with " + floatTypeReference.getSizeInBits() + " bits");
             case STRING:
             case VSTRING:
-                StringTypeReference stringTypeReference = (StringTypeReference) simpleTypeReference;
-                return "plc4c_spi_read_string(readBuffer, " + toParseExpression(thisType, field, stringTypeReference.getLengthExpression(), null) + ", \"" +
-                    stringTypeReference.getEncoding() + "\"" + ", (char**) " + valueString + ")";
+                final Term encodingTerm = field.getEncoding().orElse(new DefaultStringLiteral("UTF-8"));
+                if (!(encodingTerm instanceof StringLiteral)) {
+                    throw new RuntimeException("Encoding must be a quoted string value");
+                }
+                String encoding = ((StringLiteral) encodingTerm).getValue();
+                String length = Integer.toString(simpleTypeReference.getSizeInBits());
+                return "plc4c_spi_read_string(readBuffer, " + length + ", \"" +
+                    encoding + "\"" + ", (char**) " + valueString + ")";
             default:
                 throw new FreemarkerException("Unsupported type " + simpleTypeReference.getBaseType().name());
         }
@@ -464,9 +469,14 @@ public class CLanguageTemplateHelper extends BaseFreemarkerLanguageTemplateHelpe
                 throw new FreemarkerException("Unsupported float type with " + floatTypeReference.getSizeInBits() + " bits");
             case STRING:
             case VSTRING:
-                StringTypeReference stringTypeReference = (StringTypeReference) simpleTypeReference;
-                return "plc4c_spi_write_string(writeBuffer, " + toSerializationExpression(thisType, field, stringTypeReference.getLengthExpression(), null) + ", \"" +
-                    stringTypeReference.getEncoding() + "\", " + fieldName + ")";
+                final Term encodingTerm = field.getEncoding().orElse(new DefaultStringLiteral("UTF-8"));
+                if (!(encodingTerm instanceof StringLiteral)) {
+                    throw new RuntimeException("Encoding must be a quoted string value");
+                }
+                String encoding = ((StringLiteral) encodingTerm).getValue();
+                String length = Integer.toString(simpleTypeReference.getSizeInBits());
+                return "plc4c_spi_write_string(writeBuffer, " + length + ", \"" +
+                    encoding + "\", " + fieldName + ")";
             default:
                 throw new FreemarkerException("Unsupported type " + simpleTypeReference.getBaseType().name());
         }
@@ -726,9 +736,12 @@ public class CLanguageTemplateHelper extends BaseFreemarkerLanguageTemplateHelpe
         tracer = tracer.dive("type");
         if ((variableLiteral.getChild().isPresent()) && "encoding".equals(variableLiteral.getChild().get().getName()) && (field instanceof TypedField) && (((TypedField) field).getType() instanceof StringTypeReference)) {
             // TODO: replace with map join
-            TypedField typedField = (TypedField) field;
-            StringTypeReference stringTypeReference = (StringTypeReference) typedField.getType();
-            return tracer + "\"" + stringTypeReference.getEncoding().substring(1, stringTypeReference.getEncoding().length() - 1) + "\"";
+            final Term encodingTerm = field.getEncoding().orElse(new DefaultStringLiteral("UTF-8"));
+            if (!(encodingTerm instanceof StringLiteral)) {
+                throw new RuntimeException("Encoding must be a quoted string value");
+            }
+            String encoding = ((StringLiteral) encodingTerm).getValue();
+            return tracer + "\"" + encoding + "\"";
         } else {
             throw new FreemarkerException("_type is currently pretty much hard-coded for some use cases, please check CLanguageTemplateHelper.toVariableParseExpression");
         }
@@ -907,7 +920,11 @@ public class CLanguageTemplateHelper extends BaseFreemarkerLanguageTemplateHelpe
                         throw new FreemarkerException("Can only access 'encoding' for string types.");
                     }
                     StringTypeReference stringTypeReference = (StringTypeReference) typedField.getType();
-                    String encoding = stringTypeReference.getEncoding();
+                    final Term encodingTerm = field.getEncoding().orElse(new DefaultStringLiteral("UTF-8"));
+                    if (!(encodingTerm instanceof StringLiteral)) {
+                        throw new RuntimeException("Encoding must be a quoted string value");
+                    }
+                    String encoding = ((StringLiteral) encodingTerm).getValue();
                     // Cut off the single quotes.
                     encoding = encoding.substring(1, encoding.length() - 1);
                     return tracer + "\"" + encoding + "\"";
@@ -998,8 +1015,11 @@ public class CLanguageTemplateHelper extends BaseFreemarkerLanguageTemplateHelpe
                                 if (!(typedField.getType() instanceof StringTypeReference)) {
                                     throw new FreemarkerException("Can only access 'encoding' for string types.");
                                 }
-                                StringTypeReference stringTypeReference = (StringTypeReference) typedField.getType();
-                                String encoding = stringTypeReference.getEncoding();
+                                final Term encodingTerm = field.getEncoding().orElse(new DefaultStringLiteral("UTF-8"));
+                                if (!(encodingTerm instanceof StringLiteral)) {
+                                    throw new RuntimeException("Encoding must be a quoted string value");
+                                }
+                                String encoding = ((StringLiteral) encodingTerm).getValue();
                                 // Cut off the single quotes.
                                 encoding = encoding.substring(1, encoding.length() - 1);
                                 sb.append("\"").append(encoding).append("\"");
@@ -1078,8 +1098,11 @@ public class CLanguageTemplateHelper extends BaseFreemarkerLanguageTemplateHelpe
                             if (!(typedField.getType() instanceof StringTypeReference)) {
                                 throw new FreemarkerException("Can only access 'encoding' for string types.");
                             }
-                            StringTypeReference stringTypeReference = (StringTypeReference) typedField.getType();
-                            String encoding = stringTypeReference.getEncoding();
+                            final Term encodingTerm = field.getEncoding().orElse(new DefaultStringLiteral("UTF-8"));
+                            if (!(encodingTerm instanceof StringLiteral)) {
+                                throw new RuntimeException("Encoding must be a quoted string value");
+                            }
+                            String encoding = ((StringLiteral) encodingTerm).getValue();
                             // Cut off the single quotes.
                             encoding = encoding.substring(1, encoding.length() - 1);
                             sb.append("\"").append(encoding).append("\"");
diff --git a/code-generation/language-java/pom.xml b/code-generation/language-java/pom.xml
index f5c090f..fcbe988 100644
--- a/code-generation/language-java/pom.xml
+++ b/code-generation/language-java/pom.xml
@@ -34,6 +34,54 @@
 
   <build>
     <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-invoker-plugin</artifactId>
+        <version>3.2.2</version>
+        <executions>
+          <execution>
+            <id>integration-test</id>
+            <goals>
+              <!-- Install the current project artifacts into the maven local repo, so they can be used in the test -->
+              <goal>install</goal>
+              <!-- Execute the maven builds defines in src/test/resources -->
+              <goal>integration-test</goal>
+              <!-- Checks the results of the maven builds -->
+              <goal>verify</goal>
+            </goals>
+            <configuration>
+              <!-- 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>
+              <cloneProjectsTo>${project.build.directory}/integration-tests</cloneProjectsTo>
+              <settingsFile>src/test/resources/settings.xml</settingsFile>
+              <extraArtifacts>
+                <extraArtifact>org.apache.plc4x.plugins:plc4x-code-generation-language-base:${plc4x-code-generation.version}</extraArtifact>
+                <extraArtifact>org.apache.plc4x.plugins:plc4x-maven-plugin:${plc4x-code-generation.version}</extraArtifact>
+                <extraArtifact>org.apache.plc4x.plugins:plc4x-code-generation-protocol-base:${plc4x-code-generation.version}</extraArtifact>
+                <extraArtifact>org.apache.plc4x.plugins:plc4x-code-generation-types-base:${plc4x-code-generation.version}</extraArtifact>
+                <extraArtifact>org.apache.plc4x.plugins:plc4x-code-generation-types-base:${plc4x-code-generation.version}</extraArtifact>
+              </extraArtifacts>
+              <pomIncludes>
+                <pomInclude>*/pom.xml</pomInclude>
+              </pomIncludes>
+              <!-- The goals we will be executing in the test-projects -->
+              <goals>
+                <goal>test</goal>
+              </goals>
+            </configuration>
+          </execution>
+        </executions>
+      </plugin>
     </plugins>
   </build>
 
diff --git a/plc4c/generated-sources/modbus/src/modbus_pdu_read_file_record_response_item.c b/plc4c/generated-sources/modbus/src/modbus_pdu_read_file_record_response_item.c
index 7f30b3f..ae24540 100644
--- a/plc4c/generated-sources/modbus/src/modbus_pdu_read_file_record_response_item.c
+++ b/plc4c/generated-sources/modbus/src/modbus_pdu_read_file_record_response_item.c
@@ -62,8 +62,8 @@ plc4c_return_code plc4c_modbus_read_write_modbus_pdu_read_file_record_response_i
     uint8_t _dataLength = (dataLength) - (1);
     uint8_t dataEndPos = plc4c_spi_read_get_pos(readBuffer) + _dataLength;
     while(plc4c_spi_read_get_pos(readBuffer) < dataEndPos) {
-      int8_t _value = 0;
-      _res = plc4c_spi_read_signed_byte(readBuffer, 8, (int8_t*) &_value);
+      char _value = 0;
+      _res = plc4c_spi_read_char(readBuffer, (char*) &_value);
       if(_res != OK) {
         return _res;
       }
@@ -95,8 +95,8 @@ plc4c_return_code plc4c_modbus_read_write_modbus_pdu_read_file_record_response_i
     uint8_t itemCount = plc4c_utils_list_size(_message->data);
     for(int curItem = 0; curItem < itemCount; curItem++) {
 
-      int8_t* _value = (int8_t*) plc4c_utils_list_get_value(_message->data, curItem);
-      plc4c_spi_write_signed_byte(writeBuffer, 8, *_value);
+      char* _value = (char*) plc4c_utils_list_get_value(_message->data, curItem);
+      plc4c_spi_write_char(writeBuffer, *_value);
     }
   }
 
diff --git a/sandbox/test-java-bacnetip-driver/pom.xml b/sandbox/test-java-bacnetip-driver/pom.xml
index b2e92a6..6572650 100644
--- a/sandbox/test-java-bacnetip-driver/pom.xml
+++ b/sandbox/test-java-bacnetip-driver/pom.xml
@@ -28,7 +28,7 @@
 
   <artifactId>test-java-bacnetip-driver</artifactId>
 
-  <name>Sandbox: Test Generated BACNet/IP Driver</name>
+  <name>Sandbox: Test BACNet/IP Driver</name>
 
   <build>
     <plugins>
diff --git a/sandbox/test-java-df1-driver/pom.xml b/sandbox/test-java-df1-driver/pom.xml
index 4d686f7..5264e72 100644
--- a/sandbox/test-java-df1-driver/pom.xml
+++ b/sandbox/test-java-df1-driver/pom.xml
@@ -28,7 +28,7 @@
 
   <artifactId>test-java-df1-driver</artifactId>
 
-  <name>Sandbox: Test Generated Df1 Driver</name>
+  <name>Sandbox: Test Df1 Driver</name>
 
   <dependencies>
     <dependency>