SimpleCsc

class lsst.ts.hexrotcomm.SimpleCsc(config_dir=None, initial_state=<State.OFFLINE: 4>, simulation_mode=0)

Bases: lsst.ts.hexrotcomm.BaseCsc

Simple CSC to talk to SimpleMockController.

This is based on the Rotator CSC but only supports a small subset off commands, events and telemetry. See Notes for details. The move command sets the cmd_position and curr_position telemetry fields, then the controller slowly increments curr_position.

Parameters:
config_dir : str, optional

Directory of configuration files, or None for the standard configuration directory (obtained from _get_default_config_dir). This is provided for unit testing.

initial_state : lsst.ts.salobj.State or int (optional)

The initial state of the CSC. Ignored (other than checking that it is a valid value) except in simulation mode, because in normal operation the initial state is the current state of the controller. This is provided for unit testing.

simulation_mode : int (optional)

Simulation mode. Allowed values:

  • 0: regular operation.
  • 1: simulation: use a mock low level controller.

Notes

Error Codes

  • 1: invalid data read on the telemetry socket

Supported commands:

  • All standard state transition commands and clearError
  • move

Supported events:

  • controllerState
  • connected
  • summaryState
  • settingsApplied

Supported telemetry:

  • Application

Attributes Summary

config_dir Get or set the configuration directory.
disabled_or_enabled Return True if the summary state is State.DISABLED or State.ENABLED.
domain
simulation_mode Get the current simulation mode.
summary_state Return the current summary state as a salobj.State, or OFFLINE if unknown.
valid_simulation_modes

Methods Summary

add_arguments(parser) Add arguments to the parser created by make_from_cmd_line.
add_kwargs_from_args(args, kwargs) Add constructor keyword arguments based on parsed arguments.
amain(index, **kwargs) Make a CSC from command-line arguments and run it.
assert_commandable() Assert that the controller is connected and has CSC commands enabled.
assert_enabled([action]) Assert that an action that requires ENABLED state can be run.
assert_enabled_substate(substate) Assert the controller is enabled and in the specified substate.
assert_summary_state(*allowed_states, isbefore) Assert that the current summary state is as specified.
begin_disable(data) Begin do_disable; called before state changes.
begin_enable(data) Begin do_enable; called before state changes.
begin_exitControl(data) Begin do_exitControl; called before state changes.
begin_standby(data) Begin do_standby; called before the state changes.
begin_start(data) Begin do_start; configure the CSC before changing state.
close([exception, cancel_start]) Shut down, clean up resources and set done_task done.
close_tasks() Shut down pending tasks.
config_callback(server) Called when the TCP/IP controller outputs configuration.
configure(config) Configure the CSC.
connect_callback(server) Called when the server’s command or telemetry sockets connect or disconnect.
do_clearError(data) Reset the FAULT state to STANDBY.
do_configureAcceleration(data)
do_configureVelocity(data)
do_disable(data) Go from ENABLED state to DISABLED.
do_enable(data) Go from DISABLED state to ENABLED.
do_enterControl(data) Go from OFFLINE state, AVAILABLE offline substate to STANDBY.
do_exitControl(data) Go from STANDBY state to OFFLINE state, AVAILABLE offline substate.
do_move(data) Specify a position.
do_setAuthList(data) Update the authorization list.
do_setLogLevel(data) Set logging level.
do_standby(data) Go from DISABLED state to STANDBY.
do_start(data) Go from STANDBY state to DISABLED.
do_stop(data)
do_track(data)
do_trackStart(data)
end_disable(data) End do_disable; called after state changes but before command acknowledged.
end_enable(data) End do_enable; called after state changes but before command acknowledged.
end_exitControl(data) End do_exitControl; called after state changes but before command acknowledged.
end_standby(data) End do_standby; called after state changes but before command acknowledged.
end_start(data) End do_start; called after state changes but before command acknowledged.
fault(code, report[, traceback]) Warning: the fault method is not support in this class.
get_config_pkg() Get the name of the configuration package, e.g.
handle_summary_state() Called when the summary state has changed.
implement_simulation_mode(simulation_mode) Implement going into or out of simulation mode.
make_command(code[, param1, param2, param3, …]) Make a command from the command identifier and keyword arguments.
make_from_cmd_line(index, **kwargs) Construct a CSC from command line arguments.
make_mock_controller(initial_ctrl_state) Construct and return a mock controller.
put_log_level() Output the logLevel event.
read_config_dir() Set self.config_label_dict and output evt_settingVersions.
report_summary_state() Report a new value for summary_state, including current state.
run_command(code[, param1, param2, param3, …]) Run one command.
run_multiple_commands(*commands[, delay]) Run multiple commands, without allowing other commands to run between them.
set_simulation_mode(simulation_mode) Set the simulation mode.
start() Finish constructing the CSC.
telemetry_callback(server) Called when the TCP/IP controller outputs telemetry.

