You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@plc4x.apache.org by sr...@apache.org on 2018/02/02 07:54:51 UTC

[incubator-plc4x] branch feature/Beckhoff_ADS_protocol updated: added basic ADSPlcDriver

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

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


The following commit(s) were added to refs/heads/feature/Beckhoff_ADS_protocol by this push:
     new 1427280  added basic ADSPlcDriver
1427280 is described below

commit 1427280fa3893801a232fb74d8ea9f485b3ae3fd
Author: Sebastian Rühl <sr...@apache.org>
AuthorDate: Fri Feb 2 08:54:47 2018 +0100

    added basic ADSPlcDriver
---
 .../org/apache/plc4x/java/ads/ADSPlcDriver.java    | 75 ++++++++++++++++++++++
 1 file changed, 75 insertions(+)

diff --git a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/ADSPlcDriver.java b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/ADSPlcDriver.java
new file mode 100644
index 0000000..0b2ea3c
--- /dev/null
+++ b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/ADSPlcDriver.java
@@ -0,0 +1,75 @@
+/*
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements.  See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership.  The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License.  You may obtain a copy of the License at
+
+  http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied.  See the License for the
+specific language governing permissions and limitations
+under the License.
+*/
+package org.apache.plc4x.java.ads;
+
+import org.apache.plc4x.java.ads.api.generic.types.AMSNetId;
+import org.apache.plc4x.java.ads.api.generic.types.AMSPort;
+import org.apache.plc4x.java.ads.connection.ADSPlcConnection;
+import org.apache.plc4x.java.api.PlcDriver;
+import org.apache.plc4x.java.api.authentication.PlcAuthentication;
+import org.apache.plc4x.java.api.connection.PlcConnection;
+import org.apache.plc4x.java.api.exceptions.PlcConnectionException;
+
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/**
+ * Implementation of the ADS protocol, based on:
+ * - ADS Protocol
+ * - TCP
+ */
+public class ADSPlcDriver implements PlcDriver {
+
+    private static final Pattern ADS_ADDRESS_PATTERN =
+        Pattern.compile("^(?<targetAmsNetId>" + AMSNetId.AMS_NET_ID_REGEX + "):(?<targetAmsPort>" + AMSPort.AMS_PORT_REGEX + ")"
+            + "/"
+            + "(?<sourceAmsNetId>" + AMSNetId.AMS_NET_ID_REGEX + "):(?<sourceAmsPort>" + AMSPort.AMS_PORT_REGEX + ")");
+    private static final Pattern ADS_URI_PATTERN = Pattern.compile("^ads://(?<host>\\w+)/" + ADS_ADDRESS_PATTERN);
+
+    @Override
+    public String getProtocolCode() {
+        return "ads";
+    }
+
+    @Override
+    public String getProtocolName() {
+        return "Beckhoff Twincat ADS";
+    }
+
+    @Override
+    public PlcConnection connect(String url) throws PlcConnectionException {
+        Matcher matcher = ADS_URI_PATTERN.matcher(url);
+        if (!matcher.matches()) {
+            throw new PlcConnectionException(
+                "Connection url doesn't match the format 'ads://{host|ip}/{targetAmsNetId}:{targetAmsPort}/{sourceAmsNetId}:{sourceAmsPort}'");
+        }
+        String host = matcher.group("host");
+        AMSNetId targetAmsNetId = AMSNetId.of(matcher.group("targetAmsNetId"));
+        AMSPort targetAmsPort = AMSPort.of(matcher.group("targetAmsPort"));
+        AMSNetId sourceAmsNetId = AMSNetId.of(matcher.group("sourceAmsNetId"));
+        AMSPort sourceAmsPort = AMSPort.of(matcher.group("sourceAmsPort"));
+        return new ADSPlcConnection(host, targetAmsNetId, targetAmsPort, sourceAmsNetId, sourceAmsPort);
+    }
+
+    @Override
+    public PlcConnection connect(String url, PlcAuthentication authentication) throws PlcConnectionException {
+        throw new PlcConnectionException("Basic ADS connections don't support authentication.");
+    }
+
+}

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