def do(self, argin):
        """
        Invokes Endscan command on DishMaster.

        param argin:
            timestamp

        raises:
            DevFailed If error occurs while invoking StopCapture command on DishMaster.

        """
        command_name = "EndScan"
        cmd_ended_cb = CommandCallBack(self.logger).cmd_ended_cb

        try:
            this_server = TangoServerHelper.get_instance()
            self.dish_master_fqdn = ""
            property_value = this_server.read_property("DishMasterFQDN")
            self.dish_master_fqdn = self.dish_master_fqdn.join(property_value)
            dish_client = TangoClient(self.dish_master_fqdn)
            dish_client.send_command_async("StopCapture", callback_method=cmd_ended_cb)
            self.logger.info("'%s' command executed successfully.", command_name)
        except DevFailed as dev_failed:
            self.logger.exception(dev_failed)
            log_message = (
                f"Exception occured while executing the '{command_name}' command."
            )
            this_server.write_attr("activityMessage", log_message, False)
            tango.Except.re_throw_exception(
                dev_failed,
                f"Exception in '{command_name}' command.",
                log_message,
                "EndScan.do()",
                tango.ErrSeverity.ERR,
            )
Beispiel #2
0
    def do(self):
        """
        This command invokes Abort command on CSP Subarray.

        return:
            None

        raises:
            DevFailed if error occurs while invoking command on CSP Subarray.

        """
        try:
            this_server = TangoServerHelper.get_instance()
            csp_subarray_fqdn = ""
            property_val = this_server.read_property("CspSubarrayFQDN")
            csp_subarray_fqdn = csp_subarray_fqdn.join(property_val)
            csp_sub_client_obj = TangoClient(csp_subarray_fqdn)
            csp_sub_client_obj.send_command_async(const.CMD_ABORT, None,
                                                  self.abort_cmd_ended_cb)
            this_server.write_attr("activityMessage", const.STR_ABORT_SUCCESS,
                                   False)
            self.logger.info(const.STR_ABORT_SUCCESS)

        except DevFailed as dev_failed:
            log_msg = f"{const.ERR_ABORT_INVOKING_CMD}{dev_failed}"
            this_server.write_attr("activityMessage", log_msg, False)
            self.logger.exception(dev_failed)
            tango.Except.throw_exception(
                const.STR_ABORT_EXEC,
                log_msg,
                "CspSubarrayLeafNode.AbortCommand",
                tango.ErrSeverity.ERR,
            )
Beispiel #3
0
    def do(self):
        """
        Method to invoke Endscan command on CSP Subarray.

        return:
            None

        raises:
            DevFailed if the command execution is not successful

        """
        try:
            this_server = TangoServerHelper.get_instance()
            csp_subarray_fqdn = ""
            property_val = this_server.read_property("CspSubarrayFQDN")
            csp_subarray_fqdn = csp_subarray_fqdn.join(property_val)
            csp_sub_client_obj = TangoClient(csp_subarray_fqdn)
            csp_sub_client_obj.send_command_async(const.CMD_ENDSCAN, None,
                                                  self.endscan_cmd_ended_cb)
            this_server.write_attr("activityMessage",
                                   const.STR_ENDSCAN_SUCCESS, False)
            self.logger.info(const.STR_ENDSCAN_SUCCESS)

        except DevFailed as dev_failed:
            log_msg = f"{const.ERR_ENDSCAN_INVOKING_CMD}{dev_failed}"
            this_server.write_attr("activityMessage", log_msg, False)
            self.logger.exception(dev_failed)
            tango.Except.throw_exception(
                const.STR_ENDSCAN_EXEC,
                log_msg,
                "CspSubarrayLeafNode.EndScanCommand",
                tango.ErrSeverity.ERR,
            )
Beispiel #4
0
    def do(self):
        """
        Method to invoke Standby command on SDP Master.

        :param argin: None.

        return:
            None
        """
        this_server = TangoServerHelper.get_instance()
        try:
            sdp_master_ln_fqdn = ""
            property_val = this_server.read_property("SdpMasterFQDN")[0]
            sdp_master_ln_fqdn = sdp_master_ln_fqdn.join(property_val)
            sdp_mln_client_obj = TangoClient(sdp_master_ln_fqdn)
            sdp_mln_client_obj.send_command_async(
                const.CMD_STANDBY, callback_method=self.standby_cmd_ended_cb
                )
            log_msg = const.CMD_STANDBY + const.STR_COMMAND + const.STR_INVOKE_SUCCESS
            self.logger.debug(log_msg)

        except DevFailed as dev_failed:
            self.logger.exception(dev_failed)
            log_msg = f"{const.ERR_STANDBY_CMD_FAIL}{dev_failed}"
            tango.Except.re_throw_exception(
                dev_failed,
                const.ERR_INVOKING_CMD,
                log_msg,
                "SdpMasterLeafNode.StandbyCommand()",
                tango.ErrSeverity.ERR,
            )
Beispiel #5
0
    def _configure_band(self, band):
        """"Send the ConfigureBand<band-number> command to Dish Master"""
        command_name = f"ConfigureBand{band}"

        try:
            dish_client = TangoClient(self.dish_master_fqdn)
            cmd_ended_cb = CommandCallBack(self.logger).cmd_ended_cb
            dish_client.send_command_async(command_name,
                                           callback_method=cmd_ended_cb)
        except DevFailed as dev_failed:
            raise dev_failed
Beispiel #6
0
    def track_thread(self):
        """This thread writes coordinates to desiredPointing on DishMaster at the rate of 20 Hz."""
        self.logger.info(
            f"print track_thread thread name:{threading.currentThread().getName()}"
            f"{threading.get_ident()}")
        device_data = self.target
        dish_client = TangoClient(self.dish_master_fqdn)
        azel_converter = AzElConverter(self.logger)

        while device_data.event_track_time.is_set() is False:
            now = datetime.datetime.utcnow()
            timestamp = str(now)
            utc_time = now.replace(tzinfo=timezone.utc)
            utc_timestamp = utc_time.timestamp()
            # pylint: disable=unbalanced-tuple-unpacking
            device_data.az, device_data.el = azel_converter.point(
                self.ra_value, self.dec_value, timestamp)

            if not self._is_elevation_within_mechanical_limits():
                time.sleep(0.05)
                continue

            if device_data.az < 0:
                device_data.az = 360 - abs(device_data.az)

            if device_data.event_track_time.is_set():
                log_message = f"Break loop: {device_data.event_track_time.is_set()}"
                self.logger.debug(log_message)
                break

            # TODO (kmadisa 11-12-2020) Add a pointing lead time to the current time (like we do on MeerKAT)
            # utc_timestamp is the time used for AzEl calculation. For the timestamp to be a future timestamp
            # on DishMaster, 100 ms are added to it.
            desired_pointing = [
                (utc_timestamp * 1000) + 100,
                round(device_data.az, 12),
                round(device_data.el, 12),
            ]
            self.logger.debug("desiredPointing coordinates: %s",
                              desired_pointing)
            dish_client.deviceproxy.desiredPointing = desired_pointing
            if (self.track_on_dish == False):
                command_name = "Track"
                dish_client = TangoClient(self.dish_master_fqdn)
                cmd_ended_cb = CommandCallBack(self.logger).cmd_ended_cb
                dish_client.send_command_async(command_name,
                                               callback_method=cmd_ended_cb)
                self.logger.info("'%s' command executed successfully.",
                                 command_name)
                self.track_on_dish = True

            time.sleep(0.05)