Attributes Documentation

config_dir

Get or set the configuration directory.

Parameters:
config_dir : str, bytes, or pathlib.Path

New configuration directory.

Returns:
config_dir : pathlib.Path

Absolute path to the configuration directory.

Raises:
ValueError

If the new configuration dir is not a directory.

disabled_or_enabled

Return True if the summary state is State.DISABLED or State.ENABLED.

This is useful in handle_summary_state to determine if you should start or stop a telemetry loop, and connect to or disconnect from an external controller

domain
simulation_mode

Get the current simulation mode.

0 means normal operation (no simulation).

Raises:
ExpectedError

If the new simulation mode is not a supported value.

summary_state

Return the current summary state as a salobj.State, or OFFLINE if unknown.

valid_simulation_modes = None

Methods Documentation

classmethod add_arguments(parser)

Add arguments to the parser created by make_from_cmd_line.

Parameters:
parser : argparse.ArgumentParser

The argument parser.

Notes

If you override this method then you should almost certainly override add_kwargs_from_args as well.

classmethod add_kwargs_from_args(args, kwargs)

Add constructor keyword arguments based on parsed arguments.

Parameters:
args : argparse.namespace

Parsed command.

kwargs : dict

Keyword argument dict for the constructor. Update this based on args. The index argument will already be present if relevant.

Notes

If you override this method then you should almost certainly override add_arguments as well.

classmethod amain(index, **kwargs)

Make a CSC from command-line arguments and run it.

Parameters:
index : int, True, False or None

If the CSC is indexed: specify True make index a required command line argument, or specify a non-zero int to use that index. If the CSC is not indexed: specify None or 0.

**kwargs : dict, optional

Additional keyword arguments for your CSC’s constructor.

assert_commandable()

Assert that the controller is connected and has CSC commands enabled.

assert_enabled(action='')

Assert that an action that requires ENABLED state can be run.

Parameters:
action : str, optional

Action attempted. Not needed if this is called at the beginning of a do_... method, since the user will know what command was called.

assert_enabled_substate(substate)

Assert the controller is enabled and in the specified substate.

assert_summary_state(*allowed_states, isbefore)

Assert that the current summary state is as specified.

Also checks that the controller is commandable.

Used in do_xxx methods to check that a command is allowed.

begin_disable(data)

Begin do_disable; called before state changes.

Parameters:
data : DataType

Command data

begin_enable(data)

Begin do_enable; called before state changes.

Parameters:
data : DataType

Command data

begin_exitControl(data)

Begin do_exitControl; called before state changes.

Parameters:
data : DataType

Command data

begin_standby(data)

Begin do_standby; called before the state changes.

Parameters:
data : DataType

Command data

begin_start(data)

Begin do_start; configure the CSC before changing state.

Parameters:
data : cmd_start.DataType

Command data

Notes

The settingsToApply field must be one of:

  • The name of a config label or config file
  • The name and version of a config file, formatted as <file_name>:<version>, where the version is a git reference, such as a git tag or commit hash. This form does not support labels.
close(exception=None, cancel_start=True)

Shut down, clean up resources and set done_task done.

May be called multiple times. The first call closes the Controller; subsequent calls wait until the Controller is closed.

Subclasses should override close_tasks instead of close, unless you have a good reason to do otherwise.

Parameters:
exception : Exception, optional

The exception that caused stopping, if any, in which case the self.done_task exception is set to this value. Specify None for a normal exit, in which case the self.done_task result is set to None.

cancel_start : bool, optional

Cancel the start task? Leave this true unless calling this from the start task.

Notes

Removes the SAL log handler, calls close_tasks to stop all background tasks, pauses briefly to allow final SAL messages to be sent, then closes the dds domain.

close_tasks()

Shut down pending tasks. Called by close.

config_callback(server)

Called when the TCP/IP controller outputs configuration.

Parameters:
server : CommandTelemetryServer

TCP/IP server.

configure(config)

Configure the CSC.

Parameters:
config : object

The configuration as described by the schema at schema_path, as a struct-like object.

Notes

Called when running the start command, just before changing summary state from State.STANDBY to State.DISABLED.

connect_callback(server)

Called when the server’s command or telemetry sockets connect or disconnect.

Parameters:
server : CommandTelemetryServer

TCP/IP server.

do_clearError(data)

Reset the FAULT state to STANDBY.

do_configureAcceleration(data)
do_configureVelocity(data)
do_disable(data)

Go from ENABLED state to DISABLED.

do_enable(data)

Go from DISABLED state to ENABLED.

do_enterControl(data)

Go from OFFLINE state, AVAILABLE offline substate to STANDBY.

do_exitControl(data)

Go from STANDBY state to OFFLINE state, AVAILABLE offline substate.

do_move(data)

Specify a position.

do_setAuthList(data)

Update the authorization list.

