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/07 11:22:18 UTC
[incubator-plc4x] branch feature/Beckhoff_ADS_protocol updated
(af5db36 -> 944cebf)
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 af5db36 added calculated headers for convenient API usage
new ff07d14 added util methods for manual usage of TcpHexDumper
new 944cebf switch to LittleEndian
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:
.../plc4x/java/ads/api/commands/types/Length.java | 7 +++---
.../java/ads/api/commands/types/ReadLength.java | 7 +++---
.../java/ads/api/commands/types/SampleSize.java | 7 +++---
.../plc4x/java/ads/api/commands/types/Samples.java | 7 +++---
.../java/ads/api/commands/types/WriteLength.java | 7 +++---
.../plc4x/java/ads/api/generic/types/AMSPort.java | 3 ++-
.../plc4x/java/ads/api/generic/types/Command.java | 29 +++++++++++-----------
.../java/ads/api/generic/types/DataLength.java | 7 +++---
.../plc4x/java/ads/api/generic/types/Length.java | 7 +++---
.../plc4x/java/ads/api/generic/types/State.java | 15 ++++++-----
.../apache/plc4x/java/ads/util/TcpHexDumper.java | 22 +++++++++++++++-
11 files changed, 72 insertions(+), 46 deletions(-)
--
To stop receiving notification emails like this one, please contact
sruehl@apache.org.
[incubator-plc4x] 02/02: switch to LittleEndian
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 944cebf35cfaf74b43f23f0f55bd981febc5d597
Author: Sebastian Rühl <sr...@apache.org>
AuthorDate: Wed Feb 7 12:22:14 2018 +0100
switch to LittleEndian
---
.../plc4x/java/ads/api/commands/types/Length.java | 7 +++---
.../java/ads/api/commands/types/ReadLength.java | 7 +++---
.../java/ads/api/commands/types/SampleSize.java | 7 +++---
.../plc4x/java/ads/api/commands/types/Samples.java | 7 +++---
.../java/ads/api/commands/types/WriteLength.java | 7 +++---
.../plc4x/java/ads/api/generic/types/AMSPort.java | 3 ++-
.../plc4x/java/ads/api/generic/types/Command.java | 29 +++++++++++-----------
.../java/ads/api/generic/types/DataLength.java | 7 +++---
.../plc4x/java/ads/api/generic/types/Length.java | 7 +++---
.../plc4x/java/ads/api/generic/types/State.java | 15 ++++++-----
10 files changed, 51 insertions(+), 45 deletions(-)
diff --git a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/types/Length.java b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/types/Length.java
index 390ef3e..606f432 100644
--- a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/types/Length.java
+++ b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/types/Length.java
@@ -34,10 +34,11 @@ public class Length extends ByteValue {
public static Length of(long length) {
checkUnsignedBounds(length, NUM_BYTES);
return new Length(ByteBuffer.allocate(NUM_BYTES)
- .put((byte) (length >> 24 & 0xff))
- .put((byte) (length >> 16 & 0xff))
- .put((byte) (length >> 8 & 0xff))
+ // LE
.put((byte) (length & 0xff))
+ .put((byte) (length >> 8 & 0xff))
+ .put((byte) (length >> 16 & 0xff))
+ .put((byte) (length >> 24 & 0xff))
.array());
}
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 9f48a2b..bf2a06f 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
@@ -34,10 +34,11 @@ public class ReadLength extends ByteValue {
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))
+ // LE
.put((byte) (length & 0xff))
+ .put((byte) (length >> 8 & 0xff))
+ .put((byte) (length >> 16 & 0xff))
+ .put((byte) (length >> 24 & 0xff))
.array());
}
diff --git a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/types/SampleSize.java b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/types/SampleSize.java
index ff78866..55e1306 100644
--- a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/types/SampleSize.java
+++ b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/types/SampleSize.java
@@ -34,10 +34,11 @@ public class SampleSize extends ByteValue {
public static SampleSize of(long sampleSize) {
checkUnsignedBounds(sampleSize, NUM_BYTES);
return new SampleSize(ByteBuffer.allocate(NUM_BYTES)
- .put((byte) (sampleSize >> 24 & 0xff))
- .put((byte) (sampleSize >> 16 & 0xff))
- .put((byte) (sampleSize >> 8 & 0xff))
+ // LE
.put((byte) (sampleSize & 0xff))
+ .put((byte) (sampleSize >> 8 & 0xff))
+ .put((byte) (sampleSize >> 16 & 0xff))
+ .put((byte) (sampleSize >> 24 & 0xff))
.array());
}
diff --git a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/types/Samples.java b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/types/Samples.java
index 2298e00..4ebfddb 100644
--- a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/types/Samples.java
+++ b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/types/Samples.java
@@ -34,10 +34,11 @@ public class Samples extends ByteValue {
public static Samples of(long numberOfSamples) {
checkUnsignedBounds(numberOfSamples, NUM_BYTES);
return new Samples(ByteBuffer.allocate(NUM_BYTES)
- .put((byte) (numberOfSamples >> 24 & 0xff))
- .put((byte) (numberOfSamples >> 16 & 0xff))
- .put((byte) (numberOfSamples >> 8 & 0xff))
+ // LE
.put((byte) (numberOfSamples & 0xff))
+ .put((byte) (numberOfSamples >> 8 & 0xff))
+ .put((byte) (numberOfSamples >> 16 & 0xff))
+ .put((byte) (numberOfSamples >> 24 & 0xff))
.array());
}
diff --git a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/types/WriteLength.java b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/types/WriteLength.java
index 12931d6..4e593c0 100644
--- a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/types/WriteLength.java
+++ b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/types/WriteLength.java
@@ -34,10 +34,11 @@ public class WriteLength extends ByteValue {
public static WriteLength of(long length) {
checkUnsignedBounds(length, NUM_BYTES);
return new WriteLength(ByteBuffer.allocate(NUM_BYTES)
- .put((byte) (length >> 24 & 0xff))
- .put((byte) (length >> 16 & 0xff))
- .put((byte) (length >> 8 & 0xff))
+ // LE
.put((byte) (length & 0xff))
+ .put((byte) (length >> 8 & 0xff))
+ .put((byte) (length >> 16 & 0xff))
+ .put((byte) (length >> 24 & 0xff))
.array());
}
diff --git a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/generic/types/AMSPort.java b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/generic/types/AMSPort.java
index a0439bb..906a456 100644
--- a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/generic/types/AMSPort.java
+++ b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/generic/types/AMSPort.java
@@ -41,8 +41,9 @@ public class AMSPort extends ByteValue {
public static AMSPort of(int port) {
checkUnsignedBounds(port, NUM_BYTES);
return new AMSPort(ByteBuffer.allocate(NUM_BYTES)
- .put((byte) (port >> 8 & 0xff))
+ // LE
.put((byte) (port & 0xff))
+ .put((byte) (port >> 8 & 0xff))
.array());
}
diff --git a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/generic/types/Command.java b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/generic/types/Command.java
index f831a61..b5b8da2 100644
--- a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/generic/types/Command.java
+++ b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/generic/types/Command.java
@@ -26,22 +26,22 @@ import org.apache.plc4x.java.ads.api.util.ByteValue;
import java.nio.ByteBuffer;
public enum Command implements ByteReadable {
- Invalid(0x0000),
- ADS_Read_Device_Info(0x0001),
- ADS_Read(0x0002),
- ADS_Write(0x0003),
- ADS_Read_State(0x0004),
- ADS_Write_Control(0x0005),
- ADS_Add_Device_Notification(0x0006),
- ADS_Delete_Device_Notification(0x0007),
- ADS_Device_Notification(0x0008),
- ADS_Read_Write(0x0009),
+ Invalid(0x00),
+ ADS_Read_Device_Info(0x01),
+ ADS_Read(0x02),
+ ADS_Write(0x03),
+ ADS_Read_State(0x04),
+ ADS_Write_Control(0x05),
+ ADS_Add_Device_Notification(0x06),
+ ADS_Delete_Device_Notification(0x07),
+ ADS_Device_Notification(0x08),
+ ADS_Read_Write(0x09),
/**
* Other commands are not defined or are used internally. Therefore the Command Id is only allowed to contain the above enumerated values!
*/
UNKNOWN();
- public static final int NUM_BYTES = 4;
+ public static final int NUM_BYTES = 2;
final byte[] value;
@@ -50,13 +50,12 @@ public enum Command implements ByteReadable {
value = new byte[0];
}
- Command(long value) {
+ Command(int value) {
ByteValue.checkUnsignedBounds(value, NUM_BYTES);
this.value = ByteBuffer.allocate(NUM_BYTES)
- .put((byte) (value >> 24 & 0xff))
- .put((byte) (value >> 16 & 0xff))
- .put((byte) (value >> 8 & 0xff))
+ // LE
.put((byte) (value & 0xff))
+ .put((byte) (value >> 8 & 0xff))
.array();
}
diff --git a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/generic/types/DataLength.java b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/generic/types/DataLength.java
index 83d987b..0f56d2f 100644
--- a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/generic/types/DataLength.java
+++ b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/generic/types/DataLength.java
@@ -34,10 +34,11 @@ public class DataLength extends ByteValue {
public static DataLength of(long length) {
checkUnsignedBounds(length, NUM_BYTES);
return new DataLength(ByteBuffer.allocate(NUM_BYTES)
- .put((byte) (length >> 24 & 0xff))
- .put((byte) (length >> 16 & 0xff))
- .put((byte) (length >> 8 & 0xff))
+ // LE
.put((byte) (length & 0xff))
+ .put((byte) (length >> 8 & 0xff))
+ .put((byte) (length >> 16 & 0xff))
+ .put((byte) (length >> 24 & 0xff))
.array());
}
diff --git a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/generic/types/Length.java b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/generic/types/Length.java
index b0b4363..14da90e 100644
--- a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/generic/types/Length.java
+++ b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/generic/types/Length.java
@@ -34,10 +34,11 @@ public class Length extends ByteValue {
public static Length of(long length) {
checkUnsignedBounds(length, NUM_BYTES);
return new Length(ByteBuffer.allocate(NUM_BYTES)
- .put((byte) (length >> 24 & 0xff))
- .put((byte) (length >> 16 & 0xff))
- .put((byte) (length >> 8 & 0xff))
+ // LE
.put((byte) (length & 0xff))
+ .put((byte) (length >> 8 & 0xff))
+ .put((byte) (length >> 16 & 0xff))
+ .put((byte) (length >> 24 & 0xff))
.array());
}
diff --git a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/generic/types/State.java b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/generic/types/State.java
index bb444c2..47fbb40 100644
--- a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/generic/types/State.java
+++ b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/generic/types/State.java
@@ -42,13 +42,13 @@ import java.nio.ByteBuffer;
* Bit number 7 marks, if it should be transfered with TCP or UDP.
*/
public enum State implements ByteReadable {
- ADS_REQUEST_TCP(0x0004),
- ADS_RESPONSE_TCP(0x0005),
- ADS_REQUEST_UDP(0x0044),
- ADS_RESPONSE_UDP(0x0045),
+ ADS_REQUEST_TCP(0x04),
+ ADS_RESPONSE_TCP(0x05),
+ ADS_REQUEST_UDP(0x44),
+ ADS_RESPONSE_UDP(0x45),
UNKNOWN();
- public static final int NUM_BYTES = 4;
+ public static final int NUM_BYTES = 2;
final byte[] value;
@@ -59,10 +59,9 @@ public enum State implements ByteReadable {
State(long value) {
ByteValue.checkUnsignedBounds(value, NUM_BYTES);
this.value = ByteBuffer.allocate(NUM_BYTES)
- .put((byte) (value >> 24 & 0xff))
- .put((byte) (value >> 16 & 0xff))
- .put((byte) (value >> 8 & 0xff))
+ // LE
.put((byte) (value & 0xff))
+ .put((byte) (value >> 8 & 0xff))
.array();
}
--
To stop receiving notification emails like this one, please contact
sruehl@apache.org.
[incubator-plc4x] 01/02: added util methods for manual usage of
TcpHexDumper
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 ff07d14c113fec25c3a96c832ceeca4afea2b4e3
Author: Sebastian Rühl <sr...@apache.org>
AuthorDate: Wed Feb 7 12:21:42 2018 +0100
added util methods for manual usage of TcpHexDumper
---
.../apache/plc4x/java/ads/util/TcpHexDumper.java | 22 +++++++++++++++++++++-
1 file changed, 21 insertions(+), 1 deletion(-)
diff --git a/plc4j/protocols/ads/src/test/java/org/apache/plc4x/java/ads/util/TcpHexDumper.java b/plc4j/protocols/ads/src/test/java/org/apache/plc4x/java/ads/util/TcpHexDumper.java
index 92aa16e..4eb726f 100644
--- a/plc4j/protocols/ads/src/test/java/org/apache/plc4x/java/ads/util/TcpHexDumper.java
+++ b/plc4j/protocols/ads/src/test/java/org/apache/plc4x/java/ads/util/TcpHexDumper.java
@@ -25,6 +25,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.ByteArrayOutputStream;
+import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.net.ServerSocket;
@@ -33,7 +34,7 @@ import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
-public class TcpHexDumper implements BeforeEachCallback, AfterEachCallback, ParameterResolver {
+public class TcpHexDumper implements BeforeEachCallback, AfterEachCallback, ParameterResolver, Closeable {
private static final Logger logger = LoggerFactory.getLogger(TcpHexDumper.class);
@@ -115,6 +116,16 @@ public class TcpHexDumper implements BeforeEachCallback, AfterEachCallback, Para
}
}
+ public static TcpHexDumper runOn(int port) throws IOException, InterruptedException {
+ TcpHexDumper tcpHexDumper = new TcpHexDumper();
+ tcpHexDumper.init(port);
+ return tcpHexDumper;
+ }
+
+ public Integer getPort() {
+ return serverSocket.getLocalPort();
+ }
+
private int initShutdownTimeout(ExtensionContext context) {
ExtendWithTcpHexDumper annotation = context.getRequiredTestClass().getAnnotation(ExtendWithTcpHexDumper.class);
return annotation.shutdownTimeout();
@@ -135,4 +146,13 @@ public class TcpHexDumper implements BeforeEachCallback, AfterEachCallback, Para
return socket.getLocalPort();
}
}
+
+ @Override
+ public void close() throws IOException {
+ try {
+ stop();
+ } catch (InterruptedException e) {
+ throw new IOException(e);
+ }
+ }
}
--
To stop receiving notification emails like this one, please contact
sruehl@apache.org.