Beispiel #7
0
    def do(self, argin):
        """
        Method to invoke Scan command on MCCS Subarray.

        :param argin: JSON string consists of scan id (int) and start_time.

        Example:
        {"interface":"https://schema.skatelescope.org/ska-low-mccs-scan/1.0","scan_id":1,"start_time":0.0}


        Note: Enter the json string without spaces as a input.

        return:
            None

        raises:
            DevFailed if the command execution is not successful
        """
        this_server = TangoServerHelper.get_instance()
        device_data = DeviceData.get_instance()
        try:
            mccs_subarray_fqdn = ""
            property_value = this_server.read_property("MccsSubarrayFQDN")[0]
            mccs_subarray_fqdn = mccs_subarray_fqdn.join(property_value)
            mccs_subarray_client = TangoClient(mccs_subarray_fqdn)
            assert mccs_subarray_client.get_attribute(
                "obsState").value == ObsState.READY
            mccs_subarray_client.send_command_async(const.CMD_SCAN, argin,
                                                    self.scan_cmd_ended_cb)
            this_server.write_attr("activityMessage", const.STR_SCAN_SUCCESS,
                                   False)
            self.logger.info(const.STR_SCAN_SUCCESS)

        except AssertionError as assertion_error:
            log_msg = f"{const.ERR_DEVICE_NOT_READY}{assertion_error}"
            device_data._read_activity_message = log_msg
            self.logger.exception(log_msg)
            tango.Except.throw_exception(const.STR_SCAN_EXEC, log_msg,
                                         "MccsSubarrayLeafNode.Scan",
                                         tango.ErrSeverity.ERR)

        except DevFailed as dev_failed:
            log_msg = f"{const.ERR_SCAN_RESOURCES}{dev_failed}"
            this_server.write_attr("activityMessage", log_msg, False)
            self.logger.exception(dev_failed)
            tango.Except.throw_exception(
                const.STR_SCAN_EXEC,
                log_msg,
                "MccsSubarrayLeafNode.Scan",
                tango.ErrSeverity.ERR,
            )
Beispiel #8
0
    def do(self):
        """
        Method to invoke SetOperateMode command on DishMaster.

        param argin:
            None

        return:
            None

        raises:
            DevFailed If error occurs while invoking SetOperateMode command on DishMaster.

        """
        cmd_ended_cb = CommandCallBack(self.logger).cmd_ended_cb

        attributes_to_subscribe_to = (
            "dishMode",
            "capturing",
            "achievedPointing",
            "desiredPointing",
        )
        command_name = "SetOperateMode"
        cmd_ended_cb = CommandCallBack(self.logger).cmd_ended_cb
        try:
            self.this_server = TangoServerHelper.get_instance()

            self.dish_master_fqdn = ""
            property_value = self.this_server.read_property("DishMasterFQDN")
            self.dish_master_fqdn = self.dish_master_fqdn.join(property_value)
            dish_client = TangoClient(self.dish_master_fqdn)
            # Subscribe the DishMaster attributes
            self._subscribe_to_attribute_events(attributes_to_subscribe_to, dish_client)
            dish_client.send_command_async(command_name, callback_method=cmd_ended_cb)
            self.logger.info("'%s' command executed successfully.", command_name)

        except DevFailed as dev_failed:
            self.logger.exception(dev_failed)
            log_message = (
                f"Exception occured while executing the '{command_name}' command."
            )
            self.this_server.write_attr("activityMessage", log_message, False)
            tango.Except.re_throw_exception(
                dev_failed,
                f"Exception in '{command_name}' command.",
                log_message,
                f"DishLeafNode.{command_name}Command",
                tango.ErrSeverity.ERR,
            )
Beispiel #9
0
    def do(self):
        """
        Method to invoke On command on CSP Element.

        param argin:
            None

        return:
            A tuple containing a return code and a string message indicating status.
            The message is for information purpose only.

        rtype:
            (ResultCode, str)

        raises:
            DevFailed on communication failure with CspMaster or CspMaster is in error state.

        """
        device_data = self.target
        this_device = TangoServerHelper.get_instance()
        try:
            csp_mln_client_obj = TangoClient(
                this_device.read_property("CspMasterFQDN")[0])
            csp_mln_client_obj.send_command_async(const.CMD_ON, [],
                                                  self.on_cmd_ended_cb)
            self.logger.debug(const.STR_ON_CMD_ISSUED)
            this_device.write_attr("activityMessage", const.STR_ON_CMD_ISSUED,
                                   False)
            device_data.cbf_health_updator = CbfHealthStateAttributeUpdator()
            device_data.cbf_health_updator.start()
            device_data.pss_health_updator = PssHealthStateAttributeUpdator()
            device_data.pss_health_updator.start()
            device_data.pst_health_updator = PstHealthStateAttributeUpdator()
            device_data.pst_health_updator.start()
            return (ResultCode.OK, const.STR_ON_CMD_ISSUED)

        except DevFailed as dev_failed:
            log_msg = f"{const.ERR_EXE_ON_CMD}{dev_failed}"
            self.logger.exception(dev_failed)
            this_device.write_attr("activityMessage", const.ERR_EXE_ON_CMD,
                                   False)
            tango.Except.re_throw_exception(
                dev_failed,
                const.STR_ON_EXEC,
                log_msg,
                "CspMasterLeafNode.OnCommand",
                tango.ErrSeverity.ERR,
            )
    def do(self):
        """
        Method to invoke End command on MCCS Subarray.

        return:
            None

        raises:
            DevFailed if the command execution is not successful.
        """
        this_server = TangoServerHelper.get_instance()
        device_data = DeviceData.get_instance()
        try:
            mccs_subarray_fqdn = ""
            property_value = this_server.read_property("MccsSubarrayFQDN")[0]
            mccs_subarray_fqdn = mccs_subarray_fqdn.join(property_value)
            mccs_subarray_client = TangoClient(mccs_subarray_fqdn)
            assert mccs_subarray_client.get_attribute(
                "obsState").value == ObsState.READY
            mccs_subarray_client.send_command_async(const.CMD_END, None,
                                                    self.end_cmd_ended_cb)
            this_server.write_attr("activityMessage", const.STR_END_SUCCESS,
                                   False)
            self.logger.info(const.STR_END_SUCCESS)

        except AssertionError:
            log_msg = const.STR_OBS_STATE
            device_data._read_activity_message = const.ERR_DEVICE_NOT_READY
            self.logger.error(log_msg)
            tango.Except.throw_exception(const.STR_END_EXEC,
                                         const.ERR_DEVICE_NOT_READY,
                                         "MCCSSubarrayLeafNode.End",
                                         tango.ErrSeverity.ERR)

        except DevFailed as dev_failed:
            log_msg = f"{const.ERR_END_INVOKING_CMD}{dev_failed}"
            this_server.write_attr("activityMessage", log_msg, False)
            self.logger.exception(dev_failed)
            tango.Except.throw_exception(
                const.ERR_END_INVOKING_CMD,
                log_msg,
                "MccsSubarrayLeafNode.End()",
                tango.ErrSeverity.ERR,
            )
