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 2018/02/07 13:27:53 UTC

[incubator-plc4x] branch master updated (ab7bc2d -> a167e3e)

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

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


    from ab7bc2d  PLC4X-25 - Remove developer activity page from website?
     new 51b5db3  PLC4X-18 - Implement a Netty Pipeline that allows creating pipelines for low level protocols below TCP and UDP - Some more work on the raw socket netty support
     new e3d87d1  Simplified the plc logger code
     new 4bd1219  Simplified the S7PlcReaderSample
     new d9b993f  Some more work on the dummy driver - Should now use the "dummy" connection prefix - Should use a raw socket to send an ICMP (Ping) packet
     new 21e6f78  Exposed a parseAddress method on the connection-adapter
     new a167e3e  Implemented an example using PLC4X and Edgent to publish PLC values directly to kafka

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


Summary of changes:
 .../java/examples/dummydriver/DummyDriver.java     |  12 +-
 .../examples/dummydriver/netty/DummyProtocol.java  |  28 +++--
 .../kafka-bridge/kafka-bridge.yml                  |  23 +++-
 examples/{iotree => kafka-bridge}/pom.xml          |  45 +++++++-
 .../kafka-bridge/server.sh                         |  16 ++-
 .../java/examples/kafkabridge/KafkaBridge.java     | 121 +++++++++++++++++++++
 .../java/examples/kafkabridge/model/Address.java   |  39 +++++--
 .../examples/kafkabridge/model/Configuration.java  |  56 ++++++++++
 .../examples/kafkabridge/model/KafkaConfig.java    |  28 +++--
 .../java/examples/kafkabridge/model/PlcConfig.java |  27 +++--
 .../kafka-bridge/src/main}/resources/logback.xml   |   0
 examples/plclogger/pom.xml                         |   4 +
 .../plc4x/java/examples/plclogger/PlcLogger.java   |  74 +++----------
 examples/pom.xml                                   |   1 +
 .../apache/plc4x/edgent/PlcConnectionAdapter.java  |   4 +
 .../apache/plc4x/java/s7/S7PlcReaderSample.java    |  99 ++++++++---------
 .../utils/rawsockets/netty/RawSocketChannel.java   |  34 +++---
 ...ketAddress.java => RawSocketChannelConfig.java} |  15 +--
 ...ketAddress.java => RawSocketChannelOption.java} |  14 +--
 19 files changed, 443 insertions(+), 197 deletions(-)
 copy integrations/apache-camel/src/test/resources/META-INF/services/org.apache.plc4x.java.api.PlcDriver => examples/kafka-bridge/kafka-bridge.yml (58%)
 copy examples/{iotree => kafka-bridge}/pom.xml (64%)
 copy .mvn/wrapper/maven-wrapper.properties => examples/kafka-bridge/server.sh (57%)
 mode change 100644 => 100755
 create mode 100644 examples/kafka-bridge/src/main/java/org/apache/plc4x/java/examples/kafkabridge/KafkaBridge.java
 copy plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/items/ReadRequestItem.java => examples/kafka-bridge/src/main/java/org/apache/plc4x/java/examples/kafkabridge/model/Address.java (58%)
 create mode 100644 examples/kafka-bridge/src/main/java/org/apache/plc4x/java/examples/kafkabridge/model/Configuration.java
 copy plc4j/api/src/main/java/org/apache/plc4x/java/api/exceptions/PlcConnectionException.java => examples/kafka-bridge/src/main/java/org/apache/plc4x/java/examples/kafkabridge/model/KafkaConfig.java (56%)
 copy plc4j/protocols/s7/src/main/java/org/apache/plc4x/java/isotp/netty/model/tpdus/CustomTpdu.java => examples/kafka-bridge/src/main/java/org/apache/plc4x/java/examples/kafkabridge/model/PlcConfig.java (62%)
 copy {plc4j/protocols/s7/src/test => examples/kafka-bridge/src/main}/resources/logback.xml (100%)
 copy plc4j/utils/raw-sockets/src/main/java/org/apache/plc4x/java/utils/rawsockets/netty/{RawSocketAddress.java => RawSocketChannelConfig.java} (69%)
 copy plc4j/utils/raw-sockets/src/main/java/org/apache/plc4x/java/utils/rawsockets/netty/{RawSocketAddress.java => RawSocketChannelOption.java} (74%)

-- 
To stop receiving notification emails like this one, please contact
cdutz@apache.org.

[incubator-plc4x] 02/06: Simplified the plc logger code

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

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

commit e3d87d17ea811f3bcf5447e7ea70e3e38195da02
Author: Christofer Dutz <ch...@c-ware.de>
AuthorDate: Wed Feb 7 13:49:49 2018 +0100

    Simplified the plc logger code
---
 examples/plclogger/pom.xml                         |  4 ++
 .../plc4x/java/examples/plclogger/PlcLogger.java   | 74 +++++-----------------
 2 files changed, 21 insertions(+), 57 deletions(-)

diff --git a/examples/plclogger/pom.xml b/examples/plclogger/pom.xml
index a01f28b..75d79b4 100644
--- a/examples/plclogger/pom.xml
+++ b/examples/plclogger/pom.xml
@@ -66,6 +66,10 @@
       <version>0.0.1-SNAPSHOT</version>
       <scope>runtime</scope>
     </dependency>
+    <dependency>
+      <groupId>ch.qos.logback</groupId>
+      <artifactId>logback-classic</artifactId>
+    </dependency>
   </dependencies>
 
   <build>
