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 10:24:43 UTC

[incubator-plc4x] branch feature/Beckhoff_ADS_protocol updated (46fa650 -> 7805d0c)

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

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


    from 46fa650  fixed wrong implementation of Length
     new d0e3445  fixed ReadLength implementation
     new 7805d0c  fixed failing build

The 2 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:
 plc4j/protocols/ads/pom.xml                        | 14 ------------
 .../java/ads/api/commands/types/ReadLength.java    | 19 ++++++++++++++--
 .../types/{LengthTest.java => ReadLengthTest.java} | 25 +++++++++++-----------
 3 files changed, 29 insertions(+), 29 deletions(-)
 copy plc4j/protocols/ads/src/test/java/org/apache/plc4x/java/ads/api/commands/types/{LengthTest.java => ReadLengthTest.java} (70%)

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

[incubator-plc4x] 02/02: fixed failing build

Posted by sr...@apache.org.
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

commit 7805d0c1c89d12598250ea4a1677dec26ef6ffdd
Author: Sebastian Rühl <sr...@apache.org>
AuthorDate: Fri Feb 2 11:24:39 2018 +0100

    fixed failing build
---
 plc4j/protocols/ads/pom.xml | 14 --------------
 1 file changed, 14 deletions(-)

diff --git a/plc4j/protocols/ads/pom.xml b/plc4j/protocols/ads/pom.xml
index 18e37df..178a166 100644
--- a/plc4j/protocols/ads/pom.xml
+++ b/plc4j/protocols/ads/pom.xml
@@ -59,26 +59,12 @@
     </dependency>
 
     <dependency>
-      <groupId>ch.qos.logback</groupId>
-      <artifactId>logback-classic</artifactId>
-    </dependency>
-    <dependency>
-      <groupId>ch.qos.logback</groupId>
-      <artifactId>logback-core</artifactId>
-    </dependency>
-
-    <dependency>
       <groupId>org.apache.commons</groupId>
       <artifactId>commons-lang3</artifactId>
       <version>3.7</version>
     </dependency>
 
     <dependency>
-      <groupId>commons-io</groupId>
-      <artifactId>commons-io</artifactId>
-      <scope>test</scope>
-    </dependency>
-    <dependency>
       <groupId>commons-codec</groupId>
       <artifactId>commons-codec</artifactId>
       <version>1.11</version>

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

[incubator-plc4x] 01/02: fixed ReadLength implementation

Posted by sr...@apache.org.
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

commit d0e34452450a8b76bf033aa85e8cd30746d4aad1
Author: Sebastian Rühl <sr...@apache.org>
AuthorDate: Fri Feb 2 11:21:46 2018 +0100

    fixed ReadLength implementation
---
 .../java/ads/api/commands/types/ReadLength.java    | 19 +++++++-
 .../ads/api/commands/types/ReadLengthTest.java     | 55 ++++++++++++++++++++++
 2 files changed, 72 insertions(+), 2 deletions(-)

diff --git a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/types/ReadLength.java b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/types/ReadLength.java
index 0917ebf..9f48a2b 100644
--- a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/types/ReadLength.java
+++ b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/types/ReadLength.java
@@ -31,11 +31,26 @@ public class ReadLength extends ByteValue {
         assertLength(NUM_BYTES);
     }
 
-    public static ReadLength of(int length) {
-        return new ReadLength(ByteBuffer.allocate(NUM_BYTES).putInt(length).array());
+    public static ReadLength of(long length) {
+        checkUnsignedBounds(length, NUM_BYTES);
+        return new ReadLength(ByteBuffer.allocate(NUM_BYTES)
+            .put((byte) (length >> 24 & 0xff))
+            .put((byte) (length >> 16 & 0xff))
+            .put((byte) (length >> 8 & 0xff))
+            .put((byte) (length & 0xff))
+            .array());
+    }
+
+    public static ReadLength of(String length) {
+        return of(Long.parseLong(length));
     }
 
     public static ReadLength of(byte... values) {
         return new ReadLength(values);
     }
+
+    @Override
+    public String toString() {
+        return "" + (getBytes()[0] << 24 | getBytes()[1] << 16 | getBytes()[2] << 8 | getBytes()[3]);
+    }
 }
diff --git a/plc4j/protocols/ads/src/test/java/org/apache/plc4x/java/ads/api/commands/types/ReadLengthTest.java b/plc4j/protocols/ads/src/test/java/org/apache/plc4x/java/ads/api/commands/types/ReadLengthTest.java
new file mode 100644
index 0000000..1c93d05
--- /dev/null
+++ b/plc4j/protocols/ads/src/test/java/org/apache/plc4x/java/ads/api/commands/types/ReadLengthTest.java
@@ -0,0 +1,55 @@
+/*
+ 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.apache.commons.codec.binary.Hex;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+class ReadReadLengthTest {
+    byte NULL_BYTE = 0x0;
+
+    @Test
+    void ofBytes() {
+        Assertions.assertEquals("0", ReadLength.of(NULL_BYTE, NULL_BYTE, NULL_BYTE, NULL_BYTE).toString());
+        Assertions.assertThrows(IllegalArgumentException.class, () -> ReadLength.of(NULL_BYTE, NULL_BYTE, NULL_BYTE, NULL_BYTE, NULL_BYTE));
+    }
+
+    @Test
+    void ofLong() {
+        assertByte(ReadLength.of(1), "0x00000001");
+        assertByte(ReadLength.of(65535), "0x0000ffff");
+        Assertions.assertThrows(IllegalArgumentException.class, () -> ReadLength.of(-1));
+        Assertions.assertThrows(IllegalArgumentException.class, () -> ReadLength.of(Long.valueOf("4294967296")));
+    }
+
+    @Test
+    void ofString() {
+        assertByte(ReadLength.of("1"), "0x00000001");
+    }
+
+    @Test
+    void testToString() {
+        Assertions.assertEquals(ReadLength.of("1").toString(), "1");
+    }
+
+    void assertByte(ReadLength actual, String expected) {
+        Assertions.assertEquals(expected, "0x" + Hex.encodeHexString(actual.getBytes()));
+    }
+}
\ No newline at end of file

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