Parameters:
data : cmd_setAuthList.DataType

Authorization lists.

Notes

Add items if the data string starts with “+”, ignoring duplicates (both with respect to the existing items and within the data string). Remove items if the data string starts with “-“, ignoring missing items (items specified for removal that do not exist). Ignore whitespace after each comma and after the +/- prefix.

do_setLogLevel(data)

Set logging level.

Parameters:
data : cmd_setLogLevel.DataType

Logging level.

do_standby(data)

Go from DISABLED state to STANDBY.

Note: use the clearError command to go from FAULT to STANDBY.

do_start(data)

Go from STANDBY state to DISABLED.

Notes

This ignores the data, unlike the vendor’s CSC code, which writes the supplied file name into a file on an nfs-mounted partition. I hope we won’t need to do that, as it seems complicated.

do_stop(data)
do_track(data)
do_trackStart(data)
end_disable(data)

End do_disable; called after state changes but before command acknowledged.

Parameters:
data : DataType

Command data

end_enable(data)

End do_enable; called after state changes but before command acknowledged.

Parameters:
data : DataType

Command data

end_exitControl(data)

End do_exitControl; called after state changes but before command acknowledged.

Parameters:
data : DataType

Command data

end_standby(data)

End do_standby; called after state changes but before command acknowledged.

Parameters:
data : DataType

Command data

end_start(data)

End do_start; called after state changes but before command acknowledged.

Parameters:
data : DataType

Command data

fault(code, report, traceback='')

Warning: the fault method is not support in this class.

The problem is that the summary state is maintained by the low-level controller and the CSC has no way to reliably send the low-level controller to FAULT state.

static get_config_pkg()

Get the name of the configuration package, e.g. “ts_config_ocs”.

handle_summary_state()

Called when the summary state has changed.

Override to perform tasks such as starting and stopping telemetry (example).

Notes

The versions in BaseCsc and ConfigurableCsc do nothing, so if you subclass one of those you do not need to call await super().handle_summary_state().

implement_simulation_mode(simulation_mode)

Implement going into or out of simulation mode.

Deprecated. See simulation mode for details.

Parameters:
simulation_mode : int

Requested simulation mode; 0 for normal operation.

Raises:
ExpectedError

If simulation_mode is not a supported value.

make_command(code, param1=0, param2=0, param3=0, param4=0, param5=0, param6=0)

Make a command from the command identifier and keyword arguments.

Used to make commands for run_multiple_commands.

Parameters:
code : CommandCode

Command to run.

param1, param2, param3, param4, param5, param6: `double`

Command parameters. The meaning of these parameters depends on the command code.

Returns:
command : Command

The command. Note that the counter field is 0; it is set by CommandTelemetryServer.put_command.

classmethod make_from_cmd_line(index, **kwargs)

Construct a CSC from command line arguments.

Parameters:
index : int, True, False or None

If the CSC is indexed: specify True make index a required command line argument, or specify a non-zero int to use that index. If the CSC is not indexed: specify None or 0.

**kwargs : dict, optional

Additional keyword arguments for your CSC’s constructor.

Returns:
csc : cls

The CSC.

Notes

To add additional command-line arguments, override add_arguments and add_kwargs_from_args.

make_mock_controller(initial_ctrl_state)

Construct and return a mock controller.

Parameters:
initial_ctrl_state : int

Initial controller state.

put_log_level()

Output the logLevel event.

read_config_dir()

Set self.config_label_dict and output evt_settingVersions.

Set self.config_label_dict from self.config_dir/_labels.yaml. Output the settingVersions event (if changed) as follows:

  • recommendedSettingsLabels is a comma-separated list of labels in self.config_label_dict, truncated by omitting labels if necessary.
  • recommendedSettingsVersion is derived from git information for self.config_dir, if it is a git repository, else “”.
report_summary_state()

Report a new value for summary_state, including current state.

Subclasses may wish to override for code that depends on the current state (rather than the state transition command that got it into that state).

run_command(code, param1=0, param2=0, param3=0, param4=0, param5=0, param6=0)

Run one command.

Parameters:
code : CommandCode

Command to run.

param1, param2, param3, param4, param5, param6: `double`

Command parameters. The meaning of these parameters depends on the command code.

run_multiple_commands(*commands, delay=None)

Run multiple commands, without allowing other commands to run between them.

Parameters:
commands : List [Command]

Commands to run, as constructed by make_command.

delay : float (optional)

Delay between commands (sec); or no delay if None. Only intended for unit testing.

set_simulation_mode(simulation_mode)

Set the simulation mode.

Await implement_simulation_mode, update the simulation mode property and report the new value.

Parameters:
simulation_mode : int

Requested simulation mode; 0 for normal operation.

start()

Finish constructing the CSC.

telemetry_callback(server)

Called when the TCP/IP controller outputs telemetry.

Parameters:
server : CommandTelemetryServer

TCP/IP server.