diff --git a/examples/plclogger/src/main/java/org/apache/plc4x/java/examples/plclogger/PlcLogger.java b/examples/plclogger/src/main/java/org/apache/plc4x/java/examples/plclogger/PlcLogger.java
index 466bcdc..c24193b 100644
--- a/examples/plclogger/src/main/java/org/apache/plc4x/java/examples/plclogger/PlcLogger.java
+++ b/examples/plclogger/src/main/java/org/apache/plc4x/java/examples/plclogger/PlcLogger.java
@@ -18,10 +18,7 @@ under the License.
 */
 package org.apache.plc4x.java.examples.plclogger;
 
-import java.util.Calendar;
 import java.util.concurrent.TimeUnit;
-import java.util.concurrent.atomic.AtomicInteger;
-import java.util.concurrent.atomic.AtomicLong;
 
 import org.apache.edgent.function.Supplier;
 import org.apache.edgent.providers.direct.DirectProvider;
@@ -29,47 +26,10 @@ import org.apache.edgent.topology.TStream;
 import org.apache.edgent.topology.Topology;
 import org.apache.plc4x.edgent.PlcConnectionAdapter;
 import org.apache.plc4x.edgent.PlcFunctions;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 
 public class PlcLogger {
 
-    private static final Logger logger = LoggerFactory.getLogger(PlcLogger.class);
-
-    private final PlcConnectionAdapter plcAdapter;
-    private final String addressStr;
-    private final int interval;
-
-    private PlcLogger(PlcConnectionAdapter plcAdapter, String addressString, int interval) {
-        this.plcAdapter = plcAdapter;
-        this.addressStr = addressString;
-        this.interval = interval;
-    }
-
-    private void run() {
-        AtomicInteger counter = new AtomicInteger(0);
-        AtomicLong totalTime = new AtomicLong(0);
-        DirectProvider dp = new DirectProvider();
-        Topology top = dp.newTopology();
-
-        Supplier<Byte> plcSupplier = PlcFunctions.byteSupplier(plcAdapter, addressStr);
-        TStream<Byte> source = top.poll(() -> {
-            long start = Calendar.getInstance().getTimeInMillis();
-            Byte value = plcSupplier.get();
-            long end = Calendar.getInstance().getTimeInMillis();
-            long time = end - start;
-            System.out.println("Time: " + time);
-            int curCounter = counter.incrementAndGet();
-            long curTotalTime = totalTime.addAndGet(time);
-            System.out.println("Avg:  " + (curTotalTime / curCounter));
-            return value;
-          },
-          interval, TimeUnit.MILLISECONDS);
-        source.print();
-        dp.submit(top);
-    }
-
-    public static void main(String[] args) {
+    public static void main(String[] args) throws Exception {
         if(args.length != 3) {
             System.out.println("Usage: PlcLogger {connection-string} {resource-address-string} {interval-ms}");
             System.out.println("Example: PlcLogger s7://192.168.0.1/0/0 INPUTS/0 10");
@@ -78,24 +38,24 @@ public class PlcLogger {
         String connectionString = args[0];
         String addressString = args[1];
         Integer interval = Integer.valueOf(args[2]);
-        try (PlcConnectionAdapter plcAdapter = new PlcConnectionAdapter(connectionString)) {
-
-            // Initialize the logger itself
-            PlcLogger logger = new PlcLogger(plcAdapter, addressString, interval);
-
-            // Start the logging ...
-            logger.run();
 
-            // Yeah ... well prevent the application from exiting ;-)
-            while (System.in.available() == 0) {
-                Thread.sleep(1000);
-            }
-
-            System.exit(0);
-        } catch (Exception e) {
-            logger.error("Caught exception", e);
+        // Get a plc connection.
+        try (PlcConnectionAdapter plcAdapter = new PlcConnectionAdapter(connectionString)) {
+            // Initialize the Edgent core.
+            DirectProvider dp = new DirectProvider();
+            Topology top = dp.newTopology();
+
+            // Define the event stream.
+            // 1) PLC4X source generating a stream of bytes.
+            Supplier<Byte> plcSupplier = PlcFunctions.byteSupplier(plcAdapter, addressString);
+            // 2) Use polling to get an item from the byte-stream in regular intervals.
+            TStream<Byte> source = top.poll(plcSupplier, interval, TimeUnit.MILLISECONDS);
+            // 3) Output the events in the stream on the console.
+            source.print();
+
+            // Submit the topology and hereby start the event streams.
+            dp.submit(top);
         }
     }
 
-
 }

-- 
To stop receiving notification emails like this one, please contact
cdutz@apache.org.

[incubator-plc4x] 01/06: PLC4X-18 - Implement a Netty Pipeline that allows creating pipelines for low level protocols below TCP and UDP - Some more work on the raw socket netty support

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

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

commit 51b5db361fb1c58ba221c8a450c8911c8ed35f68
Author: Christofer Dutz <ch...@c-ware.de>
AuthorDate: Wed Feb 7 13:48:50 2018 +0100

    PLC4X-18 - Implement a Netty Pipeline that allows creating pipelines for low level protocols below TCP and UDP
    - Some more work on the raw socket netty support
---
 .../utils/rawsockets/netty/RawSocketChannel.java   | 34 +++++++++++---------
 .../rawsockets/netty/RawSocketChannelConfig.java   | 36 ++++++++++++++++++++++
 .../rawsockets/netty/RawSocketChannelOption.java   | 31 +++++++++++++++++++
 3 files changed, 87 insertions(+), 14 deletions(-)

diff --git a/plc4j/utils/raw-sockets/src/main/java/org/apache/plc4x/java/utils/rawsockets/netty/RawSocketChannel.java b/plc4j/utils/raw-sockets/src/main/java/org/apache/plc4x/java/utils/rawsockets/netty/RawSocketChannel.java
index e304418..1665686 100644
--- a/plc4j/utils/raw-sockets/src/main/java/org/apache/plc4x/java/utils/rawsockets/netty/RawSocketChannel.java
+++ b/plc4j/utils/raw-sockets/src/main/java/org/apache/plc4x/java/utils/rawsockets/netty/RawSocketChannel.java
@@ -24,17 +24,23 @@ import java.net.SocketAddress;
 
 public class RawSocketChannel extends AbstractChannel {
 
-    public RawSocketChannel(Channel parent) {
-        super(parent);
+    private static final ChannelMetadata METADATA = new ChannelMetadata(false, 16);
+
+    protected class RawByteUnsafe extends AbstractChannel.AbstractUnsafe {
+        @Override
+        public void connect(SocketAddress remoteAddress, SocketAddress localAddress, ChannelPromise promise) {
+            //getPipeline()
+            promise.setSuccess();
+        }
     }
 
-    public RawSocketChannel(Channel parent, ChannelId id) {
-        super(parent, id);
+    public RawSocketChannel() {
+        super(null);
     }
 
     @Override
     protected AbstractUnsafe newUnsafe() {
-        return null;
+        return new RawByteUnsafe();
     }
 
     @Override
@@ -54,47 +60,47 @@ public class RawSocketChannel extends AbstractChannel {
 
     @Override
     protected void doBind(SocketAddress localAddress) throws Exception {
-
+        System.out.println(localAddress);
     }
 
     @Override
     protected void doDisconnect() throws Exception {
-
+        System.out.println("disconnect");
     }
 
     @Override
     protected void doClose() throws Exception {
-
+        System.out.println("close");
     }
 
     @Override
     protected void doBeginRead() throws Exception {
-
+        System.out.println("beginRead");
     }
 
     @Override
     protected void doWrite(ChannelOutboundBuffer in) throws Exception {
-
+        System.out.println(in);
     }
 
     @Override
     public ChannelConfig config() {
-        return null;
+        return new RawSocketChannelConfig(this);
     }
 
     @Override
     public boolean isOpen() {
-        return false;
+        return true;
     }
 
     @Override
     public boolean isActive() {
-        return false;
+        return true;
     }
 
     @Override
     public ChannelMetadata metadata() {
-        return null;
+        return METADATA;
     }
 
 }
diff --git a/plc4j/utils/raw-sockets/src/main/java/org/apache/plc4x/java/utils/rawsockets/netty/RawSocketChannelConfig.java b/plc4j/utils/raw-sockets/src/main/java/org/apache/plc4x/java/utils/rawsockets/netty/RawSocketChannelConfig.java
new file mode 100644
index 0000000..96d28d8
--- /dev/null
+++ b/plc4j/utils/raw-sockets/src/main/java/org/apache/plc4x/java/utils/rawsockets/netty/RawSocketChannelConfig.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.java.utils.rawsockets.netty;
+
+import io.netty.channel.*;
+
+import java.util.Map;
+
+public class RawSocketChannelConfig extends DefaultChannelConfig implements ChannelConfig {
+
+    public RawSocketChannelConfig(Channel channel) {
+        super(channel);
+    }
+
+    @Override
+    public Map<ChannelOption<?>, Object> getOptions() {
+        return getOptions(super.getOptions(), RawSocketChannelOption.SOME_OPTION);
+    }
+
+}
diff --git a/plc4j/utils/raw-sockets/src/main/java/org/apache/plc4x/java/utils/rawsockets/netty/RawSocketChannelOption.java b/plc4j/utils/raw-sockets/src/main/java/org/apache/plc4x/java/utils/rawsockets/netty/RawSocketChannelOption.java
new file mode 100644
index 0000000..a1793be
--- /dev/null
+++ b/plc4j/utils/raw-sockets/src/main/java/org/apache/plc4x/java/utils/rawsockets/netty/RawSocketChannelOption.java
@@ -0,0 +1,31 @@
+/*
+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.rawsockets.netty;
+
+import io.netty.channel.ChannelOption;
+
+public class RawSocketChannelOption<T> extends ChannelOption<T> {
+
+    public static final ChannelOption<Boolean> SOME_OPTION = valueOf(RawSocketChannelOption.class, "SOME_OPTION");
+
+    protected RawSocketChannelOption() {
+        super(null);
+    }
+
+}

-- 
To stop receiving notification emails like this one, please contact
cdutz@apache.org.

[incubator-plc4x] 06/06: Implemented an example using PLC4X and Edgent to publish PLC values directly to kafka

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

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

commit a167e3e3424e8058c28fe67719a5717e1b8480db
Author: Christofer Dutz <ch...@c-ware.de>
AuthorDate: Wed Feb 7 14:27:49 2018 +0100

    Implemented an example using PLC4X and Edgent to publish PLC values directly to kafka
    
    Remark: This example currently only reads a hard coded memory area, as we haven't implemented batch reads with Edgent yet.
---
 examples/kafka-bridge/kafka-bridge.yml             |  34 ++++++
 examples/kafka-bridge/pom.xml                      | 122 +++++++++++++++++++++
 examples/kafka-bridge/server.sh                    |  30 +++++
 .../java/examples/kafkabridge/KafkaBridge.java     | 121 ++++++++++++++++++++
 .../java/examples/kafkabridge/model/Address.java   |  60 ++++++++++
 .../examples/kafkabridge/model/Configuration.java  |  56 ++++++++++
 .../examples/kafkabridge/model/KafkaConfig.java    |  46 ++++++++
 .../java/examples/kafkabridge/model/PlcConfig.java |  44 ++++++++
 .../kafka-bridge/src/main/resources/logback.xml    |  36 ++++++
 examples/pom.xml                                   |   1 +
 10 files changed, 550 insertions(+)

diff --git a/examples/kafka-bridge/kafka-bridge.yml b/examples/kafka-bridge/kafka-bridge.yml
new file mode 100644
index 0000000..7779071
--- /dev/null
+++ b/examples/kafka-bridge/kafka-bridge.yml
@@ -0,0 +1,34 @@
+# ----------------------------------------------------------------------------
+# 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.
+# ----------------------------------------------------------------------------
+---
+kafka:
+  topic-name: test-topic
+  bootstrap-servers: localhost:9092
+plc:
+  connection: s7://192.168.0.1/1/1
+  addresses:
+    - name: param1
+      address: INPUTS/0
+      size: 1
+      type: java.lang.Byte
+    - name: param2
+      address: OUTPUTS/0
+      size: 1
+      type: java.lang.Byte
+polling-interval: 1000
diff --git a/examples/kafka-bridge/pom.xml b/examples/kafka-bridge/pom.xml
new file mode 100644
index 0000000..f28a7ec
--- /dev/null
+++ b/examples/kafka-bridge/pom.xml
@@ -0,0 +1,122 @@
+<?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.examples</groupId>
+    <artifactId>examples</artifactId>
+    <version>0.0.1-SNAPSHOT</version>
+  </parent>
+
+  <artifactId>kafka-bridge</artifactId>
+  <name>Examples: Kafka Bridge</name>
+  <description>Sample application that reads data from a connected PLC and publishes this information to a Kafka topic.</description>
+
+  <properties>
+    <app.main.class>org.apache.plc4x.java.examples.kafkabridge.KafkaBridge</app.main.class>
+  </properties>
+
+  <dependencies>
+    <dependency>
+      <groupId>org.apache.plc4x</groupId>
+      <artifactId>plc4j-api</artifactId>
+      <version>0.0.1-SNAPSHOT</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.plc4x</groupId>
+      <artifactId>apache-edgent</artifactId>
+      <version>0.0.1-SNAPSHOT</version>
+    </dependency>
+
+    <dependency>
+      <groupId>org.apache.edgent</groupId>
+      <artifactId>edgent-api-function</artifactId>
+      <version>1.2.0</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.edgent</groupId>
+      <artifactId>edgent-api-topology</artifactId>
+      <version>1.2.0</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.edgent</groupId>
+      <artifactId>edgent-providers-direct</artifactId>
+      <version>1.2.0</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.edgent</groupId>
+      <artifactId>edgent-connectors-kafka</artifactId>
+      <version>1.2.0</version>
+    </dependency>
+
+    <dependency>
+      <groupId>com.fasterxml.jackson.dataformat</groupId>
+      <artifactId>jackson-dataformat-yaml</artifactId>
+      <version>2.9.4</version>
+    </dependency>
+    <dependency>
+      <groupId>com.fasterxml.jackson.core</groupId>
+      <artifactId>jackson-databind</artifactId>
+      <version>2.9.4</version>
+    </dependency>
+    <dependency>
+      <groupId>com.fasterxml.jackson.core</groupId>
+      <artifactId>jackson-annotations</artifactId>
+      <version>2.9.0</version>
+    </dependency>
+
+    <dependency>
+      <groupId>org.apache.commons</groupId>
+      <artifactId>commons-lang3</artifactId>
+      <version>3.7</version>
+    </dependency>
+
+    <dependency>
+      <groupId>ch.qos.logback</groupId>
+      <artifactId>logback-classic</artifactId>
+    </dependency>
+
+    <!-- Required driver implementation -->
+    <dependency>
+      <groupId>org.apache.plc4x</groupId>
+      <artifactId>plc4j-protocol-s7</artifactId>
+      <version>0.0.1-SNAPSHOT</version>
+      <scope>runtime</scope>
+    </dependency>
+  </dependencies>
+
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-dependency-plugin</artifactId>
+        <configuration>
+          <usedDependencies>
+            <usedDependency>org.apache.plc4x:plc4j-protocol-s7</usedDependency>
+          </usedDependencies>
+        </configuration>
+      </plugin>
+    </plugins>
+  </build>
+
+</project>
\ No newline at end of file
diff --git a/examples/kafka-bridge/server.sh b/examples/kafka-bridge/server.sh
new file mode 100755
index 0000000..e8971b6
--- /dev/null
+++ b/examples/kafka-bridge/server.sh
@@ -0,0 +1,30 @@
+#!/usr/bin/env bash
+# ----------------------------------------------------------------------------
+# 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.
+# ----------------------------------------------------------------------------
+
+cd /Users/christofer.dutz/Devtools/Apache/Kafka/kafka_2.12-0.11.0.1/bin
+
+# Start Zookeeper
+./zookeeper-server-start.sh -daemon ../config/zookeeper.properties
+
+# Start Kafka
+./kafka-server-start.sh -daemon ../config/server.properties
+
+./kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic test-topic --from-beginning
+
diff --git a/examples/kafka-bridge/src/main/java/org/apache/plc4x/java/examples/kafkabridge/KafkaBridge.java b/examples/kafka-bridge/src/main/java/org/apache/plc4x/java/examples/kafkabridge/KafkaBridge.java
new file mode 100644
index 0000000..2b4db45
--- /dev/null
+++ b/examples/kafka-bridge/src/main/java/org/apache/plc4x/java/examples/kafkabridge/KafkaBridge.java
@@ -0,0 +1,121 @@
+/*
+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.examples.kafkabridge;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.TimeUnit;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.edgent.connectors.kafka.KafkaProducer;
+import org.apache.edgent.function.Supplier;
+import org.apache.edgent.providers.direct.DirectProvider;
+import org.apache.edgent.topology.TStream;
+import org.apache.edgent.topology.Topology;
+import org.apache.plc4x.edgent.PlcConnectionAdapter;
+import org.apache.plc4x.edgent.PlcFunctions;
+import org.apache.plc4x.java.api.exceptions.PlcException;
+import org.apache.plc4x.java.api.messages.items.ReadRequestItem;
+import org.apache.plc4x.java.examples.kafkabridge.model.Address;
+import org.apache.plc4x.java.examples.kafkabridge.model.Configuration;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class KafkaBridge {
+
+    private static final Logger logger = LoggerFactory.getLogger(KafkaBridge.class);
+
+    private Configuration config;
+    private PlcConnectionAdapter plcAdapter;
+
+    private KafkaBridge(String propsPath) {
+        if(StringUtils.isEmpty(propsPath)) {
+            logger.error("Empty configuration file parameter");
+            throw new RuntimeException("Empty configuration file parameter");
+        }
+        File propsFile = new File(propsPath);
+        if(!(propsFile.exists() && propsFile.isFile())) {
+            logger.error("Invalid configuration file {}", propsFile.getPath());
+            throw new RuntimeException("Invalid configuration file " + propsFile.getPath());
+        }
+        ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
+        try {
+            config = mapper.readValue(propsFile, Configuration.class);
+            plcAdapter = new PlcConnectionAdapter(config.getPlcConfig().getConnection());
+        } catch (IOException e) {
+            logger.error("Error parsing configuration", e);
+        }
+    }
+
+    private void run() {
+        DirectProvider dp = new DirectProvider();
+        Topology top = dp.newTopology("kafka-bridge");
+
+        // Create the Kafka Producer broker connector
+        Map<String,Object> kafkaConfig = createKafkaConfig();
+        KafkaProducer kafka = new KafkaProducer(top, () -> kafkaConfig);
+
+        Map<String, ReadRequestItem> readRequestItems = new HashMap<>();
+
+        for(Address address : config.getPlcConfig().getAddresses()) {
+            try {
+                org.apache.plc4x.java.api.model.Address plcAddress = plcAdapter.parseAddress(address.getAddress());
+                ReadRequestItem readItem = new ReadRequestItem<>(address.getType(), plcAddress, address.getSize());
+                readRequestItems.put(address.getName(), readItem);
+            } catch (PlcException e) {
+                logger.error("Error parsing address {}", address.getAddress());
+            }
+        }
+        // TODO: Here we somehow have to create an Edgent supplier, that can cope with batch reads ...
+        // WARN: This example doesn't work at the moment ...
+        Supplier<Byte> plcSupplier = PlcFunctions.byteSupplier(plcAdapter, "INPUTS/0");
+
+        // Start polling our plc source in the given interval.
+        TStream<Byte> source = top.poll(plcSupplier, config.getPollingInterval(), TimeUnit.MILLISECONDS);
+
+        // Convert the byte into a string.
+        TStream<String> stringSource = source.map(value -> {
+            return Byte.toString(value);
+        });
+
+        // Publish the stream to the topic.  The String tuple is the message value.
+        kafka.publish(stringSource, config.getKafkaConfig().getTopicName());
+
+        dp.submit(top);
+    }
+
+    private Map<String,Object> createKafkaConfig() {
+        Map<String,Object> kafkaConfig = new HashMap<>();
+        kafkaConfig.put("bootstrap.servers", config.getKafkaConfig().getBootstrapServers());
+        return kafkaConfig;
+    }
+
+    public static void main(String[] args) {
+        if(args.length != 1) {
+            System.out.println("Usage: KafkaBridge {path-to-kafkabridge-yml}");
+        }
+        KafkaBridge kafkaBridge = new KafkaBridge(args[0]);
+        kafkaBridge.run();
+    }
+
+}
diff --git a/examples/kafka-bridge/src/main/java/org/apache/plc4x/java/examples/kafkabridge/model/Address.java b/examples/kafka-bridge/src/main/java/org/apache/plc4x/java/examples/kafkabridge/model/Address.java
new file mode 100644
index 0000000..686a49d
--- /dev/null
+++ b/examples/kafka-bridge/src/main/java/org/apache/plc4x/java/examples/kafkabridge/model/Address.java
@@ -0,0 +1,60 @@
+/*
+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.examples.kafkabridge.model;
+
+public class Address {
+
+    private String name;
+    private String address;
+    private int size;
+    private Class<?> type;
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public String getAddress() {
+        return address;
+    }
+
+    public void setAddress(String address) {
+        this.address = address;
+    }
+
+    public int getSize() {
+        return size;
+    }
+
+    public void setSize(int size) {
+        this.size = size;
+    }
+
+    public Class<?> getType() {
+        return type;
+    }
+
+    public void setType(Class<?> type) {
+        this.type = type;
+    }
+
+}
diff --git a/examples/kafka-bridge/src/main/java/org/apache/plc4x/java/examples/kafkabridge/model/Configuration.java b/examples/kafka-bridge/src/main/java/org/apache/plc4x/java/examples/kafkabridge/model/Configuration.java
new file mode 100644
index 0000000..8e2ce42
--- /dev/null
+++ b/examples/kafka-bridge/src/main/java/org/apache/plc4x/java/examples/kafkabridge/model/Configuration.java
@@ -0,0 +1,56 @@
+/*
+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.examples.kafkabridge.model;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+
+public class Configuration {
+
+    @JsonProperty("kafka")
+    private KafkaConfig kafkaConfig;
+    @JsonProperty("plc")
+    private PlcConfig plcConfig;
+    @JsonProperty("polling-interval")
+    private int pollingInterval;
+
+    public KafkaConfig getKafkaConfig() {
+        return kafkaConfig;
+    }
+
+    public void setKafkaConfig(KafkaConfig kafkaConfig) {
+        this.kafkaConfig = kafkaConfig;
+    }
+
+    public PlcConfig getPlcConfig() {
+        return plcConfig;
+    }
+
+    public void setPlcConfig(PlcConfig plcConfig) {
+        this.plcConfig = plcConfig;
+    }
+
+    public int getPollingInterval() {
+        return pollingInterval;
+    }
+
+    public void setPollingInterval(int pollingInterval) {
+        this.pollingInterval = pollingInterval;
+    }
+
+}
diff --git a/examples/kafka-bridge/src/main/java/org/apache/plc4x/java/examples/kafkabridge/model/KafkaConfig.java b/examples/kafka-bridge/src/main/java/org/apache/plc4x/java/examples/kafkabridge/model/KafkaConfig.java
new file mode 100644
index 0000000..99b9099
--- /dev/null
+++ b/examples/kafka-bridge/src/main/java/org/apache/plc4x/java/examples/kafkabridge/model/KafkaConfig.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.java.examples.kafkabridge.model;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+
+public class KafkaConfig {
+
+    @JsonProperty("topic-name")
+    private String topicName;
+    @JsonProperty("bootstrap-servers")
+    private String bootstrapServers;
+
+    public String getTopicName() {
+        return topicName;
+    }
+
+    public void setTopicName(String topicName) {
+        this.topicName = topicName;
+    }
+
+    public String getBootstrapServers() {
+        return bootstrapServers;
+    }
+
+    public void setBootstrapServers(String bootstrapServers) {
+        this.bootstrapServers = bootstrapServers;
+    }
+
+}
diff --git a/examples/kafka-bridge/src/main/java/org/apache/plc4x/java/examples/kafkabridge/model/PlcConfig.java b/examples/kafka-bridge/src/main/java/org/apache/plc4x/java/examples/kafkabridge/model/PlcConfig.java
new file mode 100644
index 0000000..76c76b9
--- /dev/null
+++ b/examples/kafka-bridge/src/main/java/org/apache/plc4x/java/examples/kafkabridge/model/PlcConfig.java
@@ -0,0 +1,44 @@
+/*
+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.examples.kafkabridge.model;
+
+import java.util.List;
+
+public class PlcConfig {
+
+    private String connection;
+    private List<Address> addresses;
+
+    public String getConnection() {
+        return connection;
+    }
+
+    public void setConnection(String connection) {
+        this.connection = connection;
+    }
+
+    public List<Address> getAddresses() {
+        return addresses;
+    }
+
+    public void setAddresses(List<Address> addresses) {
+        this.addresses = addresses;
+    }
+
+}
diff --git a/examples/kafka-bridge/src/main/resources/logback.xml b/examples/kafka-bridge/src/main/resources/logback.xml
new file mode 100644
index 0000000..bba8e02
--- /dev/null
+++ b/examples/kafka-bridge/src/main/resources/logback.xml
@@ -0,0 +1,36 @@
+<?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.
+
+-->
+<configuration xmlns="http://ch.qos.logback/xml/ns/logback"
+               xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+               xsi:schemaLocation="http://ch.qos.logback/xml/ns/logback https://raw.githubusercontent.com/enricopulatzo/logback-XSD/master/src/main/xsd/logback.xsd">
+
+  <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
+    <!-- encoders are assigned the type
+         ch.qos.logback.classic.encoder.PatternLayoutEncoder by default -->
+    <encoder>
+      <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
+    </encoder>
+  </appender>
+
+  <root level="warn">
+    <appender-ref ref="STDOUT" />
+  </root>
+
+</configuration>
\ No newline at end of file
diff --git a/examples/pom.xml b/examples/pom.xml
index f6c6721..88e92bd 100644
--- a/examples/pom.xml
+++ b/examples/pom.xml
@@ -38,6 +38,7 @@
   <modules>
     <module>dummy-driver</module>
     <module>iotree</module>
+    <module>kafka-bridge</module>
     <module>plclogger</module>
   </modules>
 

-- 
To stop receiving notification emails like this one, please contact
cdutz@apache.org.

[incubator-plc4x] 03/06: Simplified the S7PlcReaderSample

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

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

commit 4bd1219c07982c1373a212c8d0c1d86e9e7fc47d
Author: Christofer Dutz <ch...@c-ware.de>
AuthorDate: Wed Feb 7 13:50:54 2018 +0100

    Simplified the S7PlcReaderSample
---
 .../apache/plc4x/java/s7/S7PlcReaderSample.java    | 99 ++++++++++------------
 1 file changed, 45 insertions(+), 54 deletions(-)

diff --git a/plc4j/protocols/s7/src/test/java/org/apache/plc4x/java/s7/S7PlcReaderSample.java b/plc4j/protocols/s7/src/test/java/org/apache/plc4x/java/s7/S7PlcReaderSample.java
index cecdb9f..91e119a 100644
--- a/plc4j/protocols/s7/src/test/java/org/apache/plc4x/java/s7/S7PlcReaderSample.java
+++ b/plc4j/protocols/s7/src/test/java/org/apache/plc4x/java/s7/S7PlcReaderSample.java
@@ -28,6 +28,7 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import java.util.Optional;
+import java.util.concurrent.CompletableFuture;
 
 public class S7PlcReaderSample {
 
@@ -39,60 +40,50 @@ public class S7PlcReaderSample {
      * @param args ignored.
      * @throws Exception something went wrong.
      */
-    public static void main(String[] args) throws Exception {
-        // Create a connection to the S7 PLC (s7://{hostname/ip}/{racknumber}/{slotnumber})
-        logger.info("Connecting");
-        try (PlcConnection plcConnection = new PlcDriverManager().getConnection("s7://192.168.0.1/0/0")) {
-            logger.info("Connected");
-
-            Optional<PlcReader> reader = plcConnection.getReader();
-            // Check if this connection support reading of data.
-            if (reader.isPresent()) {
-                PlcReader plcReader = reader.get();
-
-                // Prepare some address object for accessing fields in the PLC.
-                // ({memory-area}/{byte-offset}[/{bit-offset}]
-                // "bit-offset is only specified if the requested type is "bit"
-                // NOTICE: This format is probably only valid when using a S7 connection.
-                Address inputs = plcConnection.parseAddress("INPUTS/0");
-                Address outputs = plcConnection.parseAddress("OUTPUTS/0");
-
-                //////////////////////////////////////////////////////////
-                // Read synchronously ...
-                // NOTICE: the ".get()" immediately lets this thread pause till
-                // the response is processed and available.
-                TypeSafePlcReadResponse<Byte> plcReadResponse = plcReader.read(new TypeSafePlcReadRequest<>(Byte.class, inputs)).get();
-                System.out.println("Inputs: " + plcReadResponse.getResponseItem()
-                    .orElseThrow(() -> new IllegalStateException("No response available"))
-                    .getValues().get(0));
-
-                //////////////////////////////////////////////////////////
-                // Read asynchronously ...
-                /*Calendar start = Calendar.getInstance();
-                CompletableFuture<PlcReadResponse<Byte>> asyncResponse = plcReader.read(
-                    new BytePlcReadRequest(outputs));
-
-                asyncResponse.thenAccept(bytePlcReadResponse -> {
-                    Calendar end = Calendar.getInstance();
-                    Byte dataAsync = bytePlcReadResponse.getValue();
-                    System.out.println("Outputs: " + dataAsync + " (in " + (end.getTimeInMillis() - start.getTimeInMillis()) + "ms)");
-                });
-
-                // Simulate doing something else ...
-                while (true) {
-                    Thread.sleep(1);
-                    if (asyncResponse.isDone()) {
-                        break;
-                    }
-                }*/
-            }
-        }
-        // Catch any exception or the application won't be able to finish if something goes wrong.
-        catch (Exception e) {
-            logger.error("S7 PLC reader sample", e);
-        }
-        // The application would cleanly terminate after several seconds ... this just speeds things up.
-        System.exit(0);
+    @SuppressWarnings("unchecked")
+public static void main(String[] args) throws Exception {
+  try (PlcConnection plcConnection =
+    new PlcDriverManager().getConnection(args[0])) {
+
+    Optional<PlcReader> reader = plcConnection.getReader();
+
+    // Check if this connection support reading of data.
+    if (reader.isPresent()) {
+      PlcReader plcReader = reader.get();
+
+      // Parse an address string.
+      Address inputs = plcConnection.parseAddress(args[1]);
+
+      //////////////////////////////////////////////////////////
+      // Read synchronously ...
+      // NOTICE: the ".get()" immediately lets this thread pause till
+      // the response is processed and available.
+      TypeSafePlcReadResponse<Byte> plcReadResponse = plcReader.read(
+        new TypeSafePlcReadRequest<>(Byte.class, inputs)).get();
+
+      System.out.println("Inputs: " + plcReadResponse.getResponseItem()
+        .orElseThrow(() -> new IllegalStateException("No response available"))
+        .getValues().get(0));
+
+      //////////////////////////////////////////////////////////
+      // Read asynchronously ...
+      CompletableFuture<TypeSafePlcReadResponse<Byte>> asyncResponse = plcReader.read(
+        new TypeSafePlcReadRequest(Byte.class, inputs));
+
+      asyncResponse.thenAccept(bytePlcReadResponse -> {
+        Byte dataAsync = bytePlcReadResponse.getResponseItem()
+          .orElseThrow(() -> new IllegalStateException("No response available"))
+          .getValues().get(0);
+        System.out.println("Inputs: " + dataAsync);
+      });
+
+      // do something else ...
     }
+  }
+  // Catch any exception or the application won't be able to finish if something goes wrong.
+  catch (Exception e) {
+    logger.error("S7 PLC reader sample", e);
+  }
+}
 
 }

-- 
To stop receiving notification emails like this one, please contact
cdutz@apache.org.

[incubator-plc4x] 04/06: Some more work on the dummy driver - Should now use the "dummy" connection prefix - Should use a raw socket to send an ICMP (Ping) packet

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

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

commit d9b993f1bf180cddca66e74cd534a4f5150bae27
Author: Christofer Dutz <ch...@c-ware.de>
AuthorDate: Wed Feb 7 13:52:39 2018 +0100

    Some more work on the dummy driver
    - Should now use the "dummy" connection prefix
    - Should use a raw socket to send an ICMP (Ping) packet
---
 .../java/examples/dummydriver/DummyDriver.java     | 12 +++++-----
 .../examples/dummydriver/netty/DummyProtocol.java  | 28 ++++++++++++++--------
 2 files changed, 24 insertions(+), 16 deletions(-)

diff --git a/examples/dummy-driver/src/main/java/org/apache/plc4x/java/examples/dummydriver/DummyDriver.java b/examples/dummy-driver/src/main/java/org/apache/plc4x/java/examples/dummydriver/DummyDriver.java
index 0e62561..efc42c2 100644
--- a/examples/dummy-driver/src/main/java/org/apache/plc4x/java/examples/dummydriver/DummyDriver.java
+++ b/examples/dummy-driver/src/main/java/org/apache/plc4x/java/examples/dummydriver/DummyDriver.java
@@ -29,24 +29,24 @@ import java.util.regex.Pattern;
 
 public class DummyDriver implements PlcDriver {
 
-    private static final Pattern RAW_URI_PATTERN = Pattern.compile("^raw://(?<host>.*)");
+    private static final Pattern DUMMY_URI_PATTERN = Pattern.compile("^dummy://(?<host>.*)");
 
     @Override
     public String getProtocolCode() {
-        return "raw";
+        return "dummy";
     }
 
     @Override
     public String getProtocolName() {
-        return "RAW";
+        return "Dummy";
     }
 
     @Override
     public PlcConnection connect(String url) throws PlcConnectionException {
-        Matcher matcher = RAW_URI_PATTERN.matcher(url);
+        Matcher matcher = DUMMY_URI_PATTERN.matcher(url);
         if (!matcher.matches()) {
             throw new PlcConnectionException(
-                "Connection url doesn't match the format 'raw://{host|ip}'");
+                "Connection url doesn't match the format 'dummy://{host|ip}'");
         }
         String host = matcher.group("host");
         return new DummyConnection(host);
@@ -54,7 +54,7 @@ public class DummyDriver implements PlcDriver {
 
     @Override
     public PlcConnection connect(String url, PlcAuthentication authentication) throws PlcConnectionException {
-        throw new PlcConnectionException("RAW connections don't support authentication.");
+        throw new PlcConnectionException("Dummy connections don't support authentication.");
     }
 
 }
diff --git a/examples/dummy-driver/src/main/java/org/apache/plc4x/java/examples/dummydriver/netty/DummyProtocol.java b/examples/dummy-driver/src/main/java/org/apache/plc4x/java/examples/dummydriver/netty/DummyProtocol.java
index 458074d..bf448ea 100644
--- a/examples/dummy-driver/src/main/java/org/apache/plc4x/java/examples/dummydriver/netty/DummyProtocol.java
+++ b/examples/dummy-driver/src/main/java/org/apache/plc4x/java/examples/dummydriver/netty/DummyProtocol.java
@@ -20,13 +20,12 @@ package org.apache.plc4x.java.examples.dummydriver.netty;
 
 import io.netty.buffer.ByteBuf;
 import io.netty.buffer.ByteBufUtil;
+import io.netty.buffer.Unpooled;
 import io.netty.channel.ChannelHandlerContext;
 import io.netty.handler.codec.MessageToMessageCodec;
-import org.apache.plc4x.java.api.exceptions.PlcException;
 import org.apache.plc4x.java.api.messages.PlcReadRequest;
 import org.apache.plc4x.java.api.messages.PlcRequest;
 import org.apache.plc4x.java.api.messages.PlcRequestContainer;
-import org.apache.plc4x.java.api.messages.PlcWriteRequest;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -40,16 +39,25 @@ public class DummyProtocol extends MessageToMessageCodec<ByteBuf, PlcRequestCont
     protected void encode(ChannelHandlerContext ctx, PlcRequestContainer in, List<Object> out) throws Exception {
         PlcRequest request = in.getRequest();
         if (request instanceof PlcReadRequest) {
-            encodeReadRequest(in, out);
-        } else if (request instanceof PlcWriteRequest) {
-            encodeWriteRequest(in, out);
-        }
-    }
 
-    private void encodeWriteRequest(PlcRequestContainer msg, List<Object> out) throws PlcException {
-    }
+            // Simple ICMP (Ping packet)
+            byte[] rawData = new byte[] {
+                // Type (ICMP Ping Request) & Code (just 0)
+                (byte) 0x08, (byte) 0x00,
+                // Checksum
+                (byte) 0xe3, (byte) 0xe5,
+                // Identifier
+                (byte) 0x00, (byte) 0x01,
+                // Sequence Number
+                (byte) 0x00, (byte) 0x00,
+                // Payload (Just random data that was used to fit to the checksum)
+                (byte) 0x00, (byte) 0x01, (byte) 0x02, (byte) 0x03, (byte) 0x04, (byte) 0x05, (byte) 0x06, (byte) 0x07, (byte) 0x08, (byte) 0x09};
 
-    private void encodeReadRequest(PlcRequestContainer msg, List<Object> out) throws PlcException {
+            ByteBuf buf = Unpooled.buffer();
+            buf.writeBytes(rawData);
+
+            out.add(buf);
+        }
     }
 
     @Override

-- 
To stop receiving notification emails like this one, please contact
cdutz@apache.org.

[incubator-plc4x] 05/06: Exposed a parseAddress method on the connection-adapter

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

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

commit 21e6f784bd727f9fd635d24d5e9f3fe651e2fde3
Author: Christofer Dutz <ch...@c-ware.de>
AuthorDate: Wed Feb 7 14:26:21 2018 +0100

    Exposed a parseAddress method on the connection-adapter
---
 .../src/main/java/org/apache/plc4x/edgent/PlcConnectionAdapter.java   | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/integrations/apache-edgent/src/main/java/org/apache/plc4x/edgent/PlcConnectionAdapter.java b/integrations/apache-edgent/src/main/java/org/apache/plc4x/edgent/PlcConnectionAdapter.java
index 3eebcfe..ca6955d 100644
--- a/integrations/apache-edgent/src/main/java/org/apache/plc4x/edgent/PlcConnectionAdapter.java
+++ b/integrations/apache-edgent/src/main/java/org/apache/plc4x/edgent/PlcConnectionAdapter.java
@@ -99,6 +99,10 @@ public class PlcConnectionAdapter implements AutoCloseable {
         }
     }
 
+    public Address parseAddress(String addressString) throws PlcException {
+        return getConnection().parseAddress(addressString);
+    }
+
     <T> Supplier<T> newSupplier(Class<T> datatype, String addressStr) {
         PlcConnectionAdapter.checkDatatype(datatype);
         return new Supplier<T>() {

-- 
To stop receiving notification emails like this one, please contact
cdutz@apache.org.