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/01/26 19:20:49 UTC

[incubator-plc4x] 01/01: added some convinience methods

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 9f18e72e90b97d4a79603a5dc6024dc2f48062b5
Author: Sebastian Rühl <sr...@apache.org>
AuthorDate: Fri Jan 26 20:10:14 2018 +0100

    added some convinience methods
---
 .../org/apache/plc4x/java/ads/model/commands/types/Length.java     | 6 ++++++
 .../org/apache/plc4x/java/ads/model/commands/types/ReadLength.java | 6 ++++++
 .../org/apache/plc4x/java/ads/model/commands/types/SampleSize.java | 6 ++++++
 .../org/apache/plc4x/java/ads/model/commands/types/Samples.java    | 6 ++++++
 .../apache/plc4x/java/ads/model/commands/types/WriteLength.java    | 6 ++++++
 .../org/apache/plc4x/java/ads/model/generic/types/AMSPort.java     | 4 ++++
 .../org/apache/plc4x/java/ads/model/generic/types/DataLength.java  | 6 +++++-
 .../java/org/apache/plc4x/java/ads/model/generic/types/Length.java | 7 +++++--
 .../java/org/apache/plc4x/java/ads/model/generic/types/State.java  | 3 ++-
 9 files changed, 46 insertions(+), 4 deletions(-)

diff --git a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/model/commands/types/Length.java b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/model/commands/types/Length.java
index f642e9d..def4e9d 100644
--- a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/model/commands/types/Length.java
+++ b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/model/commands/types/Length.java
@@ -20,6 +20,8 @@ package org.apache.plc4x.java.ads.model.commands.types;
 
 import org.apache.plc4x.java.ads.model.util.ByteValue;
 
