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/10/14 16:08:36 UTC

[plc4x] branch feature/plc-simulator created (now 0d7c768)

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

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


      at 0d7c768  - Moved some of the code from the simulator to the S7 driver - Added a skeleton for the S7 driver to the new generated s7 driver - Removed the code-generation from the plc-simulator module - Refactored the S7Server to use the code of the driver instead

This branch includes the following new commits:

     new d9539a7  - Updated the mspec format to allow non-value enum types (Ones without a "getValue" and "valueOf" method.
     new 30821cc  - Tried to clean up in the S7 mspec regarding the TransportSize (It turned out that multiple values resulted in the same transport sizes, I therefore split up everything into ParameterSize, PayloadSize and a Types type that maps the other two)
     new 0d7c768  - Moved some of the code from the simulator to the S7 driver - Added a skeleton for the S7 driver to the new generated s7 driver - Removed the code-generation from the plc-simulator module - Refactored the S7Server to use the code of the driver instead

The 3 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.



[plc4x] 01/03: - Updated the mspec format to allow non-value enum types (Ones without a "getValue" and "valueOf" method.

Posted by cd...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit d9539a7d47a084dcd66d7571e7d7deaec487cf33
Author: Christofer Dutz <ch...@c-ware.de>
AuthorDate: Mon Oct 14 17:58:04 2019 +0200

    - Updated the mspec format to allow non-value enum types (Ones without a "getValue" and "valueOf" method.
---
 .../src/main/resources/templates/java/enum-template.ftlh | 16 +++++++++-------
 .../plc4x/plugins/codegenerator/language/mspec/MSpec.g4  |  5 ++---
 .../language/mspec/parser/MessageFormatListener.java     |  4 ++--
 3 files changed, 13 insertions(+), 12 deletions(-)

diff --git a/build-utils/language-java/src/main/resources/templates/java/enum-template.ftlh b/build-utils/language-java/src/main/resources/templates/java/enum-template.ftlh
index 62c4f34..4f4cbd7 100644
--- a/build-utils/language-java/src/main/resources/templates/java/enum-template.ftlh
+++ b/build-utils/language-java/src/main/resources/templates/java/enum-template.ftlh
@@ -48,12 +48,12 @@ import java.util.Map;
 public enum ${typeName} {
 
 <#list type.enumValues as enumValue>
-    ${enumValue.name}((${helper.getLanguageTypeName(type.type, true)}) ${enumValue.value}<#if type.constantNames?has_content>, <#list type.constantNames as constantName>(${helper.getLanguageTypeName(type.getConstantType(constantName), true)}) ${helper.escapeValue(type.getConstantType(constantName), enumValue.getConstant(constantName))?no_esc}<#sep>, </#sep></#list></#if>)<#sep>,
+    ${enumValue.name}(<#if type.type?has_content>(${helper.getLanguageTypeName(type.type, true)}) ${enumValue.value}</#if><#if (type.constantNames?has_content && type.type?has_content)>, </#if><#list type.constantNames as constantName>(${helper.getLanguageTypeName(type.getConstantType(constantName), true)}) ${helper.escapeValue(type.getConstantType(constantName), enumValue.getConstant(constantName))?no_esc}<#sep>, </#sep></#list>)<#sep>,
 </#sep></#list>;
 
     private static final Logger logger = LoggerFactory.getLogger(${typeName}.class);
 
-    private static final Map<${helper.getLanguageTypeName(type.type, false)}, ${typeName}> map;
+    <#if type.type?has_content>private static final Map<${helper.getLanguageTypeName(type.type, false)}, ${typeName}> map;
     static {
         map = new HashMap<>();
         for (${typeName} value : ${typeName}.values()) {
@@ -61,15 +61,15 @@ public enum ${typeName} {
         }
     }
 
-    private ${helper.getLanguageTypeName(type.type, true)} value;
+    private ${helper.getLanguageTypeName(type.type, true)} value;</#if>
     <#if type.constantNames?has_content>
         <#list type.constantNames as constantName>
     private ${helper.getLanguageTypeName(type.getConstantType(constantName), true)} ${constantName};
         </#list>
     </#if>
 
-    ${typeName}(${helper.getLanguageTypeName(type.type, true)} value<#if type.constantNames?has_content>, <#list type.constantNames as constantName>${helper.getLanguageTypeName(type.getConstantType(constantName), true)} ${constantName}<#sep>, </#sep></#list></#if>) {
-        this.value = value;
+    ${typeName}(<#if type.type?has_content>${helper.getLanguageTypeName(type.type, true)} value</#if><#if (type.constantNames?has_content && type.type?has_content)>, </#if><#list type.constantNames as constantName>${helper.getLanguageTypeName(type.getConstantType(constantName), true)} ${constantName}<#sep>, </#sep></#list>) {
+        <#if type.type?has_content>this.value = value;</#if>
         <#if type.constantNames?has_content>
             <#list type.constantNames as constantName>
         this.${constantName} = ${constantName};
@@ -77,9 +77,10 @@ public enum ${typeName} {
         </#if>
     }
 
-    public ${helper.getLanguageTypeName(type.type, true)} getValue() {
+    <#if type.type?has_content>public ${helper.getLanguageTypeName(type.type, true)} getValue() {
         return value;
     }
+    </#if>
 
     <#if type.constantNames?has_content>
         <#list type.constantNames as constantName>
@@ -89,11 +90,12 @@ public enum ${typeName} {
 
         </#list>
     </#if>
-    public static ${typeName} valueOf(${helper.getLanguageTypeName(type.type, true)} value) {
+    <#if type.type?has_content>public static ${typeName} valueOf(${helper.getLanguageTypeName(type.type, true)} value) {
         if (!map.containsKey(value)) {
             logger.error("No ${typeName} for value {}", value);
         }
         return map.get(value);
     }
+    </#if>
 
 }
\ No newline at end of file
diff --git a/build-utils/protocol-base-mspec/src/main/antlr4/org/apache/plc4x/plugins/codegenerator/language/mspec/MSpec.g4 b/build-utils/protocol-base-mspec/src/main/antlr4/org/apache/plc4x/plugins/codegenerator/language/mspec/MSpec.g4
index 8d058ca..75a09de 100644
--- a/build-utils/protocol-base-mspec/src/main/antlr4/org/apache/plc4x/plugins/codegenerator/language/mspec/MSpec.g4
+++ b/build-utils/protocol-base-mspec/src/main/antlr4/org/apache/plc4x/plugins/codegenerator/language/mspec/MSpec.g4
@@ -30,7 +30,7 @@ complexTypeDefinition
 complexType
  : 'type' name=idExpression (LBRACKET params=argumentList RBRACKET)? fieldDefinition+
  | 'discriminatedType' name=idExpression (LBRACKET params=argumentList RBRACKET)? fieldDefinition+
- | 'enum' type=typeReference name=idExpression (LBRACKET params=argumentList RBRACKET)? enumValues=enumValueDefinition+
+ | 'enum' (type=typeReference)? name=idExpression (LBRACKET params=argumentList RBRACKET)? enumValues=enumValueDefinition+
  ;
 
 
@@ -112,10 +112,9 @@ virtualField
  ;
 
 enumValueDefinition
- : LBRACKET valueExpression=expression name=IDENTIFIER (LBRACKET constantValueExpressions=multipleExpressions RBRACKET)? RBRACKET
+ : LBRACKET (valueExpression=expression)? name=IDENTIFIER (LBRACKET constantValueExpressions=multipleExpressions RBRACKET)? RBRACKET
  ;
 
-
 typeReference
  : complexTypeReference=IDENTIFIER
  | simpleTypeReference=dataType
diff --git a/build-utils/protocol-base-mspec/src/main/java/org/apache/plc4x/plugins/codegenerator/language/mspec/parser/MessageFormatListener.java b/build-utils/protocol-base-mspec/src/main/java/org/apache/plc4x/plugins/codegenerator/language/mspec/parser/MessageFormatListener.java
index 74ff1cf..2556408 100644
--- a/build-utils/protocol-base-mspec/src/main/java/org/apache/plc4x/plugins/codegenerator/language/mspec/parser/MessageFormatListener.java
+++ b/build-utils/protocol-base-mspec/src/main/java/org/apache/plc4x/plugins/codegenerator/language/mspec/parser/MessageFormatListener.java
@@ -86,7 +86,7 @@ public class MessageFormatListener extends MSpecBaseListener {
         }
 
         if(ctx.enumValues != null) {
-            TypeReference type = getTypeReference(ctx.type);
+            TypeReference type = (ctx.type != null) ? getTypeReference(ctx.type) : null;
             EnumValue[] enumValues = getEnumValues();
             DefaultEnumTypeDefinition enumType = new DefaultEnumTypeDefinition(typeName, type, enumValues,
                 parserArguments, null);
@@ -343,7 +343,7 @@ public class MessageFormatListener extends MSpecBaseListener {
 
     @Override
     public void enterEnumValueDefinition(MSpecParser.EnumValueDefinitionContext ctx) {
-        String value = unquoteString(ctx.valueExpression.getText());
+        String value = (ctx.valueExpression != null) ? unquoteString(ctx.valueExpression.getText()) : null;
         String name = ctx.name.getText();
         Map<String, String> constants = null;
         if(ctx.constantValueExpressions != null) {


[plc4x] 03/03: - Moved some of the code from the simulator to the S7 driver - Added a skeleton for the S7 driver to the new generated s7 driver - Removed the code-generation from the plc-simulator module - Refactored the S7Server to use the code of the driver instead

Posted by cd...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 0d7c768c5d14307be288dba14ea03b072b583f55
Author: Christofer Dutz <ch...@c-ware.de>
AuthorDate: Mon Oct 14 18:01:55 2019 +0200

    - Moved some of the code from the simulator to the S7 driver
    - Added a skeleton for the S7 driver to the new generated s7 driver
    - Removed the code-generation from the plc-simulator module
    - Refactored the S7Server to use the code of the driver instead
---
 sandbox/plc-simulator/pom.xml                      |  38 ++------
 .../SimulatorExcepiton.java}                       |  19 ++--
 .../plc4x/simulator/server/ServerModule.java       |   6 +-
 .../apache/plc4x/simulator/server/s7/S7Server.java |  69 --------------
 .../plc4x/simulator/server/s7/S7ServerModule.java  |  55 ++++++++---
 ...rverProtocol.java => S7Step7ServerAdapter.java} |  51 ++++++++---
 sandbox/test-java-s7-driver/pom.xml                |  10 ++
 .../java/org/apache/plc4x/java/s7/S7PlcDriver.java |  75 +++++++++++++++
 .../plc4x/java/s7/connection/S7PlcConnection.java  | 101 +++++++++++++++++++++
 .../java/s7/protocol/S7Step7ClientAdapter.java}    |  35 ++-----
 .../java/s7/protocol/S7Step7Plc4xAdapter.java}     |  35 ++-----
 .../plc4x/java}/s7/protocol/S7Step7Protocol.java   |   2 +-
 .../services/org.apache.plc4x.java.spi.PlcDriver   |  19 ++++
 13 files changed, 332 insertions(+), 183 deletions(-)

diff --git a/sandbox/plc-simulator/pom.xml b/sandbox/plc-simulator/pom.xml
index e853987..fcb7a7a 100644
--- a/sandbox/plc-simulator/pom.xml
+++ b/sandbox/plc-simulator/pom.xml
@@ -34,30 +34,10 @@
 
   <build>
     <plugins>
-      <!-- Generate the code for parsing and serializing S7 packets -->
-      <plugin>
-        <groupId>org.apache.plc4x.plugins</groupId>
-        <artifactId>plc4x-maven-plugin</artifactId>
-        <executions>
-          <execution>
-            <id>test</id>
-            <phase>generate-sources</phase>
-            <goals>
-              <goal>generate-driver</goal>
-            </goals>
-            <configuration>
-              <protocolName>s7</protocolName>
-              <languageName>java</languageName>
-              <outputFlavor>read-write</outputFlavor>
-            </configuration>
-          </execution>
-        </executions>
-      </plugin>
       <!-- Build a fat jar containing all dependencies -->
       <plugin>
         <groupId>org.apache.maven.plugins</groupId>
         <artifactId>maven-shade-plugin</artifactId>
-        <version>3.2.1</version>
         <executions>
           <execution>
             <id>generate-uber-jar</id>
@@ -79,6 +59,13 @@
   </build>
 
   <dependencies>
+    <!-- The Server is based on the same generated code as the client -->
+    <dependency>
+      <groupId>org.apache.plc4x.sandbox</groupId>
+      <artifactId>test-java-s7-driver</artifactId>
+      <version>0.5.0-SNAPSHOT</version>
+    </dependency>
+
     <dependency>
       <groupId>org.apache.plc4x</groupId>
       <artifactId>plc4j-utils-driver-base-java</artifactId>
@@ -89,15 +76,8 @@
       <artifactId>plc4j-protocol-driver-base</artifactId>
       <version>0.5.0-SNAPSHOT</version>
     </dependency>
-    <dependency>
-      <groupId>io.netty</groupId>
-      <artifactId>netty-all</artifactId>
-      <version>${netty.version}</version>
-    </dependency>
-    <dependency>
-      <groupId>com.fasterxml.jackson.core</groupId>
-      <artifactId>jackson-annotations</artifactId>
-    </dependency>
+
+    <!-- Explicitly override the scope to compile to include these -->
     <dependency>
       <groupId>ch.qos.logback</groupId>
       <artifactId>logback-classic</artifactId>
diff --git a/sandbox/plc-simulator/src/main/java/org/apache/plc4x/simulator/server/ServerModule.java b/sandbox/plc-simulator/src/main/java/org/apache/plc4x/simulator/exceptions/SimulatorExcepiton.java
similarity index 68%
copy from sandbox/plc-simulator/src/main/java/org/apache/plc4x/simulator/server/ServerModule.java
copy to sandbox/plc-simulator/src/main/java/org/apache/plc4x/simulator/exceptions/SimulatorExcepiton.java
index 41aecac..1557e32 100644
--- a/sandbox/plc-simulator/src/main/java/org/apache/plc4x/simulator/server/ServerModule.java
+++ b/sandbox/plc-simulator/src/main/java/org/apache/plc4x/simulator/exceptions/SimulatorExcepiton.java
@@ -16,17 +16,20 @@ KIND, either express or implied.  See the License for the
 specific language governing permissions and limitations
 under the License.
 */
-package org.apache.plc4x.simulator.server;
+package org.apache.plc4x.simulator.exceptions;
 
-public interface ServerModule {
+public class SimulatorExcepiton extends Exception {
 
-    /**
-     * @return the name of the server module
-     */
-    String getName();
+    public SimulatorExcepiton(String message) {
+        super(message);
+    }
 
-    void start();
+    public SimulatorExcepiton(String message, Throwable cause) {
+        super(message, cause);
+    }
 
-    void stop();
+    public SimulatorExcepiton(Throwable cause) {
+        super(cause);
+    }
 
 }
diff --git a/sandbox/plc-simulator/src/main/java/org/apache/plc4x/simulator/server/ServerModule.java b/sandbox/plc-simulator/src/main/java/org/apache/plc4x/simulator/server/ServerModule.java
index 41aecac..da67ef6 100644
--- a/sandbox/plc-simulator/src/main/java/org/apache/plc4x/simulator/server/ServerModule.java
+++ b/sandbox/plc-simulator/src/main/java/org/apache/plc4x/simulator/server/ServerModule.java
@@ -18,6 +18,8 @@ under the License.
 */
 package org.apache.plc4x.simulator.server;
 
+import org.apache.plc4x.simulator.exceptions.SimulatorExcepiton;
+
 public interface ServerModule {
 
     /**
@@ -25,8 +27,8 @@ public interface ServerModule {
      */
     String getName();
 
-    void start();
+    void start() throws SimulatorExcepiton;
 
-    void stop();
+    void stop() throws SimulatorExcepiton;
 
 }
diff --git a/sandbox/plc-simulator/src/main/java/org/apache/plc4x/simulator/server/s7/S7Server.java b/sandbox/plc-simulator/src/main/java/org/apache/plc4x/simulator/server/s7/S7Server.java
deleted file mode 100644
index ca7d8e4..0000000
--- a/sandbox/plc-simulator/src/main/java/org/apache/plc4x/simulator/server/s7/S7Server.java
+++ /dev/null
@@ -1,69 +0,0 @@
-/*
-Licensed to the Apache Software Foundation (ASF) under one
-or more contributor license agreements.  See the NOTICE file
-distributed with this work for additional information
-regarding copyright ownership.  The ASF licenses this file
-to you under the Apache License, Version 2.0 (the
-"License"); you may not use this file except in compliance
-with the License.  You may obtain a copy of the License at
-
-  http://www.apache.org/licenses/LICENSE-2.0
-
-Unless required by applicable law or agreed to in writing,
-software distributed under the License is distributed on an
-"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-KIND, either express or implied.  See the License for the
-specific language governing permissions and limitations
-under the License.
-*/
-package org.apache.plc4x.simulator.server.s7;
-
-import io.netty.bootstrap.ServerBootstrap;
-import io.netty.channel.*;
-import io.netty.channel.nio.NioEventLoopGroup;
-import io.netty.channel.socket.SocketChannel;
-import io.netty.channel.socket.nio.NioServerSocketChannel;
-import org.apache.plc4x.simulator.server.s7.protocol.S7Step7Protocol;
-import org.apache.plc4x.simulator.server.s7.protocol.S7Step7ServerProtocol;
-
-public class S7Server {
-
-    private static final int ISO_ON_TCP_PORT = 102;
-
-    private EventLoopGroup loopGroup;
-    private EventLoopGroup workerGroup;
-
-    public void start() throws Exception {
-        if(loopGroup != null) {
-            return;
-        }
-
-        loopGroup = new NioEventLoopGroup();
-        workerGroup = new NioEventLoopGroup();
-
-        ServerBootstrap bootstrap = new ServerBootstrap();
-        bootstrap.group(loopGroup, workerGroup)
-            .channel(NioServerSocketChannel.class)
-            .childHandler(new ChannelInitializer<SocketChannel>() {
-                @Override
-                public void initChannel(SocketChannel channel) {
-                    ChannelPipeline pipeline = channel.pipeline();
-                    pipeline.addLast(new S7Step7Protocol());
-                    pipeline.addLast(new S7Step7ServerProtocol());
-                }
-            }).option(ChannelOption.SO_BACKLOG, 128)
-            .childOption(ChannelOption.SO_KEEPALIVE, true);
-
-        bootstrap.bind(ISO_ON_TCP_PORT).sync();
-    }
-
-    public void stop() {
-        if(workerGroup == null) {
-            return;
-        }
-
-        workerGroup.shutdownGracefully();
-        loopGroup.shutdownGracefully();
-    }
-
-}
diff --git a/sandbox/plc-simulator/src/main/java/org/apache/plc4x/simulator/server/s7/S7ServerModule.java b/sandbox/plc-simulator/src/main/java/org/apache/plc4x/simulator/server/s7/S7ServerModule.java
index b067305..ed1b160 100644
--- a/sandbox/plc-simulator/src/main/java/org/apache/plc4x/simulator/server/s7/S7ServerModule.java
+++ b/sandbox/plc-simulator/src/main/java/org/apache/plc4x/simulator/server/s7/S7ServerModule.java
@@ -18,15 +18,25 @@ under the License.
 */
 package org.apache.plc4x.simulator.server.s7;
 
+import io.netty.bootstrap.ServerBootstrap;
+import io.netty.channel.ChannelInitializer;
+import io.netty.channel.ChannelOption;
+import io.netty.channel.ChannelPipeline;
+import io.netty.channel.EventLoopGroup;
+import io.netty.channel.nio.NioEventLoopGroup;
+import io.netty.channel.socket.SocketChannel;
+import io.netty.channel.socket.nio.NioServerSocketChannel;
+import org.apache.plc4x.java.s7.protocol.S7Step7Protocol;
+import org.apache.plc4x.simulator.exceptions.SimulatorExcepiton;
 import org.apache.plc4x.simulator.server.ServerModule;
+import org.apache.plc4x.simulator.server.s7.protocol.S7Step7ServerAdapter;
 
 public class S7ServerModule implements ServerModule {
 
-    private S7Server server;
+    private static final int ISO_ON_TCP_PORT = 102;
 
-    public S7ServerModule() {
-        this.server = new S7Server();
-    }
+    private EventLoopGroup loopGroup;
+    private EventLoopGroup workerGroup;
 
     @Override
     public String getName() {
@@ -34,22 +44,43 @@ public class S7ServerModule implements ServerModule {
     }
 
     @Override
-    public void start() {
+    public void start() throws SimulatorExcepiton {
+        if(loopGroup != null) {
+            return;
+        }
 
         try {
-            server.start();
-        } catch(Exception e) {
-            e.printStackTrace();
+            loopGroup = new NioEventLoopGroup();
+            workerGroup = new NioEventLoopGroup();
+
+            ServerBootstrap bootstrap = new ServerBootstrap();
+            bootstrap.group(loopGroup, workerGroup)
+                .channel(NioServerSocketChannel.class)
+                .childHandler(new ChannelInitializer<SocketChannel>() {
+                    @Override
+                    public void initChannel(SocketChannel channel) {
+                        ChannelPipeline pipeline = channel.pipeline();
+                        pipeline.addLast(new S7Step7Protocol());
+                        pipeline.addLast(new S7Step7ServerAdapter());
+                    }
+                }).option(ChannelOption.SO_BACKLOG, 128)
+                .childOption(ChannelOption.SO_KEEPALIVE, true);
+
+            bootstrap.bind(ISO_ON_TCP_PORT).sync();
+        } catch (InterruptedException e) {
+            Thread.currentThread().interrupt();
+            throw new SimulatorExcepiton(e);
         }
     }
 
     @Override
     public void stop() {
-        try {
-            server.stop();
-        } catch(Exception e) {
-            e.printStackTrace();
+        if(workerGroup == null) {
+            return;
         }
+
+        workerGroup.shutdownGracefully();
+        loopGroup.shutdownGracefully();
     }
 
 }
diff --git a/sandbox/plc-simulator/src/main/java/org/apache/plc4x/simulator/server/s7/protocol/S7Step7ServerProtocol.java b/sandbox/plc-simulator/src/main/java/org/apache/plc4x/simulator/server/s7/protocol/S7Step7ServerAdapter.java
similarity index 82%
rename from sandbox/plc-simulator/src/main/java/org/apache/plc4x/simulator/server/s7/protocol/S7Step7ServerProtocol.java
rename to sandbox/plc-simulator/src/main/java/org/apache/plc4x/simulator/server/s7/protocol/S7Step7ServerAdapter.java
index a166538..46a4191 100644
--- a/sandbox/plc-simulator/src/main/java/org/apache/plc4x/simulator/server/s7/protocol/S7Step7ServerProtocol.java
+++ b/sandbox/plc-simulator/src/main/java/org/apache/plc4x/simulator/server/s7/protocol/S7Step7ServerAdapter.java
@@ -24,9 +24,9 @@ import org.apache.plc4x.java.s7.readwrite.types.*;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-public class S7Step7ServerProtocol extends ChannelInboundHandlerAdapter {
+public class S7Step7ServerAdapter extends ChannelInboundHandlerAdapter {
 
-    private static final Logger LOGGER = LoggerFactory.getLogger(S7Step7ServerProtocol.class);
+    private static final Logger LOGGER = LoggerFactory.getLogger(S7Step7ServerAdapter.class);
 
     private State state = State.INITIAL;
 
@@ -52,9 +52,9 @@ public class S7Step7ServerProtocol extends ChannelInboundHandlerAdapter {
     public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
         if(msg instanceof TPKTPacket) {
             TPKTPacket packet = (TPKTPacket) msg;
+            final COTPPacket cotpPacket = packet.getPayload();
             switch (state) {
                 case INITIAL: {
-                    final COTPPacket cotpPacket = packet.getPayload();
                     if (!(cotpPacket instanceof COTPPacketConnectionRequest)) {
                         LOGGER.error("Expecting COTP Connection-Request");
                         return;
@@ -64,7 +64,7 @@ public class S7Step7ServerProtocol extends ChannelInboundHandlerAdapter {
                     COTPPacketConnectionRequest cotpConnectionRequest = (COTPPacketConnectionRequest) cotpPacket;
                     for (COTPParameter parameter : cotpConnectionRequest.getParameters()) {
                         if (parameter instanceof COTPParameterCalledTsap) {
-                            COTPParameterCalledTsap calledTsapParameter = (COTPParameterCalledTsap) parameter;
+                            // this is actually ignored as it doesn't contain any information.
                         } else if (parameter instanceof COTPParameterCallingTsap) {
                             COTPParameterCallingTsap callingTsapParameter = (COTPParameterCallingTsap) parameter;
                             remoteTsapId = callingTsapParameter.getTsapId();
@@ -72,14 +72,15 @@ public class S7Step7ServerProtocol extends ChannelInboundHandlerAdapter {
                             COTPParameterTpduSize tpduSizeParameter = (COTPParameterTpduSize) parameter;
                             proposedTpduSize = tpduSizeParameter.getTpduSize();
                         } else {
-                            LOGGER.error(
-                                "Unexpected COTP Connection-Request Parameter " + parameter.getClass().getName());
+                            LOGGER.error(String.format("Unexpected COTP Connection-Request Parameter %s",
+                                parameter.getClass().getName()));
                             return;
                         }
                     }
 
                     remoteReference = cotpConnectionRequest.getSourceReference();
                     protocolClass = cotpConnectionRequest.getProtocolClass();
+                    assert proposedTpduSize != null;
                     tpduSize = (proposedTpduSize.getSizeInBytes() > maxTpduSize.getSizeInBytes()) ? maxTpduSize : proposedTpduSize;
 
                     // Prepare a response and send it back to the remote.
@@ -95,7 +96,6 @@ public class S7Step7ServerProtocol extends ChannelInboundHandlerAdapter {
                     break;
                 }
                 case COTP_CONNECTED: {
-                    final COTPPacket cotpPacket = packet.getPayload();
                     if (!(cotpPacket instanceof COTPPacketData)) {
                         LOGGER.error("Expecting COTP Data packet");
                         return;
@@ -133,7 +133,6 @@ public class S7Step7ServerProtocol extends ChannelInboundHandlerAdapter {
                     break;
                 }
                 case S7_CONNECTED: {
-                    final COTPPacket cotpPacket = packet.getPayload();
                     if (!(cotpPacket instanceof COTPPacketData)) {
                         LOGGER.error("Expecting COTP Data packet");
                         return;
@@ -177,7 +176,7 @@ public class S7Step7ServerProtocol extends ChannelInboundHandlerAdapter {
 
                                                 S7PayloadUserDataItemCpuFunctionReadSzlResponse readSzlResponsePayload =
                                                     new S7PayloadUserDataItemCpuFunctionReadSzlResponse(
-                                                        (short) 0xFF, DataTransportSize.OCTET_STRING, szlId,
+                                                        (short) 0xFF, PayloadSize.OCTET_STRING, szlId,
                                                         readSzlRequestPayload.getSzlIndex(), items);
 
                                                 S7ParameterUserDataItem[] responseParameterItems =
@@ -207,14 +206,42 @@ public class S7Step7ServerProtocol extends ChannelInboundHandlerAdapter {
                         } else {
                             LOGGER.error("Unsupported type of S7MessageUserData parameter " +
                                 s7Parameter.getClass().getName());
-                            return;
                         }
                     } else {
-                        LOGGER.error("Unsupported type of message " + payload.getClass().getName());
-                        return;
+                        if(cotpPacket.getPayload() instanceof S7MessageRequest) {
+                            S7MessageRequest request = (S7MessageRequest) cotpPacket.getPayload();
+                            if(request.getParameter() instanceof S7ParameterReadVarRequest) {
+                                S7ParameterReadVarRequest readVarRequestParameter =
+                                    (S7ParameterReadVarRequest) request.getParameter();
+                                final S7VarRequestParameterItem[] items = readVarRequestParameter.getItems();
+                                for (S7VarRequestParameterItem item : items) {
+                                    if(item instanceof S7VarRequestParameterItemAddress) {
+                                        S7VarRequestParameterItemAddress address =
+                                            (S7VarRequestParameterItemAddress) item;
+                                        final S7Address address1 = address.getAddress();
+                                        if(address1 instanceof S7AddressAny) {
+                                            S7AddressAny addressAny = (S7AddressAny) address1;
+
+                                        }
+                                    }
+                                }
+                            }
+                            else if(request.getParameter() instanceof S7ParameterWriteVarRequest) {
+                                S7ParameterWriteVarRequest writeVarRequestParameter =
+                                    (S7ParameterWriteVarRequest) request.getParameter();
+
+                            } else {
+                                LOGGER.error("Unsupported type of S7MessageRequest parameter " +
+                                    request.getParameter().getClass().getName());
+                            }
+                        } else {
+                            LOGGER.error("Unsupported type of message " + payload.getClass().getName());
+                        }
                     }
                     break;
                 }
+                default:
+                    throw new IllegalStateException("Unexpected value: " + state);
             }
         }
     }
diff --git a/sandbox/test-java-s7-driver/pom.xml b/sandbox/test-java-s7-driver/pom.xml
index f5985b6..98bca1d 100644
--- a/sandbox/test-java-s7-driver/pom.xml
+++ b/sandbox/test-java-s7-driver/pom.xml
@@ -62,6 +62,16 @@
       <version>0.5.0-SNAPSHOT</version>
     </dependency>
     <dependency>
+      <groupId>org.apache.plc4x</groupId>
+      <artifactId>plc4j-protocol-driver-base</artifactId>
+      <version>0.5.0-SNAPSHOT</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.plc4x</groupId>
+      <artifactId>plc4j-protocol-driver-base-tcp</artifactId>
+      <version>0.5.0-SNAPSHOT</version>
+    </dependency>
+    <dependency>
       <groupId>com.fasterxml.jackson.core</groupId>
       <artifactId>jackson-annotations</artifactId>
     </dependency>
diff --git a/sandbox/test-java-s7-driver/src/main/java/org/apache/plc4x/java/s7/S7PlcDriver.java b/sandbox/test-java-s7-driver/src/main/java/org/apache/plc4x/java/s7/S7PlcDriver.java
new file mode 100644
index 0000000..d967959
--- /dev/null
+++ b/sandbox/test-java-s7-driver/src/main/java/org/apache/plc4x/java/s7/S7PlcDriver.java
@@ -0,0 +1,75 @@
+/*
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements.  See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership.  The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License.  You may obtain a copy of the License at
+
+  http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied.  See the License for the
+specific language governing permissions and limitations
+under the License.
+*/
+package org.apache.plc4x.java.s7;
+
+import org.apache.plc4x.java.PlcDriverManager;
+import org.apache.plc4x.java.api.PlcConnection;
+import org.apache.plc4x.java.api.authentication.PlcAuthentication;
+import org.apache.plc4x.java.api.exceptions.PlcConnectionException;
+import org.apache.plc4x.java.s7.connection.S7PlcConnection;
+import org.apache.plc4x.java.spi.PlcDriver;
+
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+public class S7PlcDriver implements PlcDriver {
+
+    private static final Pattern S7_URI_PATTERN = Pattern.compile("^s7://(?<host>.*)/(?<rack>\\d{1,4})/(?<slot>\\d{1,4})(?<params>\\?.*)?");
+
+    @Override
+    public String getProtocolCode() {
+        return "s7";
+    }
+
+    @Override
+    public String getProtocolName() {
+        return "Siemens S7 (Basic)";
+    }
+
+    @Override
+    public PlcConnection connect(String url) throws PlcConnectionException {
+        Matcher matcher = S7_URI_PATTERN.matcher(url);
+        if (!matcher.matches()) {
+            throw new PlcConnectionException(
+                "Connection url doesn't match the format 's7://{host|ip}/{rack}/{slot}'");
+        }
+        String host = matcher.group("host");
+
+        int rack = Integer.parseInt(matcher.group("rack"));
+        int slot = Integer.parseInt(matcher.group("slot"));
+        String params = matcher.group("params") != null ? matcher.group("params").substring(1) : null;
+
+        try {
+            InetAddress serverInetAddress = InetAddress.getByName(host);
+            return new S7PlcConnection(serverInetAddress, rack, slot, params);
+        } catch (UnknownHostException e) {
+            throw new PlcConnectionException("Error parsing address", e);
+        } catch (Exception e) {
+            throw new PlcConnectionException("Error connecting to host", e);
+        }
+    }
+
+    @Override
+    public PlcConnection connect(String url, PlcAuthentication authentication) throws PlcConnectionException {
+        throw new PlcConnectionException("Basic S7 connections don't support authentication.");
+    }
+
+}
diff --git a/sandbox/test-java-s7-driver/src/main/java/org/apache/plc4x/java/s7/connection/S7PlcConnection.java b/sandbox/test-java-s7-driver/src/main/java/org/apache/plc4x/java/s7/connection/S7PlcConnection.java
new file mode 100644
index 0000000..aa02626
--- /dev/null
+++ b/sandbox/test-java-s7-driver/src/main/java/org/apache/plc4x/java/s7/connection/S7PlcConnection.java
@@ -0,0 +1,101 @@
+/*
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements.  See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership.  The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License.  You may obtain a copy of the License at
+
+  http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied.  See the License for the
+specific language governing permissions and limitations
+under the License.
+*/
+package org.apache.plc4x.java.s7.connection;
+
+import io.netty.channel.*;
+import org.apache.plc4x.java.api.exceptions.PlcInvalidFieldException;
+import org.apache.plc4x.java.api.messages.PlcReadRequest;
+import org.apache.plc4x.java.api.messages.PlcReadResponse;
+import org.apache.plc4x.java.api.model.PlcField;
+import org.apache.plc4x.java.base.connection.ChannelFactory;
+import org.apache.plc4x.java.base.connection.DefaultPlcFieldHandler;
+import org.apache.plc4x.java.base.connection.NettyPlcConnection;
+import org.apache.plc4x.java.base.connection.TcpSocketChannelFactory;
+import org.apache.plc4x.java.base.events.ConnectedEvent;
+import org.apache.plc4x.java.base.messages.DefaultPlcReadRequest;
+import org.apache.plc4x.java.base.messages.PlcReader;
+import org.apache.plc4x.java.s7.protocol.S7Step7ClientAdapter;
+import org.apache.plc4x.java.s7.protocol.S7Step7Plc4xAdapter;
+import org.apache.plc4x.java.s7.protocol.S7Step7Protocol;
+
+import java.net.InetAddress;
+import java.util.concurrent.CompletableFuture;
+
+public class S7PlcConnection extends NettyPlcConnection implements PlcReader {
+
+    private static final int ISO_ON_TCP_PORT = 102;
+
+    public S7PlcConnection(InetAddress address, int rack, int slot, String params) {
+        this(new TcpSocketChannelFactory(address, ISO_ON_TCP_PORT), rack, slot, params);
+    }
+
+    public S7PlcConnection(ChannelFactory channelFactory, int rack, int slot, String param) {
+        super(channelFactory, false);
+    }
+
+    @Override
+    protected ChannelHandler getChannelHandler(CompletableFuture<Void> sessionSetupCompleteFuture) {
+        return new ChannelInitializer() {
+            @Override
+            protected void initChannel(Channel channel) {
+                // Build the protocol stack for communicating with the s7 protocol.
+                ChannelPipeline pipeline = channel.pipeline();
+                pipeline.addLast(new ChannelInboundHandlerAdapter() {
+                    @Override
+                    public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
+                        if (evt instanceof ConnectedEvent) {
+                            sessionSetupCompleteFuture.complete(null);
+                        } else {
+                            super.userEventTriggered(ctx, evt);
+                        }
+                    }
+                });
+                pipeline.addLast(new S7Step7Protocol());
+                pipeline.addLast(new S7Step7ClientAdapter());
+                pipeline.addLast(new S7Step7Plc4xAdapter());
+            }
+        };
+    }
+
+    @Override
+    public boolean canRead() {
+        return true;
+    }
+
+    @Override
+    public PlcReadRequest.Builder readRequestBuilder() {
+        return new DefaultPlcReadRequest.Builder(this, new DefaultPlcFieldHandler() {
+            @Override
+            public PlcField createField(String fieldQuery) throws PlcInvalidFieldException {
+                return new PlcField() {
+                    @Override
+                    public Class<?> getDefaultJavaType() {
+                        return String.class;
+                    }
+                };
+            }
+        });
+    }
+
+    @Override
+    public CompletableFuture<PlcReadResponse> read(PlcReadRequest readRequest) {
+        return new CompletableFuture<>();
+    }
+
+}
diff --git a/sandbox/plc-simulator/src/main/java/org/apache/plc4x/simulator/server/s7/S7ServerModule.java b/sandbox/test-java-s7-driver/src/main/java/org/apache/plc4x/java/s7/protocol/S7Step7ClientAdapter.java
similarity index 56%
copy from sandbox/plc-simulator/src/main/java/org/apache/plc4x/simulator/server/s7/S7ServerModule.java
copy to sandbox/test-java-s7-driver/src/main/java/org/apache/plc4x/java/s7/protocol/S7Step7ClientAdapter.java
index b067305..1904beb 100644
--- a/sandbox/plc-simulator/src/main/java/org/apache/plc4x/simulator/server/s7/S7ServerModule.java
+++ b/sandbox/test-java-s7-driver/src/main/java/org/apache/plc4x/java/s7/protocol/S7Step7ClientAdapter.java
@@ -16,40 +16,25 @@ KIND, either express or implied.  See the License for the
 specific language governing permissions and limitations
 under the License.
 */
-package org.apache.plc4x.simulator.server.s7;
+package org.apache.plc4x.java.s7.protocol;
 
-import org.apache.plc4x.simulator.server.ServerModule;
+import io.netty.channel.ChannelHandlerContext;
+import org.apache.plc4x.java.base.PlcMessageToMessageCodec;
+import org.apache.plc4x.java.base.messages.PlcRequestContainer;
+import org.apache.plc4x.java.s7.readwrite.S7Message;
 
-public class S7ServerModule implements ServerModule {
+import java.util.List;
 
-    private S7Server server;
-
-    public S7ServerModule() {
-        this.server = new S7Server();
-    }
-
-    @Override
-    public String getName() {
-        return "S7-STEP7";
-    }
+public class S7Step7ClientAdapter extends PlcMessageToMessageCodec<S7Message, PlcRequestContainer> {
 
     @Override
-    public void start() {
+    protected void encode(ChannelHandlerContext ctx, PlcRequestContainer msg, List<Object> out) throws Exception {
 
-        try {
-            server.start();
-        } catch(Exception e) {
-            e.printStackTrace();
-        }
     }
 
     @Override
-    public void stop() {
-        try {
-            server.stop();
-        } catch(Exception e) {
-            e.printStackTrace();
-        }
+    protected void decode(ChannelHandlerContext ctx, S7Message msg, List<Object> out) throws Exception {
+
     }
 
 }
diff --git a/sandbox/plc-simulator/src/main/java/org/apache/plc4x/simulator/server/s7/S7ServerModule.java b/sandbox/test-java-s7-driver/src/main/java/org/apache/plc4x/java/s7/protocol/S7Step7Plc4xAdapter.java
similarity index 56%
copy from sandbox/plc-simulator/src/main/java/org/apache/plc4x/simulator/server/s7/S7ServerModule.java
copy to sandbox/test-java-s7-driver/src/main/java/org/apache/plc4x/java/s7/protocol/S7Step7Plc4xAdapter.java
index b067305..5bd694f 100644
--- a/sandbox/plc-simulator/src/main/java/org/apache/plc4x/simulator/server/s7/S7ServerModule.java
+++ b/sandbox/test-java-s7-driver/src/main/java/org/apache/plc4x/java/s7/protocol/S7Step7Plc4xAdapter.java
@@ -16,40 +16,25 @@ KIND, either express or implied.  See the License for the
 specific language governing permissions and limitations
 under the License.
 */
-package org.apache.plc4x.simulator.server.s7;
+package org.apache.plc4x.java.s7.protocol;
 
-import org.apache.plc4x.simulator.server.ServerModule;
+import io.netty.channel.ChannelHandlerContext;
+import org.apache.plc4x.java.base.PlcMessageToMessageCodec;
+import org.apache.plc4x.java.base.messages.PlcRequestContainer;
+import org.apache.plc4x.java.s7.readwrite.S7Message;
 
-public class S7ServerModule implements ServerModule {
+import java.util.List;
 
-    private S7Server server;
-
-    public S7ServerModule() {
-        this.server = new S7Server();
-    }
-
-    @Override
-    public String getName() {
-        return "S7-STEP7";
-    }
+public class S7Step7Plc4xAdapter extends PlcMessageToMessageCodec<S7Message, PlcRequestContainer> {
 
     @Override
-    public void start() {
+    protected void encode(ChannelHandlerContext ctx, PlcRequestContainer msg, List<Object> out) throws Exception {
 
-        try {
-            server.start();
-        } catch(Exception e) {
-            e.printStackTrace();
-        }
     }
 
     @Override
-    public void stop() {
-        try {
-            server.stop();
-        } catch(Exception e) {
-            e.printStackTrace();
-        }
+    protected void decode(ChannelHandlerContext ctx, S7Message msg, List<Object> out) throws Exception {
+
     }
 
 }
diff --git a/sandbox/plc-simulator/src/main/java/org/apache/plc4x/simulator/server/s7/protocol/S7Step7Protocol.java b/sandbox/test-java-s7-driver/src/main/java/org/apache/plc4x/java/s7/protocol/S7Step7Protocol.java
similarity index 98%
rename from sandbox/plc-simulator/src/main/java/org/apache/plc4x/simulator/server/s7/protocol/S7Step7Protocol.java
rename to sandbox/test-java-s7-driver/src/main/java/org/apache/plc4x/java/s7/protocol/S7Step7Protocol.java
index f79b3bd..239f02e 100644
--- a/sandbox/plc-simulator/src/main/java/org/apache/plc4x/simulator/server/s7/protocol/S7Step7Protocol.java
+++ b/sandbox/test-java-s7-driver/src/main/java/org/apache/plc4x/java/s7/protocol/S7Step7Protocol.java
@@ -16,7 +16,7 @@ KIND, either express or implied.  See the License for the
 specific language governing permissions and limitations
 under the License.
 */
-package org.apache.plc4x.simulator.server.s7.protocol;
+package org.apache.plc4x.java.s7.protocol;
 
 import io.netty.buffer.ByteBuf;
 import org.apache.plc4x.java.base.GeneratedDriverByteToMessageCodec;
diff --git a/sandbox/test-java-s7-driver/src/main/resources/META-INF/services/org.apache.plc4x.java.spi.PlcDriver b/sandbox/test-java-s7-driver/src/main/resources/META-INF/services/org.apache.plc4x.java.spi.PlcDriver
new file mode 100644
index 0000000..0998600
--- /dev/null
+++ b/sandbox/test-java-s7-driver/src/main/resources/META-INF/services/org.apache.plc4x.java.spi.PlcDriver
@@ -0,0 +1,19 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+org.apache.plc4x.java.s7.S7PlcDriver


[plc4x] 02/03: - Tried to clean up in the S7 mspec regarding the TransportSize (It turned out that multiple values resulted in the same transport sizes, I therefore split up everything into ParameterSize, PayloadSize and a Types type that maps the other two)

Posted by cd...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 30821ccfdebe8c34016fc73884b0807416f2e873
Author: Christofer Dutz <ch...@c-ware.de>
AuthorDate: Mon Oct 14 17:59:55 2019 +0200

    - Tried to clean up in the S7 mspec regarding the TransportSize (It turned out that multiple values resulted in the same transport sizes, I therefore split up everything into ParameterSize, PayloadSize and a Types type that maps the other two)
---
 .../s7/src/main/resources/protocols/s7/s7.mspec    | 87 +++++++++++++---------
 1 file changed, 50 insertions(+), 37 deletions(-)

diff --git a/protocols/s7/src/main/resources/protocols/s7/s7.mspec b/protocols/s7/src/main/resources/protocols/s7/s7.mspec
index 31b588c..21f2db8 100644
--- a/protocols/s7/src/main/resources/protocols/s7/s7.mspec
+++ b/protocols/s7/src/main/resources/protocols/s7/s7.mspec
@@ -162,7 +162,7 @@
     [discriminator uint 8 'addressType']
     [typeSwitch 'addressType'
         ['0x10' S7AddressAny
-            [enum     TransportSize 'transportSize']
+            [enum     ParameterSize 'transportSize']
             [simple   uint 16       'numberOfElements']
             [simple   uint 16       'dbNumber']
             [enum     MemoryArea    'area']
@@ -228,11 +228,11 @@
 
 // This is actually not quite correct as depending pon the transportSize the length is either defined in bits or bytes.
 [type 'S7VarPayloadDataItem'
-    [simple  uint 8             'returnCode']
-    [enum    DataTransportSize  'transportSize']
-    [simple  uint 16            'dataLength']
-    [array   uint 8             'data' count 'dataLength / 8']
-    [padding uint 8             'pad' '0x00' '(dataLength / 8) % 2 == 1']
+    [simple  uint 8       'returnCode']
+    [enum    PayloadSize  'transportSize']
+    [simple  uint 16      'dataLength']
+    [array   uint 8       'data' count 'dataLength / 8']
+    [padding uint 8       'pad' '0x00' '(dataLength / 8) % 2 == 1']
 ]
 
 [type 'S7VarPayloadStatusItem'
@@ -240,11 +240,11 @@
 ]
 
 [discriminatedType 'S7PayloadUserDataItem' [uint 4 'cpuFunctionType']
-    [simple   uint 8            'returnCode']
-    [enum     DataTransportSize 'transportSize']
-    [implicit uint 16           'dataLength' 'lengthInBytes - 4']
-    [simple   SzlId             'szlId']
-    [simple   uint 16           'szlIndex']
+    [simple   uint 8      'returnCode']
+    [enum     PayloadSize 'transportSize']
+    [implicit uint 16     'dataLength' 'lengthInBytes - 4']
+    [simple   SzlId       'szlId']
+    [simple   uint 16     'szlIndex']
     [typeSwitch 'cpuFunctionType'
         ['0x04' S7PayloadUserDataItemCpuFunctionReadSzlRequest
         ]
@@ -275,7 +275,20 @@
     ['0x40' CLASS_4]
 ]
 
-[enum int 8 'DataTransportSize' [bit 'sizeInBits']
+[enum int 8 'ParameterSize' [uint 8 'sizeInBytes']
+    ['0x01' BOOL                     ['1']]
+    ['0x02' BYTE                     ['1']]
+    ['0x03' CHAR                     ['1']]
+    ['0x04' WORD                     ['2']]
+    ['0x05' INT                      ['2']]
+    ['0x06' DWORD                    ['4']]
+    ['0x07' DINT                     ['4']]
+    ['0x08' REAL                     ['4']]
+    ['0x0B' TIME                     ['4']]
+    ['0x13' WCHAR                    ['2']]
+]
+
+[enum int 8 'PayloadSize' [bit 'sizeInBits']
     ['0x00' NULL            ['false']]
     ['0x03' BIT             ['true']]
     ['0x04' BYTE_WORD_DWORD ['true']]
@@ -285,31 +298,31 @@
     ['0x09' OCTET_STRING    ['false']]
 ]
 
-[enum int 8 'TransportSize'  [uint 8 'sizeCode', uint 8 'sizeInBytes', TransportSize 'baseType', DataTransportSize 'dataTransportSize']
-    ['0x01' BOOL             ['X'              , '1'                 , 'null'                  , 'DataTransportSize.BIT']]
-    ['0x02' BYTE             ['B'              , '1'                 , 'null'                  , 'DataTransportSize.BYTE_WORD_DWORD']]
-    ['0x04' WORD             ['W'              , '2'                 , 'null'                  , 'DataTransportSize.BYTE_WORD_DWORD']]
-    ['0x06' DWORD            ['D'              , '4'                 , 'WORD'                  , 'DataTransportSize.BYTE_WORD_DWORD']]
-    ['0x00' LWORD            ['X'              , '8'                 , 'null'                  , 'null']]
-    ['0x05' INT              ['W'              , '2'                 , 'null'                  , 'DataTransportSize.BYTE_WORD_DWORD']]
-    ['0x05' UINT             ['W'              , '2'                 , 'INT'                   , 'DataTransportSize.BYTE_WORD_DWORD']]
-    ['0x02' SINT             ['B'              , '1'                 , 'INT'                   , 'DataTransportSize.BYTE_WORD_DWORD']]
-    ['0x02' USINT            ['B'              , '1'                 , 'INT'                   , 'DataTransportSize.BYTE_WORD_DWORD']]
-    ['0x07' DINT             ['D'              , '4'                 , 'INT'                   , 'DataTransportSize.BYTE_WORD_DWORD']]
-    ['0x07' UDINT            ['D'              , '4'                 , 'INT'                   , 'DataTransportSize.BYTE_WORD_DWORD']]
-    ['0x00' LINT             ['X'              , '8'                 , 'INT'                   , 'null']]
-    ['0x00' ULINT            ['X'              , '16'                , 'INT'                   , 'null']]
-    ['0x08' REAL             ['D'              , '4'                 , 'null'                  , 'DataTransportSize.BYTE_WORD_DWORD']]
-    ['0x00' LREAL            ['X'              , '8'                 , 'REAL'                  , 'null']]
-    ['0x0B' TIME             ['X'              , '4'                 , 'null'                  , 'null']]
-    ['0x00' LTIME            ['X'              , '8'                 , 'TIME'                  , 'null']]
-    ['0x02' DATE             ['X'              , '2'                 , 'null'                  , 'DataTransportSize.BYTE_WORD_DWORD']]
-    ['0x02' TIME_OF_DAY      ['X'              , '4'                 , 'null'                  , 'DataTransportSize.BYTE_WORD_DWORD']]
-    ['0x02' DATE_AND_TIME    ['X'              , '8'                 , 'null'                  , 'null']]
-    ['0x03' CHAR             ['B'              , '1'                 , 'null'                  , 'DataTransportSize.BYTE_WORD_DWORD']]
-    ['0x13' WCHAR            ['X'              , '2'                 , 'null'                  , 'null']]
-    ['0x03' STRING           ['X'              , '1'                 , 'null'                  , 'DataTransportSize.BYTE_WORD_DWORD']]
-    ['0x00' WSTRING          ['X'              , '1'                 , 'null'                  , 'null']]
+[enum 'Types'      [uint 8 'sizeCode', Types 'baseType', ParameterSize 'sizeInBytes', PayloadSize 'dataTransportSize']
+    [BOOL          ['X'              , 'null'          , 'ParameterSize.BOOL'       , 'PayloadSize.BIT']]
+    [BYTE          ['B'              , 'null'          , 'ParameterSize.BYTE'       , 'PayloadSize.BYTE_WORD_DWORD']]
+    [WORD          ['W'              , 'null'          , 'ParameterSize.WORD'       , 'PayloadSize.BYTE_WORD_DWORD']]
+    [DWORD         ['D'              , 'WORD'          , 'ParameterSize.DWORD'      , 'PayloadSize.BYTE_WORD_DWORD']]
+    [LWORD         ['X'              , 'null'          , 'null'                     , 'null']]
+    [INT           ['W'              , 'null'          , 'ParameterSize.INT'        , 'PayloadSize.BYTE_WORD_DWORD']]
+    [UINT          ['W'              , 'INT'           , 'ParameterSize.INT'        , 'PayloadSize.BYTE_WORD_DWORD']]
+    [SINT          ['B'              , 'INT'           , 'ParameterSize.BYTE'       , 'PayloadSize.BYTE_WORD_DWORD']]
+    [USINT         ['B'              , 'INT'           , 'ParameterSize.BYTE'       , 'PayloadSize.BYTE_WORD_DWORD']]
+    [DINT          ['D'              , 'INT'           , 'ParameterSize.DINT'       , 'PayloadSize.BYTE_WORD_DWORD']]
+    [UDINT         ['D'              , 'INT'           , 'ParameterSize.DINT'       , 'PayloadSize.BYTE_WORD_DWORD']]
+    [LINT          ['X'              , 'INT'           , 'null'                     , 'null']]
+    [ULINT         ['X'              , 'INT'           , 'null'                     , 'null']]
+    [REAL          ['D'              , 'null'          , 'ParameterSize.REAL'       , 'PayloadSize.BYTE_WORD_DWORD']]
+    [LREAL         ['X'              , 'REAL'          , 'null'                     , 'null']]
+    [TIME          ['X'              , 'null'          , 'ParameterSize.TIME'       , 'null']]
+    [LTIME         ['X'              , 'TIME'          , 'null'                     , 'null']]
+    [DATE          ['X'              , 'null'          , 'null'                     , 'PayloadSize.BYTE_WORD_DWORD']]
+    [TIME_OF_DAY   ['X'              , 'null'          , 'null'                     , 'PayloadSize.BYTE_WORD_DWORD']]
+    [DATE_AND_TIME ['X'              , 'null'          , 'null'                     , 'null']]
+    [CHAR          ['B'              , 'null'          , 'null'                     , 'PayloadSize.BYTE_WORD_DWORD']]
+    [WCHAR         ['X'              , 'null'          , 'ParameterSize.WCHAR'      , 'null']]
+    [STRING        ['X'              , 'null'          , 'ParameterSize.CHAR'       , 'PayloadSize.BYTE_WORD_DWORD']]
+    [WSTRING       ['X'              , 'null'          , 'null'                     , 'null']]
 ]
 
 [enum int 8 'MemoryArea'             [string 'shortName']