Beispiel #11
0
    def do(self):
        """
        Invokes TrackStop command on the DishMaster.

        param argin:
            None

        return:
            None

        raises:
            DevFailed If error occurs while invoking TrackStop command on DishMaster.

        """
        device_data = self.target
        command_name = "Abort"
        device_data.event_track_time.set()
        cmd_ended_cb = CommandCallBack(self.logger).cmd_ended_cb
        try:
            this_server = TangoServerHelper.get_instance()
            self.dish_master_fqdn = ""
            property_value = this_server.read_property("DishMasterFQDN")
            self.dish_master_fqdn = self.dish_master_fqdn.join(property_value)
            dish_client = TangoClient(self.dish_master_fqdn)
            dish_pointing_state = dish_client.get_attribute("pointingState")
            if (dish_pointing_state.value is not PointingState.READY):
                dish_client.send_command_async("TrackStop",
                                               callback_method=cmd_ended_cb)
            self.logger.info("'%s' command executed successfully.",
                             command_name)
        except DevFailed as dev_failed:
            self.logger.exception(dev_failed)
            log_message = (
                f"Exception occured while executing the '{command_name}' command."
            )
            this_server.write_attr("activityMessage", log_message, False)
            tango.Except.re_throw_exception(
                dev_failed,
                f"Exception in '{command_name}' command.",
                log_message,
                "Abort.do()",
                tango.ErrSeverity.ERR,
            )
    def do(self):
        """
        Method to invoke ReleaseAllResources command on CSP Subarray.

        return:
            None

        raises:
            DevFailed if the command execution is not successful

        """
        device_data = self.target
        try:
            # Invoke RemoveAllResources command on CspSubarray
            device_data.receptorIDList_str = []
            device_data.fsids_list = []
            this_server = TangoServerHelper.get_instance()
            csp_subarray_fqdn = ""
            property_val = this_server.read_property("CspSubarrayFQDN")
            csp_subarray_fqdn = csp_subarray_fqdn.join(property_val)
            csp_sub_client_obj = TangoClient(csp_subarray_fqdn)
            csp_sub_client_obj.send_command_async(
                const.CMD_RELEASE_ALL_RESOURCES,
                None,
                self.releaseallresources_cmd_ended_cb,
            )
            this_server.write_attr("activityMessage",
                                   const.STR_RELEASE_ALL_RESOURCES_SUCCESS,
                                   False)
            self.logger.info(const.STR_RELEASE_ALL_RESOURCES_SUCCESS)

        except DevFailed as dev_failed:
            log_msg = f"{const.ERR_RELEASE_ALL_RESOURCES}{dev_failed}"
            this_server.write_attr("activityMessage", log_msg, False)
            self.logger.exception(dev_failed)
            tango.Except.throw_exception(
                const.STR_RELEASE_RES_EXEC,
                log_msg,
                "CspSubarrayLeafNode.ReleaseAllResourcesCommand",
                tango.ErrSeverity.ERR,
            )
    def do(self):
        """
        Method to invoke Off command on the MCCS.

        param argin:
            None.

        return:
            A tuple containing a return code and a string message indicating status.
            The message is for information purpose only.

        rtype:
            (ResultCode, str)

        """
        # If the array length is 0, the command applies to the whole MCCS Element.
        # If the array length is >, each array element specifies the FQDN of the MCCS SubElement to switch OFF.
        try:
            self.this_server = TangoServerHelper.get_instance()

            mccs_master_fqdn = ""
            property_value = self.this_server.read_property("MccsMasterFQDN")
            mccs_master_fqdn = mccs_master_fqdn.join(property_value)
            mccs_master_client = TangoClient(mccs_master_fqdn)
            mccs_master_client.send_command_async(
                const.CMD_OFF, None, self.off_cmd_ended_cb
            )
            self.logger.debug(const.STR_OFF_CMD_ISSUED)
            self.this_server.write_attr("activityMessage", const.STR_OFF_CMD_ISSUED, False)
            return (ResultCode.OK, const.STR_OFF_CMD_ISSUED)

        except DevFailed as dev_failed:
            log_msg = f"{const.ERR_OFF_RESOURCES}{dev_failed}"
            self.this_server.write_attr("activityMessage", log_msg, False)
            self.logger.exception(dev_failed)
            tango.Except.throw_exception(
                const.STR_OFF_EXEC,
                log_msg,
                "MccsMasterLeafNode.Off",
                tango.ErrSeverity.ERR,
            )
Beispiel #14
0
    def do(self, argin):
        """
        Method to invoke Slew command on Dish Master.

        :param argin: list
            [0] = Azimuth, in degrees
            [1] = Elevation, in degrees

        return:
            None

        raises:
            DevFailed If error occurs while invoking Slew command on DishMaster.

        """
        command_name = "Slew"
        cmd_ended_cb = CommandCallBack(self.logger).cmd_ended_cb
        try:
            this_server = TangoServerHelper.get_instance()
            self.dish_master_fqdn = ""
            property_value = this_server.read_property("DishMasterFQDN")
            self.dish_master_fqdn = self.dish_master_fqdn.join(property_value)
            dish_client = TangoClient(self.dish_master_fqdn)
            dish_client.send_command_async(command_name,
                                           command_data=argin,
                                           callback_method=cmd_ended_cb)
            self.logger.info("'%s' command executed successfully.",
                             command_name)
        except DevFailed as dev_failed:
            self.logger.exception(dev_failed)
            log_message = (
                f"Exception occured while executing the '{command_name}' command."
            )
            this_server.write_attr("activityMessage", log_message, False)
            tango.Except.re_throw_exception(
                dev_failed,
                f"Exception in '{command_name}' command.",
                log_message,
                "Slew.do()",
                tango.ErrSeverity.ERR,
            )
Beispiel #15
0
    def do(self):
        """
        Invokes TrackStop command on the DishMaster.

        param argin:
            None

        return:
            None

        raises:
            DevFailed If error occurs while invoking TrackStop command on DishMaster.

        """
        device_data = self.target
        command_name = "StopTrack"
        cmd_ended_cb = CommandCallBack(self.logger).cmd_ended_cb
        device_data.event_track_time.set()
        try:
            this_server = TangoServerHelper.get_instance()
            # Note: The DishMaster implements the 'TrackStop' command. This is in accordance to the
            # SKA-TEL-SKO-0000150-04-SKA1-Mid TM to Dish ICD.
            self.dish_master_fqdn = ""
            property_value = this_server.read_property("DishMasterFQDN")
            self.dish_master_fqdn = self.dish_master_fqdn.join(property_value)
            dish_client = TangoClient(self.dish_master_fqdn)
            dish_client.send_command_async("TrackStop", callback_method=cmd_ended_cb)
            self.logger.info("'%s' command executed successfully.", command_name)
        except DevFailed as dev_failed:
            self.logger.exception(dev_failed)
            log_message = (
                f"Exception occured while executing the '{command_name}' command."
            )
            this_server.write_attr("activityMessage", log_message, False)
            tango.Except.re_throw_exception(
                dev_failed,
                f"Exception in '{command_name}' command.",
                log_message,
                f"DishLeafNode.{command_name}Command",
                tango.ErrSeverity.ERR,
            )
