From 4bbe1340a3f26982fc2e4b3113462a08eb939b67 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Romain=20BRON=C3=88S?= <romain.brones@synchrotron-soleil.fr>
Date: Wed, 7 Aug 2024 13:56:39 +0200
Subject: [PATCH] Add configuration command, status

---
 DG_PY_FOFBTool/DG_PY_FOFBTool.py  | 60 +++++++++++++++++++++++++++++--
 DG_PY_FOFBTool/DG_PY_FOFBTool.xmi |  6 +++-
 2 files changed, 62 insertions(+), 4 deletions(-)

diff --git a/DG_PY_FOFBTool/DG_PY_FOFBTool.py b/DG_PY_FOFBTool/DG_PY_FOFBTool.py
index 10f04d8..e2d2eee 100644
--- a/DG_PY_FOFBTool/DG_PY_FOFBTool.py
+++ b/DG_PY_FOFBTool/DG_PY_FOFBTool.py
@@ -62,8 +62,26 @@ class DG_PY_FOFBTool(Device):
             - Type:'DevString'
         tangopath_centraltiming
             - Type:'DevString'
+        tangopath_centralnode
+            - Type:'DevString'
     """
     # PROTECTED REGION ID(DG_PY_FOFBTool.class_variable) ENABLED START #
+
+    d_status = {}
+
+    """
+    def dev_status(self):
+        return my_status()
+    """
+
+    def my_status(self):
+        try:
+            return "\n\n".join([str(v) for v in self.d_status.values()])+"\n"
+        except Exception:
+            self.debug_stream(str(self.d_status))
+            return "Status failure\n"
+
+
     # PROTECTED REGION END #    //  DG_PY_FOFBTool.class_variable
 
     # -----------------
@@ -114,6 +132,11 @@ class DG_PY_FOFBTool(Device):
         dtype='DevString',
     )
 
+    tangopath_centralnode = device_property(
+        dtype='DevString',
+        mandatory=True
+    )
+
     # ----------
     # Attributes
     # ----------
@@ -148,7 +171,7 @@ class DG_PY_FOFBTool(Device):
     def always_executed_hook(self):
         """Method always executed before any TANGO command is executed."""
         #----- PROTECTED REGION ID(DG_PY_FOFBTool.always_executed_hook) ENABLED START -----#
-        
+        self.set_status(self.my_status())
         #----- PROTECTED REGION END -----#	//	DG_PY_FOFBTool.always_executed_hook
 
     def delete_device(self):
@@ -182,6 +205,7 @@ class DG_PY_FOFBTool(Device):
     # --------
 
     @command(
+        dtype_out='DevBoolean',
     )
     @DebugIt()
     def configure(self):
@@ -190,13 +214,43 @@ class DG_PY_FOFBTool(Device):
 
         :return:None
         """
+        success=True
+        self.d_status["configure"]="Configure: pending"
 
-        self.debug_stream("Configure COMBPM")
+        self.info_stream("Configure COMBPM")
         for cn, bpm in zip(self.tangopath_cellnode, self.combpm_bpmfilter):
             bpmid = [int(b) for b in bpm.split()]
             self.debug_stream("Set {} to {}".format(cn, bpmid))
-            FofbTool.Configuration.cellnode_configure_combpm(cn, bpmid)
+            s=FofbTool.Configuration.cellnode_configure_combpm(cn, bpmid)
+            success = success and s
+            if not s:
+                self.error_stream("Failed to configure COMBPM on {}".format(cn))
+
+        self.info_stream("Configure COMCORR")
+        for cn, psc in zip(self.tangopath_cellnode, self.comcorr_pscid):
+            pscid = [int(b) for b in psc.split()]
+            self.debug_stream("Set {} to {}".format(cn, pscid))
+            s=FofbTool.Configuration.cellnode_configure_comcorr(cn, pscid, True)
+            success = success and s
+            if not s:
+                self.error_stream("Failed to configure COMCORR on {}".format(cn))
+
+        self.info_stream("Configure CCN")
+        for cn, nbpm in zip(self.tangopath_cellnode, self.ccn_nbpm):
+            self.debug_stream("Set {} to {} bpm and {} psc".format(cn, nbpm, self.ccn_npsc))
+            FofbTool.Configuration.cellnode_configure_ccn(cn, nbpm, self.ccn_npsc)
+            success = success and s
+            if not s:
+                self.error_stream("Failed to configure CCN on {}".format(cn))
+
+        s=FofbTool.Configuration.centralnode_configure_ccn(self.tangopath_centralnode, self.ccn_nbpm, self.ccn_npsc)
+
+        if success:
+            self.d_status["configure"]="Configure: success"
+        else:
+            self.d_status["configure"]="Configure: failed"
 
+        return success
         # PROTECTED REGION END #    //  DG_PY_FOFBTool.configure
 
     @command(
diff --git a/DG_PY_FOFBTool/DG_PY_FOFBTool.xmi b/DG_PY_FOFBTool/DG_PY_FOFBTool.xmi
index c5754a0..a73cea7 100644
--- a/DG_PY_FOFBTool/DG_PY_FOFBTool.xmi
+++ b/DG_PY_FOFBTool/DG_PY_FOFBTool.xmi
@@ -41,6 +41,10 @@
       <type xsi:type="pogoDsl:StringType"/>
       <status abstract="false" inherited="false" concrete="true" concreteHere="true"/>
     </deviceProperties>
+    <deviceProperties name="tangopath_centralnode" mandatory="true" description="">
+      <type xsi:type="pogoDsl:StringType"/>
+      <status abstract="false" inherited="false" concrete="true" concreteHere="true"/>
+    </deviceProperties>
     <commands name="State" description="This command gets the device state (stored in its device_state data member) and returns it to the caller." execMethod="dev_state" displayLevel="OPERATOR" polledPeriod="0">
       <argin description="none">
         <type xsi:type="pogoDsl:VoidType"/>
@@ -64,7 +68,7 @@
         <type xsi:type="pogoDsl:VoidType"/>
       </argin>
       <argout description="">
-        <type xsi:type="pogoDsl:VoidType"/>
+        <type xsi:type="pogoDsl:BooleanType"/>
       </argout>
       <status abstract="false" inherited="false" concrete="true" concreteHere="true"/>
     </commands>
-- 
GitLab