Commit 3211095c authored by Gianluca Marotta's avatar Gianluca Marotta
Browse files

CT-207 changes in OffCommand

parent 13feac24
Loading
Loading
Loading
Loading
Loading
+33 −37
Original line number Diff line number Diff line
@@ -353,7 +353,7 @@ class CspSubarray(SKASubarray):
            device = self.target
            subelement_thr = {}
            self.thread_succeeded = {}
            try:
            off_failed = False
            # First loop that start the sub-element threads to get the ObsState.EMPTY
            for fqdn in device._sc_subarray_fqdn:
                # check if the sub-element subarray is already in the
@@ -365,32 +365,28 @@ class CspSubarray(SKASubarray):
                                                           name="Thread-OffSequence",
                                                           args=(fqdn,))
                    subelement_thr[fqdn].start()
                else:
                    self.logger.info(f'ObsState of device {fqdn} is not EMPTY. ObsState:{device._sc_subarray_obs_state[fqdn]}')
            # Second loop check if the thread is succeeded and send the Off command to sub-element
            for fqdn in subelement_thr.keys():
                subelement_thr[fqdn].join()
                    if not self.thread_succeeded[fqdn]:
                        self.logger.info(f'ObsState of device {fqdn} is not EMPTY. ObsState:{device._sc_subarray_obs_state[fqdn]}')
                        # TODO: GM: anche se non sono EMPTY li mandiamo in OFF?
                        if fqdn != device.CbfSubarray:
                            device._health_state = HealthState.DEGRADED
                            continue
                        else:
                            # TODO: check message
                            return ResultCode.FAILED, 'CBF is not EMPTY, impossible to send OFF command'
                    # turn off the sub-element

            if any(self.thread_succeeded[fqdn] == True for fqdn in subelement_thr.keys()):
                for fqdn in subelement_thr.keys():
                    try:
                        (result_code, message) = device._sc_subarray_proxies[fqdn].Off()
                    if result_code == ResultCode.FAILED:
                        self.logger.error("Off command failed on device {}".format(fqdn))
                        if fqdn != device.CbfSubarray:
                            device._health_state = HealthState.DEGRADED
                            continue
                        else:
                            return ResultCode.FAILED, message
            # TODO: OFF the CSP-Subarray?
                    except tango.DevFailed as tango_err:
                        message = str(tango_err.args[0].desc)
                return ResultCode.FAILED, message
            super().do()
                        result_code = ResultCode.FAILED

                if result_code == ResultCode.FAILED:
                    self.logger.error("Off command failed on device {}".format(fqdn))
                    self.logger.info(message)
                    off_failed = True          

            if off_failed:
                return ResultCode.FAILED, 'Off command Failed'
            
            message = "Off command completed OK"
            self.logger.info(message)
            return ResultCode.OK, message