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/07/26 15:11:07 UTC
[incubator-plc4x] 03/03: fixed double implementation in S7
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 810d649f4912c5f720f44f6aed41440a7b99fb27
Author: Sebastian Rühl <sr...@apache.org>
AuthorDate: Thu Jul 26 17:11:00 2018 +0200
fixed double implementation in S7
---
.../plc4x/java/s7/netty/util/S7TypeEncoder.java | 20 ++++++++++++++++++++
1 file changed, 20 insertions(+)
diff --git a/plc4j/protocols/s7/src/main/java/org/apache/plc4x/java/s7/netty/util/S7TypeEncoder.java b/plc4j/protocols/s7/src/main/java/org/apache/plc4x/java/s7/netty/util/S7TypeEncoder.java
index 4ff0f4b..19f9af6 100644
--- a/plc4j/protocols/s7/src/main/java/org/apache/plc4x/java/s7/netty/util/S7TypeEncoder.java
+++ b/plc4j/protocols/s7/src/main/java/org/apache/plc4x/java/s7/netty/util/S7TypeEncoder.java
@@ -49,6 +49,8 @@ public class S7TypeEncoder {
throw new PlcNotImplementedException("calender not yet implemented in s7");
} else if (valueType == Float.class) {
result = encodeFloat(values, length);
+ } else if (valueType == Double.class) {
+ result = encodeDouble(values, length);
} else if (valueType == String.class) {
result = encodeString(values, length);
} else {
@@ -89,6 +91,24 @@ public class S7TypeEncoder {
return result;
}
+ public static byte[] encodeDouble(Object[] values, int length) {
+ byte[] result;
+ result = new byte[length * 8];
+ for (int i = 0; i < length; i++) {
+ double doubleValue = (double) values[i];
+ long longValue = Double.doubleToLongBits(doubleValue);
+ result[(i * 8)] = (byte) ((longValue & 0xFF000000_00000000L) >> 56);
+ result[(i * 8) + 1] = (byte) ((longValue & 0x00FF0000_00000000L) >> 48);
+ result[(i * 8) + 2] = (byte) ((longValue & 0x0000FF00_00000000L) >> 40);
+ result[(i * 8) + 3] = (byte) ((longValue & 0x000000FF_00000000L) >> 32);
+ result[(i * 8) + 4] = (byte) ((longValue & 0x00000000_FF000000L) >> 24);
+ result[(i * 8) + 5] = (byte) ((longValue & 0x00000000_00FF0000L) >> 16);
+ result[(i * 8) + 6] = (byte) ((longValue & 0x00000000_0000FF00L) >> 8);
+ result[(i * 8) + 7] = (byte) (longValue & 0x00000000_000000FFL);
+ }
+ return result;
+ }
+
public static byte[] encodeInteger(Object[] values, int length) {
byte[] result;
result = new byte[length * 4];