Beispiel #16
0
    def do(self, argin):
        """
        Method to invoke StartScan command on CSP Subarray.

        :param argin: JSON string consists of scan id (int).

        Example:
        {"id":1}

        Note: Enter the json string without spaces as a input.

        return:
            None

        raises:
            DevFailed if the command execution is not successful

        """
        try:
            this_server = TangoServerHelper.get_instance()
            csp_subarray_fqdn = ""
            property_val = this_server.read_property("CspSubarrayFQDN")
            csp_subarray_fqdn = csp_subarray_fqdn.join(property_val)
            csp_sub_client_obj = TangoClient(csp_subarray_fqdn)
            csp_sub_client_obj.send_command_async(const.CMD_STARTSCAN, "0",
                                                  self.startscan_cmd_ended_cb)
            this_server.write_attr("activityMessage",
                                   const.STR_STARTSCAN_SUCCESS, False)
            self.logger.info(const.STR_STARTSCAN_SUCCESS)

        except DevFailed as dev_failed:
            log_msg = f"{const.ERR_STARTSCAN_RESOURCES}{dev_failed}"
            this_server.write_attr("activityMessage", log_msg, False)
            self.logger.exception(dev_failed)
            tango.Except.throw_exception(
                const.STR_START_SCAN_EXEC,
                log_msg,
                "CspSubarrayLeafNode.StartScanCommand",
                tango.ErrSeverity.ERR,
            )
    def do(self):
        """
        Method to invoke On command on SDP Subarray.

        :param argin: None.

        return:
            A tuple containing a return code and a string message indicating status.
            The message is for information purpose only.

        rtype:
            (ResultCode, str)

        raises:
            DevFailed if error occurs while invoking command on SDPSubarray.

        """
        this_server = TangoServerHelper.get_instance()
        try:
            sdp_sa_ln_client_obj=TangoClient(this_server.read_property("SdpSubarrayFQDN")[0])
            sdp_sa_ln_client_obj.send_command_async(
                const.CMD_ON, None, self.on_cmd_ended_cb
            )
            log_msg = const.CMD_ON + const.STR_COMMAND + const.STR_INVOKE_SUCCESS
            this_server.set_status(log_msg)
            self.logger.debug(log_msg)

            return (ResultCode.OK, log_msg)

        except DevFailed as dev_failed:
            log_msg = f"{const.ERR_INVOKING_ON_CMD} {dev_failed}"
            this_server.write_attr("activityMessage", log_msg, False)
            this_server.set_status(log_msg)
            self.logger.exception(dev_failed)
            tango.Except.throw_exception(
                const.STR_ON_EXEC,
                log_msg,
                "SdpSubarrayLeafNode.On()",
                tango.ErrSeverity.ERR,
            )
    def do(self, argin):
        """
        Method to invoke Standby command on CSP Element.

        :param argin: DevStringArray.
        If the array length is 0, the command applies to the whole CSP Element. If the array length is > 1
        , each array element specifies the FQDN of the CSP SubElement to put in STANDBY mode.

        return:
            None

        raises:
            DevFailed on communication failure with CspMaster or CspMaster is in error state.

        """
        this_device = TangoServerHelper.get_instance()

        try:
            csp_mln_client_obj = TangoClient(
                this_device.read_property("CspMasterFQDN")[0])
            csp_mln_client_obj.send_command_async(
                const.CMD_STANDBY,
                command_data=argin,
                callback_method=self.standby_cmd_ended_cb)
            self.logger.debug(const.STR_STANDBY_CMD_ISSUED)
            this_device.write_attr("activityMessage",
                                   const.STR_STANDBY_CMD_ISSUED, False)

        except DevFailed as dev_failed:
            log_msg = f"{const.ERR_EXE_STANDBY_CMD}{dev_failed}"
            self.logger.exception(dev_failed)
            this_device.write_attr("activityMessage",
                                   const.ERR_EXE_STANDBY_CMD, False)
            tango.Except.re_throw_exception(
                dev_failed,
                const.STR_STANDBY_EXEC,
                log_msg,
                "CspMasterLeafNode.StandbyCommand",
                tango.ErrSeverity.ERR,
            )
Beispiel #19
0
    def do(self):
        """
        Method to invoke On command on SDP Master.

        :param argin: None.

        return:
            A tuple containing a return code and a string message indicating status.
            The message is for information purpose only.

        rtype:
            (ResultCode, str)

        """
        this_server = TangoServerHelper.get_instance()
        try:
            sdp_master_ln_fqdn = ""
            property_val = this_server.read_property("SdpMasterFQDN")[0]
            sdp_master_ln_fqdn = sdp_master_ln_fqdn.join(property_val)
            sdp_mln_client_obj = TangoClient(sdp_master_ln_fqdn)
            
            sdp_mln_client_obj.send_command_async(
                const.CMD_ON, None, self.on_cmd_ended_cb
            )
            log_msg = const.STR_ON_CMD_SUCCESS
            self.logger.debug(log_msg)
            return (ResultCode.OK, log_msg)

        except DevFailed as dev_failed:
            self.logger.exception(dev_failed)
            log_msg = f"{const.ERR_ON_CMD_FAIL}{dev_failed}"
            tango.Except.re_throw_exception(
                dev_failed,
                const.ERR_INVOKING_CMD,
                log_msg,
                "SdpMasterLeafNode.OnCommand()",
                tango.ErrSeverity.ERR,
            )
    def do(self):
        """
         Method to invoke Restart command on MCCS Controller.

        :param argin: None

        return:
            None

        raises:
            DevFailed if the command execution is not successful

        """
        try:
            # On mccs side this implementation is not finalize yet modifications are expected.
            # Hence hardcoded controller FQDN and input arguement (subarray ID).
            mccs_controller_fqdn = "low-mccs/control/control"
            input_to_mccs_controller = {"subarray_id": 1}
            argin = json.dumps(input_to_mccs_controller)
            mccs_controller_client = TangoClient(mccs_controller_fqdn)
            mccs_controller_client.send_command_async(
                const.CMD_RESTART, argin, self.restart_cmd_ended_cb)
            self.this_server.write_attr("activityMessage",
                                        const.STR_RESTART_SUCCESS, False)
            self.logger.info(const.STR_RESTART_SUCCESS)

        except DevFailed as dev_failed:
            log_msg = f"{const.ERR_RESTART_COMMAND}{dev_failed}"
            self.this_server.write_attr("activityMessage", log_msg, False)
            self.logger.exception(dev_failed)
            tango.Except.throw_exception(
                const.ERR_RESTART_COMMAND,
                log_msg,
                "MccsSubarrayLeafNode.Restart",
                tango.ErrSeverity.ERR,
            )
