# -*- coding: utf-8 -*
#
# This file is part of the SKA Low MCCS project
#
#
# Distributed under the terms of the BSD 3-clause new license.
# See LICENSE for more info.
# Instruct MyPy to ignore this file as it's not used
# type: ignore
"""The command line interface for the MCCS Controller device server."""
from __future__ import annotations # allow forward references in type hints
import functools
import json
import types
from typing import Any, Callable, Optional, Type
import tango
from fire import Fire
from fire.core import FireError
from ska_tango_base.commands import ResultCode
[docs]
class MccsControllerCli(metaclass=CliMeta):
"""Command-line interface to the MccsController tango device."""
[docs]
def __init__(
self: MccsControllerCli, trl: str = "low-mccs/control/control"
) -> None:
"""
Initialise a new CLI instance.
:param trl: the TRL of the controller device. Optional:
defaults to "low-mccs/control/control"
"""
self._dp = tango.DeviceProxy(trl)
self._log_levels = [
lvl for lvl in dir(self._dp.logginglevel.__class__) if lvl.isupper()
]
[docs]
def adminmode(self: MccsControllerCli) -> str:
"""
Show the admin mode.
:todo: make writable
:return: the admin mode
"""
return self._dp.adminmode.name
[docs]
def controlmode(self: MccsControllerCli) -> str:
"""
Show the control mode.
:todo: make writable
:return: control mode
"""
return self._dp.controlmode.name
[docs]
def simulationmode(self: MccsControllerCli) -> str:
"""
Show the control mode.
:todo: make writable
:return: simulation mode
"""
return self._dp.simulationmode.name
[docs]
def healthstate(self: MccsControllerCli) -> str:
"""
Show the health state.
:return: health state
"""
return self._dp.healthstate.name
[docs]
def logginglevel(self: MccsControllerCli, level: Optional[str] = None) -> str:
"""
Get and/or set the logging level of the device.
:param level: the logging level, defaults to None (only print the level)
:return: logging level value
"""
if level is not None:
elevel = self._dp.logginglevel.__class__[level.upper()]
self._dp.logginglevel = elevel
return self._dp.logginglevel.name
[docs]
@format_wrapper
def on(self: MccsControllerCli) -> str: # type: ignore[misc]
"""
Turn the controller (and hence all of MCCS) on.
:return: A return code and a string message
indicating status converted into a two line string
"""
return self._dp.command_inout("On")
[docs]
@format_wrapper
def off(self: MccsControllerCli) -> str: # type: ignore[misc]
"""
Turn the controller (and hence all of MCCS) off.
:return: A return code and a string message
indicating status converted into a two line string
"""
return self._dp.command_inout("Off")
[docs]
@format_wrapper
def standbyfull(self: MccsControllerCli) -> str: # type: ignore[misc]
"""
Put the controller (and hence all of MCCS) into full-power standby mode.
:return: A return code and a string message
indicating status converted into a two line string
"""
return self._dp.command_inout("StandbyFull")
[docs]
@format_wrapper
def reset(self: MccsControllerCli) -> str: # type: ignore[misc]
"""
Reset the controller following a fatal error.
:return: A return code and a string message
indicating status converted into a two line string
"""
return self._dp.command_inout("Reset")
[docs]
@format_wrapper
def allocate( # type: ignore[misc]
self: MccsControllerCli,
subarray_id: int = 0,
station_ids: Optional[list[list[int]]] = None,
subarray_beam_ids: Optional[list[int]] = None,
channel_blocks: Optional[list[int]] = None,
) -> str:
"""
Allocate stations to a subarray.
:param subarray_id: the subarray id, defaults to 1
:param station_ids: the station ids, defaults to [[1]]
:param subarray_beam_ids: the subarray_beam ids, defaults to [1]
:param channel_blocks: the nos. of channel_blocks, defaults to [1]
:return: a result message
"""
if station_ids is None:
station_ids = [[1]]
if subarray_beam_ids is None:
subarray_beam_ids = [1]
if channel_blocks is None:
channel_blocks = [1]
(rc, message) = self._dp.command_inout(
"Allocate",
json.dumps(
{
"subarray_id": subarray_id,
"station_ids": station_ids,
"subarray_beam_ids": subarray_beam_ids,
"channel_blocks": channel_blocks,
}
),
)
return message
[docs]
@format_wrapper
def release( # type: ignore[misc]
self: MccsControllerCli, subarray_id: int = 0
) -> str:
"""
Release resources from a subarray.
:param subarray_id: the subarray id, defaults to 0
:return: A return code and a string message
indicating status converted into a two line string
"""
return self._dp.command_inout("Release", subarray_id)
[docs]
def main(*args: str, **kwargs: str) -> int:
"""
Entry point for module.
:param args: positional arguments
:param kwargs: named arguments
:return: exit code
"""
return Fire(MccsControllerCli)
if __name__ == "__main__":
main()