Base Device¶
This module implements a generic base model and device for SKA. It exposes the generic attributes, properties and commands of an SKA device.
Tango Device Class¶
-
class
ska_tango_base.
SKABaseDevice
(*args: Any, **kwargs: Any)[source]¶ A generic base device for SKA.
-
class
InitCommand
(target, state_model, logger=None)[source]¶ A class for the SKABaseDevice’s init_device() “command”.
Create a new InitCommand
- Parameters
target (object) – the object that this command acts upon; for example, the SKASubarray device for which this class implements the command
state_model (
DeviceStateModel
) – the state model that this command uses to check that it is allowed to run, and that it drives with actions.logger (a logger that implements the standard library logger interface) – the logger to be used by this Command. If not provided, then a default module logger will be used.
-
do
()[source]¶ Stateless hook for device initialisation.
- Returns
A tuple containing a return code and a string message indicating status. The message is for information purpose only.
- Return type
(ResultCode, str)
-
SkaLevel
= tango.server.device_property(dtype=int16, default_value=4)¶ Device property.
Indication of importance of the device in the SKA hierarchy to support drill-down navigation: 1..6, with 1 highest.
-
GroupDefinitions
= tango.server.device_property(dtype=('str',))¶ Device property.
Each string in the list is a JSON serialised dict defining the
group_name
,devices
andsubgroups
in the group. A TANGO Group object is created for each item in the list, according to the hierarchy defined. This provides easy access to the managed devices in bulk, or individually.The general format of the list is as follows, with optional
devices
andsubgroups
keys:[ {"group_name": "<name>", "devices": ["<dev name>", ...]}, {"group_name": "<name>", "devices": ["<dev name>", "<dev name>", ...], "subgroups" : [{<nested group>}, {<nested group>}, ...]}, ... ]
For example, a hierarchy of racks, servers and switches:
[ {"group_name": "servers", "devices": ["elt/server/1", "elt/server/2", "elt/server/3", "elt/server/4"]}, {"group_name": "switches", "devices": ["elt/switch/A", "elt/switch/B"]}, {"group_name": "pdus", "devices": ["elt/pdu/rackA", "elt/pdu/rackB"]}, {"group_name": "racks", "subgroups": [ {"group_name": "rackA", "devices": ["elt/server/1", "elt/server/2", "elt/switch/A", "elt/pdu/rackA"]}, {"group_name": "rackB", "devices": ["elt/server/3", "elt/server/4", "elt/switch/B", "elt/pdu/rackB"], "subgroups": []} ]} ]
-
LoggingLevelDefault
= tango.server.device_property(dtype=uint16, default_value=4)¶ Device property.
Default logging level at device startup. See
LoggingLevel
-
LoggingTargetsDefault
= tango.server.device_property(dtype=DevVarStringArray, default_value=['tango::logger'])¶ Device property.
Default logging targets at device startup. See the project readme for details.
-
buildState
= tango.server.attribute(dtype=str, doc=Build state of this device)¶ Device attribute.
-
versionId
= tango.server.attribute(dtype=str, doc=Version Id of this device)¶ Device attribute.
-
loggingLevel
= tango.server.attribute(dtype=<enum 'LoggingLevel'>, access=tango.AttrWriteType.READ_WRITE, doc=Current logging level for this device - initialises to LoggingLevelDefault on startup)¶ Device attribute.
See
LoggingLevel
-
loggingTargets
= tango.server.attribute(dtype=('str',), access=tango.AttrWriteType.READ_WRITE, max_dim_x=4, doc=Logging targets for this device, excluding ska_ser_logging defaults - initialises to LoggingTargetsDefault on startup)¶ Device attribute.
-
healthState
= tango.server.attribute(dtype=<enum 'HealthState'>, doc=The health state reported for this device. It interprets the current device condition and condition of all managed devices to set this. Most possibly an aggregate attribute.)¶ Device attribute.
-
adminMode
= tango.server.attribute(dtype=<enum 'AdminMode'>, access=tango.AttrWriteType.READ_WRITE, memorized=True, doc=The admin mode reported for this device. It may interpret the current device condition and condition of all managed devices to set this. Most possibly an aggregate attribute.)¶ Device attribute.
-
controlMode
= tango.server.attribute(dtype=<enum 'ControlMode'>, access=tango.AttrWriteType.READ_WRITE, memorized=True, doc=The control mode of the device. REMOTE, LOCAL TANGO Device accepts only from a ‘local’ client and ignores commands and queries received from TM or any other ‘remote’ clients. The Local clients has to release LOCAL control before REMOTE clients can take control again.)¶ Device attribute.
-
simulationMode
= tango.server.attribute(dtype=<enum 'SimulationMode'>, access=tango.AttrWriteType.READ_WRITE, memorized=True, doc=Reports the simulation mode of the device. Some devices may implement both modes, while others will have simulators that set simulationMode to True while the real devices always set simulationMode to False.)¶ Device attribute.
-
testMode
= tango.server.attribute(dtype=<enum 'TestMode'>, access=tango.AttrWriteType.READ_WRITE, memorized=True, doc=The test mode of the device. Either no test mode or an indication of the test mode.)¶ Device attribute.
-
set_state
(state)[source]¶ Helper method for setting device state, ensuring that change events are pushed.
- Parameters
state (
tango.DevState
) – the new state
-
set_status
(status)[source]¶ Helper method for setting device status, ensuring that change events are pushed.
- Parameters
status (str) – the new status
-
init_device
()[source]¶ Initializes the tango device after startup.
Subclasses that have no need to override the default default implementation of state management may leave
init_device()
alone. Override thedo()
method on the nested classInitCommand
instead.
-
register_command_object
(command_name, command_object)[source]¶ Registers a command object as the object to handle invocations of a given command
- Parameters
command_name (str) – name of the command for which the object is being registered
command_object (Command instance) – the object that will handle invocations of the given command
-
get_command_object
(command_name)[source]¶ Returns the command object (handler) for a given command.
- Parameters
command_name (str) – name of the command for which a command object (handler) is sought
- Returns
the registered command object (handler) for the command
- Return type
Command instance
-
init_command_objects
()[source]¶ Creates and registers command objects (handlers) for the commands supported by this device.
-
always_executed_hook
()[source]¶ Method that is always executed before any device command gets executed.
-
read_buildState
()[source]¶ Reads the Build State of the device.
- Returns
the build state of the device
-
read_loggingLevel
()[source]¶ Reads logging level of the device.
- Returns
Logging level of the device.
-
write_loggingLevel
(value)[source]¶ Sets logging level for the device. Both the Python logger and the Tango logger are updated.
- Parameters
value – Logging level for logger
- Raises
LoggingLevelError – for invalid value
-
read_loggingTargets
()[source]¶ Reads the additional logging targets of the device.
Note that this excludes the handlers provided by the ska_ser_logging library defaults.
- Returns
Logging level of the device.
-
write_loggingTargets
(value)[source]¶ Sets the additional logging targets for the device.
Note that this excludes the handlers provided by the ska_ser_logging library defaults.
- Parameters
value – Logging targets for logger
-
read_adminMode
()[source]¶ Reads Admin Mode of the device.
- Returns
Admin Mode of the device
- Return type
-
write_adminMode
(value)[source]¶ Sets Admin Mode of the device.
- Parameters
value (
AdminMode
) – Admin Mode of the device.- Raises
ValueError – for unknown adminMode
-
write_controlMode
(value)[source]¶ Sets Control Mode of the device.
- Parameters
value – Control mode value
-
read_simulationMode
()[source]¶ Reads Simulation Mode of the device.
- Returns
Simulation Mode of the device.
-
write_simulationMode
(value)[source]¶ Sets Simulation Mode of the device
- Parameters
value – SimulationMode
-
class
GetVersionInfoCommand
(target, state_model, logger=None)[source]¶ A class for the SKABaseDevice’s Reset() command.
Creates a new BaseCommand object for a device.
- Parameters
state_model (SKABaseClassStateModel or a subclass of same) – the state model that this command uses, for example to raise a fatal error if the command errors out.
target (object) – the object that this base command acts upon. For example, the device that this BaseCommand implements the command for.
logger (a logger that implements the standard library logger interface) – the logger to be used by this Command. If not provided, then a default module logger will be used.
-
do
()[source]¶ Stateless hook for device GetVersionInfo() command.
- Returns
A tuple containing a return code and a string message indicating status. The message is for information purpose only.
- Return type
(ResultCode, str)
-
GetVersionInfo
()[source]¶ Returns the version information of the device.
To modify behaviour for this command, modify the do() method of the command class.
- Returns
Version details of the device.
-
class
ResetCommand
(target, state_model, logger=None)[source]¶ A class for the SKABaseDevice’s Reset() command.
Create a new ResetCommand
- Parameters
target (object) – the object that this command acts upon; for example, the SKASubarray device for which this class implements the command
state_model (
DeviceStateModel
) – the state model that this command uses to check that it is allowed to run, and that it drives with actions.logger (a logger that implements the standard library logger interface) – the logger to be used by this Command. If not provided, then a default module logger will be used.
-
check_allowed
()[source]¶ Checks whether the command is allowed to be run in the current state of the state model.
- Returns
True if the command is allowed to be run
-
is_allowed
()[source]¶ Whether this command is allowed to run in the current state of the state model.
- Returns
whether this command is allowed to run
- Return type
boolean
-
do
()[source]¶ Stateless hook for device reset.
- Returns
A tuple containing a return code and a string message indicating status. The message is for information purpose only.
- Return type
(ResultCode, str)
-
is_Reset_allowed
()[source]¶ Whether the
Reset()
command is allowed to be run in the current state- Returns
whether the
Reset()
command is allowed to be run in the current state- Return type
boolean
-
Reset
()[source]¶ Reset the device from the FAULT state.
To modify behaviour for this command, modify the do() method of the command class.
- Returns
A tuple containing a return code and a string message indicating status. The message is for information purpose only.
- Return type
(ResultCode, str)
-
class
DisableCommand
(target, state_model, logger=None)[source]¶ A class for the SKABaseDevice’s Disable() command.
Constructor for DisableCommand
- Parameters
target (object) – the object that this command acts upon; for example, the SKABaseDevice for which this class implements the command
state_model (
DeviceStateModel
) – the state model that this command uses to check that it is allowed to run, and that it drives with actions.logger (a logger that implements the standard library logger interface) – the logger to be used by this Command. If not provided, then a default module logger will be used.
-
do
()[source]¶ Stateless hook for Disable() command functionality.
- Returns
A tuple containing a return code and a string message indicating status. The message is for information purpose only.
- Return type
(ResultCode, str)
-
is_Disable_allowed
()[source]¶ Check if command Disable is allowed in the current device state.
- Raises
tango.DevFailed – if the command is not allowed
- Returns
True
if the command is allowed- Return type
boolean
-
Disable
()[source]¶ Put the device into disabled mode
To modify behaviour for this command, modify the do() method of the command class.
- Returns
A tuple containing a return code and a string message indicating status. The message is for information purpose only.
- Return type
(ResultCode, str)
-
class
StandbyCommand
(target, state_model, logger=None)[source]¶ A class for the SKABaseDevice’s Standby() command.
Constructor for StandbyCommand
- Parameters
target (object) – the object that this command acts upon; for example, the SKABaseDevice for which this class implements the command
state_model (
DeviceStateModel
) – the state model that this command uses to check that it is allowed to run, and that it drives with actions.logger (a logger that implements the standard library logger interface) – the logger to be used by this Command. If not provided, then a default module logger will be used.
-
do
()[source]¶ Stateless hook for Standby() command functionality.
- Returns
A tuple containing a return code and a string message indicating status. The message is for information purpose only.
- Return type
(ResultCode, str)
-
is_Standby_allowed
()[source]¶ Check if command Standby is allowed in the current device state.
- Raises
tango.DevFailed – if the command is not allowed
- Returns
True
if the command is allowed- Return type
boolean
-
Standby
()[source]¶ Put the device into standby mode
To modify behaviour for this command, modify the do() method of the command class.
- Returns
A tuple containing a return code and a string message indicating status. The message is for information purpose only.
- Return type
(ResultCode, str)
-
class
OffCommand
(target, state_model, logger=None)[source]¶ A class for the SKABaseDevice’s Off() command.
Constructor for OffCommand
- Parameters
target (object) – the object that this command acts upon; for example, the SKABaseDevice for which this class implements the command
state_model (
DeviceStateModel
) – the state model that this command uses to check that it is allowed to run, and that it drives with actions.logger (a logger that implements the standard library logger interface) – the logger to be used by this Command. If not provided, then a default module logger will be used.
-
do
()[source]¶ Stateless hook for Off() command functionality.
- Returns
A tuple containing a return code and a string message indicating status. The message is for information purpose only.
- Return type
(ResultCode, str)
-
is_Off_allowed
()[source]¶ Check if command Off is allowed in the current device state.
- Raises
tango.DevFailed – if the command is not allowed
- Returns
True
if the command is allowed- Return type
boolean
-
Off
()[source]¶ Turn the device off
To modify behaviour for this command, modify the do() method of the command class.
- Returns
A tuple containing a return code and a string message indicating status. The message is for information purpose only.
- Return type
(ResultCode, str)
-
class
OnCommand
(target, state_model, logger=None)[source]¶ A class for the SKABaseDevice’s On() command.
Constructor for OnCommand
- Parameters
target (object) – the object that this command acts upon; for example, the SKABaseDevice for which this class implements the command
state_model (
DeviceStateModel
) – the state model that this command uses to check that it is allowed to run, and that it drives with actions.logger (a logger that implements the standard library logger interface) – the logger to be used by this Command. If not provided, then a default module logger will be used.
-
do
()[source]¶ Stateless hook for On() command functionality.
- Returns
A tuple containing a return code and a string message indicating status. The message is for information purpose only.
- Return type
(ResultCode, str)
-
is_On_allowed
()[source]¶ Check if command On is allowed in the current device state.
- Raises
tango.DevFailed – if the command is not allowed
- Returns
True
if the command is allowed- Return type
boolean
-
On
()[source]¶ Turn device on
To modify behaviour for this command, modify the do() method of the command class.
- Returns
A tuple containing a return code and a string message indicating status. The message is for information purpose only.
- Return type
(ResultCode, str)
-
class
Device State Model¶
-
class
ska_tango_base.
DeviceStateModel
(logger, op_state_callback=None, admin_mode_callback=None)[source]¶ Implements the state model for the SKABaseDevice.
This implementation contains separate state machines for adminMode and opState. Since the two are slightly but inextricably coupled, the opState machine includes “ADMIN” flavours for the “INIT”, “FAULT” and “DISABLED” states, to represent states where the device has been administratively disabled via the adminModes “RESERVED”, “NOT_FITTED” and “OFFLINE”. This model drives the two state machines to ensure they remain coherent.
Initialises the state model.
- Parameters
logger (a logger that implements the standard library logger interface) – the logger to be used by this state model.
op_state_callback (callable) – A callback to be called when the state machine for op_state reports a change of state
admin_mode_callback (callable) – A callback to be called when the state machine for admin_mode reports a change of state
-
property
admin_mode
¶ Returns the admin_mode
- Returns
admin_mode of this state model
- Return type
-
property
op_state
¶ Returns the op_state of this state model
- Returns
op_state of this state model
- Return type
tango.DevState
-
is_action_allowed
(action)[source]¶ Whether a given action is allowed in the current state.
- Parameters
action (str) – an action, as given in the transitions table
- Raises
StateModelError – if the action is unknown to the state machine
- Returns
whether the action is allowed in the current state
- Return type
bool
-
try_action
(action)[source]¶ Checks whether a given action is allowed in the current state, and raises a StateModelError if it is not.
- Parameters
action (str) – an action, as given in the transitions table
- Raises
StateModelError – if the action is not allowed in the current state
- Returns
True if the action is allowed
- Return type
boolean