From 75d91f88cea83926b32e744356d9bc509905efe7 Mon Sep 17 00:00:00 2001
From: Thomas Juerges <4-jurges@users.noreply.git.astron.nl>
Date: Wed, 24 Jun 2020 14:49:48 +0200
Subject: [PATCH] Add states

---
 StatsCrosslet-DS/StatsCrosslet.py  | 49 ++++++++++++++++++++++++++++--
 StatsCrosslet-DS/StatsCrosslet.xmi | 39 ++++++++++++++++++++++++
 2 files changed, 85 insertions(+), 3 deletions(-)

diff --git a/StatsCrosslet-DS/StatsCrosslet.py b/StatsCrosslet-DS/StatsCrosslet.py
index 350a7415d..40cae0659 100644
--- a/StatsCrosslet-DS/StatsCrosslet.py
+++ b/StatsCrosslet-DS/StatsCrosslet.py
@@ -229,18 +229,36 @@ class StatsCrosslet(Device):
         self._subband = value
         # PROTECTED REGION END #    //  StatsCrosslet.subband_write
 
+    def is_subband_allowed(self, attr):
+        # PROTECTED REGION ID(StatsCrosslet.is_subband_allowed) ENABLED START #
+        if attr==attr.READ_REQ:
+            return self.get_state() not in [DevState.STANDBY]
+        else:
+            return self.get_state() not in [DevState.STANDBY]
+        # PROTECTED REGION END #    //  StatsCrosslet.is_subband_allowed
+
     def read_integration_time(self):
         # PROTECTED REGION ID(StatsCrosslet.integration_time_read) ENABLED START #
         """Return the integration_time attribute."""
         return self._integration_time
         # PROTECTED REGION END #    //  StatsCrosslet.integration_time_read
 
+    def is_integration_time_allowed(self, attr):
+        # PROTECTED REGION ID(StatsCrosslet.is_integration_time_allowed) ENABLED START #
+        return self.get_state() not in [DevState.ON,DevState.OFF,DevState.INIT]
+        # PROTECTED REGION END #    //  StatsCrosslet.is_integration_time_allowed
+
     def read_time_stamp(self):
         # PROTECTED REGION ID(StatsCrosslet.time_stamp_read) ENABLED START #
         """Return the time_stamp attribute."""
         return self._time_stamp
         # PROTECTED REGION END #    //  StatsCrosslet.time_stamp_read
 
+    def is_time_stamp_allowed(self, attr):
+        # PROTECTED REGION ID(StatsCrosslet.is_time_stamp_allowed) ENABLED START #
+        return self.get_state() not in [DevState.ON,DevState.OFF,DevState.INIT]
+        # PROTECTED REGION END #    //  StatsCrosslet.is_time_stamp_allowed
+
     def read_pause_time(self):
         # PROTECTED REGION ID(StatsCrosslet.pause_time_read) ENABLED START #
         """Return the pause_time attribute."""
@@ -259,18 +277,33 @@ class StatsCrosslet(Device):
         return self._rcu_modes
         # PROTECTED REGION END #    //  StatsCrosslet.rcu_modes_read
 
+    def is_rcu_modes_allowed(self, attr):
+        # PROTECTED REGION ID(StatsCrosslet.is_rcu_modes_allowed) ENABLED START #
+        return self.get_state() not in [DevState.ON,DevState.OFF,DevState.INIT]
+        # PROTECTED REGION END #    //  StatsCrosslet.is_rcu_modes_allowed
+
     def read_visibilities_imag(self):
         # PROTECTED REGION ID(StatsCrosslet.visibilities_imag_read) ENABLED START #
         """Return the visibilities_imag attribute."""
         return self._visibilities_imag
         # PROTECTED REGION END #    //  StatsCrosslet.visibilities_imag_read
 
+    def is_visibilities_imag_allowed(self, attr):
+        # PROTECTED REGION ID(StatsCrosslet.is_visibilities_imag_allowed) ENABLED START #
+        return self.get_state() not in [DevState.ON,DevState.OFF,DevState.INIT]
+        # PROTECTED REGION END #    //  StatsCrosslet.is_visibilities_imag_allowed
+
     def read_visibilities_real(self):
         # PROTECTED REGION ID(StatsCrosslet.visibilities_real_read) ENABLED START #
         """Return the visibilities_real attribute."""
         return self._visibilities_real
         # PROTECTED REGION END #    //  StatsCrosslet.visibilities_real_read
 
