BaseMockController#
- class lsst.ts.hexrotcomm.BaseMockController(log, CommandCode, extra_commands, config, telemetry, port, host='127.0.0.1', initial_state=ControllerState.STANDBY)#
Bases:
OneClientReadLoopServer,ABCBase 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 byupdate_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 (seelsst.ts.tcpip.OneClientServer).host (
strorNone, optional) – IP address for this server. Typically “127.0.0.1” (the default) for an IPV4 server and “::” for an IPV6 server. IfNonethen bind to all network interfaces and run both IPV4 and IPV6 servers. Do not specifyNonewith port=0 (seelsst.ts.tcpip.OneClientServerfor 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.
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 execute one command.
run_command(command)Run a command and wait for the reply.
set_state(state)Set the current state and substates.
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 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.
- async close_client(**kwargs)#
Close the connected client (if any) and stop background tasks.
- 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:
- abstract async end_run_command(command, cmd_method)#
Called when run_command is done.
Can be used to clear the set position.
- get_command_key(command)#
Return the key to command_table.
- 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:
floator None- Raises:
CommandError – If the command fails.
- set_state(state)#
Set the current state and substates.
- Parameters:
state (
lsst.ts.xml.enums.MTHexapod.ControllerStateorint) – New state.- Return type:
Notes
Sets the substates as follows:
lsst.ts.xml.enums.MTHexapod.EnabledSubstate.STATIONARYif state ==lsst.ts.xml.enums.MTHexapod.ControllerState.ENABLED
- async telemetry_loop()#
Write configuration once, then telemetry at regular intervals.
- Return type:
- 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.
- abstract async update_telemetry(curr_tai)#
Update self.client.telemetry.
- 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 (
floatorNone, 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:
- async write_config()#
Write the current configuration.
- Raises:
RuntimeError – If not connected.
- Return type: