From db59995df65c6e3fc04f8c88af29fd82916cc4df Mon Sep 17 00:00:00 2001
From: guillaumepichon <guillaume.pichon@synchrotron-soleil.fr>
Date: Wed, 9 Apr 2025 16:29:42 +0200
Subject: [PATCH] Management of unsigned attributes

---
 pom.xml                                       |  2 +-
 .../attributes/OpcUaTangoUtils.java           | 19 +++++++++----------
 2 files changed, 10 insertions(+), 11 deletions(-)

diff --git a/pom.xml b/pom.xml
index 3228abe..9231d15 100755
--- a/pom.xml
+++ b/pom.xml
@@ -11,7 +11,7 @@
 
 	<groupId>fr.soleil.deviceservers</groupId>
 	<artifactId>OpcUaProxy</artifactId>
-	<version>1.1.5</version>
+	<version>1.1.6</version>
 	<name>OpcUaProxy</name>
 	<description>Proxy device between OPCUA and Tango</description>
 
diff --git a/src/main/java/fr/soleil/opcuaproxy/attributes/OpcUaTangoUtils.java b/src/main/java/fr/soleil/opcuaproxy/attributes/OpcUaTangoUtils.java
index d0ec5c9..a5f9b6a 100755
--- a/src/main/java/fr/soleil/opcuaproxy/attributes/OpcUaTangoUtils.java
+++ b/src/main/java/fr/soleil/opcuaproxy/attributes/OpcUaTangoUtils.java
@@ -1,6 +1,7 @@
 package fr.soleil.opcuaproxy.attributes;
 
 import java.lang.reflect.Array;
+import java.math.BigInteger;
 import java.time.Instant;
 import java.util.ArrayList;
 import java.util.HashMap;
@@ -38,8 +39,8 @@ public abstract class OpcUaTangoUtils {
 	}
 
 	public static class FullTangoType {
-		private AttrDataFormat format;
-		private AttributeTangoType type;
+		private final AttrDataFormat format;
+		private final AttributeTangoType type;
 
 		public FullTangoType(AttributeTangoType type, AttrDataFormat format) {
 			super();
@@ -119,8 +120,7 @@ public abstract class OpcUaTangoUtils {
 					format = AttrDataFormat.IMAGE;
 					if (Array.getLength(opcuaValue) > 0) {
 						Class<? extends Object> imgInnerClass = extractArrayInnerClass(Array.get(opcuaValue, 0));
-						AttributeTangoType tangoImgType = getTangoBasicType(imgInnerClass, nullIfNative);
-						tangoArrayType = tangoImgType;
+						tangoArrayType = getTangoBasicType(imgInnerClass, nullIfNative);
 					}
 				}
 				if (tangoArrayType != null) {
@@ -129,8 +129,7 @@ public abstract class OpcUaTangoUtils {
 			} else if (!nullIfNative) {
 				try {
 					fullTangoType = new FullTangoType(AttributeTangoType.getTypeFromClass(opcuaClass), format);
-				} catch (DevFailed e) {
-					fullTangoType = null;
+				} catch (DevFailed ignored) {
 				}
 			}
 		} else {
@@ -144,8 +143,7 @@ public abstract class OpcUaTangoUtils {
 		if (tangoType == null && !nullIfNative) {
 			try {
 				tangoType = AttributeTangoType.getTypeFromClass(clazz);
-			} catch (DevFailed e) {
-				tangoType = null;
+			} catch (DevFailed ignored) {
 			}
 		}
 		return tangoType;
@@ -190,9 +188,10 @@ public abstract class OpcUaTangoUtils {
 				} else if (opcuaClass == UShort.class) {
 					opcuaValue = UShort.valueOf(((Short) tangoValue).shortValue());
 				} else if (opcuaClass == UInteger.class) {
-					opcuaValue = UInteger.valueOf(((Integer) tangoValue).longValue());
+					opcuaValue = UInteger.valueOf(Integer.toUnsignedLong((Integer) tangoValue));
 				} else if (opcuaClass == ULong.class) {
-					opcuaValue = ULong.valueOf(((Long) tangoValue).longValue());
+					BigInteger bi = new BigInteger(Long.toUnsignedString((Long)tangoValue));
+					opcuaValue = ULong.valueOf(bi);
 				} else if (opcuaClass == DateTime.class) {
 					opcuaValue = new DateTime(Instant.parse((String) tangoValue));
 				} else if (opcuaClass == NodeId.class) {
-- 
GitLab