Пример #1
0
    def _decorator(command_method: Callable):

        # Define a wrapper that takes an optional string argument.

        @functools.wraps(command_method)
        def wrapper(self, params_json="{}"):
            name = command_method.__name__
            LOG.debug("command %s device %s", name, type(self).__name__)
            params = json.loads(params_json)

            with transaction(name, params, logger=LOG) as txn_id:
                with log_transaction_id(txn_id):
                    LOG.debug("Execute command %s", name)
                    if argdesc:
                        ret = command_method(self, txn_id, params_json)
                    else:
                        ret = command_method(self, txn_id)
            return ret

        # Use the Tango command function to create the command.

        if argdesc:
            # Create command with a string argument and use the supplied
            # description
            desc = f"JSON string containing {argdesc} and optional transaction ID"
            command_wrapped = command(f=wrapper, dtype_in=str, doc_in=desc)
        elif FEATURE_ALL_COMMANDS_HAVE_ARGUMENT.is_active():
            # Create command with a string argument and a generic description
            desc = "JSON string containing optional transaction ID"
            command_wrapped = command(f=wrapper, dtype_in=str, doc_in=desc)
        else:
            # Create command with no argument for backwards compatibility
            command_wrapped = command(f=wrapper, dtype_in=None)

        return command_wrapped
    def initialize_per_channel_attributes(self):
        nchans = self.streamer.instrument.num_chan
        for ch in range(0, nchans):
            name = "Window1_Ch" + str(ch)
            win1 = SpectrumAttr(name, PyTango.DevLong,
                                PyTango.AttrWriteType.READ_WRITE,
                                2)  #attr value is [lo,hi]
            self.add_attribute(attr=win1,
                               r_meth=self.read_window_config,
                               w_meth=self.write_window_config)
            name = "Window2_Ch" + str(ch)
            win2 = SpectrumAttr(name, PyTango.DevLong,
                                PyTango.AttrWriteType.READ_WRITE,
                                2)  #attr value is [lo,hi]
            self.add_attribute(attr=win2,
                               r_meth=self.read_window_config,
                               w_meth=self.write_window_config)
            #event width
            name = "EventWidth_Ch" + str(ch)
            ew = Attr(name, PyTango.DevShort, PyTango.AttrWriteType.READ)
            self.add_attribute(attr=ew, r_meth=self.read_event_widths)

        # If required, counts in windows can be read directly from Tango e.g. by Sardana (they are always written to file)
        if self.ReturnCounters:
            cmd = command(
                f=self.ReadRawCounts_Window1,
                dtype_in=(int, ),
                dtype_out=(int, ),
                doc_in="channel, first frame, last frame",
                doc_out=
                "window0 raw counts for requested channel for requested frames"
            )
            self.add_command(cmd, True)
            cmd = command(
                f=self.ReadRawCounts_Window2,
                dtype_in=(int, ),
                dtype_out=(int, ),
                doc_in="channel, first frame, last frame",
                doc_out=
                "window1 raw counts for requested channel for requested frames"
            )
            self.add_command(cmd, True)
            cmd = command(
                f=self.ReadDtcCounts_Window1,
                dtype_in=(int, ),
                dtype_out=(float, ),
                doc_in="channel, first frame, last frame",
                doc_out=
                "window0 dead time corrected counts for requested channel for requested frames"
            )
            self.add_command(cmd, True)
            cmd = command(
                f=self.ReadDtcCounts_Window2,
                dtype_in=(int, ),
                dtype_out=(float, ),
                doc_in="channel, first frame, last frame",
                doc_out=
                "window1 dead time corrected counts for requested channel for requested frames"
            )
            self.add_command(cmd, True)
Пример #3
0
    def Off(self):
        """
        Turn the device off

        To modify behaviour for this command, modify the do() method of
        the command class.
        """
        command = self.get_command_object("Off")
        (return_code, message) = command()
        return [[return_code], [message]]
Пример #4
0
 def add_dyn_cmd(self):
     device_level = True
     cmd = command(f=self.start,
                   dtype_in=str,
                   dtype_out=int,
                   doc_in='description of input',
                   doc_out='description of output',
                   display_level=DispLevel.EXPERT,
                   polling_period=5.1)
     self.add_command(cmd, device_level)
