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/08/22 09:15:11 UTC
[plc4x] branch develop updated: - Added Passive mode templates and
an sandbox passive mode s7 driver
This is an automated email from the ASF dual-hosted git repository.
cdutz pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/plc4x.git
The following commit(s) were added to refs/heads/develop by this push:
new cc9c016 - Added Passive mode templates and an sandbox passive mode s7 driver
cc9c016 is described below
commit cc9c0168713ce6c7d48b5d0290f8058b990c869f
Author: Christofer Dutz <ch...@c-ware.de>
AuthorDate: Thu Aug 22 11:15:05 2019 +0200
- Added Passive mode templates and an sandbox passive mode s7 driver
---
...geOutput.java => JavaActiveLanguageOutput.java} | 4 +-
...eOutput.java => JavaPassiveLanguageOutput.java} | 17 +-
...x.plugins.codegenerator.language.LanguageOutput | 3 +-
.../{io-template.ftlh => active-io-template.ftlh} | 0
.../{io-template.ftlh => passive-io-template.ftlh} | 111 +----------
.../org/apache/plc4x/java/utils/MessageIO.java | 7 +-
.../org/apache/plc4x/java/utils/MessageInput.java | 25 +++
.../org/apache/plc4x/java/utils/MessageOutput.java | 25 +++
sandbox/pom.xml | 1 +
sandbox/test-java-passive-s7-driver/pom.xml | 91 +++++++++
.../src/test/java/BenchmarkGeneratedPassiveS7.java | 45 +++++
.../main/resources/protocols/df1/protocol.mspec | 222 ---------------------
12 files changed, 204 insertions(+), 347 deletions(-)
diff --git a/build-utils/language-java/src/main/java/org/apache/plc4x/language/java/JavaLanguageOutput.java b/build-utils/language-java/src/main/java/org/apache/plc4x/language/java/JavaActiveLanguageOutput.java
similarity index 94%
copy from build-utils/language-java/src/main/java/org/apache/plc4x/language/java/JavaLanguageOutput.java
copy to build-utils/language-java/src/main/java/org/apache/plc4x/language/java/JavaActiveLanguageOutput.java
index ba791e6..7132f41 100644
--- a/build-utils/language-java/src/main/java/org/apache/plc4x/language/java/JavaLanguageOutput.java
+++ b/build-utils/language-java/src/main/java/org/apache/plc4x/language/java/JavaActiveLanguageOutput.java
@@ -27,7 +27,7 @@ import org.apache.plc4x.plugins.codegenerator.types.definitions.ComplexTypeDefin
import java.io.*;
import java.util.*;
-public class JavaLanguageOutput extends FreemarkerLanguageOutput {
+public class JavaActiveLanguageOutput extends FreemarkerLanguageOutput {
@Override
public String getName() {
@@ -37,7 +37,7 @@ public class JavaLanguageOutput extends FreemarkerLanguageOutput {
protected List<Template> getTemplates(Configuration freemarkerConfiguration) throws IOException {
return Arrays.asList(
freemarkerConfiguration.getTemplate("templates/java/pojo-template.ftlh"),
- freemarkerConfiguration.getTemplate("templates/java/io-template.ftlh"));
+ freemarkerConfiguration.getTemplate("templates/java/active-io-template.ftlh"));
}
protected FreemarkerLanguageTemplateHelper getHelper(Map<String, ComplexTypeDefinition> types) {
diff --git a/build-utils/language-java/src/main/java/org/apache/plc4x/language/java/JavaLanguageOutput.java b/build-utils/language-java/src/main/java/org/apache/plc4x/language/java/JavaPassiveLanguageOutput.java
similarity index 77%
rename from build-utils/language-java/src/main/java/org/apache/plc4x/language/java/JavaLanguageOutput.java
rename to build-utils/language-java/src/main/java/org/apache/plc4x/language/java/JavaPassiveLanguageOutput.java
index ba791e6..3273814 100644
--- a/build-utils/language-java/src/main/java/org/apache/plc4x/language/java/JavaLanguageOutput.java
+++ b/build-utils/language-java/src/main/java/org/apache/plc4x/language/java/JavaPassiveLanguageOutput.java
@@ -19,25 +19,30 @@
package org.apache.plc4x.language.java;
-import freemarker.template.*;
+import freemarker.template.Configuration;
+import freemarker.template.Template;
+import org.apache.plc4x.language.java.JavaLanguageTemplateHelper;
import org.apache.plc4x.plugins.codegenerator.protocol.freemarker.FreemarkerLanguageOutput;
import org.apache.plc4x.plugins.codegenerator.protocol.freemarker.FreemarkerLanguageTemplateHelper;
import org.apache.plc4x.plugins.codegenerator.types.definitions.ComplexTypeDefinition;
-import java.io.*;
-import java.util.*;
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
-public class JavaLanguageOutput extends FreemarkerLanguageOutput {
+public class JavaPassiveLanguageOutput extends FreemarkerLanguageOutput {
@Override
public String getName() {
- return "Java";
+ return "Java-Passive";
}
protected List<Template> getTemplates(Configuration freemarkerConfiguration) throws IOException {
return Arrays.asList(
freemarkerConfiguration.getTemplate("templates/java/pojo-template.ftlh"),
- freemarkerConfiguration.getTemplate("templates/java/io-template.ftlh"));
+ // The passive variant doesn't generate serialize methods in the IO modules.
+ freemarkerConfiguration.getTemplate("templates/java/passive-io-template.ftlh"));
}
protected FreemarkerLanguageTemplateHelper getHelper(Map<String, ComplexTypeDefinition> types) {
diff --git a/build-utils/language-java/src/main/resources/META-INF/services/org.apache.plc4x.plugins.codegenerator.language.LanguageOutput b/build-utils/language-java/src/main/resources/META-INF/services/org.apache.plc4x.plugins.codegenerator.language.LanguageOutput
index ace91ab..7f07221 100644
--- a/build-utils/language-java/src/main/resources/META-INF/services/org.apache.plc4x.plugins.codegenerator.language.LanguageOutput
+++ b/build-utils/language-java/src/main/resources/META-INF/services/org.apache.plc4x.plugins.codegenerator.language.LanguageOutput
@@ -16,4 +16,5 @@
# specific language governing permissions and limitations
# under the License.
#
-org.apache.plc4x.language.java.JavaLanguageOutput
\ No newline at end of file
+org.apache.plc4x.language.java.JavaActiveLanguageOutput
+org.apache.plc4x.language.java.JavaPassiveLanguageOutput
\ No newline at end of file
diff --git a/build-utils/language-java/src/main/resources/templates/java/io-template.ftlh b/build-utils/language-java/src/main/resources/templates/java/active-io-template.ftlh
similarity index 100%
copy from build-utils/language-java/src/main/resources/templates/java/io-template.ftlh
copy to build-utils/language-java/src/main/resources/templates/java/active-io-template.ftlh
diff --git a/build-utils/language-java/src/main/resources/templates/java/io-template.ftlh b/build-utils/language-java/src/main/resources/templates/java/passive-io-template.ftlh
similarity index 75%
rename from build-utils/language-java/src/main/resources/templates/java/io-template.ftlh
rename to build-utils/language-java/src/main/resources/templates/java/passive-io-template.ftlh
index d6770a8..c354b00 100644
--- a/build-utils/language-java/src/main/resources/templates/java/io-template.ftlh
+++ b/build-utils/language-java/src/main/resources/templates/java/passive-io-template.ftlh
@@ -48,7 +48,7 @@ import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.*;
-public class ${typeName}IO implements MessageIO<${typeName}<#if helper.isDiscriminatedType(type)>IO.${typeName}Builder</#if>, ${typeName}> {
+public class ${typeName}IO implements MessageInput<${typeName}<#if helper.isDiscriminatedType(type)>IO.${typeName}Builder</#if>> {
private static final Logger LOGGER = LoggerFactory.getLogger(${typeName}IO.class);
@@ -281,115 +281,6 @@ public class ${typeName}IO implements MessageIO<${typeName}<#if helper.isDiscrim
</#if>
}
- public void serialize(WriteBuffer io, ${typeName} value, Object... args) throws ParseException {
-<#if type.parserArguments?has_content>
-<#list type.parserArguments as parserArgument>
- ${helper.getLanguageTypeNameForSpecType(parserArgument.type)} ${parserArgument.name} = (${helper.getLanguageTypeNameForSpecType(parserArgument.type)}) args[${parserArgument?index}];
-</#list>
-</#if>
-<#list type.fields as field>
-<#switch field.typeName>
- <#case "array">
-
- // Array Field (${field.name})
- if(value.get${field.name?cap_first}() != null) {
- for(${helper.getLanguageTypeNameForField(field)} element : value.get${field.name?cap_first}()) {
- <#if helper.isSimpleType(field.type)>
- io.${helper.getWriteBufferReadMethodCall(field.type, "element")};
- <#else>
- ${field.type.name?uncap_first}IO.serialize(io, element);
- </#if>
- }
- }
- <#break>
- <#case "checksum">
-
- // Checksum Field (${field.name}) (Calculated)
- ${helper.getLanguageTypeNameForField(field)} ${field.name} = (${helper.getLanguageTypeNameForField(field)}) (${helper.toSerializationExpression(field.checksumExpression, type.parserArguments)});
- io.${helper.getWriteBufferReadMethodCall(field.type, "(" + field.name + ")")?no_esc};
- <#break>
- <#case "const">
-
- // Const Field (${field.name})
- io.${helper.getWriteBufferReadMethodCall(field.type, field.referenceValue)};
- <#break>
- <#case "discriminator">
-
- // Discriminator Field (${field.name}) (Used as input to a switch field)
- ${helper.getLanguageTypeNameForField(field)} ${field.name} = (${helper.getLanguageTypeNameForField(field)}) value.getDiscriminatorValues()[0];
- io.${helper.getWriteBufferReadMethodCall(field.type, "(" + field.name + ")")};
- <#break>
- <#case "implicit">
-
- // Implicit Field (${field.name}) (Used for parsing, but it's value is not stored as it's implicitly given by the objects content)
- ${helper.getLanguageTypeNameForField(field)} ${field.name} = (${helper.getLanguageTypeNameForField(field)}) (${helper.toSerializationExpression(field.serializationExpression, type.parserArguments)});
- io.${helper.getWriteBufferReadMethodCall(field.type, "(" + field.name + ")")?no_esc};
- <#break>
- <#case "manualArray">
-
- // Manual Array Field (${field.name})
- if(value.get${field.name?cap_first}() != null) {
- for(${helper.getLanguageTypeNameForField(field)} element : value.get${field.name?cap_first}()) {
- ${helper.toSerializationExpression(field.serializationExpression, type.parserArguments)};
- }
- }
- <#break>
- <#case "manual">
-
- // Manual Field (${field.name})
- ${helper.getLanguageTypeNameForField(field)} ${field.name} = (${helper.getLanguageTypeNameForField(field)}) (${helper.toSerializationExpression(field.serializationExpression, type.parserArguments)});
- io.${helper.getWriteBufferReadMethodCall(field.type, "(" + field.name + ")")?no_esc};
- <#break>
- <#case "optional">
-
- // Optional Field (${field.name}) (Can be skipped, if the value is null)
- ${helper.getLanguageTypeNameForField(field)} ${field.name} = null;
- if(value.get${field.name?cap_first}() != null) {
- ${field.name} = (${helper.getLanguageTypeNameForField(field)}) value.get${field.name?cap_first}();
- <#if helper.isSimpleType(field.type)>
- io.${helper.getWriteBufferReadMethodCall(field.type, "(" + field.name + ")")};
- <#else>
- ${field.type.name?uncap_first}IO.serialize(io, ${field.name});
- </#if>
- }
- <#break>
- <#case "padding">
-
- // Padding Field (${field.name})
- boolean _${field.name}NeedsPadding = (boolean) (${helper.toSerializationExpression(field.paddingCondition, type.parserArguments)});
- if(_${field.name}NeedsPadding) {
- ${helper.getLanguageTypeNameForField(field)} _${field.name}PaddingValue = (${helper.getLanguageTypeNameForField(field)}) (${helper.toSerializationExpression(field.paddingValue, type.parserArguments)});
- io.${helper.getWriteBufferReadMethodCall(field.type, "(_" + field.name + "PaddingValue)")?no_esc};
- }
- <#break>
- <#case "reserved">
-
- // Reserved Field
- io.${helper.getWriteBufferReadMethodCall(field.type, field.referenceValue)};
- <#break>
- <#case "simple">
-
- // Simple Field (${field.name})
- ${helper.getLanguageTypeNameForField(field)} ${field.name} = (${helper.getLanguageTypeNameForField(field)}) value.get${field.name?cap_first}();
- <#if helper.isSimpleType(field.type)>
- io.${helper.getWriteBufferReadMethodCall(field.type, "(" + field.name + ")")};
- <#else>
- ${field.type.name?uncap_first}IO.serialize(io, ${field.name}<#if field.params?has_content>, <#list field.params as term>(${helper.getArgumentType(field.type, term?index)}) (${helper.toDeserializationExpression(term, type.parserArguments)})<#sep>, </#sep></#list></#if>);
- </#if>
- <#break>
- <#case "switch">
-
- // Switch field (Depending on the discriminator values, passes the instantiation to a sub-type)
- <#list field.cases as case>
- if(value instanceof ${case.name}) {
- ${case.name?uncap_first}IO.serialize(io, (${case.name}) value<#if case.parserArguments?has_content>, <#list case.parserArguments as parserArgument>${parserArgument.name}<#sep>, </#sep></#list></#if>);
- }<#sep> else </#sep>
- </#list>
- <#break>
-</#switch>
-</#list>
- }
-
private static int COUNT(Object obj) {
if(obj.getClass().isArray()) {
Object[] arr = (Object[]) obj;
diff --git a/plc4j/utils/driver-base-java/src/main/java/org/apache/plc4x/java/utils/MessageIO.java b/plc4j/utils/driver-base-java/src/main/java/org/apache/plc4x/java/utils/MessageIO.java
index 1375d1a..34e5536 100644
--- a/plc4j/utils/driver-base-java/src/main/java/org/apache/plc4x/java/utils/MessageIO.java
+++ b/plc4j/utils/driver-base-java/src/main/java/org/apache/plc4x/java/utils/MessageIO.java
@@ -16,13 +16,8 @@
specific language governing permissions and limitations
under the License.
*/
-
package org.apache.plc4x.java.utils;
-public interface MessageIO<PARSER_TYPE, SERIALIZER_TYPE> {
-
- PARSER_TYPE parse(ReadBuffer io, Object... args) throws ParseException;
-
- void serialize(WriteBuffer io, SERIALIZER_TYPE value, Object... args) throws ParseException;
+public interface MessageIO<PARSER_TYPE, SERIALIZER_TYPE> extends MessageInput<PARSER_TYPE>, MessageOutput<SERIALIZER_TYPE> {
}
diff --git a/plc4j/utils/driver-base-java/src/main/java/org/apache/plc4x/java/utils/MessageInput.java b/plc4j/utils/driver-base-java/src/main/java/org/apache/plc4x/java/utils/MessageInput.java
new file mode 100644
index 0000000..b83afa0
--- /dev/null
+++ b/plc4j/utils/driver-base-java/src/main/java/org/apache/plc4x/java/utils/MessageInput.java
@@ -0,0 +1,25 @@
+/*
+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.utils;
+
+public interface MessageInput<PARSER_TYPE> {
+
+ PARSER_TYPE parse(ReadBuffer io, Object... args) throws ParseException;
+
+}
diff --git a/plc4j/utils/driver-base-java/src/main/java/org/apache/plc4x/java/utils/MessageOutput.java b/plc4j/utils/driver-base-java/src/main/java/org/apache/plc4x/java/utils/MessageOutput.java
new file mode 100644
index 0000000..c76ade2
--- /dev/null
+++ b/plc4j/utils/driver-base-java/src/main/java/org/apache/plc4x/java/utils/MessageOutput.java
@@ -0,0 +1,25 @@
+/*
+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.utils;
+
+public interface MessageOutput<SERIALIZER_TYPE> {
+
+ void serialize(WriteBuffer io, SERIALIZER_TYPE value, Object... args) throws ParseException;
+
+}
diff --git a/sandbox/pom.xml b/sandbox/pom.xml
index 1a1f452..f4f5422 100644
--- a/sandbox/pom.xml
+++ b/sandbox/pom.xml
@@ -38,6 +38,7 @@
<module>code-gen</module>
<module>test-java-knxnetip-driver</module>
<module>test-java-s7-driver</module>
+ <module>test-java-passive-s7-driver</module>
<module>test-java-df1-driver</module>
</modules>
diff --git a/sandbox/test-java-passive-s7-driver/pom.xml b/sandbox/test-java-passive-s7-driver/pom.xml
new file mode 100644
index 0000000..dc25643
--- /dev/null
+++ b/sandbox/test-java-passive-s7-driver/pom.xml
@@ -0,0 +1,91 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+ -->
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.plc4x.sandbox</groupId>
+ <artifactId>plc4x-sandbox</artifactId>
+ <version>0.5.0-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>test-java-passive-s7-driver</artifactId>
+
+ <name>Sandbox: Test Generated S7 Driver (Passive)</name>
+
+ <build>
+ <plugins>
+ <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-passive</languageName>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.plc4x</groupId>
+ <artifactId>plc4j-utils-driver-base-java</artifactId>
+ <version>0.5.0-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>com.fasterxml.jackson.core</groupId>
+ <artifactId>jackson-annotations</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>commons-codec</groupId>
+ <artifactId>commons-codec</artifactId>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.plc4x</groupId>
+ <artifactId>plc4x-build-utils-language-java</artifactId>
+ <version>0.5.0-SNAPSHOT</version>
+ <!-- Scope is 'provided' as this way it's not shipped with the driver -->
+ <scope>provided</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.plc4x</groupId>
+ <artifactId>plc4x-protocols-s7</artifactId>
+ <version>0.5.0-SNAPSHOT</version>
+ <!-- Scope is 'provided' as this way it's not shipped with the driver -->
+ <scope>provided</scope>
+ </dependency>
+ </dependencies>
+
+</project>
diff --git a/sandbox/test-java-passive-s7-driver/src/test/java/BenchmarkGeneratedPassiveS7.java b/sandbox/test-java-passive-s7-driver/src/test/java/BenchmarkGeneratedPassiveS7.java
new file mode 100644
index 0000000..48207b7
--- /dev/null
+++ b/sandbox/test-java-passive-s7-driver/src/test/java/BenchmarkGeneratedPassiveS7.java
@@ -0,0 +1,45 @@
+/*
+ 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.
+ */
+
+import org.apache.commons.codec.binary.Hex;
+import org.apache.plc4x.javapassive.s7.TPKTPacket;
+import org.apache.plc4x.javapassive.s7.io.TPKTPacketIO;
+import org.apache.plc4x.java.utils.ReadBuffer;
+
+public class BenchmarkGeneratedPassiveS7 {
+
+ public static void main(String[] args) throws Exception {
+ byte[] rData = Hex.decodeHex("0300006702f080320100000001005600000407120a10060001032b84000160120a10020001032b840001a0120a10010001032b840001a9120a10050001032b84000150120a10020001032b84000198120a10040001032b84000140120a10020001032b84000190");
+ long start = System.currentTimeMillis();
+ int numRunsParse = 2000000;
+ TPKTPacketIO tpktPacketIO = new TPKTPacketIO();
+
+ // Benchmark the parsing code
+ TPKTPacket packet = null;
+ for(int i = 0; i < numRunsParse; i++) {
+ ReadBuffer rBuf = new ReadBuffer(rData);
+ packet = tpktPacketIO.parse(rBuf);
+ }
+ long endParsing = System.currentTimeMillis();
+
+ System.out.println("Parsed " + numRunsParse + " packets in " + (endParsing - start) + "ms");
+ System.out.println("That's " + ((float) (endParsing - start) / numRunsParse) + "ms per packet");
+ }
+
+}
diff --git a/sandbox/test-java-s7-driver/src/main/resources/protocols/df1/protocol.mspec b/sandbox/test-java-s7-driver/src/main/resources/protocols/df1/protocol.mspec
deleted file mode 100644
index 6b5749d..0000000
--- a/sandbox/test-java-s7-driver/src/main/resources/protocols/df1/protocol.mspec
+++ /dev/null
@@ -1,222 +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.
-//
-
-////////////////////////////////////////////////////////////////
-// IsoOnTcp/TPKT
-////////////////////////////////////////////////////////////////
-
-[type 'TPKTPacket'
- [const uint 8 'protocolId' '0x03']
- [reserved uint 8 '0x00']
- [reserved uint 8 '0x00']
- [implicit uint 16 'len' 'payload.lengthInBytes + 4']
- [simple COTPPacket 'payload']
-]
-
-////////////////////////////////////////////////////////////////
-// COTP
-////////////////////////////////////////////////////////////////
-
-[discriminatedType 'COTPPacket'
- [implicit uint 8 'headerLength' 'lengthInBytes - (payload.lengthInBytes + 1)']
- [discriminator uint 8 'tpduCode']
- [typeSwitch 'tpduCode'
- ['0xF0' COTPPacketData
- [simple bit 'eot']
- [simple uint 7 'tpduRef']
- ]
- ['0xE0' COTPPacketConnectionRequest
- [simple uint 16 'destinationReference']
- [simple uint 16 'sourceReference']
- [simple uint 8 'protocolClass']
- ]
- ['0xD0' COTPPacketConnectionResponse
- [simple uint 16 'destinationReference']
- [simple uint 16 'sourceReference']
- [simple uint 8 'protocolClass']
- ]
- ['0x80' COTPPacketDisconnectRequest
- [simple uint 16 'destinationReference']
- [simple uint 16 'sourceReference']
- [simple uint 8 'protocolClass']
- ]
- ['0xC0' COTPPacketDisconnectResponse
- [simple uint 16 'destinationReference']
- [simple uint 16 'sourceReference']
- ]
- ['0x70' COTPPacketTpduError
- [simple uint 16 'destinationReference']
- [simple uint 8 'rejectCause']
- ]
- ]
- [array COTPParameter 'parameters' length '(headerLength + 1) - curPos' ['(headerLength + 1) - curPos']]
- [simple S7Message 'payload']
-]
-
-[discriminatedType 'COTPParameter' [uint 8 'rest']
- [discriminator uint 8 'parameterType']
- [typeSwitch 'parameterType'
- ['0xC0' COTPParameterTpduSize
- [simple uint 8 'tpduSize']
- ]
- ['0xC1' COTPParameterCallingTsap
- [simple uint 16 'tsapId']
- ]
- ['0xC2' COTPParameterCalledTsap
- [simple uint 16 'tsapId']
- ]
- ['0xC3' COTPParameterChecksum
- [simple uint 8 'checksum']
- ]
- ['0xE0' COTPParameterDisconnectAdditionalInformation
- [array uint 8 'data' count 'rest']
- ]
- ]
-]
-
-////////////////////////////////////////////////////////////////
-// S7
-////////////////////////////////////////////////////////////////
-
-[discriminatedType 'S7Message'
- [const uint 8 'protocolId' '0x32']
- [discriminator uint 8 'messageType']
- [reserved uint 16 '0x0000']
- [simple uint 16 'tpduReference']
- [implicit uint 16 'parameterLength' 'parameter.lengthInBytes']
- [implicit uint 16 'payloadLength' 'payload.lengthInBytes']
- [typeSwitch 'messageType'
- ['0x01' S7MessageRequest
- ]
- ['0x03' S7MessageResponse
- [simple uint 8 'errorClass']
- [simple uint 8 'errorCode']
- ]
- ['0x07' S7MessageUserData
- ]
- ]
- [simple S7Parameter 'parameter' ['messageType']]
- [simple S7Payload 'payload' ['messageType', 'parameter']]
-]
-
-////////////////////////////////////////////////////////////////
-// Parameters
-
-[discriminatedType 'S7Parameter' [uint 8 'messageType']
- [discriminator uint 8 'parameterType']
- [typeSwitch 'parameterType','messageType'
- ['0xF0' S7ParameterSetupCommunication
- [reserved uint 8 '0x00']
- [simple uint 16 'maxAmqCaller']
- [simple uint 16 'maxAmqCallee']
- [simple uint 16 'pduLength']
- ]
- ['0x04','0x01' S7ParameterReadVarRequest
- [implicit uint 8 'numItems' 'COUNT(items)']
- [array S7VarRequestParameterItem 'items' count 'numItems']
- ]
- ['0x04','0x03' S7ParameterReadVarResponse
- [simple uint 8 'numItems']
- ]
- ['0x05','0x01' S7ParameterWriteVarRequest
- [implicit uint 8 'numItems' 'COUNT(items)']
- [array S7VarRequestParameterItem 'items' count 'numItems']
- ]
- ['0x05','0x03' S7ParameterWriteVarResponse
- [simple uint 8 'numItems']
- ]
- ['0x00','0x07' S7ParameterUserData
- [implicit uint 8 'numItems' 'COUNT(items)']
- [array UserDataItem 'items' count 'numItems']
- ]
- ]
-]
-
-[discriminatedType 'S7VarRequestParameterItem'
- [discriminator uint 8 'parameterItemType']
- [typeSwitch 'parameterItemType'
- ['0x12' S7VarRequestParameterItemAddress
- [implicit uint 8 'addressLength' 'address.lengthInBytes']
- [simple S7Address 'address']
- ]
- ]
-]
-
-[discriminatedType 'S7Address'
- [discriminator uint 8 'addressType']
- [typeSwitch 'addressType'
- ['0x10' S7AddressAny
- [simple uint 8 'transportSize']
- [simple uint 16 'numberOfElements']
- [simple uint 16 'dbNumber']
- [simple uint 8 'area']
- [reserved uint 5 '0x00']
- [simple uint 16 'byteAddress']
- [simple uint 3 'bitAddress']
- ]
- ]
-]
-
-// TODO: CPUFunctions still need some love ...
-[discriminatedType 'UserDataItem'
- [discriminator uint 8 'itemType']
- [typeSwitch 'itemType'
- ['0x12' UserDataItemCPUFunctions
- [implicit uint 8 'parameterLength' 'lengthInBytes']
- [simple uint 16 'cpuFunctionType']
- [simple uint 8 'subFunctionGroup']
- [simple uint 8 'sequenceNumber']
- [optional uint 8 'dataUnitReferenceNumber' 'parameterLength == 8']
- [optional uint 8 'lastDataUnit' 'parameterLength == 8']
- [optional uint 8 'errorCode' 'parameterLength == 8']
- ]
- ]
-]
-
-////////////////////////////////////////////////////////////////
-// Payloads
-
-[discriminatedType 'S7Payload' [uint 8 'messageType', S7Parameter 'parameter']
- [typeSwitch 'parameter.discriminatorValues[0]', 'messageType'
- ['0xF0' S7PayloadSetupCommunication]
- ['0x04','0x01' S7PayloadReadVarRequest]
- ['0x04','0x03' S7PayloadReadVarResponse
- [array S7VarPayloadDataItem 'items' count 'CAST(parameter, S7ParameterReadVarResponse).numItems']
- ]
- ['0x05','0x01' S7PayloadWriteVarRequest
- [array S7VarPayloadDataItem 'items' count 'COUNT(CAST(parameter, S7ParameterWriteVarRequest).items)']
- ]
- ['0x05','0x03' S7PayloadWriteVarResponse
- [array S7VarPayloadStatusItem 'items' count 'CAST(parameter, S7ParameterWriteVarResponse).numItems']
- ]
- ['0x00','0x07' S7PayloadUserData
- ]
- ]
-]
-
-[type 'S7VarPayloadDataItem'
- [simple uint 8 'returnCode']
- [simple uint 8 'transportSize']
- [simple uint 16 'dataLength']
- [array uint 8 'data' count 'dataLength']
-]
-
-[type 'S7VarPayloadStatusItem'
- [simple uint 8 'returnCode']
-]
\ No newline at end of file