CommandHandler

class lsst.ts.ess.controller.CommandHandler(callback: Callable, simulation_mode: int)

Bases: AbstractCommandHandler

Handle incoming commands and send replies. Apply configuration and read sensor data.

Parameters:
callbackCallable

The callback coroutine handling the sensor telemetry. This can be a coroutine that sends the data via a socket connection or a coroutine in a test class to verify that the command has been handled correctly.

simulation_modeint

Indicating if a simulation mode (> 0) or not (0) is active. Simulation mode 0 means “connect to the real sensors.” Set simulation_mode to 1 to enable simulation mode and connect to a mock sensor.

The commands that can be handled are:

configure: Load the configuration that is passed on with the command and connect to the devices specified in that configuration. This command can be sent multiple times before a start is received and only the last configuration is kept. start: Start reading the sensor data of the connected devices and send it as plain text via the socket. If no configuration was sent then the start command is ignored. Once started no configuration changes can be done anymore. stop: Stop sending sensor data and disconnect from all devices. Once stopped, configuration changes can be done again and/or reading of sensor data can be started again.

Attributes Summary

valid_simulation_modes

Methods Summary

configure(configuration)

Apply the configuration and start sending telemetry.

create_device(device_configuration)

Get the device to connect to by using the specified configuration.

handle_command(command, **kwargs)

Handle incomming commands and parameters.

stop_sending_telemetry()

Stop reading the sensor data.

Attributes Documentation

valid_simulation_modes = (0, 1)

Methods Documentation

async configure(configuration: dict[str, Any]) None

Apply the configuration and start sending telemetry.

Parameters:
configurationdict

The contents of the dict depend on the type of sensor. See the ts_ess configuration schema for more details.

Raises:
CommandError

A CommandError with ResponseCode ALREADY_STARTED is raised if the command handler already was started.

create_device(device_configuration: Dict[str, Any]) BaseDevice

Get the device to connect to by using the specified configuration.

Parameters:
device_configurationdict

A dict representing the device to connect to. The format of the dict follows the configuration of the ts_ess_csc project.

Returns:
devicecommon.device.BaseDevice

The device to connect to.

Raises:
RuntimeError

In case an incorrect configuration has been loaded.

Notes

In case simulation_mode is set to 1, only the sensor type is used and a mock device is instantiated. In case a serial device is specified, the device will only be instantiated if the code is running on a Raspberry Pi. In all other cases, the architecture of the platform is irrelevant.

async handle_command(command: str, **kwargs: Any) None

Handle incomming commands and parameters.

Parameters:
commandstr

The command to handle.

kwargs:

The parameters to the command.

async stop_sending_telemetry() None

Stop reading the sensor data.

Raises:
CommandError

A CommandError with ResponseCode NOT_STARTED is raised if the command handler was not started yet.