From beb189ca6c4cb415a5758300c6c15b61cd15d6f2 Mon Sep 17 00:00:00 2001
From: mnabywan <mnabywan@asl751.acc.gsi.de>
Date: Fri, 21 Oct 2022 10:41:48 +0200
Subject: [PATCH] Fix sending boolean values

---
 .../interface/equipment/SilecsRegister.cpp    | 29 ++++++++++---------
 .../interface/equipment/SilecsRegister.h      |  4 +--
 2 files changed, 18 insertions(+), 15 deletions(-)

diff --git a/silecs-communication-cpp/src/silecs-communication/interface/equipment/SilecsRegister.cpp b/silecs-communication-cpp/src/silecs-communication/interface/equipment/SilecsRegister.cpp
index 921ebde..2981e38 100644
--- a/silecs-communication-cpp/src/silecs-communication/interface/equipment/SilecsRegister.cpp
+++ b/silecs-communication-cpp/src/silecs-communication/interface/equipment/SilecsRegister.cpp
@@ -450,9 +450,7 @@ bool Register::getValBool()
     if ( (format_ != Bool) || !isScalar())
         throw SilecsException(__FILE__, __LINE__, PARAM_FORMAT_TYPE_MISMATCH, getName());
 
-
-
-    if (* ((int*)pRecvValue_) == 0)
+    if (* ((int8_t*)pRecvValue_) == 0)
         return false;
     else
         return true;
@@ -982,16 +980,17 @@ void Register::setValDateArray2D(const double* pVal, uint32_t dim1, uint32_t dim
 
 // .........................................................................
 //Recommended: from SLC6 (32bits and 64bits platform)
-void Register::setValBool(bool val)
+void Register::setValBool(int32_t val)
 {
     if (!isWritable())
         throw SilecsException(__FILE__, __LINE__, DATA_WRITE_ACCESS_TYPE_MISMATCH, getName());
     if ( (format_ != Bool) || (dimension1_ != 1))
         throw SilecsException(__FILE__, __LINE__, PARAM_FORMAT_TYPE_MISMATCH, getName());
-    if ( val == true )
-        * ((int8_t*)pSendValue_) = 1;
+
+    if ( val == 0 )
+        * ((bool*)pSendValue_) = false;
     else
-        * ((int8_t*)pSendValue_) = 0;
+        * ((bool*)pSendValue_) = true;
     isInitialized_ = true;
 }
 void Register::setValInt8(int8_t val)
@@ -1438,12 +1437,16 @@ void Register::setScalarfromString(std::string stringValue)
             setValString(stringValue);
             break;
         }
-        //case Bool:
-        //{
-        //    LOG((COMM|DIAG)) << "For BOOL string value is: " << stringValue;
-        //    throw SilecsException(__FILE__, __LINE__, " '" + name_+ "' has a unknown format type");
-        //    break;
-        //}
+        case Bool:
+        {
+            int32_t val = 0;
+            if(!StringUtilities::from_string<int32_t>(val, stringValue, std::dec))
+            {
+                throw SilecsException(__FILE__, __LINE__,"Conversion from string '" + stringValue + "'to Int32 failed for register '" + name_ + "'");
+            }
+            setValBool((int32_t)val);
+            break;
+        }
         case Date:
         {
             double val;
diff --git a/silecs-communication-cpp/src/silecs-communication/interface/equipment/SilecsRegister.h b/silecs-communication-cpp/src/silecs-communication/interface/equipment/SilecsRegister.h
index 350a1af..bdfc290 100644
--- a/silecs-communication-cpp/src/silecs-communication/interface/equipment/SilecsRegister.h
+++ b/silecs-communication-cpp/src/silecs-communication/interface/equipment/SilecsRegister.h
@@ -1325,9 +1325,9 @@ public:
     //Recommended: from SLC6 (32bits and 64bits platform)
     /*!
      * \brief Set the value for the register output buffer.(Send must be done afterwards)
-     * \param val Value to be written in the buffer in a bool format
+     * \param val Value to be written in the buffer in a int32_t format
      */
-    void setValBool(bool val);
+    void setValBool(int32_t val);
 
     /*!
      * \brief Set the value for the register output buffer.(Send must be done afterwards)
-- 
GitLab