This is an automated email from the ASF dual-hosted git repository.
jfeinauer pushed a commit to branch feature/plc4rs
in repository https://gitbox.apache.org/repos/asf/plc4x.git
The following commit(s) were added to refs/heads/feature/plc4rs by this push:
new 1b48148475 Extend enum generation to be able to generate TransportSize
in S7
1b48148475 is described below
commit 1b4814847562f78d5f29c82945f7c80c7db755a9
Author: julian <[email protected]>
AuthorDate: Sat Jun 4 15:40:06 2022 +0200
Extend enum generation to be able to generate TransportSize in S7
---
.../language/rust/RustLanguageTemplateHelper.java | 95 ++++++++-
.../resources/templates/rust/enum-template.rs.ftlh | 48 +++++
plc4rust/pom.xml | 3 +-
plc4rust/s7/pom.xml | 201 +++++++++++++++++++
plc4rust/src/lib.rs | 1 +
plc4rust/src/modbus/driver_type.rs | 1 +
plc4rust/src/modbus/mod.rs | 1 +
plc4rust/src/modbus/modbus_data_type.rs | 215 +++++++++++++++++++++
plc4rust/src/s7/mod.rs | 18 ++
9 files changed, 576 insertions(+), 7 deletions(-)
diff --git
a/code-generation/language-rust/src/main/java/org/apache/plc4x/language/rust/RustLanguageTemplateHelper.java
b/code-generation/language-rust/src/main/java/org/apache/plc4x/language/rust/RustLanguageTemplateHelper.java
index ce677c733b..a55a4f5666 100644
---
a/code-generation/language-rust/src/main/java/org/apache/plc4x/language/rust/RustLanguageTemplateHelper.java
+++
b/code-generation/language-rust/src/main/java/org/apache/plc4x/language/rust/RustLanguageTemplateHelper.java
@@ -21,11 +21,14 @@ package org.apache.plc4x.language.rust;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.math.NumberUtils;
import org.apache.commons.text.WordUtils;
+import
org.apache.plc4x.plugins.codegenerator.language.mspec.model.definitions.DefaultEnumTypeDefinition;
+import
org.apache.plc4x.plugins.codegenerator.language.mspec.model.references.DefaultEnumTypeReference;
import
org.apache.plc4x.plugins.codegenerator.language.mspec.model.terms.DefaultStringLiteral;
import
org.apache.plc4x.plugins.codegenerator.protocol.freemarker.BaseFreemarkerLanguageTemplateHelper;
import
org.apache.plc4x.plugins.codegenerator.protocol.freemarker.FreemarkerException;
import org.apache.plc4x.plugins.codegenerator.protocol.freemarker.Tracer;
import org.apache.plc4x.plugins.codegenerator.types.definitions.*;
+import org.apache.plc4x.plugins.codegenerator.types.enums.EnumValue;
import org.apache.plc4x.plugins.codegenerator.types.fields.*;
import org.apache.plc4x.plugins.codegenerator.types.references.*;
import org.apache.plc4x.plugins.codegenerator.types.terms.*;
@@ -42,6 +45,7 @@ import java.util.function.Function;
public class RustLanguageTemplateHelper extends
BaseFreemarkerLanguageTemplateHelper {
private final Map<String, String> options;
+ private List<TypeReference> imports = new ArrayList<>();
public RustLanguageTemplateHelper(TypeDefinition thisType, String
protocolName, String flavorName, Map<String, TypeDefinition> types,
Map<String, String> options) {
@@ -76,6 +80,18 @@ public class RustLanguageTemplateHelper extends
BaseFreemarkerLanguageTemplateHe
return getLanguageTypeNameForTypeReference(((TypedField)
field).getType(), !field.isOptionalField());
}
+ public List<String> generateImports(EnumTypeDefinition typeDefinition) {
+ // Iterate all Types to see what kind of other Enums / Objects are
references
+ List<String> imports = new ArrayList<>();
+ for (String constantName : typeDefinition.getConstantNames()) {
+ TypeReference constantType =
typeDefinition.getConstantType(constantName);
+ if (constantType instanceof DefaultEnumTypeReference) {
+ imports.add(((DefaultEnumTypeReference)
constantType).getName());
+ }
+ }
+ return imports;
+ }
+
public String getNonPrimitiveLanguageTypeNameForField(TypedField field) {
return getLanguageTypeNameForTypeReference(field.getType(), false);
}
@@ -96,6 +112,57 @@ public class RustLanguageTemplateHelper extends
BaseFreemarkerLanguageTemplateHe
return false;
}
+ public String sink(Object definition) {
+ return "";
+ }
+
+ private static boolean canParseInt(String i) {
+ // Hex number
+ if (i.startsWith("0x")) {
+ return true;
+ }
+ try {
+ Integer.parseInt(i);
+ return true;
+ } catch (NumberFormatException e) {
+ return false;
+ }
+ }
+
+ public String formatLiteral(Argument argument, List<EnumValue> values,
String literal) {
+ String innerValue = this.formatLiteral(argument.getType(), literal);
+ if (isNullable(argument, values)) {
+ if (Objects.equals(innerValue, "null")) {
+ return "None";
+ }
+ return "Some(" + innerValue + ")";
+ }
+ return innerValue;
+ }
+
+ public String formatLiteral(TypeReference type, String literal) {
+ if ("null".equals(literal)) {
+ return "null";
+ }
+ if (type instanceof DefaultEnumTypeReference) {
+ return ((DefaultEnumTypeReference) type).getName() + "::" +
literal;
+ }
+ if (!(type instanceof SimpleTypeReference)) {
+ return literal;
+ }
+ switch (((SimpleTypeReference) type).getBaseType()) {
+ case UINT:
+ if (!canParseInt(literal)) {
+ return "b'" + literal + "'";
+ }
+ break;
+ case STRING:
+ case VSTRING:
+ return "String::from(\"" + literal + "\")";
+ }
+ return literal;
+ }
+
public boolean isExactBitLength(Optional<TypeReference>
optionalTypeReference) {
TypeReference typeReference = optionalTypeReference.get();
if (isUnsigned(typeReference)) {
@@ -108,6 +175,22 @@ public class RustLanguageTemplateHelper extends
BaseFreemarkerLanguageTemplateHe
return ((SimpleTypeReference)
optionalTypeReference.get()).getSizeInBits();
}
+ public String getNullsafeLanguageTypeNameForTypeReference(Argument
argument, List<EnumValue> enumValues) {
+ String innerType =
this.getLanguageTypeNameForTypeReference(argument.getType());
+ // Check if nullable
+ if (isNullable(argument, enumValues)) {
+ return "Option<" + innerType + ">";
+ }
+ return innerType;
+ }
+
+ private boolean isNullable(Argument argument, List<EnumValue> enumValues) {
+ return enumValues.stream().anyMatch(val -> {
+ Optional<String> constant = val.getConstant(argument.getName());
+ return constant.map(s -> s.equals("null")).orElse(false);
+ });
+ }
+
public String getLanguageTypeNameForTypeReference(TypeReference
typeReference, boolean allowPrimitive) {
Objects.requireNonNull(typeReference);
if (typeReference instanceof ArrayTypeReference) {
@@ -128,9 +211,9 @@ public class RustLanguageTemplateHelper extends
BaseFreemarkerLanguageTemplateHe
SimpleTypeReference simpleTypeReference = (SimpleTypeReference)
typeReference;
switch (simpleTypeReference.getBaseType()) {
case BIT:
- return allowPrimitive ? boolean.class.getSimpleName() :
Boolean.class.getSimpleName();
+ return "bool";
case BYTE:
- return "u8";
+ return "i8";
case UINT:
IntegerTypeReference unsignedIntegerTypeReference =
(IntegerTypeReference) simpleTypeReference;
if (unsignedIntegerTypeReference.getSizeInBits() <= 8) {
@@ -166,15 +249,15 @@ public class RustLanguageTemplateHelper extends
BaseFreemarkerLanguageTemplateHe
FloatTypeReference floatTypeReference = (FloatTypeReference)
simpleTypeReference;
int sizeInBits = floatTypeReference.getSizeInBits();
if (sizeInBits <= 32) {
- return allowPrimitive ? float.class.getSimpleName() :
Float.class.getSimpleName();
+ return "f32";
}
if (sizeInBits <= 64) {
- return allowPrimitive ? double.class.getSimpleName() :
Double.class.getSimpleName();
+ return "f64";
}
- return BigDecimal.class.getSimpleName();
+ throw new UnsupportedOperationException("");
case STRING:
case VSTRING:
- return String.class.getSimpleName();
+ return "String";
case TIME:
return LocalTime.class.getSimpleName();
case DATE:
diff --git
a/code-generation/language-rust/src/main/resources/templates/rust/enum-template.rs.ftlh
b/code-generation/language-rust/src/main/resources/templates/rust/enum-template.rs.ftlh
index 2c194148e5..ee321d89c7 100644
---
a/code-generation/language-rust/src/main/resources/templates/rust/enum-template.rs.ftlh
+++
b/code-generation/language-rust/src/main/resources/templates/rust/enum-template.rs.ftlh
@@ -46,11 +46,59 @@ ${helper.packageName(protocolName, languageName,
outputFlavor)?replace(".", "/")
* under the License.
*/
// package ${helper.packageName(protocolName, languageName, outputFlavor)};
+use crate::plc4x_enum;
+use std::io::{Error, ErrorKind, Read, Write};
+use crate::{Message, NoOption, ReadBuffer, WriteBuffer};
+<#list helper.generateImports(type) as import>
+<#if type.name != import>
+<#-- File -> Struct -->
+use crate::${import}::${import};
+</#if>
+</#list>
+
+<#if type.parserArguments.isEmpty()>
plc4x_enum!
[enum <#if
helper.isExactBitLength(type.type)>${helper.getLanguageTypeNameForTypeReference(type.type.orElseThrow(),
true)}<#else>${helper.getExactBitLength(type.type)} =>
${helper.getLanguageTypeNameForTypeReference(type.type.orElseThrow(),
true)}</#if> : ${type.name}
<#list type.enumValues as enumValue>
[${enumValue.value} => ${enumValue.name}]<#sep>, </#sep>
</#list>
];
+<#else>
+pub struct ${type.name}Arguments {
+ <#list type.parserArguments.orElseThrow() as arg>
+ ${helper.sink(arg)}${arg.name}:
${helper.getNullsafeLanguageTypeNameForTypeReference(arg,
type.enumValues)}<#sep>, </#sep>
+ </#list>
+}
+
+plc4x_enum!
+[enum <#if
helper.isExactBitLength(type.type)>${helper.getLanguageTypeNameForTypeReference(type.type.orElseThrow(),
true)}<#else>${helper.getExactBitLength(type.type)} =>
${helper.getLanguageTypeNameForTypeReference(type.type.orElseThrow(),
true)}</#if> : ${type.name}
+<#list type.enumValues as enumValue>
+ [${enumValue.value} => ${enumValue.name}]<#sep>, </#sep>
+</#list>
+];
+
+impl ${type.name} {
+
+ fn get_arguments(self) -> ${type.name}Arguments {
+ match self {
+ <#list type.enumValues as enumValue>
+ ${enumValue.name} => {
+ ${type.name}Arguments {
+ <#list type.parserArguments.orElseThrow() as constant>
+ ${constant.name}: ${helper.formatLiteral(constant,
type.enumValues,
enumValue.getConstant(constant.name).orElseThrow())}<#sep>,</#sep>
+ </#list>
+ }
+ }<#sep>, </#sep>
+ </#list>
+ }
+<#-- match value {-->
+<#-- <#list type.enumValues as val>-->
+<#-- (<#list type.parserArguments.orElseThrow() as
constant>${val.getConstant(constant.name).orElseThrow()}
<#sep>,</#sep></#list>) => {}-->
+<#-- </#list>-->
+<#-- ${helper.sink(type)}-->
+<#-- <#list type.parserArguments as k,
v>${k}<#sep>,</#sep></#list>-->
+ }
+}
+</#if>
</#outputformat>
diff --git a/plc4rust/pom.xml b/plc4rust/pom.xml
index 03c113357f..ffa50a6917 100644
--- a/plc4rust/pom.xml
+++ b/plc4rust/pom.xml
@@ -35,6 +35,7 @@
<modules>
<module>modbus</module>
+ <module>s7</module>
</modules>
<!-- Disabled for now as C# support is currently not installed in Apache
SonarQube -->
@@ -144,7 +145,7 @@
<dependency>
<groupId>org.apache.plc4x</groupId>
- <artifactId>plc4x-protocols-modbus</artifactId>
+ <artifactId>plc4x-protocols-s7</artifactId>
<version>0.10.0-SNAPSHOT</version>
<!-- Scope is 'provided' as this way it's not shipped with the driver -->
<scope>provided</scope>
diff --git a/plc4rust/s7/pom.xml b/plc4rust/s7/pom.xml
new file mode 100644
index 0000000000..bdfd2027f7
--- /dev/null
+++ b/plc4rust/s7/pom.xml
@@ -0,0 +1,201 @@
+<?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</groupId>
+ <artifactId>plc4rust</artifactId>
+ <version>0.10.0-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>plc4rust-driver-s7</artifactId>
+ <name>PLC4RS: Driver: S7</name>
+ <description>Implementation of a PLC4X driver for the S7
protocol.</description>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.plc4x.plugins</groupId>
+ <artifactId>plc4x-maven-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>generate-driver</id>
+ <phase>generate-sources</phase>
+ <goals>
+ <goal>generate-driver</goal>
+ </goals>
+ <configuration>
+ <protocolName>s7</protocolName>
+ <languageName>rust</languageName>
+ <outputFlavor>read-write</outputFlavor>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.karaf.tooling</groupId>
+ <artifactId>karaf-maven-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>generate-feature-xml</id>
+ <phase>compile</phase>
+ <goals>
+ <!-- Generate the feature.xml -->
+ <goal>features-generate-descriptor</goal>
+ <!-- Check the feature.xml -->
+ <goal>verify</goal>
+ </goals>
+ <configuration>
+ <enableGeneration>true</enableGeneration>
+ <aggregateFeatures>true</aggregateFeatures>
+ </configuration>
+ </execution>
+ <execution>
+ <id>build-kar</id>
+ <phase>package</phase>
+ <goals>
+ <!--
+ Build a kar archive (Jar containing the feature.xml
+ as well as the module content and it's dependencies.
+ -->
+ <goal>kar</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <extensions>true</extensions>
+ <configuration>
+ <instructions>
+
<Bundle-SymbolicName>${project.groupId}.${project.artifactId}</Bundle-SymbolicName>
+
<Bundle-Activator>org.apache.plc4x.java.osgi.DriverActivator</Bundle-Activator>
+
<Export-Service>org.apache.plc4x.java.api.PlcDriver,org.apache.plc4x.java.modbus.tcp.ModbusTcpDriver</Export-Service>
+ <Import-Package>
+ com.fasterxml.jackson.annotation;resolution:=optional,
+ *
+ </Import-Package>
+ </instructions>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-dependency-plugin</artifactId>
+ <configuration>
+ <usedDependencies combine.children="append">
+
<usedDependency>org.apache.plc4x:plc4j-transport-serial</usedDependency>
+
<usedDependency>org.apache.plc4x:plc4j-transport-raw-socket</usedDependency>
+
<usedDependency>org.apache.plc4x:plc4x-code-generation-language-java</usedDependency>
+
<usedDependency>org.apache.plc4x:plc4x-protocols-modbus</usedDependency>
+ </usedDependencies>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.plc4x</groupId>
+ <artifactId>plc4j-api</artifactId>
+ <version>0.10.0-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.plc4x</groupId>
+ <artifactId>plc4j-spi</artifactId>
+ <version>0.10.0-SNAPSHOT</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.plc4x</groupId>
+ <artifactId>plc4j-transport-tcp</artifactId>
+ <version>0.10.0-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.plc4x</groupId>
+ <artifactId>plc4j-transport-serial</artifactId>
+ <version>0.10.0-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.plc4x</groupId>
+ <artifactId>plc4j-transport-raw-socket</artifactId>
+ <version>0.10.0-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.plc4x</groupId>
+ <artifactId>plc4j-utils-raw-sockets</artifactId>
+ <version>0.10.0-SNAPSHOT</version>
+ </dependency>
+
+ <dependency>
+ <groupId>io.netty</groupId>
+ <artifactId>netty-buffer</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>com.fasterxml.jackson.core</groupId>
+ <artifactId>jackson-annotations</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.commons</groupId>
+ <artifactId>commons-lang3</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>commons-codec</groupId>
+ <artifactId>commons-codec</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.pcap4j</groupId>
+ <artifactId>pcap4j-core</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.plc4x</groupId>
+ <artifactId>plc4j-utils-test-utils</artifactId>
+ <version>0.10.0-SNAPSHOT</version>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.plc4x</groupId>
+ <artifactId>plc4x-code-generation-language-rust</artifactId>
+ <version>0.10.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-modbus</artifactId>
+ <version>0.10.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-modbus</artifactId>
+ <version>0.10.0-SNAPSHOT</version>
+ <classifier>tests</classifier>
+ <type>test-jar</type>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+</project>
diff --git a/plc4rust/src/lib.rs b/plc4rust/src/lib.rs
index e806b8c09c..4190f43b88 100644
--- a/plc4rust/src/lib.rs
+++ b/plc4rust/src/lib.rs
@@ -29,6 +29,7 @@ pub mod modbus;
pub mod read_buffer;
mod r#enum;
mod types;
+mod s7;
#[allow(dead_code)]
#[derive(Debug)]
diff --git a/plc4rust/src/modbus/driver_type.rs
b/plc4rust/src/modbus/driver_type.rs
index 9d8e71fa54..3096194b6e 100644
--- a/plc4rust/src/modbus/driver_type.rs
+++ b/plc4rust/src/modbus/driver_type.rs
@@ -20,6 +20,7 @@
use std::io::{Error, ErrorKind, Read, Write};
use crate::{Message, NoOption, ReadBuffer, WriteBuffer};
+
// [enum DriverType
// ['0x01' MODBUS_TCP ]
// ['0x02' MODBUS_RTU ]
diff --git a/plc4rust/src/modbus/mod.rs b/plc4rust/src/modbus/mod.rs
index 1b78534e91..38c0ff6ff1 100644
--- a/plc4rust/src/modbus/mod.rs
+++ b/plc4rust/src/modbus/mod.rs
@@ -32,6 +32,7 @@ mod modbus_device_information_conformity_level;
mod modbus_device_information_more_follows;
mod modbus_device_information_level;
mod test;
+pub mod modbus_data_type;
pub use driver_type::DriverType;
pub use modbus_adu::ModbusADU;
diff --git a/plc4rust/src/modbus/modbus_data_type.rs
b/plc4rust/src/modbus/modbus_data_type.rs
new file mode 100644
index 0000000000..b77ab335e3
--- /dev/null
+++ b/plc4rust/src/modbus/modbus_data_type.rs
@@ -0,0 +1,215 @@
+/*
+ * 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.rust.modbus.readwrite;
+use crate::plc4x_enum;
+use std::io::{Error, ErrorKind, Read, Write};
+use crate::{Message, NoOption, ReadBuffer, WriteBuffer};
+
+pub struct ModbusDataTypeArguments {
+ dataTypeSize: u8
+}
+
+plc4x_enum!
+[enum u8 : ModbusDataType
+ [1 => BOOL],
+ [2 => BYTE],
+ [3 => WORD],
+ [4 => DWORD],
+ [5 => LWORD],
+ [6 => SINT],
+ [7 => INT],
+ [8 => DINT],
+ [9 => LINT],
+ [10 => USINT],
+ [11 => UINT],
+ [12 => UDINT],
+ [13 => ULINT],
+ [14 => REAL],
+ [15 => LREAL],
+ [16 => TIME],
+ [17 => LTIME],
+ [18 => DATE],
+ [19 => LDATE],
+ [20 => TIME_OF_DAY],
+ [21 => LTIME_OF_DAY],
+ [22 => DATE_AND_TIME],
+ [23 => LDATE_AND_TIME],
+ [24 => CHAR],
+ [25 => WCHAR],
+ [26 => STRING],
+ [27 => WSTRING]
+];
+
+impl ModbusDataType {
+
+ fn get_arguments(self) -> ModbusDataTypeArguments {
+ match self {
+ BOOL => {
+ ModbusDataTypeArguments {
+ dataTypeSize: 2
+ }
+ },
+ BYTE => {
+ ModbusDataTypeArguments {
+ dataTypeSize: 2
+ }
+ },
+ WORD => {
+ ModbusDataTypeArguments {
+ dataTypeSize: 2
+ }
+ },
+ DWORD => {
+ ModbusDataTypeArguments {
+ dataTypeSize: 4
+ }
+ },
+ LWORD => {
+ ModbusDataTypeArguments {
+ dataTypeSize: 8
+ }
+ },
+ SINT => {
+ ModbusDataTypeArguments {
+ dataTypeSize: 2
+ }
+ },
+ INT => {
+ ModbusDataTypeArguments {
+ dataTypeSize: 2
+ }
+ },
+ DINT => {
+ ModbusDataTypeArguments {
+ dataTypeSize: 4
+ }
+ },
+ LINT => {
+ ModbusDataTypeArguments {
+ dataTypeSize: 8
+ }
+ },
+ USINT => {
+ ModbusDataTypeArguments {
+ dataTypeSize: 2
+ }
+ },
+ UINT => {
+ ModbusDataTypeArguments {
+ dataTypeSize: 2
+ }
+ },
+ UDINT => {
+ ModbusDataTypeArguments {
+ dataTypeSize: 4
+ }
+ },
+ ULINT => {
+ ModbusDataTypeArguments {
+ dataTypeSize: 8
+ }
+ },
+ REAL => {
+ ModbusDataTypeArguments {
+ dataTypeSize: 4
+ }
+ },
+ LREAL => {
+ ModbusDataTypeArguments {
+ dataTypeSize: 8
+ }
+ },
+ TIME => {
+ ModbusDataTypeArguments {
+ dataTypeSize: 8
+ }
+ },
+ LTIME => {
+ ModbusDataTypeArguments {
+ dataTypeSize: 8
+ }
+ },
+ DATE => {
+ ModbusDataTypeArguments {
+ dataTypeSize: 8
+ }
+ },
+ LDATE => {
+ ModbusDataTypeArguments {
+ dataTypeSize: 8
+ }
+ },
+ TIME_OF_DAY => {
+ ModbusDataTypeArguments {
+ dataTypeSize: 8
+ }
+ },
+ LTIME_OF_DAY => {
+ ModbusDataTypeArguments {
+ dataTypeSize: 8
+ }
+ },
+ DATE_AND_TIME => {
+ ModbusDataTypeArguments {
+ dataTypeSize: 8
+ }
+ },
+ LDATE_AND_TIME => {
+ ModbusDataTypeArguments {
+ dataTypeSize: 8
+ }
+ },
+ CHAR => {
+ ModbusDataTypeArguments {
+ dataTypeSize: 1
+ }
+ },
+ WCHAR => {
+ ModbusDataTypeArguments {
+ dataTypeSize: 2
+ }
+ },
+ STRING => {
+ ModbusDataTypeArguments {
+ dataTypeSize: 1
+ }
+ },
+ WSTRING => {
+ ModbusDataTypeArguments {
+ dataTypeSize: 2
+ }
+ }
+ }
+ }
+}
+
+
+#[cfg(test)]
+mod modbus_tests {
+ use crate::{Endianess, Message, ReadBuffer, WriteBuffer};
+ use crate::modbus::modbus_pdu::{ModbusPDUReadCoilsRequest,
ModbusPDUReadCoilsResponse, ModbusPDUReadDiscreteInputsRequest,
ModbusPDUReadDiscreteInputsResponse};
+ use crate::modbus::{DriverType, ModbusADU, ModbusADUOptions, ModbusPDU};
+ use crate::modbus::modbus_adu::ModbusTcpADU;
+ use crate::modbus::modbus_data_type::{ModbusDataType,
ModbusDataTypeArguments};
+
+ #[test]
+ fn read_write() {
+ let data_type: ModbusDataTypeArguments =
ModbusDataType::BOOL.get_arguments();
+ }
+}
\ No newline at end of file
diff --git a/plc4rust/src/s7/mod.rs b/plc4rust/src/s7/mod.rs
new file mode 100644
index 0000000000..042f3ce1f3
--- /dev/null
+++ b/plc4rust/src/s7/mod.rs
@@ -0,0 +1,18 @@
+/*
+ * 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.
+ */