Beispiel #21
0
    def do(self, argin):
        """
        Method to invoke Configure command on CSP Subarray.

        :param argin:DevString. The string in JSON format. The JSON contains following values:

        Example:
        {"interface":"https://schema.skatelescope.org/ska-csp-configure/1.0","subarray":{"subarrayName":"science period 23"},"common":{"id":"sbi-mvp01-20200325-00001-science_A","frequencyBand":"1","subarrayID":"1"},
        "cbf":{"fsp":[{"fspID":1,"functionMode":"CORR","frequencySliceID":1,"integrationTime":1400,"corrBandwidth":0,"channelAveragingMap":[[0,2],[744,0]],"ChannelOffset":0,"outputLinkMap":[[0,0],[200,1]],"outputHost"
        :[[0,"192.168.1.1"]],"outputPort":[[0,9000,1]]},{"fspID":2,"functionMode":"CORR","frequencySliceID":2,"integrationTime":1400,"corrBandwidth":0,"channelAveragingMap":[[0,2],[744,0]],"fspChannelOffset":744,
        "outputLinkMap":[[0,4],[200,5]],"outputHost":[[0,"192.168.1.1"]],"outputPort":[[0,9744,1]]}],"vlbi":{},"delayModelSubscriptionPoint":"ska_mid/tm_leaf_node/csp_subarray01/delayModel"},"pss":{},"pst":{},
        "pointing":{"target":{"system":"ICRS","name":"Polaris Australis","RA":"21:08:47.92","dec":"-88:57:22.9"}}}

        Note: Enter the json string without spaces as a input.

        return:
            None

        raises:
            DevFailed if the command execution is not successful

            ValueError if input argument json string contains invalid value
        """
        device_data = self.target
        target_Ra = ""
        target_Dec = ""
        this_server = TangoServerHelper.get_instance()
        device_data.fsp_ids_object = []
        try:
            argin_json = json.loads(argin)
            # Used to extract FSP IDs
            device_data.fsp_ids_object = argin_json["cbf"]["fsp"]
            delay_manager_obj = DelayManager.get_instance()
            delay_manager_obj.update_config_params()
            pointing_params = argin_json["pointing"]
            target_Ra = pointing_params["target"]["RA"]
            target_Dec = pointing_params["target"]["dec"]

            # Create target object
            device_data.target = katpoint.Target(
                f"radec , {target_Ra} , {target_Dec}")
            csp_configuration = argin_json.copy()
            # Keep configuration specific to CSP and delete pointing configuration
            if "pointing" in csp_configuration:
                del csp_configuration["pointing"]
            log_msg = (
                "Input JSON for CSP Subarray Leaf Node Configure command is: "
                + argin)
            self.logger.debug(log_msg)
            csp_subarray_fqdn = ""
            property_val = this_server.read_property("CspSubarrayFQDN")
            csp_subarray_fqdn = csp_subarray_fqdn.join(property_val)
            csp_sub_client_obj = TangoClient(csp_subarray_fqdn)
            csp_sub_client_obj.send_command_async(
                const.CMD_CONFIGURE,
                json.dumps(csp_configuration),
                self.configure_cmd_ended_cb,
            )
            this_server.write_attr("activityMessage",
                                   const.STR_CONFIGURE_SUCCESS, False)
            self.logger.info(const.STR_CONFIGURE_SUCCESS)

        except ValueError as value_error:
            log_msg = f"{const.ERR_INVALID_JSON_CONFIG}{value_error}"
            this_server.write_attr("activityMessage", log_msg, False)
            self.logger.exception(value_error)
            tango.Except.throw_exception(
                const.ERR_CONFIGURE_INVOKING_CMD,
                log_msg,
                "CspSubarrayLeafNode.ConfigureCommand",
                tango.ErrSeverity.ERR,
            )

        except DevFailed as dev_failed:
            log_msg = f"{const.ERR_CONFIGURE_INVOKING_CMD}{dev_failed}"
            this_server.write_attr("activityMessage", log_msg, False)
            self.logger.exception(dev_failed)
            tango.Except.throw_exception(
                const.ERR_CONFIGURE_INVOKING_CMD,
                log_msg,
                "CspSubarrayLeafNode.ConfigureCommand",
                tango.ErrSeverity.ERR,
            )
