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/02/03 15:34:24 UTC
[incubator-plc4x] branch develop updated: - Added a first poc on a
purely xml dynamic plc4x 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/incubator-plc4x.git
The following commit(s) were added to refs/heads/develop by this push:
new c212f77 - Added a first poc on a purely xml dynamic plc4x driver
c212f77 is described below
commit c212f77e5333fdafc1a8ed5cf7e8d58f26d50840
Author: Christofer Dutz <ch...@c-ware.de>
AuthorDate: Sun Feb 3 16:34:20 2019 +0100
- Added a first poc on a purely xml dynamic plc4x driver
---
examples/hello-webapp/webapp/pom.xml | 1 +
pom.xml | 25 ++-
.../apache/plc4x/protocols/s7/protocol.scxml.xml | 198 +++++++++++----------
sandbox/dynamic-driver-s7/pom.xml | 80 ++-------
.../java/org/apache/plc4x/sandbox/java/s7/Poc.java | 70 ++++++++
.../sandbox/java/s7/actions/ConnectAction.java | 75 ++++++++
.../sandbox/java/s7/actions/InitContextAction.java | 36 ++++
.../sandbox/java/s7/actions/ReceiveAction.java | 46 +++++
.../plc4x/sandbox/java/s7/actions/SendAction.java | 127 +++++++++++++
sandbox/pom.xml | 1 +
10 files changed, 502 insertions(+), 157 deletions(-)
diff --git a/examples/hello-webapp/webapp/pom.xml b/examples/hello-webapp/webapp/pom.xml
index ce92ab4..a8b3350 100644
--- a/examples/hello-webapp/webapp/pom.xml
+++ b/examples/hello-webapp/webapp/pom.xml
@@ -53,6 +53,7 @@
</executions>
<configuration>
<mainClass>${start.class}</mainClass>
+ <executable>true</executable>
</configuration>
</plugin>
<plugin>
diff --git a/pom.xml b/pom.xml
index 9943353..ac58c96 100644
--- a/pom.xml
+++ b/pom.xml
@@ -153,9 +153,6 @@
<!-- Integration modules for other frameworks -->
<module>integrations</module>
- <!-- Sandbox for testing new stuff -->
- <module>sandbox</module>
-
<!-- Examples -->
<module>examples</module>
</modules>
@@ -1290,6 +1287,20 @@
</plugins>
</reporting>
+ <!-- Make Snapshots of Apache projects available -->
+ <repositories>
+ <repository>
+ <id>apache-snapshots</id>
+ <url>https://repository.apache.org/content/repositories/snapshots</url>
+ <releases>
+ <enabled>false</enabled>
+ </releases>
+ <snapshots>
+ <enabled>true</enabled>
+ </snapshots>
+ </repository>
+ </repositories>
+
<profiles>
<!-- Build PLC4X including the CPP modules -->
<profile>
@@ -1299,6 +1310,14 @@
</modules>
</profile>
+ <!-- Build PLC4X including the CPP modules -->
+ <profile>
+ <id>with-sandbox</id>
+ <modules>
+ <module>sandbox</module>
+ </modules>
+ </profile>
+
<!--
This profile is intended to help when having problems with Maven.
When enabled, it automatically generates an "effective.pom" in the target directory.
diff --git a/protocols/s7/src/main/resources/org/apache/plc4x/protocols/s7/protocol.scxml.xml b/protocols/s7/src/main/resources/org/apache/plc4x/protocols/s7/protocol.scxml.xml
index d9c54aa..7f07b76 100644
--- a/protocols/s7/src/main/resources/org/apache/plc4x/protocols/s7/protocol.scxml.xml
+++ b/protocols/s7/src/main/resources/org/apache/plc4x/protocols/s7/protocol.scxml.xml
@@ -16,89 +16,95 @@
specific language governing permissions and limitations
under the License.
-->
-<scxml xmlns="http://www.w3.org/2005/07/scxml"
- version="1.0"
- xmlns:plc4x="https://plc4x.apache.org/scxml-extension"
- xmlns:s7="http://plc4x.apache.org/s7"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- initial="init"
- datamodel="jexl"
- xsi:schemaLocation="http://www.w3.org/2005/07/scxml http://www.w3.org/2011/04/SCXML/scxml.xsd">
+<sc:scxml version="1.0"
+ xmlns:plc4x="https://plc4x.apache.org/scxml-extension"
+ xmlns:sc="http://www.w3.org/2005/07/scxml"
+ xmlns:s7="http://plc4x.apache.org/s7"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ initial="init"
+ datamodel="jexl"
+ xsi:schemaLocation="http://www.w3.org/2005/07/scxml http://www.w3.org/2011/04/SCXML/scxml.xsd">
- <state id="init">
- <onentry>
+ <sc:datamodel>
+ <sc:data id="args"/>
+ <sc:data id="connection"/>
+ </sc:datamodel>
+
+ <sc:state id="init">
+ <sc:onentry>
<!-- Setup the initial content of the connection context (Callback in the driver) -->
<plc4x:initContext/>
- </onentry>
- <initial>
- <transition target="connect"/>
- </initial>
- <onentry>
- <log expr="'Connecting'"/>
- </onentry>
- </state>
+ </sc:onentry>
+ <sc:transition event="success" target="connect">
+ <sc:assign location="args" expr="_event.data"/>
+ </sc:transition>
+ </sc:state>
- <state id="connect">
- <initial>
- <transition target="establishNetworkConnection"/>
- </initial>
+ <sc:state id="connect">
+ <sc:initial>
+ <sc:transition target="establishNetworkConnection"/>
+ </sc:initial>
- <state id="establishNetworkConnection">
- <onentry>
+ <sc:state id="establishNetworkConnection">
+ <sc:onentry>
<!-- Initialize the network connection to the remote host using the tcp adapter with a given host and port -->
- <plc4x:connect type="tcp" host="{connection-host}" port="{connection-port}"/>
- </onentry>
- <transition target="sendCotpConnectionRequest"/>
- </state>
+ <plc4x:connect type="tcp" host="10.10.64.20" port="102"/>
+ </sc:onentry>
+ <sc:transition event="success" target="sendCotpConnectionRequest">
+ <sc:assign location="connection" expr="_event.data"/>
+ </sc:transition>
+ <sc:transition event="failure" target="error"/>
+ </sc:state>
- <state id="sendCotpConnectionRequest">
- <onentry>
- <plc4x:send>
- <s7:tpktMessage>
+ <sc:state id="sendCotpConnectionRequest">
+ <sc:onentry>
+ <plc4x:send socket="connection">
+ <s7:TpktMessage>
<magicByte>3</magicByte>
<reserved>0</reserved>
- <length>18</length>
+ <length>22</length>
<userData>
<headerLength>17</headerLength>
<type>224</type>
- <CotpTpduConnectionRequest>
- <destinationReference>1</destinationReference>
+ <s7:CotpTpduConnectionRequest>
+ <destinationReference>0</destinationReference>
<!-- Insert the value for "cotp-local-reference" as short here -->
- <sourceReference><plc4x:insert type="s7:short" name="cotp-local-reference"/></sourceReference>
+ <sourceReference>16</sourceReference><!--plc4x:insert type="s7:short" name="cotp-local-reference"/-->
<protocolClass>0</protocolClass>
- <parameters>
+ <s7:parameters>
<parameter>
<type>193</type>
<parameterLength>2</parameterLength>
- <CotpParameterCallingTsap>
- <tsapId><plc4x:insert type="s7:short" name="cotp-calling-tsap"/></tsapId>
- </CotpParameterCallingTsap>
+ <s7:CotpParameterCallingTsap>
+ <tsapId>256</tsapId><!--plc4x:insert type="s7:short" name="cotp-calling-tsap"/-->
+ </s7:CotpParameterCallingTsap>
</parameter>
<parameter>
<type>194</type>
<parameterLength>2</parameterLength>
- <CotpParameterCalledTsap>
- <tsapId><plc4x:insert type="s7:short" name="cotp-called-tsap"/></tsapId>
- </CotpParameterCalledTsap>
+ <s7:CotpParameterCalledTsap>
+ <tsapId>258</tsapId><!--plc4x:insert type="s7:short" name="cotp-called-tsap"/-->
+ </s7:CotpParameterCalledTsap>
</parameter>
<parameter>
<type>192</type>
<parameterLength>1</parameterLength>
- <CotpParameterTpduSize>
- <tpduSize><plc4x:insert type="s7:byte" name="cotp-tpdu-size"/></tpduSize>
- </CotpParameterTpduSize>
+ <s7:CotpParameterTpduSize>
+ <tpduSize>10</tpduSize><!--plc4x:insert type="s7:byte" name="cotp-tpdu-size"/-->
+ </s7:CotpParameterTpduSize>
</parameter>
- </parameters>
- </CotpTpduConnectionRequest>
+ </s7:parameters>
+ </s7:CotpTpduConnectionRequest>
</userData>
- </s7:tpktMessage>
+ </s7:TpktMessage>
</plc4x:send>
- </onentry>
- <transition target="receiveCotpConnectionResponse"/>
- </state>
+ </sc:onentry>
+ <sc:transition event="success" target="receiveCotpConnectionResponse"/>
+ <sc:transition event="failure" target="error"/>
+ </sc:state>
- <state id="receiveCotpConnectionResponse">
- <onentry>
+ <sc:state id="receiveCotpConnectionResponse">
+ <sc:onentry>
<plc4x:receive timeout="5000">
<s7:tpktMessage>
<magicByte>3</magicByte>
@@ -150,13 +156,13 @@
</userData>
</s7:tpktMessage>
</plc4x:receive>
- </onentry>
- <transition cond="" target="sendS7SetupCommunicationRequest"/>
- <transition cond="" target="error"/>
- </state>
+ </sc:onentry>
+ <sc:transition event="success" target="sendS7SetupCommunicationRequest"/>
+ <sc:transition event="failure" target="error"/>
+ </sc:state>
- <state id="sendS7SetupCommunicationRequest">
- <onentry>
+ <sc:state id="sendS7SetupCommunicationRequest">
+ <sc:onentry>
<plc4x:send>
<s7:tpktMessage>
<magicByte>3</magicByte>
@@ -198,12 +204,13 @@
</userData>
</s7:tpktMessage>
</plc4x:send>
- </onentry>
- <transition target="receiveS7SetupCommunicationResponse"/>
- </state>
+ </sc:onentry>
+ <sc:transition event="success" target="receiveS7SetupCommunicationResponse"/>
+ <sc:transition event="failure" target="error"/>
+ </sc:state>
- <state id="receiveS7SetupCommunicationResponse">
- <onentry>
+ <sc:state id="receiveS7SetupCommunicationResponse">
+ <sc:onentry>
<plc4x:receive timeout="5000">
<s7:tpktMessage>
<magicByte>3</magicByte>
@@ -250,14 +257,14 @@
</userData>
</s7:tpktMessage>
</plc4x:receive>
- </onentry>
- <transition cond="{type == null}" target="sendS7IdentificationRequest"/>
- <transition cond="{type != null}" target="connected"/>
- <transition cond="" target="error"/>
- </state>
+ </sc:onentry>
+ <sc:transition event="" target="sendS7IdentificationRequest"/>
+ <sc:transition event="success" target="connected"/>
+ <sc:transition event="failure" target="error"/>
+ </sc:state>
- <state id="sendS7IdentificationRequest">
- <onentry>
+ <sc:state id="sendS7IdentificationRequest">
+ <sc:onentry>
<plc4x:send>
<s7:tpktMessage>
<magicByte>3</magicByte>
@@ -308,12 +315,13 @@
</userData>
</s7:tpktMessage>
</plc4x:send>
- </onentry>
- <transition target="receiveS7IdentificationRequest"/>
- </state>
+ </sc:onentry>
+ <sc:transition event="success" target="receiveS7IdentificationRequest"/>
+ <sc:transition event="failure" target="error"/>
+ </sc:state>
- <state id="receiveS7IdentificationRequest">
- <onentry>
+ <sc:state id="receiveS7IdentificationRequest">
+ <sc:onentry>
<plc4x:receive>
<s7:tpktMessage>
<magicByte>3</magicByte>
@@ -418,22 +426,26 @@
</userData>
</s7:tpktMessage>
</plc4x:receive>
- </onentry>
- <transition cond="" target="connected"/>
- <transition cond="" target="error"/>
- </state>
+ </sc:onentry>
+ <sc:transition event="success" target="connected"/>
+ <sc:transition event="failure" target="error"/>
+ </sc:state>
+
+ <sc:state id="connected">
+ <sc:onentry>
+ <sc:log expr="'Connected'"/>
+ </sc:onentry>
+ </sc:state>
+
+ <sc:final id="disconnected">
- <final id="connected">
- <onentry>
- <log expr="'Connected'"/>
- </onentry>
- </final>
+ </sc:final>
- <final id="error">
- <onentry>
- <log expr="'Error connecting'"/>
- </onentry>
- </final>
- </state>
+ <sc:final id="error">
+ <sc:onentry>
+ <sc:log expr="'Error connecting'"/>
+ </sc:onentry>
+ </sc:final>
+ </sc:state>
-</scxml>
\ No newline at end of file
+</sc:scxml>
\ No newline at end of file
diff --git a/sandbox/dynamic-driver-s7/pom.xml b/sandbox/dynamic-driver-s7/pom.xml
index daa559e..80e9432 100644
--- a/sandbox/dynamic-driver-s7/pom.xml
+++ b/sandbox/dynamic-driver-s7/pom.xml
@@ -33,80 +33,37 @@
<dependencies>
<dependency>
- <groupId>org.apache.plc4x</groupId>
- <artifactId>plc4j-api</artifactId>
- <version>0.4.0-SNAPSHOT</version>
- </dependency>
-
- <dependency>
- <groupId>org.apache.plc4x</groupId>
- <artifactId></artifactId>
- </dependency>
-
- <dependency>
- <groupId>org.apache.plc4x</groupId>
- <artifactId>plc4j-protocol-driver-base</artifactId>
- <version>0.4.0-SNAPSHOT</version>
- </dependency>
- <dependency>
- <groupId>org.apache.plc4x</groupId>
- <artifactId>plc4j-protocol-driver-base-tcp</artifactId>
- <version>0.4.0-SNAPSHOT</version>
- </dependency>
-
- <dependency>
- <groupId>io.netty</groupId>
- <artifactId>netty-common</artifactId>
- </dependency>
- <dependency>
- <groupId>io.netty</groupId>
- <artifactId>netty-transport</artifactId>
- </dependency>
- <dependency>
- <groupId>io.netty</groupId>
- <artifactId>netty-buffer</artifactId>
- </dependency>
-
- <dependency>
<groupId>org.apache.commons</groupId>
- <artifactId>commons-configuration2</artifactId>
+ <artifactId>commons-scxml2</artifactId>
+ <version>2.0-SNAPSHOT</version>
</dependency>
<dependency>
- <groupId>org.apache.commons</groupId>
- <artifactId>commons-lang3</artifactId>
+ <groupId>org.apache.daffodil</groupId>
+ <artifactId>daffodil-japi_2.12</artifactId>
+ <version>2.2.0</version>
</dependency>
<dependency>
- <groupId>commons-io</groupId>
- <artifactId>commons-io</artifactId>
+ <groupId>org.apache.commons</groupId>
+ <artifactId>commons-jexl3</artifactId>
+ <version>3.1</version>
</dependency>
<dependency>
- <groupId>org.apache.plc4x</groupId>
- <artifactId>plc4j-protocol-driver-base-test</artifactId>
- <version>0.4.0-SNAPSHOT</version>
- <scope>test</scope>
+ <groupId>commons-logging</groupId>
+ <artifactId>commons-logging</artifactId>
+ <version>1.1.3</version>
</dependency>
<dependency>
- <groupId>org.pcap4j</groupId>
- <artifactId>pcap4j-core</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.pcap4j</groupId>
- <artifactId>pcap4j-packetfactory-static</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.apache.plc4x</groupId>
- <artifactId>plc4j-utils-test-utils</artifactId>
- <version>0.4.0-SNAPSHOT</version>
- <scope>test</scope>
+ <groupId>xml-apis</groupId>
+ <artifactId>xml-apis</artifactId>
+ <version>1.4.01</version>
</dependency>
+
<dependency>
<groupId>org.apache.plc4x</groupId>
- <artifactId>plc4j-utils-test-utils</artifactId>
+ <artifactId>plc4x-protocols-s7</artifactId>
<version>0.4.0-SNAPSHOT</version>
- <scope>test</scope>
+ <scope>runtime</scope>
</dependency>
</dependencies>
@@ -117,7 +74,8 @@
<artifactId>maven-dependency-plugin</artifactId>
<configuration>
<usedDependencies combine.children="append">
- <usedDependency>org.pcap4j:pcap4j-packetfactory-static</usedDependency>
+ <usedDependency>org.apache.plc4x:plc4x-protocols-s7</usedDependency>
+ <usedDependency>org.apache.commons:commons-jexl3</usedDependency>
</usedDependencies>
</configuration>
</plugin>
diff --git a/sandbox/dynamic-driver-s7/src/main/java/org/apache/plc4x/sandbox/java/s7/Poc.java b/sandbox/dynamic-driver-s7/src/main/java/org/apache/plc4x/sandbox/java/s7/Poc.java
new file mode 100644
index 0000000..08e6e8a
--- /dev/null
+++ b/sandbox/dynamic-driver-s7/src/main/java/org/apache/plc4x/sandbox/java/s7/Poc.java
@@ -0,0 +1,70 @@
+/*
+ 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.sandbox.java.s7;
+
+import org.apache.commons.scxml2.SCXMLExecutor;
+import org.apache.commons.scxml2.env.SimpleDispatcher;
+import org.apache.commons.scxml2.env.SimpleErrorReporter;
+import org.apache.commons.scxml2.invoke.SimpleSCXMLInvoker;
+import org.apache.commons.scxml2.io.SCXMLReader;
+import org.apache.commons.scxml2.model.CustomAction;
+import org.apache.commons.scxml2.model.SCXML;
+import org.apache.plc4x.sandbox.java.s7.actions.ConnectAction;
+import org.apache.plc4x.sandbox.java.s7.actions.InitContextAction;
+import org.apache.plc4x.sandbox.java.s7.actions.ReceiveAction;
+import org.apache.plc4x.sandbox.java.s7.actions.SendAction;
+
+import java.util.LinkedList;
+import java.util.List;
+
+public class Poc {
+
+ private SCXMLExecutor executor;
+
+ public Poc() throws Exception {
+
+ List<CustomAction> customActions = new LinkedList<>();
+ customActions.add(
+ new CustomAction("https://plc4x.apache.org/scxml-extension", "initContext", InitContextAction.class));
+ customActions.add(
+ new CustomAction("https://plc4x.apache.org/scxml-extension", "connect", ConnectAction.class));
+ customActions.add(
+ new CustomAction("https://plc4x.apache.org/scxml-extension", "send", SendAction.class));
+ customActions.add(
+ new CustomAction("https://plc4x.apache.org/scxml-extension", "receive", ReceiveAction.class));
+
+ SCXML scxml = SCXMLReader.read(
+ Poc.class.getClassLoader().getResource("org/apache/plc4x/protocols/s7/protocol.scxml.xml"),
+ new SCXMLReader.Configuration(null, null, customActions));
+ executor = new SCXMLExecutor(null, new SimpleDispatcher(), new SimpleErrorReporter());
+ executor.setStateMachine(scxml);
+ executor.registerInvokerClass("scxml", SimpleSCXMLInvoker.class);
+ }
+
+ protected void run() throws Exception {
+ executor.go();
+ }
+
+ public static void main(String[] args) throws Exception {
+ Poc poc = new Poc();
+ poc.run();
+ }
+
+}
diff --git a/sandbox/dynamic-driver-s7/src/main/java/org/apache/plc4x/sandbox/java/s7/actions/ConnectAction.java b/sandbox/dynamic-driver-s7/src/main/java/org/apache/plc4x/sandbox/java/s7/actions/ConnectAction.java
new file mode 100644
index 0000000..490ad05
--- /dev/null
+++ b/sandbox/dynamic-driver-s7/src/main/java/org/apache/plc4x/sandbox/java/s7/actions/ConnectAction.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.sandbox.java.s7.actions;
+
+import org.apache.commons.scxml2.ActionExecutionContext;
+import org.apache.commons.scxml2.EventBuilder;
+import org.apache.commons.scxml2.TriggerEvent;
+import org.apache.commons.scxml2.model.Action;
+
+import java.io.IOException;
+import java.net.Socket;
+
+public class ConnectAction extends Action {
+
+ private String type;
+ private String host;
+ private String port;
+
+ public String getType() {
+ return type;
+ }
+
+ public void setType(String type) {
+ this.type = type;
+ }
+
+ public String getHost() {
+ return host;
+ }
+
+ public void setHost(String host) {
+ this.host = host;
+ }
+
+ public String getPort() {
+ return port;
+ }
+
+ public void setPort(String port) {
+ this.port = port;
+ }
+
+ @Override
+ public void execute(ActionExecutionContext ctx) {
+ ctx.getAppLog().info("Connecting.");
+ try {
+ if ("TCP".equalsIgnoreCase(type)) {
+ Socket socket = new Socket(host, Integer.parseInt(port));
+ TriggerEvent event = new EventBuilder("success", TriggerEvent.SIGNAL_EVENT).data(socket).build();
+ ctx.getInternalIOProcessor().addEvent(event);
+ }
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ return;
+ }
+
+}
diff --git a/sandbox/dynamic-driver-s7/src/main/java/org/apache/plc4x/sandbox/java/s7/actions/InitContextAction.java b/sandbox/dynamic-driver-s7/src/main/java/org/apache/plc4x/sandbox/java/s7/actions/InitContextAction.java
new file mode 100644
index 0000000..9285c64
--- /dev/null
+++ b/sandbox/dynamic-driver-s7/src/main/java/org/apache/plc4x/sandbox/java/s7/actions/InitContextAction.java
@@ -0,0 +1,36 @@
+/*
+ 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.sandbox.java.s7.actions;
+
+import org.apache.commons.scxml2.ActionExecutionContext;
+import org.apache.commons.scxml2.EventBuilder;
+import org.apache.commons.scxml2.TriggerEvent;
+import org.apache.commons.scxml2.model.Action;
+
+public class InitContextAction extends Action {
+
+ @Override
+ public void execute(ActionExecutionContext ctx) {
+ ctx.getAppLog().info("Initializing Context.");
+ TriggerEvent event = new EventBuilder("success", TriggerEvent.SIGNAL_EVENT).build();
+ ctx.getInternalIOProcessor().addEvent(event);
+ }
+
+}
diff --git a/sandbox/dynamic-driver-s7/src/main/java/org/apache/plc4x/sandbox/java/s7/actions/ReceiveAction.java b/sandbox/dynamic-driver-s7/src/main/java/org/apache/plc4x/sandbox/java/s7/actions/ReceiveAction.java
new file mode 100644
index 0000000..f6f62c0
--- /dev/null
+++ b/sandbox/dynamic-driver-s7/src/main/java/org/apache/plc4x/sandbox/java/s7/actions/ReceiveAction.java
@@ -0,0 +1,46 @@
+/*
+ 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.sandbox.java.s7.actions;
+
+import org.apache.commons.scxml2.ActionExecutionContext;
+import org.apache.commons.scxml2.EventBuilder;
+import org.apache.commons.scxml2.TriggerEvent;
+import org.apache.commons.scxml2.model.Action;
+
+public class ReceiveAction extends Action {
+
+ private String timeout;
+
+ public String getTimeout() {
+ return timeout;
+ }
+
+ public void setTimeout(String timeout) {
+ this.timeout = timeout;
+ }
+
+ @Override
+ public void execute(ActionExecutionContext ctx) {
+ ctx.getAppLog().info("Receiving.");
+ TriggerEvent event = new EventBuilder("success", TriggerEvent.SIGNAL_EVENT).build();
+ ctx.getInternalIOProcessor().addEvent(event);
+ }
+
+}
diff --git a/sandbox/dynamic-driver-s7/src/main/java/org/apache/plc4x/sandbox/java/s7/actions/SendAction.java b/sandbox/dynamic-driver-s7/src/main/java/org/apache/plc4x/sandbox/java/s7/actions/SendAction.java
new file mode 100644
index 0000000..392d0c5
--- /dev/null
+++ b/sandbox/dynamic-driver-s7/src/main/java/org/apache/plc4x/sandbox/java/s7/actions/SendAction.java
@@ -0,0 +1,127 @@
+/*
+ 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.sandbox.java.s7.actions;
+
+import org.apache.commons.scxml2.ActionExecutionContext;
+import org.apache.commons.scxml2.EventBuilder;
+import org.apache.commons.scxml2.TriggerEvent;
+import org.apache.commons.scxml2.model.Action;
+import org.apache.commons.scxml2.model.ParsedValue;
+import org.apache.commons.scxml2.model.ParsedValueContainer;
+import org.apache.daffodil.japi.Compiler;
+import org.apache.daffodil.japi.*;
+import org.apache.daffodil.japi.infoset.InfosetInputter;
+import org.apache.daffodil.japi.infoset.W3CDOMInfosetInputter;
+import org.w3c.dom.Document;
+import org.w3c.dom.Node;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+import java.io.DataOutputStream;
+import java.io.IOException;
+import java.net.Socket;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.nio.channels.Channels;
+import java.nio.channels.WritableByteChannel;
+import java.util.List;
+
+public class SendAction extends Action implements ParsedValueContainer {
+
+ private ParsedValue message;
+
+ @Override
+ public ParsedValue getParsedValue() {
+ return message;
+ }
+
+ @Override
+ public void setParsedValue(ParsedValue parsedValue) {
+ message = parsedValue;
+ }
+
+ @Override
+ public void execute(ActionExecutionContext ctx) {
+ if(message != null) {
+ if(message.getType() == ParsedValue.ValueType.NODE) {
+ try {
+ Node messageTemplate = (Node) message.getValue();
+ DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
+ DocumentBuilder builder = dbf.newDocumentBuilder();
+ Document doc = builder.newDocument();
+ Node messageTemplateClone = doc.importNode(messageTemplate, true);
+ doc.appendChild(messageTemplateClone);
+ Compiler c = Daffodil.compiler();
+ c.setValidateDFDLSchemas(true);
+ URL shemaUrl = SendAction.class.getClassLoader().getResource("org/apache/plc4x/protocols/s7/protocol.dfdl.xsd");
+ if(shemaUrl != null) {
+ URI schemaUri = shemaUrl.toURI();
+ ProcessorFactory pf = c.compileSource(schemaUri);
+ if(pf.isError()) {
+ List<Diagnostic> diags = pf.getDiagnostics();
+ for (Diagnostic d : diags) {
+ System.err.println(d.getSomeMessage());
+ }
+ return;
+ }
+ DataProcessor dp = pf.onPath("/");
+ if(dp.isError()) {
+ List<Diagnostic> diags = dp.getDiagnostics();
+ for (Diagnostic d : diags) {
+ System.err.println(d.getSomeMessage());
+ }
+ return;
+ }
+ InfosetInputter inputter = new W3CDOMInfosetInputter(doc);
+
+ Socket connection = (Socket) ctx.getGlobalContext().get("connection");
+ DataOutputStream outputStream = new DataOutputStream(connection.getOutputStream());
+ WritableByteChannel wbc = Channels.newChannel(outputStream);
+
+ UnparseResult byteMessage = dp.unparse(inputter, wbc);
+ if(byteMessage.isError()) {
+ List<Diagnostic> diags = byteMessage.getDiagnostics();
+ for (Diagnostic d : diags) {
+ System.err.println(d.getSomeMessage());
+ }
+ return;
+ }
+
+ outputStream.flush();
+ }
+ } catch(URISyntaxException e) {
+ e.printStackTrace();
+ } catch (IOException e) {
+ e.printStackTrace();
+ } catch (ParserConfigurationException e) {
+ e.printStackTrace();
+ }
+ } else if(message.getType() == ParsedValue.ValueType.JSON) {
+
+ }
+ }
+ ctx.getAppLog().info("Sending.");
+ TriggerEvent event = new EventBuilder("success", TriggerEvent.SIGNAL_EVENT).build();
+ ctx.getInternalIOProcessor().addEvent(event);
+ }
+
+}
diff --git a/sandbox/pom.xml b/sandbox/pom.xml
index 7df89ba..f5301bf 100644
--- a/sandbox/pom.xml
+++ b/sandbox/pom.xml
@@ -35,6 +35,7 @@
<description>Place where new stuff is located before it is regarded production-quality.</description>
<modules>
+ <module>dynamic-driver-s7</module>
</modules>
</project>
\ No newline at end of file