+    def is_visibilities_real_allowed(self, attr):
+        # PROTECTED REGION ID(StatsCrosslet.is_visibilities_real_allowed) ENABLED START #
+        return self.get_state() not in [DevState.ON,DevState.OFF,DevState.INIT]
+        # PROTECTED REGION END #    //  StatsCrosslet.is_visibilities_real_allowed
+
     # --------
     # Commands
     # --------
@@ -287,10 +320,15 @@ class StatsCrosslet(Device):
 
         :return:None
         """
-#        self.data_acquisition_is_active.set()
-        self.data_acquisition_is_active = True
+        if is_start_acquisition_allowed() is True:
+            self.data_acquisition_is_active = True
         # PROTECTED REGION END #    //  StatsCrosslet.start_acquisition
 
+    def is_start_acquisition_allowed(self):
+        # PROTECTED REGION ID(StatsCrosslet.is_start_acquisition_allowed) ENABLED START #
+        return self.get_state() not in [DevState.ON,DevState.OFF,DevState.STANDBY,DevState.RUNNING]
+        # PROTECTED REGION END #    //  StatsCrosslet.is_start_acquisition_allowed
+
     @command(
     )
     @DebugIt()
@@ -301,10 +339,15 @@ class StatsCrosslet(Device):
 
         :return:None
         """
-#        self.data_acquisition_is_active.clear()
+        if is_stop_acquisition_allowed() is True:
         self.data_acquisition_is_active = False
         # PROTECTED REGION END #    //  StatsCrosslet.stop_acquisition
 
+    def is_stop_acquisition_allowed(self):
+        # PROTECTED REGION ID(StatsCrosslet.is_stop_acquisition_allowed) ENABLED START #
+        return self.get_state() not in [DevState.ON,DevState.INIT,DevState.RUNNING]
+        # PROTECTED REGION END #    //  StatsCrosslet.is_stop_acquisition_allowed
+
 # ----------
 # Run server
 # ----------
diff --git a/StatsCrosslet-DS/StatsCrosslet.xmi b/StatsCrosslet-DS/StatsCrosslet.xmi
index 7ce474dbf..4a1222bc6 100644
--- a/StatsCrosslet-DS/StatsCrosslet.xmi
+++ b/StatsCrosslet-DS/StatsCrosslet.xmi
@@ -61,6 +61,10 @@
         <type xsi:type="pogoDsl:VoidType"/>
       </argout>
       <status abstract="false" inherited="false" concrete="true" concreteHere="true"/>
+      <excludedStates>ON</excludedStates>
+      <excludedStates>OFF</excludedStates>
+      <excludedStates>STANDBY</excludedStates>
+      <excludedStates>RUNNING</excludedStates>
     </commands>
     <commands name="stop_acquisition" description="Stop the data acquisition." execMethod="stop_acquisition" displayLevel="OPERATOR" polledPeriod="0" isDynamic="false">
       <argin description="">
@@ -70,6 +74,9 @@
         <type xsi:type="pogoDsl:VoidType"/>
       </argout>
       <status abstract="false" inherited="false" concrete="true" concreteHere="true"/>
+      <excludedStates>ON</excludedStates>
+      <excludedStates>INIT</excludedStates>
+      <excludedStates>RUNNING</excludedStates>
     </commands>
     <attributes name="subband" attType="Scalar" rwType="READ_WRITE" displayLevel="OPERATOR" polledPeriod="0" maxX="" maxY="" allocReadMember="true" isDynamic="false">
       <dataType xsi:type="pogoDsl:UShortType"/>
@@ -78,6 +85,8 @@
       <dataReadyEvent fire="false" libCheckCriteria="true"/>
       <status abstract="false" inherited="false" concrete="true" concreteHere="true"/>
       <properties description="" label="" unit="" standardUnit="" displayUnit="" format="" maxValue="" minValue="" maxAlarm="" minAlarm="" maxWarning="" minWarning="" deltaTime="" deltaValue=""/>
+      <readExcludedStates>STANDBY</readExcludedStates>
+      <writeExcludedStates>STANDBY</writeExcludedStates>
     </attributes>
     <attributes name="integration_time" attType="Scalar" rwType="READ" displayLevel="OPERATOR" polledPeriod="0" maxX="" maxY="" allocReadMember="true" isDynamic="false">
       <dataType xsi:type="pogoDsl:DoubleType"/>
@@ -86,6 +95,9 @@
       <dataReadyEvent fire="false" libCheckCriteria="true"/>
       <status abstract="false" inherited="false" concrete="true" concreteHere="true"/>
       <properties description="" label="" unit="" standardUnit="" displayUnit="" format="" maxValue="" minValue="" maxAlarm="" minAlarm="" maxWarning="" minWarning="" deltaTime="" deltaValue=""/>
