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/06/21 08:45:57 UTC

[incubator-plc4x] branch master updated (de97867 -> 971acb2)

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

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


    from de97867  fix remaining sonar bug
     new cf6d54d  added tests for AdsNotificationSample and AdsStampHeader
     new 151a20f  fixed serial driver regex to match the serial port the right way
     new 971acb2  added serial testing to ManualPlc4AdsTest

The 3 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:
 .../org/apache/plc4x/java/ads/AdsPlcDriver.java    |  2 +-
 .../apache/plc4x/java/ads/ManualPlc4XAdsTest.java  | 10 ++-
 .../commands/types/AdsNotificationSampleTest.java  | 69 +++++++++++++++++
 .../ads/api/commands/types/AdsStampHeaderTest.java | 90 ++++++++++++++++++++++
 4 files changed, 169 insertions(+), 2 deletions(-)
 create mode 100644 plc4j/protocols/ads/src/test/java/org/apache/plc4x/java/ads/api/commands/types/AdsNotificationSampleTest.java
 create mode 100644 plc4j/protocols/ads/src/test/java/org/apache/plc4x/java/ads/api/commands/types/AdsStampHeaderTest.java


[incubator-plc4x] 02/03: fixed serial driver regex to match the serial port the right way

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

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

commit 151a20ffbcf00082b2336f97cbbb1881425cdbc7
Author: Sebastian Rühl <sr...@apache.org>
AuthorDate: Thu Jun 21 10:34:49 2018 +0200

    fixed serial driver regex to match the serial port the right way
---
 .../ads/src/main/java/org/apache/plc4x/java/ads/AdsPlcDriver.java       | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

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
index 2e6b3bf..2a208ad 100644
--- 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
@@ -46,7 +46,7 @@ public class AdsPlcDriver implements PlcDriver {
             + "(?<sourceAmsNetId>" + AmsNetId.AMS_NET_ID_PATTERN + "):(?<sourceAmsPort>" + AmsPort.AMS_PORT_PATTERN + ")"
             + ")?");
     public static final Pattern INET_ADDRESS_PATTERN = Pattern.compile("tcp://(?<host>[\\w.]+)(:(?<port>\\d*))?");
-    public static final Pattern SERIAL_PATTERN = Pattern.compile("serial://(?<serialDefinition>.*)");
+    public static final Pattern SERIAL_PATTERN = Pattern.compile("serial://(?<serialDefinition>((?!/\\d).)*)");
     public static final Pattern ADS_URI_PATTERN = Pattern.compile("^ads:(" + INET_ADDRESS_PATTERN + "|" + SERIAL_PATTERN + ")/" + ADS_ADDRESS_PATTERN + "(\\?.*)?");
 
     private AdsConnectionFactory adsConnectionFactory;


[incubator-plc4x] 01/03: added tests for AdsNotificationSample and AdsStampHeader

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

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

commit cf6d54d85b82178e6d4242aeda6850d4b07a3286
Author: Sebastian Rühl <sr...@apache.org>
AuthorDate: Thu Jun 21 10:12:35 2018 +0200

    added tests for AdsNotificationSample and AdsStampHeader
---
 .../commands/types/AdsNotificationSampleTest.java  | 69 +++++++++++++++++
 .../ads/api/commands/types/AdsStampHeaderTest.java | 90 ++++++++++++++++++++++
 2 files changed, 159 insertions(+)