Beispiel #22
0
    def do(self, argin):
        """
        Method to invoke ReleaseResources command on Mccs Master.

        :param argin:
                     StringType. The string in JSON format.

        Example:
            {
                "interface":"https://schema.skatelescope.org/ska-low-tmc-releaseresources/1.0",
                "subarray_id":1,
                "release_all":true
            }

        return:
            None.

        raises:
            DevFailed if the command execution is not successful

            ValueError if invalid json string.

        """
        log_msg = "Input JSON for MCCS master leaf node Release command is: " + argin
        self.logger.debug(log_msg)
        self.logger.info("Invoking Release on MCCS master")

        try:
            self.this_server = TangoServerHelper.get_instance()
            mccs_master_fqdn = ""
            property_value = self.this_server.read_property("MccsMasterFQDN")
            mccs_master_fqdn = mccs_master_fqdn.join(property_value)
            mccs_master_client = TangoClient(mccs_master_fqdn)
            mccs_master_client.send_command_async(
                const.CMD_Release, argin, self.releaseresources_cmd_ended_cb
            )
            self.this_server.write_attr("activityMessage", const.STR_REMOVE_ALL_RECEPTORS_SUCCESS, False)
            self.logger.info(const.STR_REMOVE_ALL_RECEPTORS_SUCCESS)

        except ValueError as value_error:
            log_msg = f"{const.ERR_INVALID_JSON_RELEASE_RES_MCCS}{value_error}"
            self.this_server.write_attr("activityMessage",
                                        f"{const.ERR_INVALID_JSON_RELEASE_RES_MCCS}{value_error}", False)
            self.logger.exception(value_error)
            tango.Except.re_throw_exception(
                value_error,
                const.STR_RELEASE_RES_EXEC,
                log_msg,
                "MccsMasterLeafNode.ReleaseResources",
                tango.ErrSeverity.ERR,
            )

        except DevFailed as dev_failed:
            log_msg = f"{const.ERR_RELEASE_ALL_RESOURCES} {dev_failed}"
            self.this_server.write_attr("activityMessage", log_msg, False)
            self.logger.exception(dev_failed)
            tango.Except.re_throw_exception(
                dev_failed,
                const.STR_RELEASE_RES_EXEC,
                log_msg,
                "MccsMasterLeafNode.ReleaseAllResources",
                tango.ErrSeverity.ERR,
            )
    def do(self, argin):
        """
        Method to invoke AssignResources command on CSP Subarray.

        :param argin:DevString. The string in JSON format. The JSON contains following values:
            subarrayID: integer

            dish:
                Mandatory JSON object consisting of

                receptorIDList:
                    DevVarString
                    The individual string should contain dish numbers in string format
                    with preceding zeroes upto 3 digits. E.g. 0001, 0002.

        Example:
            {
                    "subarrayID":1,
                    "dish": {
                    "receptorIDList": [
                        "0001",
                        "0002"
                    ]
                    }
            }


        Note: Enter the json string without spaces as an input.

        return:
            None

        raises:
            ValueError if input argument json string contains invalid value

            KeyError if input argument json string contains invalid key

            DevFailed if the command execution is not successful
        """
        device_data = self.target
        try:
            json_argument = json.loads(argin)
            device_data.receptorIDList_str = json_argument[const.STR_DISH][const.STR_RECEPTORID_LIST]
            delay_manager_obj = DelayManager.get_instance()
            delay_manager_obj.update_config_params()
            # Invoke AssignResources command on CspSubarray
            self.logger.info("Invoking AssignResources on CSP subarray")
            this_server = TangoServerHelper.get_instance()
            csp_subarray_fqdn = ""
            property_val = this_server.read_property("CspSubarrayFQDN")
            csp_subarray_fqdn = csp_subarray_fqdn.join(property_val)
            csp_sub_client_obj = TangoClient(csp_subarray_fqdn)
            csp_sub_client_obj.send_command_async(
                const.CMD_ASSIGN_RESOURCES, argin, self.assign_resources_ended
            )
            self.logger.info("After invoking AssignResources on CSP subarray")
            this_server.write_attr("activityMessage", const.STR_ASSIGN_RESOURCES_SUCCESS, False)
            self.logger.info(const.STR_ASSIGN_RESOURCES_SUCCESS)

        except DevFailed as dev_failed:
            log_msg = f"{const.ERR_ASSGN_RESOURCES}{dev_failed}"
            this_server.write_attr("activityMessage", log_msg, False)
            self.logger.exception(dev_failed)
            tango.Except.throw_exception(
                const.STR_ASSIGN_RES_EXEC,
                log_msg,
                "CspSubarrayLeafNode.AssignResourcesCommand",
                tango.ErrSeverity.ERR,
            )
    def do(self, argin):
        """
        Method to invoke Configure command on MCCS Subarray.

        :param argin: DevString.
                      The string in JSON format. The JSON contains following values:

        Example:
        {'interface':'https://schema.skatelescope.org/ska-low-tmc-configure/1.0','stations':[{'station_id':1},{'station_id':2}],'subarray_beams':[{'subarray_beam_id':1,'station_ids':[1,2],'update_rate':0.0,'channels':[[0,8,1,1],[8,8,2,1],[24,16,2,1]],'antenna_weights':[1.0,1.0,1.0],'phase_centre':[0.0,0.0],'target':{'system':'HORIZON','name':'DriftScan','az':180.0,'el':45.0}}]}

        Note: Enter the json string without spaces as a input.

        return:
            None

        raises:
            DevFailed if the command execution is not successful

            ValueError if input argument json string contains invalid value

            KeyError if input argument json string contains invalid key
        """
        this_server = TangoServerHelper.get_instance()
        device_data = DeviceData.get_instance()
        try:
            mccs_subarray_fqdn = ""
            property_value = this_server.read_property("MccsSubarrayFQDN")[0]
            mccs_subarray_fqdn = mccs_subarray_fqdn.join(property_value)
            mccs_subarray_client = TangoClient(mccs_subarray_fqdn)
            assert (mccs_subarray_client.get_attribute("obsState").value
                    in (ObsState.IDLE, ObsState.READY))
            log_msg = (
                "Input JSON for MCCS Subarray Leaf Node Configure command is: "
                + argin)
            self.logger.debug(log_msg)

            configuration_string = json.loads(argin)
            cmd_data = self.create_cmd_data(configuration_string)

            # Invoke Configure command on MCCSSubarray.
            log_msg = "Output Configure JSON is: " + cmd_data
            self.logger.info(log_msg)
            mccs_subarray_client.send_command_async(
                const.CMD_CONFIGURE, cmd_data, self.configure_cmd_ended_cb)
            this_server.write_attr("activityMessage",
                                   const.STR_CONFIGURE_SUCCESS, False)

            self.logger.info(const.STR_CONFIGURE_SUCCESS)

        except AssertionError:
            obsState_val = mccs_subarray_client.get_attribute("obsState").value
            log_msg = (f"Mccs Subarray is in ObsState {obsState_val}."
                       "Unable to invoke Configure command")
            device_data._read_activity_message = log_msg
            self.logger.exception(log_msg)
            tango.Except.throw_exception(
                const.STR_CONFIGURE_EXEC, log_msg,
                "MccsSubarrayLeafNode.ConfigureCommand", tango.ErrSeverity.ERR)

        except ValueError as value_error:
            log_msg = f"{const.ERR_INVALID_JSON_CONFIG}{value_error}"
            this_server.write_attr("activityMessage", log_msg, False)
            self.logger.exception(value_error)
            tango.Except.throw_exception(
                const.ERR_CONFIGURE_INVOKING_CMD,
                log_msg,
                "MccsSubarrayLeafNode.Configure",
                tango.ErrSeverity.ERR,
            )

        except KeyError as key_error:
            log_msg = f"{const.ERR_JSON_KEY_NOT_FOUND}{key_error}"
            this_server.write_attr("activityMessage", log_msg, False)
            self.logger.exception(key_error)
            tango.Except.throw_exception(
                const.ERR_CONFIGURE_INVOKING_CMD,
                log_msg,
                "MccsSubarrayLeafNode.Configure",
                tango.ErrSeverity.ERR,
            )

        except DevFailed as dev_failed:
            log_msg = f"{const.ERR_CONFIGURE_INVOKING_CMD}{dev_failed}"
            this_server.write_attr("activityMessage", log_msg, False)
            self.logger.exception(dev_failed)
            tango.Except.throw_exception(
                const.ERR_CONFIGURE_INVOKING_CMD,
                log_msg,
                "MccsSubarrayLeafNode.Configure",
                tango.ErrSeverity.ERR,
            )
Beispiel #25
0
    def do(self, argin):
        """
        Method to invoke AssignResources command on SDP Subarray.

        :param argin: The string in JSON format. The JSON contains following values:

            SBI ID and maximum length of the SBI:
            Mandatory JSON object consisting of

            SBI ID :
                String

            max_length:
                Float

        Scan types:
            Consist of Scan type id name

            scan_type:
                DevVarStringArray

        Processing blocks:
            Mandatory JSON object consisting of

                processing_blocks:
                    DevVarStringArray

        Example:
            {"id":"sbi-mvp01-20200325-00001","max_length":100.0,"scan_types":[{"id":"science_A",
            "coordinate_system":"ICRS","ra":"02:42:40.771","dec":"-00:00:47.84","channels":[{"count"
            :744,"start":0,"stride":2,"freq_min":0.35e9,"freq_max":0.368e9,"link_map":[[0,0],[200,1],
            [744,2],[944,3]]},{"count":744,"start":2000,"stride":1,"freq_min":0.36e9,"freq_max":0.368e9,
            "link_map":[[2000,4],[2200,5]]}]},{"id":"calibration_B","coordinate_system":"ICRS","ra":
            "12:29:06.699","dec":"02:03:08.598","channels":[{"count":744,"start":0,"stride":2,
            "freq_min":0.35e9,"freq_max":0.368e9,"link_map":[[0,0],[200,1],[744,2],[944,3]]},{"count":744,
            "start":2000,"stride":1,"freq_min":0.36e9,"freq_max":0.368e9,"link_map":[[2000,4],[2200,5]]}]}]
            ,"processing_blocks":[{"id":"pb-mvp01-20200325-00001","workflow":{"type":"realtime","id":
            "vis_receive","version":"0.1.0"},"parameters":{}},{"id":"pb-mvp01-20200325-00002","workflow":
            {"type":"realtime","id":"test_realtime","version":"0.1.0"},"parameters":{}},{"id":
            "pb-mvp01-20200325-00003","workflow":{"type":"batch","id":"ical","version":"0.1.0"},"parameters"
            :{},"dependencies":[{"pb_id":"pb-mvp01-20200325-00001","type":["visibilities"]}]},{"id":
            "pb-mvp01-20200325-00004","workflow":{"type":"batch","id":"dpreb","version":"0.1.0"},"parameters"
            :{},"dependencies":[{"pb_id":"pb-mvp01-20200325-00003","type":["calibration"]}]}]}

        Note: Enter input without spaces

        return:
            None

        raises:
            ValueError if input argument json string contains invalid value.

            DevFailed if the command execution is not successful.
        """
        try:
            # Call SDP Subarray Command asynchronously
            sdp_sa_ln_client_obj = TangoClient(
                self.this_server.read_property("SdpSubarrayFQDN")[0])
            sdp_sa_ln_client_obj.send_command_async(
                const.CMD_ASSIGN_RESOURCES,
                command_data=argin,
                callback_method=self.assign_resources_ended)
            # Update the status of command execution status in activity message
            self.this_server.write_attr("activityMessage",
                                        const.STR_ASSIGN_RESOURCES_SUCCESS,
                                        False)
            self.logger.info(const.STR_ASSIGN_RESOURCES_SUCCESS)

        except ValueError as value_error:
            log_msg = f"{const.ERR_INVALID_JSON}{value_error}"
            self.logger.exception(log_msg)
            self.this_server.write_attr(
                "activityMessage", f"{const.ERR_INVALID_JSON}{value_error}",
                False)
            tango.Except.throw_exception(
                const.STR_CMD_FAILED,
                log_msg,
                const.ERR_INVALID_JSON,
                tango.ErrSeverity.ERR,
            )

        except DevFailed as dev_failed:
            log_msg = f"{const.ERR_ASSGN_RESOURCES}{dev_failed}"
            self.this_server.write_attr("activityMessage", log_msg)
            self.logger.exception(dev_failed)
            tango.Except.throw_exception(
                const.STR_ASSIGN_RES_EXEC,
                log_msg,
                "SdpSubarrayLeafNode.AssignResources()",
                tango.ErrSeverity.ERR,
            )