+      <readExcludedStates>ON</readExcludedStates>
+      <readExcludedStates>OFF</readExcludedStates>
+      <readExcludedStates>INIT</readExcludedStates>
     </attributes>
     <attributes name="time_stamp" attType="Scalar" rwType="READ" displayLevel="OPERATOR" polledPeriod="0" maxX="" maxY="" allocReadMember="true" isDynamic="false">
       <dataType xsi:type="pogoDsl:StringType"/>
@@ -94,6 +106,9 @@
       <dataReadyEvent fire="false" libCheckCriteria="true"/>
       <status abstract="false" inherited="false" concrete="true" concreteHere="true"/>
       <properties description="" label="" unit="" standardUnit="" displayUnit="" format="" maxValue="" minValue="" maxAlarm="" minAlarm="" maxWarning="" minWarning="" deltaTime="" deltaValue=""/>
+      <readExcludedStates>ON</readExcludedStates>
+      <readExcludedStates>OFF</readExcludedStates>
+      <readExcludedStates>INIT</readExcludedStates>
     </attributes>
     <attributes name="pause_time" attType="Scalar" rwType="READ_WRITE" displayLevel="OPERATOR" polledPeriod="0" maxX="" maxY="" allocReadMember="true" isDynamic="false">
       <dataType xsi:type="pogoDsl:DoubleType"/>
@@ -110,6 +125,9 @@
       <dataReadyEvent fire="false" libCheckCriteria="true"/>
       <status abstract="false" inherited="false" concrete="true" concreteHere="true"/>
       <properties description="" label="" unit="" standardUnit="" displayUnit="" format="" maxValue="" minValue="" maxAlarm="" minAlarm="" maxWarning="" minWarning="" deltaTime="" deltaValue=""/>
+      <readExcludedStates>ON</readExcludedStates>
+      <readExcludedStates>OFF</readExcludedStates>
+      <readExcludedStates>INIT</readExcludedStates>
     </attributes>
     <attributes name="visibilities_imag" attType="Image" rwType="READ" displayLevel="OPERATOR" polledPeriod="0" maxX="96" maxY="96" allocReadMember="true" isDynamic="false">
       <dataType xsi:type="pogoDsl:DoubleType"/>
@@ -118,6 +136,9 @@
       <dataReadyEvent fire="false" libCheckCriteria="true"/>
       <status abstract="false" inherited="false" concrete="true" concreteHere="true"/>
       <properties description="" label="" unit="" standardUnit="" displayUnit="" format="" maxValue="" minValue="" maxAlarm="" minAlarm="" maxWarning="" minWarning="" deltaTime="" deltaValue=""/>
+      <readExcludedStates>ON</readExcludedStates>
+      <readExcludedStates>OFF</readExcludedStates>
+      <readExcludedStates>INIT</readExcludedStates>
     </attributes>
     <attributes name="visibilities_real" attType="Image" rwType="READ" displayLevel="OPERATOR" polledPeriod="0" maxX="96" maxY="96" allocReadMember="true" isDynamic="false">
       <dataType xsi:type="pogoDsl:DoubleType"/>
@@ -126,7 +147,25 @@
       <dataReadyEvent fire="false" libCheckCriteria="true"/>
       <status abstract="false" inherited="false" concrete="true" concreteHere="true"/>
       <properties description="" label="" unit="" standardUnit="" displayUnit="" format="" maxValue="" minValue="" maxAlarm="" minAlarm="" maxWarning="" minWarning="" deltaTime="" deltaValue=""/>
+      <readExcludedStates>ON</readExcludedStates>
+      <readExcludedStates>OFF</readExcludedStates>
+      <readExcludedStates>INIT</readExcludedStates>
     </attributes>
+    <states name="ON" description="">
+      <status abstract="false" inherited="false" concrete="true" concreteHere="true"/>
+    </states>
+    <states name="OFF" description="">
+      <status abstract="false" inherited="false" concrete="true" concreteHere="true"/>
+    </states>
+    <states name="STANDBY" description="">
+      <status abstract="false" inherited="false" concrete="true" concreteHere="true"/>
+    </states>
+    <states name="INIT" description="">
+      <status abstract="false" inherited="false" concrete="true" concreteHere="true"/>
+    </states>
+    <states name="RUNNING" description="">
+      <status abstract="false" inherited="false" concrete="true" concreteHere="true"/>
+    </states>
     <preferences docHome="./doc_html" makefileHome="/usr/local/share/pogo/preferences"/>
   </classes>
 </pogoDsl:PogoSystem>
-- 
GitLab