# -*- coding: utf-8 -*-
#
# This file is part of the SKACapability project
#
#
#
""" SKACapability
Capability handling device
"""
# PROTECTED REGION ID(SKACapability.additionnal_import) ENABLED START #
# Tango imports
from tango import DebugIt
from tango.server import run, attribute, command, device_property
# SKA specific imports
from ska_tango_base import SKAObsDevice
from ska_tango_base.commands import ResponseCommand, ResultCode
# PROTECTED REGION END # // SKACapability.additionnal_imports
__all__ = ["SKACapability", "main"]
[docs]class SKACapability(SKAObsDevice):
"""
A Subarray handling device. It exposes the instances of configured capabilities.
"""
[docs] def init_command_objects(self):
"""
Sets up the command objects
"""
super().init_command_objects()
self.register_command_object(
"ConfigureInstances", self.ConfigureInstancesCommand(
self, self.state_model, self.logger
)
)
[docs] class InitCommand(SKAObsDevice.InitCommand):
[docs] def do(self):
"""
Stateless hook for device initialisation.
:return: A tuple containing a return code and a string
message indicating status. The message is for
information purpose only.
:rtype: (ResultCode, str)
"""
super().do()
device = self.target
device._activation_time = 0.0
device._configured_instances = 0
device._used_components = [""]
message = "SKACapability Init command completed OK"
self.logger.info(message)
return (ResultCode.OK, message)
# PROTECTED REGION ID(SKACapability.class_variable) ENABLED START #
# PROTECTED REGION END # // SKACapability.class_variable
# -----------------
# Device Properties
# -----------------
CapType = device_property(
dtype='str',
)
CapID = device_property(
dtype='str',
)
subID = device_property(
dtype='str',
)
# ----------
# Attributes
# ----------
activationTime = attribute(
dtype='double',
unit="s",
standard_unit="s",
display_unit="s",
doc="Time of activation in seconds since Unix epoch.",
)
"""Device attribute."""
configuredInstances = attribute(
dtype='uint16',
doc="Number of instances of this Capability Type currently in use on this subarray.",
)
"""Device attribute."""
usedComponents = attribute(
dtype=('str',),
max_dim_x=100,
doc="A list of components with no. of instances in use on this Capability.",
)
"""Device attribute."""
# ---------------
# General methods
# ---------------
[docs] def always_executed_hook(self):
# PROTECTED REGION ID(SKACapability.always_executed_hook) ENABLED START #
pass
# PROTECTED REGION END # // SKACapability.always_executed_hook
[docs] def delete_device(self):
# PROTECTED REGION ID(SKACapability.delete_device) ENABLED START #
pass
# PROTECTED REGION END # // SKACapability.delete_device
# ------------------
# Attributes methods
# ------------------
[docs] def read_activationTime(self):
# PROTECTED REGION ID(SKACapability.activationTime_read) ENABLED START #
"""
Reads time of activation since Unix epoch.
:return: Activation time in seconds
"""
return self._activation_time
# PROTECTED REGION END # // SKACapability.activationTime_read
# PROTECTED REGION END # // SKACapability.configuredInstances_read
[docs] def read_usedComponents(self):
# PROTECTED REGION ID(SKACapability.usedComponents_read) ENABLED START #
"""
Reads the list of components with no. of instances in use on this Capability
:return: The number of components currently in use.
"""
return self._used_components
# PROTECTED REGION END # // SKACapability.usedComponents_read
# --------
# Commands
# --------
# PROTECTED REGION END # // SKACapability.ConfigureInstances
# ----------
# Run server
# ----------
def main(args=None, **kwargs):
# PROTECTED REGION ID(SKACapability.main) ENABLED START #
"""Main function of the SKACapability module."""
return run((SKACapability,), args=args, **kwargs)
# PROTECTED REGION END # // SKACapability.main
if __name__ == '__main__':
main()