Beispiel #26
0
class Configure(BaseCommand):
    """
    A class for SdpSubarrayLeafNode's Configure() command.

    Configures the SDP Subarray device by providing the SDP PB
    configuration needed to execute the receive workflow

    """

    def check_allowed(self):
        """
        Checks whether this command is allowed to be run in current device state

        :return: True if this command is allowed to be run in current device state

        :rtype: boolean

        :raises: Exception if command execution throws any type of exception

        """
        self.this_server = TangoServerHelper.get_instance()
        sdp_subarray_fqdn = self.this_server.read_property("SdpSubarrayFQDN")[0]
        self.sdp_sa_ln_client_obj = TangoClient(sdp_subarray_fqdn)

        if self.state_model.op_state in [
            DevState.FAULT,
            DevState.UNKNOWN,
            DevState.DISABLE,
        ]:
            tango.Except.throw_exception(
                f"Configure() is not allowed in current state {self.state_model.op_state}",
                "Failed to invoke Configure command on SdpSubarrayLeafNode.",
                "sdpsubarrayleafnode.Configure()",
                tango.ErrSeverity.ERR,
            )

        if self.sdp_sa_ln_client_obj.get_attribute("obsState").value not in [ObsState.IDLE, ObsState.READY]:
            tango.Except.throw_exception(const.ERR_DEVICE_NOT_READY_OR_IDLE, const.ERR_CONFIGURE,
                                         "SdpSubarrayLeafNode.ConfigureCommand",
                                         tango.ErrSeverity.ERR)
        return True

    def configure_cmd_ended_cb(self, event):
        """
        Callback function immediately executed when the asynchronous invoked command returns.
        Checks whether the configure command has been successfully invoked on SDP Subarray.

        :param event: A CmdDoneEvent object. This class is used to pass data to the callback method in asynchronous
                        callback model for command execution.

        :type: CmdDoneEvent object

            It has the following members:
                - device     : (DeviceProxy) The DeviceProxy object on which the call was executed.
                - cmd_name   : (str) The command name
                - argout_raw : (DeviceData) The command argout
                - argout     : The command argout
                - err        : (bool) A boolean flag set to true if the command failed. False otherwise
                - errors     : (sequence<DevError>) The error stack
                - ext

        :return: none
        """
        if event.err:
            log = f"{const.ERR_INVOKING_CMD}{event.cmd_name}\n{event.errors}"
            self.this_server.write_attr("activityMessage", log, False)
            self.logger.error(log)
        else:
            log = const.STR_COMMAND + event.cmd_name + const.STR_INVOKE_SUCCESS
            self.this_server.write_attr("activityMessage", log, False)
            self.logger.info(log)

    @identify_with_id("configure", "argin")
    def do(self, argin):
        """
        Method to invoke Configure command on SDP Subarray.

        :param argin: The string in JSON format. The JSON contains following values:

        Example:

        { "scan_type": "science_A" }

        return:
            None

        raises:
            ValueError if input argument json string contains invalid value.

            KeyError if input argument json string contains invalid key.

            DevFailed if the command execution is not successful
        """
        try:
            log_msg = (
                "Input JSON for SDP Subarray Leaf Node Configure command is: " + argin
            )
            self.logger.debug(log_msg)
            self.sdp_sa_ln_client_obj.send_command_async(
                const.CMD_CONFIGURE, command_data=argin, callback_method=self.configure_cmd_ended_cb
                )
            self.this_server.write_attr("activityMessage", const.STR_CONFIGURE_SUCCESS, False)
            self.logger.info(const.STR_CONFIGURE_SUCCESS)

        except DevFailed as dev_failed:
            log_msg = f"{const.ERR_CONFIGURE}{dev_failed}"
            self.this_server.write_attr("activityMessage", log_msg, False)
            self.logger.exception(dev_failed)
            tango.Except.throw_exception(
                const.STR_CONFIG_EXEC,
                log_msg,
                "SdpSubarrayLeafNode.Configure()",
                tango.ErrSeverity.ERR,
            )
class EndScan(BaseCommand):
    """
    A class for SdpSubarrayLeafNode's EndScan() command.

    It invokes EndScan command on Sdp Subarray.
    This command is allowed when Sdp Subarray is in SCANNING state.
    """
    def check_allowed(self):
        """
        Checks whether this command is allowed to be run in current device
        state

        :return: True if this command is allowed to be run in current device state

        :rtype: boolean

        :raises: Exception if command execution throws any type of exception.

        """
        self.this_server = TangoServerHelper.get_instance()
        sdp_subarray_fqdn = self.this_server.read_property(
            "SdpSubarrayFQDN")[0]
        self.sdp_sa_ln_client_obj = TangoClient(sdp_subarray_fqdn)

        if self.state_model.op_state in [
                DevState.FAULT,
                DevState.UNKNOWN,
                DevState.DISABLE,
        ]:
            tango.Except.throw_exception(
                f"EndScan() is not allowed in current state{self.state_model.op_state}",
                "Failed to invoke EndScan command on SdpSubarrayLeafNode.",
                "sdpsubarrayleafnode.EndScan()",
                tango.ErrSeverity.ERR,
            )

        if self.sdp_sa_ln_client_obj.get_attribute(
                "obsState").value != ObsState.SCANNING:
            tango.Except.throw_exception(const.ERR_ENDSCAN_INVOKING_CMD,
                                         const.ERR_DEVICE_NOT_IN_SCAN,
                                         "SdpSubarrayLeafNode.EndScan",
                                         tango.ErrSeverity.ERR)
        return True

    def endscan_cmd_ended_cb(self, event):
        """
        Callback function immediately executed when the asynchronous invoked command returns.
        Checks whether the endscan command has been successfully invoked on SDP Subarray.

        :param event: A CmdDoneEvent object.
        This class is used to pass data to the callback method in asynchronous callback model
        for command execution.

        :type: CmdDoneEvent object

            It has the following members:
                - device     : (DeviceProxy) The DeviceProxy object on which the call was executed.
                - cmd_name   : (str) The command name
                - argout_raw : (DeviceData) The command argout
                - argout     : The command argout
                - err        : (bool) A boolean flag set to true if the command failed. False otherwise
                - errors     : (sequence<DevError>) The error stack
                - ext

        :return: none
        """
        if event.err:
            log = f"{const.ERR_INVOKING_CMD}{event.cmd_name}\n{event.errors}"
            self.this_server.write_attr("activityMessage", log, False)
            self.logger.error(log)
        else:
            log = const.STR_COMMAND + event.cmd_name + const.STR_INVOKE_SUCCESS
            self.this_server.write_attr("activityMessage", log, False)
            self.logger.info(log)

    def do(self):
        """
        Method to invoke EndScan command on SDP Subarray.

        :param argin: None

        return:
            None

        raises:
            DevFailed if the command execution is not successful.
        """
        try:
            self.sdp_sa_ln_client_obj.send_command_async(
                const.CMD_ENDSCAN, None, self.endscan_cmd_ended_cb)
            self.this_server.write_attr("activityMessage",
                                        const.STR_ENDSCAN_SUCCESS, False)
            self.logger.info(const.STR_ENDSCAN_SUCCESS)

        except DevFailed as dev_failed:
            log_msg = f"{const.ERR_ENDSCAN_INVOKING_CMD}{dev_failed}"
            self.this_server.write_attr("activityMessage", log_msg, False)
            self.logger.exception(dev_failed)
            tango.Except.throw_exception(
                const.STR_ENDSCAN_EXEC,
                log_msg,
                "SdpSubarrayLeafNode.EndScan()",
                tango.ErrSeverity.ERR,
            )