diff --git a/plc4j/protocols/ads/src/test/java/org/apache/plc4x/java/ads/api/commands/types/AdsNotificationSampleTest.java b/plc4j/protocols/ads/src/test/java/org/apache/plc4x/java/ads/api/commands/types/AdsNotificationSampleTest.java
new file mode 100644
index 0000000..3d5f947
--- /dev/null
+++ b/plc4j/protocols/ads/src/test/java/org/apache/plc4x/java/ads/api/commands/types/AdsNotificationSampleTest.java
@@ -0,0 +1,69 @@
+/*
+ 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.api.commands.types;
+
+import org.junit.Test;
+
+import static org.apache.plc4x.java.ads.util.Assert.assertByteEquals;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+public class AdsNotificationSampleTest {
+
+    @Test
+    public void builder() throws Exception {
+        {
+            AdsNotificationSample adsNotificationSample = AdsNotificationSample.of(NotificationHandle.of(13), Data.of("Hello World!"));
+            assertNotNull(adsNotificationSample);
+            byte[] expected = {
+                0x0D, 0x00, 0x00, 0x00,
+                0x0D, 0x00, 0x00, 0x00,
+                0x48, 0x65, 0x6C, 0x6C,
+                0x6F, 0x20, 0x57, 0x6F,
+                0x72, 0x6C, 0x64, 0x21,
+                0x00
+            };
+            assertByteEquals(expected, adsNotificationSample.getBytes());
+            assertEquals(SampleSize.of(13), adsNotificationSample.getSampleSize());
+            assertEquals(Data.of("Hello World!"), adsNotificationSample.getData());
+        }
+        {
+            AdsNotificationSample adsNotificationSample = AdsNotificationSample.of(NotificationHandle.of(13), SampleSize.of(13), Data.of("Hello World!"));
+            assertNotNull(adsNotificationSample);
+            byte[] expected = {
+                0x0D, 0x00, 0x00, 0x00,
+                0x0D, 0x00, 0x00, 0x00,
+                0x48, 0x65, 0x6C, 0x6C,
+                0x6F, 0x20, 0x57, 0x6F,
+                0x72, 0x6C, 0x64, 0x21,
+                0x00
+            };
+            assertByteEquals(expected, adsNotificationSample.getBytes());
+            assertEquals(SampleSize.of(13), adsNotificationSample.getSampleSize());
+            assertEquals(Data.of("Hello World!"), adsNotificationSample.getData());
+        }
+    }
+
+    @Test
+    public void sizeCalculation() {
+        AdsNotificationSample adsNotificationSample1 = AdsNotificationSample.of(NotificationHandle.of(13), SampleSize.of(13), Data.of("Hello World!"));
+        AdsNotificationSample adsNotificationSample2 = AdsNotificationSample.of(NotificationHandle.of(13), Data.of("Hello World!"));
+        assertEquals(adsNotificationSample1, adsNotificationSample2);
+    }
+}
\ No newline at end of file
diff --git a/plc4j/protocols/ads/src/test/java/org/apache/plc4x/java/ads/api/commands/types/AdsStampHeaderTest.java b/plc4j/protocols/ads/src/test/java/org/apache/plc4x/java/ads/api/commands/types/AdsStampHeaderTest.java
new file mode 100644
index 0000000..86a8e01
--- /dev/null
+++ b/plc4j/protocols/ads/src/test/java/org/apache/plc4x/java/ads/api/commands/types/AdsStampHeaderTest.java
@@ -0,0 +1,90 @@
+/*
+ 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.api.commands.types;
+
+import org.junit.Test;
+
+import java.util.Arrays;
+
+import static org.apache.plc4x.java.ads.util.Assert.assertByteEquals;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+public class AdsStampHeaderTest {
+
+    @Test
+    public void builder() throws Exception {
+        {
+            AdsStampHeader adsStampHeader = AdsStampHeader.of(TimeStamp.of(13), Arrays.asList(AdsNotificationSample.of(NotificationHandle.of(13), Data.of("Hello World!")), AdsNotificationSample.of(NotificationHandle.of(14), Data.of("Hello World!"))));
+            assertNotNull(adsStampHeader);
+            byte[] expected = {
+                (byte) 0xD0, 0x7B, 0x40, (byte) 0xD5,
+                (byte) 0xDE, (byte) 0xB1, (byte) 0x9D, 0x01,
+                0x02, 0x00, 0x00, 0x00,
+                0x0D, 0x00, 0x00, 0x00,
+                0x0D, 0x00, 0x00, 0x00,
+                0x48, 0x65, 0x6C, 0x6C,
+                0x6F, 0x20, 0x57, 0x6F,
+                0x72, 0x6C, 0x64, 0x21,
+                0x00, 0x0E, 0x00, 0x00,
+                0x00, 0x0D, 0x00, 0x00,
+                0x00, 0x48, 0x65, 0x6C,
+                0x6C, 0x6F, 0x20, 0x57,
+                0x6F, 0x72, 0x6C, 0x64,
+                0x21, 0x00
+            };
+            assertByteEquals(expected, adsStampHeader.getBytes());
+            assertEquals(Samples.of(2), adsStampHeader.getSamples());
+            assertEquals(2, adsStampHeader.getAdsNotificationSamples().size());
+            assertEquals(Data.of("Hello World!"), adsStampHeader.getAdsNotificationSamples().get(0).getData());
+        }
+        {
+            AdsStampHeader adsStampHeader = AdsStampHeader.of(TimeStamp.of(13), Samples.of(2), Arrays.asList(AdsNotificationSample.of(NotificationHandle.of(13), Data.of("Hello World!")), AdsNotificationSample.of(NotificationHandle.of(14), Data.of("Hello World!"))));
+            assertNotNull(adsStampHeader);
+            byte[] expected = {
+                (byte) 0xD0, 0x7B, 0x40, (byte) 0xD5,
+                (byte) 0xDE, (byte) 0xB1, (byte) 0x9D, 0x01,
+                0x02, 0x00, 0x00, 0x00,
+                0x0D, 0x00, 0x00, 0x00,
+                0x0D, 0x00, 0x00, 0x00,
+                0x48, 0x65, 0x6C, 0x6C,
+                0x6F, 0x20, 0x57, 0x6F,
+                0x72, 0x6C, 0x64, 0x21,
+                0x00, 0x0E, 0x00, 0x00,
+                0x00, 0x0D, 0x00, 0x00,
+                0x00, 0x48, 0x65, 0x6C,
+                0x6C, 0x6F, 0x20, 0x57,
+                0x6F, 0x72, 0x6C, 0x64,
+                0x21, 0x00
+            };
+            assertByteEquals(expected, adsStampHeader.getBytes());
+            assertEquals(Samples.of(2), adsStampHeader.getSamples());
+            assertEquals(2, adsStampHeader.getAdsNotificationSamples().size());
+            assertEquals(Data.of("Hello World!"), adsStampHeader.getAdsNotificationSamples().get(0).getData());
+        }
+
+    }
+
+    @Test
+    public void sizeCalculation() {
+        AdsStampHeader adsStampHeader1 = AdsStampHeader.of(TimeStamp.of(13), Arrays.asList(AdsNotificationSample.of(NotificationHandle.of(13), Data.of("Hello World!")), AdsNotificationSample.of(NotificationHandle.of(14), Data.of("Hello World!"))));
+        AdsStampHeader adsStampHeader2 = AdsStampHeader.of(TimeStamp.of(13), Samples.of(2), Arrays.asList(AdsNotificationSample.of(NotificationHandle.of(13), Data.of("Hello World!")), AdsNotificationSample.of(NotificationHandle.of(14), Data.of("Hello World!"))));
+        assertEquals(adsStampHeader1, adsStampHeader2);
+    }
+}
\ No newline at end of file


[incubator-plc4x] 03/03: added serial testing to ManualPlc4AdsTest

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

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

commit 971acb28dd7b171763e8c1909bcc13e835d4389b
Author: Sebastian Rühl <sr...@apache.org>
AuthorDate: Thu Jun 21 10:45:50 2018 +0200

    added serial testing to ManualPlc4AdsTest
---
 .../java/org/apache/plc4x/java/ads/ManualPlc4XAdsTest.java     | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/plc4j/protocols/ads/src/test/java/org/apache/plc4x/java/ads/ManualPlc4XAdsTest.java b/plc4j/protocols/ads/src/test/java/org/apache/plc4x/java/ads/ManualPlc4XAdsTest.java
index 345b87c..7d8566e 100644
--- a/plc4j/protocols/ads/src/test/java/org/apache/plc4x/java/ads/ManualPlc4XAdsTest.java
+++ b/plc4j/protocols/ads/src/test/java/org/apache/plc4x/java/ads/ManualPlc4XAdsTest.java
@@ -35,7 +35,15 @@ import java.util.function.Consumer;
 public class ManualPlc4XAdsTest {
 
     public static void main(String... args) throws Exception {
-        try (PlcConnection plcConnection = new PlcDriverManager().getConnection("ads:tcp://10.10.64.40/10.10.64.40.1.1:851/10.10.56.23.1.1:30000")) {
+        String connectionUrl;
+        if (args.length > 0 && "serial".equalsIgnoreCase(args[0])) {
+            System.out.println("Using serial");
+            connectionUrl = "ads:serial:///dev/ttys003/10.10.64.40.1.1:851/10.10.56.23.1.1:30000";
+        } else {
+            System.out.println("Using tcp");
+            connectionUrl = "ads:tcp://10.10.64.40/10.10.64.40.1.1:851/10.10.56.23.1.1:30000";
+        }
+        try (PlcConnection plcConnection = new PlcDriverManager().getConnection(connectionUrl)) {
             System.out.println("PlcConnection " + plcConnection);
 
             PlcReader reader = plcConnection.getReader().orElseThrow(() -> new RuntimeException("No Reader found"));