Пример #5
0
    def EndScan(self):
        """
        End the scan

        To modify behaviour for this command, modify the do() method of
        the command class.
        """
        command = self.get_command_object("EndScan")
        (return_code, message) = command()
        return [[return_code], [message]]
Пример #6
0
    def ObsReset(self):
        """
        Reset the current observation process.

        To modify behaviour for this command, modify the do() method of
        the command class.
        """
        command = self.get_command_object("ObsReset")
        (return_code, message) = command()
        return [[return_code], [message]]
Пример #7
0
    def End(self):
        # PROTECTED REGION ID(SKASubarray.EndSB) ENABLED START #
        """
        End the scan block.

        To modify behaviour for this command, modify the do() method of
        the command class.
        """
        command = self.get_command_object("End")
        (return_code, message) = command()
        return [[return_code], [message]]
Пример #8
0
    def Abort(self):
        """
        Abort any long-running command such as ``Configure()`` or
        ``Scan()``.

        To modify behaviour for this command, modify the do() method of
        the command class.
        """
        command = self.get_command_object("Abort")
        (return_code, message) = command()
        return [[return_code], [message]]
Пример #9
0
    def Restart(self):
        """
        Restart the subarray. That is, deconfigure and release
        all resources.

        To modify behaviour for this command, modify the do() method of
        the command class.
        """
        command = self.get_command_object("Restart")
        (return_code, message) = command()
        return [[return_code], [message]]
Пример #10
0
    def GetVersionInfo(self):
        # PROTECTED REGION ID(SKABaseDevice.GetVersionInfo) ENABLED START #
        """
        Returns the version information of the device.

        To modify behaviour for this command, modify the do() method of
        the command class.

        :return: Version details of the device.
        """
        command = self.get_command_object("GetVersionInfo")
        return command()
Пример #11
0
    def Reset(self):
        """
        Reset the device from the FAULT state.

        To modify behaviour for this command, modify the do() method of
        the command class.

        :return: None
        """
        command = self.get_command_object("Reset")
        (return_code, message) = command()
        return [[return_code], [message]]
Пример #12
0
    def GetAlertStats(self):
        # PROTECTED REGION ID(SKAAlarmHandler.GetAlertStats) ENABLED START #
        """
        Get current alert stats.

        To modify behaviour for this command, modify the do() method of
        the command class.

        :return: JSON string containing alert statistics
        """
        command = self.get_command_object("GetAlertStats")
        return command()
Пример #13
0
    def GetAlarmAdditionalInfo(self, argin):
        # PROTECTED REGION ID(SKAAlarmHandler.GetAlarmAdditionalInfo) ENABLED START #
        """
        Get additional alarm information.

        To modify behaviour for this command, modify the do() method of
        the command class.

        :param argin: Name of the alarm
        :return: JSON string containing additional alarm information
        """
        command = self.get_command_object("GetAlarmAdditionalInfo")
        return command(argin)
Пример #14
0
    def GetAlarmRule(self, argin):
        # PROTECTED REGION ID(SKAAlarmHandler.GetAlarmRule) ENABLED START #
        """
        Get all configuration info of the alarm, e.g. rule, defined action, etc.

        To modify behaviour for this command, modify the do() method of
        the command class.

        :param argin: Name of the alarm
        :return: JSON string containing configuration information of the alarm
        """
        command = self.get_command_object("GetAlarmRule")
        return command(argin)
Пример #15
0
    def AssignResources(self, argin):
        """
        Assign resources to this subarray

        To modify behaviour for this command, modify the do() method of
        the command class.

        :param argin: the resources to be assigned
        :type argin: list of str
        """
        command = self.get_command_object("AssignResources")
        (return_code, message) = command(argin)
        return [[return_code], [message]]
Пример #16
0
    def ReleaseResources(self, argin):
        """
        Delta removal of assigned resources.

        To modify behaviour for this command, modify the do() method of
        the command class.

        :param argin: the resources to be released
        :type argin: list of str
        """
        command = self.get_command_object("ReleaseResources")
        (return_code, message) = command(argin)
        return [[return_code], [message]]