Beispiel #28
0
    def do(self, argin):
        """
        Method to invoke AssignResources command on MCCS Master.

        :param argin:
                     StringType. The string in JSON format.

        Example:
                {
                  "interface": "https://schema.skatelescope.org/ska-low-mccs-assignresources/1.0",
                  "subarray_id": 1,
                  "subarray_beam_ids": [
                    1
                  ],
                  "station_ids": [
                    [
                      1,
                      2
                    ]
                  ],
                  "channel_blocks": [
                    3
                  ]
                }

        Note: Enter the json string without spaces as an input.

        return:
            None

        raises:
            ValueError if input argument json string contains invalid value

            KeyError if input argument json string contains invalid key

            DevFailed if the command execution is not successful
        """

        try:
            self.this_server = TangoServerHelper.get_instance()
            log_msg = (
                "Input JSON for MCCS master leaf node AssignResources command is: "
                + argin)
            self.logger.debug(log_msg)

            mccs_master_fqdn = ""
            property_value = self.this_server.read_property("MccsMasterFQDN")
            mccs_master_fqdn = mccs_master_fqdn.join(property_value)
            mccs_master_client = TangoClient(mccs_master_fqdn)
            mccs_master_client.send_command_async(const.CMD_ALLOCATE, argin,
                                                  self.allocate_ended)
            self.this_server.write_attr("activityMessage",
                                        const.STR_ALLOCATE_SUCCESS, False)
            self.logger.info(const.STR_ALLOCATE_SUCCESS)

        except DevFailed as dev_failed:
            log_msg = f"{const.ERR_ASSGN_RESOURCE_MCCS}{dev_failed}"
            self.this_server.write_attr("activityMessage", log_msg, False)
            self.logger.exception(dev_failed)
            tango.Except.re_throw_exception(
                dev_failed,
                const.STR_ASSIGN_RES_EXEC,
                log_msg,
                "MccsMasterLeafNode.AssignResources",
                tango.ErrSeverity.ERR,
            )
class Abort(BaseCommand):
    """
    A class for MccsSubarrayLeafNode's Abort() command.

    Command to abort the current operation being done on the MCCS Subarray.

    """
    def check_allowed(self):
        """
        Checks whether the command is allowed to be executed in the current state

        :return: True if this command is allowed to be run in
            current device state

        :rtype: boolean

        :raises: DevFailed if this command is not allowed to be run
            in current device state

        """
        if self.state_model.op_state in [
                DevState.FAULT,
                DevState.UNKNOWN,
                DevState.DISABLE,
        ]:
            tango.Except.throw_exception(
                f"Abort() is not allowed in current state {self.state_model.op_state}",
                "Failed to invoke Abort command on MccsSubarrayLeafNode.",
                "Mccssubarrayleafnode.Abort()",
                tango.ErrSeverity.ERR,
            )
        self.this_server = TangoServerHelper.get_instance()
        self.mccs_sa_fqdn = self.this_server.read_property(
            "MccsSubarrayFQDN")[0]
        self.mccs_sa_client = TangoClient(self.mccs_sa_fqdn)
        if self.mccs_sa_client.get_attribute("obsState").value not in [
                ObsState.READY, ObsState.CONFIGURING, ObsState.SCANNING,
                ObsState.IDLE, ObsState.RESETTING
        ]:
            tango.Except.throw_exception(const.ERR_DEVICE_NOT_IN_VALID_OBSTATE,
                                         const.ERR_ABORT_COMMAND,
                                         "MccsSubarrayLeafNode.Abort()",
                                         tango.ErrSeverity.ERR)
        return True

    def abort_cmd_ended_cb(self, event):
        """
        Callback function immediately executed when the asynchronous invoked
        command returns.

        :param event: a CmdDoneEvent object. This class is used to pass data
            to the callback method in asynchronous callback model for command
            execution.

        :type: CmdDoneEvent object
            It has the following members:
                - device     : (DeviceProxy) The DeviceProxy object on which the call was executed.
                - cmd_name   : (str) The command name
                - argout_raw : (DeviceData) The command argout
                - argout     : The command argout
                - err        : (bool) A boolean flag set to true if the command failed. False otherwise
                - errors     : (sequence<DevError>) The error stack
                - ext

        :return: none
        """
        # Update logs and activity message attribute with received event
        if event.err:
            log_msg = f"{const.ERR_INVOKING_CMD}{event.cmd_name}\n{event.errors}"
            self.logger.error(log_msg)
            self.this_server.write_attr("activityMessage", log_msg, False)
        else:
            log_msg = f"{const.STR_COMMAND}{event.cmd_name}{const.STR_INVOKE_SUCCESS}"
            self.logger.info(log_msg)
            self.this_server.write_attr("activityMessage", log_msg, False)

    def do(self):
        """
         Method to invoke Abort command on MCCS Subarray.

        :param argin: None

        return:
            None

        raises:
            DevFailed if the command execution is not successful

        """
        try:
            self.mccs_sa_client.send_command_async(const.CMD_ABORT, None,
                                                   self.abort_cmd_ended_cb)
            self.this_server.write_attr("activityMessage",
                                        const.STR_ABORT_SUCCESS, False)
            self.logger.info(const.STR_ABORT_SUCCESS)

        except DevFailed as dev_failed:
            log_msg = f"{const.ERR_ABORT_COMMAND}{dev_failed}"
            self.this_server.write_attr("activityMessage", log_msg, False)
            self.logger.exception(dev_failed)
            tango.Except.throw_exception(
                const.ERR_ABORT_COMMAND,
                log_msg,
                "MccsSubarrayLeafNode.Abort",
                tango.ErrSeverity.ERR,
            )