You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@plc4x.apache.org by cd...@apache.org on 2024/09/10 08:42:07 UTC

(plc4x) branch develop updated: fix: Updated the handling of real values in EIP

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

cdutz pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/plc4x.git


The following commit(s) were added to refs/heads/develop by this push:
     new ba5fcded4b fix: Updated the handling of real values in EIP
ba5fcded4b is described below

commit ba5fcded4b88224161868e5b6638daafd9e7fccd
Author: Christofer Dutz <cd...@apache.org>
AuthorDate: Tue Sep 10 10:41:59 2024 +0200

    fix: Updated the handling of real values in EIP
    
    possibly fixes:  #1748
---
 .../java/eip/base/protocol/EipProtocolLogic.java   | 24 +++++++++++++++++++---
 1 file changed, 21 insertions(+), 3 deletions(-)

diff --git a/plc4j/drivers/eip/src/main/java/org/apache/plc4x/java/eip/base/protocol/EipProtocolLogic.java b/plc4j/drivers/eip/src/main/java/org/apache/plc4x/java/eip/base/protocol/EipProtocolLogic.java
index d4b243665e..1e75cf460e 100644
--- a/plc4j/drivers/eip/src/main/java/org/apache/plc4x/java/eip/base/protocol/EipProtocolLogic.java
+++ b/plc4j/drivers/eip/src/main/java/org/apache/plc4x/java/eip/base/protocol/EipProtocolLogic.java
@@ -877,6 +877,8 @@ public class EipProtocolLogic extends Plc4xProtocolBase<EipPacket> implements Ha
                     return new PlcLINT(Long.reverseBytes(data.getLong(0)));
                 case REAL:
                     return new PlcREAL(swap(data.getFloat(0)));
+                case LREAL:
+                    return new PlcLREAL(swap(data.getDouble(0)));
                 case BOOL:
                     return new PlcBOOL(data.getBoolean(0));
                 case STRING:
@@ -907,6 +909,19 @@ public class EipProtocolLogic extends Plc4xProtocolBase<EipPacket> implements Ha
         return Float.intBitsToFloat(b1 << 24 | b2 << 16 | b3 << 8 | b4);
     }
 
+    public double swap(double value) {
+        long bytes = Double.doubleToLongBits(value);
+        long b1 = (bytes) & 0xff;
+        long b2 = (bytes >> 8) & 0xff;
+        long b3 = (bytes >> 16) & 0xff;
+        long b4 = (bytes >> 24) & 0xff;
+        long b5 = (bytes >> 32) & 0xff;
+        long b6 = (bytes >> 40) & 0xff;
+        long b7 = (bytes >> 48) & 0xff;
+        long b8 = (bytes >> 56) & 0xff;
+        return Double.longBitsToDouble(b1 << 56 | b2 << 48 | b3 << 40 | b4 << 32 | b5 << 24 | b6 << 16 | b7 << 8 | b8);
+    }
+
     public CompletableFuture<PlcWriteResponse> writeWithoutMessageRouter(PlcWriteRequest writeRequest) {
         CompletableFuture<PlcWriteResponse> future = new CompletableFuture<>();
         DefaultPlcWriteRequest request = (DefaultPlcWriteRequest) writeRequest;
@@ -1301,12 +1316,15 @@ public class EipProtocolLogic extends Plc4xProtocolBase<EipPacket> implements Ha
             case DINT:
                 buffer.putInt(value.getInteger());
                 break;
-            case REAL:
-                buffer.putDouble(value.getDouble());
-                break;
             case LINT:
                 buffer.putLong(value.getLong());
                 break;
+            case REAL:
+                buffer.putFloat(value.getFloat());
+                break;
+            case LREAL:
+                buffer.putDouble(value.getDouble());
+                break;
             case STRING:
             case STRUCTURED:
                 buffer.putInt(value.getString().length());