Commit 06ff3aea authored by Gianluca Marotta's avatar Gianluca Marotta
Browse files

CT-207 Implementation of OffCommand

parent 1dce9bc7
Loading
Loading
Loading
Loading
Loading
+40 −46
Original line number Diff line number Diff line
@@ -352,52 +352,47 @@ class CspSubarray(SKASubarray):
            self.logger.info("Call Off Command")
            device = self.target
            subelement_thr = {}
            self.succeeded = []
            try:
                # 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
                    # requested state
                    if device._sc_subarray_state[fqdn] == tango.DevState.OFF:
                        continue

                    if device._sc_subarray_obs_state[fqdn] is not ObsState.EMPTY:
                        subelement_thr[fqdn] = threading.Thread(target=self.off_sequence,
                                                               name="Thread-OffSequence",
                                                               args=(fqdn,))
                        subelement_thr[fqdn].start()

                # 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.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:
                return (ResultCode.FAILED, message)





                try:
                except tango.DevFailed as tango_err:
                    message = str(tango_err.args[0].desc)
                    return (ResultCode.FAILED, message)


                            # TODO: check message
                            return ResultCode.FAILED, 'CBF is not EMPTY, impossible to send OFF command'
                    # turn off the sub-element
                    (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)

                            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
            message = "Off command completed OK"
            self.logger.info(message)
                    return (ResultCode.OK, message)


            return ResultCode.OK, message

        def off_sequence(self, fqdn):
            #Off command send the device in the state:OFF, ObsState:EMPTY
@@ -427,20 +422,19 @@ class CspSubarray(SKASubarray):
                time.sleep(0.1)
                # if ObsState is: RESOURCING, ABORTING start again to wait end of the transition


            if device._sc_subarray_obs_state[fqdn] is  ObsState.EMPTY:
                self.succeeded[fqdn] = True
            else:
                self.succeeded[fqdn] = False

    class AssignResourcesCommand(SKASubarray.AssignResourcesCommand):

        @transaction_id
        def do(self, argin):
            #TODO: Edit the logger
            self.logger.info('Assign resource command ... ')
            return (ResultCode.OK, "Assign Resources command completed OK")



    class ConfigureCommand(SKASubarray.ConfigureCommand):

        @transaction_id
        def do(self, argin):
            # checks on State, adminMode and obsState values are performed inside the