Пример #17
0
    def ReleaseAllResources(self):
        """
        Remove all resources to tear down to an empty subarray.

        To modify behaviour for this command, modify the do() method of
        the command class.

        :return: list of resources removed
        :rtype: list of string
        """
        command = self.get_command_object("ReleaseAllResources")
        (return_code, message) = command()
        return [[return_code], [message]]
Пример #18
0
    def Scan(self, argin):
        """
        Start scanning

        To modify behaviour for this command, modify the do() method of
        the command class.

        :param argin: Information about the scan
        :type argin: Array of str
        """
        command = self.get_command_object("Scan")
        (return_code, message) = command(argin)
        return [[return_code], [message]]
Пример #19
0
    def Configure(self, argin):
        """
        Configures the capabilities of this subarray

        To modify behaviour for this command, modify the do() method of
        the command class.

        :param argin: configuration specification
        :type argin: string
        """
        command = self.get_command_object("Configure")
        (return_code, message) = command(argin)
        return [[return_code], [message]]
Пример #20
0
    def GetAlarmData(self, argin):
        # PROTECTED REGION ID(SKAAlarmHandler.GetAlarmData) ENABLED START #
        """
        Get list of current value, quality factor and status of
        all attributes participating in the alarm rule.

        To modify behaviour for this command, modify the do() method of
        the command class.

        :param argin: Name of the alarm
        :return: JSON string containing alarm data
        """
        command = self.get_command_object("GetAlarmData")
        return command(argin)
Пример #21
0
    def ConfigureScan(self, argin):
        # PROTECTED REGION ID(Vcc.ConfigureScan) ENABLED START #
        """
        Configure the observing device parameters for the current scan.

        :param argin: JSON formatted string with the scan configuration.
        :type argin: 'DevString'

        :return: A tuple containing a return code and a string message indicating status.
            The message is for information purpose only.
        :rtype: (ResultCode, str)
        """
        command = self.get_command_object("ConfigureScan")
        (return_code, message) = command(argin)
        return [[return_code], [message]]
Пример #22
0
    def ConfigureInstances(self, argin):
        # PROTECTED REGION ID(SKACapability.ConfigureInstances) ENABLED START #
        """
        This function indicates how many number of instances of the current capacity
        should to be configured.

        To modify behaviour for this command, modify the do() method of
        the command class.

        :param argin: Number of instances to configure
        :return: None.
        """
        command = self.get_command_object("ConfigureInstances")
        (return_code, message) = command(argin)
        return [[return_code], [message]]
Пример #23
0
 def _start_event_loop(self):
     """Start event loop."""
     if FEATURE_EVENT_LOOP.is_active():
         # Start event loop in thread
         self._el_thread = threading.Thread(
             target=self._event_loop, name="EventLoop", daemon=True
         )
         self._el_watcher = None
         self._el_exit = False
         self._el_thread.start()
     else:
         # Add command to manually update attributes
         self._el_thread = None
         self._el_watcher = None
         self._el_exit = False
         cmd = command(f=self.update_attributes)
         self.add_command(cmd, True)
Пример #24
0
    def SetLoggingLevel(self, argin):
        # PROTECTED REGION ID(SKALogger.SetLoggingLevel) ENABLED START #
        """
        Sets logging level of the specified devices.

        To modify behaviour for this command, modify the do() method of
        the command class.

        :param argin: Array consisting of

            * argin[0]: list of DevLong. Desired logging level.
            * argin[1]: list of DevString. Desired tango device.

        :type argin: DevVarLongStringArray

        :returns: None.
        """
        command = self.get_command_object("SetLoggingLevel")
        (return_code, message) = command(argin)
        return [[return_code], [message]]
Пример #25
0
    def isCapabilityAchievable(self, argin):
        # PROTECTED REGION ID(SKAMaster.isCapabilityAchievable) ENABLED START #
        """
        Checks of provided capabilities can be achieved by the resource(s).

        To modify behaviour for this command, modify the do() method of
        the command class.

        :param argin: An array consisting pair of

            * [nrInstances]: DevLong. Number of instances of the capability.
            * [Capability types]: DevString. Type of capability.

        :type argin: DevVarLongStringArray.

        :return: True if capability can be achieved, False if cannot
        :rtype: DevBoolean
        """
        command = self.get_command_object("IsCapabilityAchievable")
        return command(argin)