BaseMockController#

class lsst.ts.hexrotcomm.BaseMockController(log, CommandCode, extra_commands, config, telemetry, port, host='127.0.0.1', initial_state=ControllerState.STANDBY)#

Bases: OneClientReadLoopServer, ABC

Base class for a mock Moog TCP/IP controller with states.

The controller uses two TCP/IP server sockets, one to read commands and the other to write telemetry.

Parameters:
  • log (logging.Logger) – Logger.

  • extra_commands (dict of command key: method) – Device-specific commands, as a dict of command key (as returned by get_command_key): method to call for that command. Note: BaseMockController already supports the standard state transition commands, including CLEAR_ERROR. If the command is not done when the method returns, the method should return the predicted duration, in seconds.

  • CommandCode (enum) – Command codes.

  • config (ctypes.Structure) – Configuration data that must contain the “drives_enabled” field as boolean. May be modified.

  • telemetry (ctypes.Structure) – Telemetry data. Modified by update_telemetry.

  • port (int) – TCP/IP port. Specify 0 to choose a random free port; this is recommended for unit tests, to avoid collision with other tests. Do not specify 0 with host=None (see lsst.ts.tcpip.OneClientServer).

  • host (str or None, optional) – IP address for this server. Typically “127.0.0.1” (the default) for an IPV4 server and “::” for an IPV6 server. If None then bind to all network interfaces and run both IPV4 and IPV6 servers. Do not specify None with port=0 (see lsst.ts.tcpip.OneClientServer for details).

  • initial_state (lsst.ts.xml.enums.MTHexapod.ControllerState (optional)) – Initial state of mock controller.

Notes

To start a mock controller:

ctrl = MockController(…) await ctrl.connect_task

To stop the server:

await ctrl.stop()

Attributes Summary

Methods Summary

assert_state(state[, enabled_substate])

Check the state and, optionally, the substate.

assert_stationary()

close_client(**kwargs)

Close the connected client (if any) and stop background tasks.

connect_callback(server)

Called when the server connection state changes.

do_clear_error(command)

do_enable(command)

do_enable_drives(command)

do_standby(command)

end_run_command(command, cmd_method)

Called when run_command is done.

get_command_key(command)

Return the key to command_table.

read_and_dispatch()

Read and execute one command.

run_command(command)

Run a command and wait for the reply.

set_state(state)

Set the current state and substates.

telemetry_loop()

Write configuration once, then telemetry at regular intervals.

update_and_get_header(frame_id)

Update the config or telemetry header and return it and the time.

update_telemetry(curr_tai)

Update self.client.telemetry.

write_command_status(counter, status[, ...])

Write a command status.

write_config()

Write the current configuration.

Attributes Documentation

enabled_substate#
state#
telemetry_interval = 0.1#

Methods Documentation

assert_state(state, enabled_substate=None)#

Check the state and, optionally, the substate.

Parameters:
  • state (int) – Required state.

  • enabled_substate (int or None, optional) – Required enabled substate, or None to not check.

Raises:

CommandError – If the state is not as expected.

Return type:

None

assert_stationary()#
Return type:

None

async close_client(**kwargs)#

Close the connected client (if any) and stop background tasks.

Parameters:

kwargs (dict[str, Any])

Return type:

None

async connect_callback(server)#

Called when the server connection state changes.

If connected: start the command and telemetry loops. If not connected: stop the command and telemetry loops.

Parameters:

server (OneClientReadLoopServer)

Return type:

None

async do_clear_error(command)#
Parameters:

command (Command)

Return type:

None

async do_enable(command)#
Parameters:

command (Command)

Return type:

None

async do_enable_drives(command)#
Parameters:

command (Command)

Return type:

None

async do_standby(command)#
Parameters:

command (Command)

Return type:

None

abstract async end_run_command(command, cmd_method)#

Called when run_command is done.

Can be used to clear the set position.

Parameters:
Return type:

None

get_command_key(command)#

Return the key to command_table.

Parameters:

command (Command)

Return type:

Any

async read_and_dispatch()#

Read and execute one command.

Return type:

None

async run_command(command)#

Run a command and wait for the reply.

Parameters:

command (Command) – The command to run. This method sets the commander and counter fields.

Returns:

duration – Estimated duration (seconds) until the command is finished. 0 if the command is already done or almost already done.

Return type:

float or None

Raises:

CommandError – If the command fails.

set_state(state)#

Set the current state and substates.

Parameters:

state (lsst.ts.xml.enums.MTHexapod.ControllerState or int) – New state.

Return type:

None

Notes

Sets the substates as follows:

  • lsst.ts.xml.enums.MTHexapod.EnabledSubstate.STATIONARY if state == lsst.ts.xml.enums.MTHexapod.ControllerState.ENABLED

async telemetry_loop()#

Write configuration once, then telemetry at regular intervals.

Return type:

None

update_and_get_header(frame_id)#

Update the config or telemetry header and return it and the time.

Call this prior to writing configuration or telemetry.

Parameters:

frame_id (FrameId) – Frame ID of header to write.

Return type:

tuple[Header, float]

Returns:

  • header (structs.Header) – The header.

  • curr_tai (float) – Current time in header timestamp (TAI, unix seconds).

abstract async update_telemetry(curr_tai)#

Update self.client.telemetry.

Parameters:

curr_tai (float) – Time at which to compute telemetry (TAI, unix seconds). This is the time in the header, which is (approximately) the current time.

Return type:

None

async write_command_status(counter, status, duration=0.0, reason='')#

Write a command status.

Parameters:
  • counter (int) – counter field of command being acknowledged.

  • status (CommandStatusCode) – Command status code.

  • duration (float or None, optional) – Estimated duration. None is treated as 0.

  • reason (str, optional) – Reason for failure. Should be non-blank if and only if the command failed.

Raises:

ConnectionError – If not connected.

Return type:

None

async write_config()#

Write the current configuration.

Raises:

RuntimeError – If not connected.

Return type:

None