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/10/18 17:50:42 UTC

[incubator-plc4x] branch master updated: [ADS] fixed max for UINT32 and UINT64 (currently not supported by ADS at all)

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


The following commit(s) were added to refs/heads/master by this push:
     new 3bd42a5  [ADS] fixed max for UINT32 and UINT64 (currently not supported by ADS at all)
3bd42a5 is described below

commit 3bd42a5637ba6310ffacbaf399f16878c8f11be8
Author: Sebastian Rühl <sr...@apache.org>
AuthorDate: Thu Oct 18 19:50:36 2018 +0200

    [ADS] fixed max for UINT32 and UINT64 (currently not supported by ADS at all)
---
 .../apache/plc4x/java/ads/model/AdsDataType.java   | 27 ++++++++++++++++++----
 1 file changed, 23 insertions(+), 4 deletions(-)

diff --git a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/model/AdsDataType.java b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/model/AdsDataType.java
index 87925a8..c5fd420 100644
--- a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/model/AdsDataType.java
+++ b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/model/AdsDataType.java
@@ -18,10 +18,15 @@
  */
 package org.apache.plc4x.java.ads.model;
 
+import org.apache.commons.lang3.ArrayUtils;
+
+import java.io.ByteArrayOutputStream;
+import java.math.BigInteger;
 import java.time.Duration;
 import java.time.LocalDateTime;
 import java.time.LocalTime;
 import java.time.temporal.ChronoUnit;
+import java.util.stream.IntStream;
 
 /**
  * Documentation can be found here:
@@ -43,10 +48,8 @@ public enum AdsDataType {
     INT64(Long.MIN_VALUE, Long.MAX_VALUE, 64),
     UINT8(0, Short.MAX_VALUE, 8),
     UINT16(0, Integer.MAX_VALUE, 16),
-    // TODO: max might be off here
-    UINT32(0, Double.MAX_VALUE, 32),
-    // TODO: max might be off here
-    UINT64(0, Double.MAX_VALUE, 64),
+    UINT32(0, produceUnsignedMaxValue(32), 32),
+    UINT64(0, produceUnsignedMaxValue(64), 64),
     FLOAT(Float.MIN_VALUE, Float.MAX_VALUE, 32),
     DOUBLE(Double.MIN_VALUE, Double.MAX_VALUE, 64),
     // https://infosys.beckhoff.com/english.php?content=../content/1033/tcplccontrol/html/tcplcctrl_plc_data_types_overview.htm&id
@@ -547,4 +550,20 @@ public enum AdsDataType {
             ", targetByteSize=" + targetByteSize +
             "} " + super.toString();
     }
+
+    private static double produceUnsignedMaxValue(int numberOfBytes) {
+        return new BigInteger(
+            ArrayUtils.insert(
+                0,
+                IntStream.range(0, numberOfBytes)
+                    .map(ignore -> 0xff)
+                    .collect(
+                        ByteArrayOutputStream::new,
+                        (baos, i) -> baos.write((byte) i),
+                        (baos1, baos2) -> baos1.write(baos2.toByteArray(), 0, baos2.size())
+                    )
+                    .toByteArray(),
+                (byte) 0x0)
+        ).doubleValue();
+    }
 }