+import java.nio.ByteBuffer;
+
 public class Length extends ByteValue {
 
     public static final int NUM_BYTES = 4;
@@ -29,6 +31,10 @@ public class Length extends ByteValue {
         assertLength(NUM_BYTES);
     }
 
+    public static Length of(int length) {
+        return new Length(ByteBuffer.allocate(NUM_BYTES).putInt(length).array());
+    }
+
     public static Length of(byte... values) {
         return new Length(values);
     }
diff --git a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/model/commands/types/ReadLength.java b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/model/commands/types/ReadLength.java
index 6ad08c2..ad596e9 100644
--- a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/model/commands/types/ReadLength.java
+++ b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/model/commands/types/ReadLength.java
@@ -20,6 +20,8 @@ package org.apache.plc4x.java.ads.model.commands.types;
 
 import org.apache.plc4x.java.ads.model.util.ByteValue;
 
+import java.nio.ByteBuffer;
+
 public class ReadLength extends ByteValue {
 
     public static final int NUM_BYTES = 4;
@@ -29,6 +31,10 @@ 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(byte... values) {
         return new ReadLength(values);
     }
diff --git a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/model/commands/types/SampleSize.java b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/model/commands/types/SampleSize.java
index 99eef7b..f0c444c 100644
--- a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/model/commands/types/SampleSize.java
+++ b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/model/commands/types/SampleSize.java
@@ -20,6 +20,8 @@ package org.apache.plc4x.java.ads.model.commands.types;
 
 import org.apache.plc4x.java.ads.model.util.ByteValue;
 
+import java.nio.ByteBuffer;
+
 public class SampleSize extends ByteValue {
 
     public static final int NUM_BYTES = 4;
@@ -29,6 +31,10 @@ public class SampleSize extends ByteValue {
         assertLength(NUM_BYTES);
     }
 
+    public static SampleSize of(int size) {
+        return new SampleSize(ByteBuffer.allocate(NUM_BYTES).putInt(size).array());
+    }
+
     public static SampleSize of(byte... values) {
         return new SampleSize(values);
     }
diff --git a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/model/commands/types/Samples.java b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/model/commands/types/Samples.java
index 0f23fc7..0adb1f6 100644
--- a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/model/commands/types/Samples.java
+++ b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/model/commands/types/Samples.java
@@ -20,6 +20,8 @@ package org.apache.plc4x.java.ads.model.commands.types;
 
 import org.apache.plc4x.java.ads.model.util.ByteValue;
 
+import java.nio.ByteBuffer;
+
 public class Samples extends ByteValue {
 
     public static final int NUM_BYTES = 4;
@@ -29,6 +31,10 @@ public class Samples extends ByteValue {
         assertLength(NUM_BYTES);
     }
 
+    public static Samples of(int numberOfSamples) {
+        return new Samples(ByteBuffer.allocate(NUM_BYTES).putInt(numberOfSamples).array());
+    }
+
     public static Samples of(byte... values) {
         return new Samples(values);
     }
diff --git a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/model/commands/types/WriteLength.java b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/model/commands/types/WriteLength.java
index e486ec4..4a7d93e 100644
--- a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/model/commands/types/WriteLength.java
+++ b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/model/commands/types/WriteLength.java
@@ -20,6 +20,8 @@ package org.apache.plc4x.java.ads.model.commands.types;
 
 import org.apache.plc4x.java.ads.model.util.ByteValue;
 
+import java.nio.ByteBuffer;
+
 public class WriteLength extends ByteValue {
 
     public static final int NUM_BYTES = 4;
@@ -32,4 +34,8 @@ public class WriteLength extends ByteValue {
     public static WriteLength of(byte... values) {
         return new WriteLength(values);
     }
+
+    public static WriteLength of(int length) {
+        return new WriteLength(ByteBuffer.allocate(NUM_BYTES).putInt(length).array());
+    }
 }
diff --git a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/model/generic/types/AMSPort.java b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/model/generic/types/AMSPort.java
index acc1dfc..09d6fc6 100644
--- a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/model/generic/types/AMSPort.java
+++ b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/model/generic/types/AMSPort.java
@@ -31,6 +31,10 @@ public class AMSPort extends ByteValue {
         assertLength(NUM_BYTES);
     }
 
+    public static AMSPort of(byte... values) {
+        return new AMSPort(values);
+    }
+
     public static AMSPort of(int port) {
         return new AMSPort(ByteBuffer.allocate(NUM_BYTES).putInt(port).array());
     }
diff --git a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/model/generic/types/DataLength.java b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/model/generic/types/DataLength.java
index 37ae40c..4fdbac7 100644
--- a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/model/generic/types/DataLength.java
+++ b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/model/generic/types/DataLength.java
@@ -31,7 +31,11 @@ public class DataLength extends ByteValue {
         assertLength(NUM_BYTES);
     }
 
+    public static DataLength of(byte... values) {
+        return new DataLength(values);
+    }
+
     public static DataLength of(int length) {
-        return new DataLength(ByteBuffer.allocate(4).putInt(length).array());
+        return new DataLength(ByteBuffer.allocate(NUM_BYTES).putInt(length).array());
     }
 }
diff --git a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/model/generic/types/Length.java b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/model/generic/types/Length.java
index 1be27c3..db7261e 100644
--- a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/model/generic/types/Length.java
+++ b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/model/generic/types/Length.java
@@ -26,11 +26,14 @@ public class Length extends ByteValue {
 
     public static final int NUM_BYTES = 4;
 
-    Length(byte... value) {
-        super(value);
+    Length(byte... values) {
+        super(values);
         assertLength(NUM_BYTES);
     }
 
+    public static Length of(byte... values) {
+        return new Length(values);
+    }
     public static Length of(int length) {
         return new Length(ByteBuffer.allocate(NUM_BYTES).putInt(length).array());
     }
diff --git a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/model/generic/types/State.java b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/model/generic/types/State.java
index 5bd4a45..4830bb2 100644
--- a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/model/generic/types/State.java
+++ b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/model/generic/types/State.java
@@ -44,7 +44,8 @@ public enum State implements ByteReadable {
     ADS_REQUEST_TCP(0x0004),
     ADS_RESPONSE_TCP(0x0005),
     ADS_REQUEST_UDP(0x0044),
-    ADS_RESPONSE_UDP(0x0045);
+    ADS_RESPONSE_UDP(0x0045),
+    UNKNOWN(0xffff);
 
     public static final int NUM_BYTES = 4;
 

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