MockMTDomeController

class lsst.ts.mtdome.MockMTDomeController(port: int, log: Logger, connect_callback: Union[None, Callable[[BaseClientOrServer], Awaitable[None]]] = None)

Bases: OneClientReadLoopServer

Mock MTDome Controller that talks over TCP/IP.

Parameters:
portint

TCP/IP port

loglogging.Logger

The logger to use.

connect_callbackcallable

The callback to use when a client connects.

Notes

There are six sub-systems that are under control:

  • AMCS: Azimuth Motion Control System

  • ApSCS: Aperture Shutter Control System

  • LCS: Louvers Control System

  • LWSCS: Light and Wind Screen Control System

  • MonCS: Monitoring Control System, which interfaces with the MTDome

    Interlock System

  • ThCS: Thermal Control System, which interfaces with the MTDome

    Environment Control System

To start the server:

ctrl = MockMTDomeController(…) await ctrl.start()

To stop the server:

await ctrl.stop()

Known Limitations:

  • Just a framework that needs to be implemented properly.

Attributes Summary

LONG_DURATION

SLOW_NETWORK_SLEEP

connected

Return True if self._reader and self._writer are connected.

Methods Summary

basic_close_client()

Close the connected client socket, if any.

call_connect_callback()

A client has connected or disconnected.

close()

Close socket server and client socket, and set done_task done.

close_client([cancel_read_loop_task])

Stop the read loop and close the client.

close_louvers()

Close all louvers.

close_shutter()

Close the shutter.

config(system, settings)

Configure the lower level components.

crawl_az(velocity)

Crawl the dome.

crawl_el(velocity)

Crawl the light and wind screen.

determine_current_tai()

Determine the current TAI time.

exit_fault()

Exit from fault state.

fans(speed)

Enable or disable the fans in the dome.

go_stationary_az()

Stop azimuth motion and engage the brakes.

go_stationary_el()

Stop elevation motion and engage the brakes.

go_stationary_louvers()

Stop louvers motion and engage the brakes.

go_stationary_shutter()

Stop shutter motion and engage the brakes.

inflate(action)

Inflate or deflate the inflatable seal.

move_az(position, velocity)

Move the dome.

move_el(position)

Move the light and wind screen.

open_shutter()

Open the shutter.

park()

Park the dome.

read(n)

Read up to n bytes.

read_and_dispatch()

Read, parse, and dispatch one item of data.

read_into(struct)

Read binary data from a stream reader into a ctypes.Structure.

read_json()

Read JSON data.

read_loop()

Read incoming data and handle them.

read_str()

Read and decode a terminated str; strip the terminator.

readexactly(n)

Read exactly n bytes.

readline()

Read a sequence of bytes ending with \n.

readuntil([separator])

Read one line, where “line” is a sequence of bytes ending with separator.

request_and_send_status(llc, llc_name)

Request the status of the given Lower Level Component and write it to the requester.

reset_drives_az(reset)

Reset one or more AZ drives.

reset_drives_shutter(reset)

Reset one or more Aperture Shutter drives.

restore()

Restore the default configuration of the lower level components.

search_zero_shutter()

Search the zero position of the Aperture Shutter, which is the closed position.

set_degraded_az()

Set az operational mode to degraded (as opposed to normal).

set_degraded_el()

Set el operational mode to degraded (as opposed to normal).

set_degraded_louvers()

Set louvers operational mode to degraded (as opposed to normal).

set_degraded_monitoring()

Set monitoring operational mode to degraded (as opposed to normal).

set_degraded_shutter()

Set shutter operational mode to degraded (as opposed to normal).

set_degraded_thermal()

Set thermal operational mode to degraded (as opposed to normal).

set_louvers(position)

Set the positions of the louvers.

set_normal_az()

Set az operational mode to normal (as opposed to degraded).

set_normal_el()

Set el operational mode to normal (as opposed to degraded).

set_normal_louvers()

Set louvers operational mode to normal (as opposed to degraded).

set_normal_monitoring()

Set monitoring operational mode to normal (as opposed to degraded).

set_normal_shutter()

Set shutter operational mode to normal (as opposed to degraded).

set_normal_thermal()

Set thermal operational mode to normal (as opposed to degraded).

set_temperature(temperature)

Set the preferred temperature in the dome.

set_zero_az()

Take the current position of the dome as zero.

start(**kwargs)

Start the TCP/IP server.

start_or_stop_thcs_if_necessary()

status_amcs()

Request the status from the AMCS lower level component and write it in reply.

status_apscs()

Request the status from the ApSCS lower level component and write it in reply.

status_cbcs()

Request the status from the CBCS lower level component and write it in reply.

status_cscs()

Request the status from the Calibration Screen and write it in reply.

status_lcs()

Request the status from the LCS lower level component and write it in reply.

status_lwscs()

Request the status from the LWSCS lower level component and write it in reply.

status_moncs()

Request the status from the MonCS lower level component and write it in reply.

status_rad()

Request the status from the RAD lower level component and write it in reply.

status_thcs()

Request the status from the ThCS lower level component and write it in reply.

stop_az()

Stop all dome motion.

stop_el()

Stop all light and wind screen motion.

stop_louvers()

Stop the motion of all louvers.

stop_shutter()

Stop the motion of the shutter.

write(data)

Write data and call drain.

write_from(*structs)

Write binary data from one or more ctypes.Structures.

write_json(data)

Write data in JSON format.

write_reply(**data)

Write the data appended with the commandId.

write_str(line)

Encode, terminate, and write a str.

writelines(lines)

Write an iterable of bytes and call drain.

Attributes Documentation

LONG_DURATION = 20
SLOW_NETWORK_SLEEP = 10.0
connected

Return True if self._reader and self._writer are connected.

Note: if the other end drops the connection and if you are not trying to read data (e.g. in a background loop), then it takes the operating system awhile to realize the connection is lost. So this can return true for some unknown time after the connection has been dropped.

Methods Documentation

async basic_close_client() None

Close the connected client socket, if any.

Also:

  • Reset self.connected_task to a new Future.

  • Call connect_callback, if a client was connected.

Unlike close_client, this does not touch self.should_be_connected.

Always safe to call.

async call_connect_callback() None

A client has connected or disconnected.

async close() None

Close socket server and client socket, and set done_task done.

Call connect_callback if a client was connected.

Always safe to call.

async close_client(cancel_read_loop_task: bool = True) None

Stop the read loop and close the client.

Parameters:
cancel_read_loop_taskbool

Cancel the read loop task or not? Defaults to True and should be False when called from the read loop task itself.

async close_louvers() None

Close all louvers.

async close_shutter() float

Close the shutter.

Returns:
float

The estimated duration of the execution of the command.

async config(system: str, settings: dict) None

Configure the lower level components.

Parameters:
system: `str`

The name of the system to configure.

settings: `dict`

An array containing a single dict with key,value pairs for all the parameters that need to be configured. The structure is:

[
    {
      "Parameter1_name": Value,
      "Parameter2_name": Value,
      ...
    }
  ]

It is assumed that the values of the configuration parameters are validated to lie within the limits before being passed on to this function. It is assumed that all configuration parameters are present and that their values represent the value to set even unchanged.

async crawl_az(velocity: float) float

Crawl the dome.

Parameters:
velocity: `float`

The velocity, in rad/sec, to crawl at.

Returns:
float

The estimated duration of the execution of the command.

async crawl_el(velocity: float) float

Crawl the light and wind screen.

Parameters:
velocity: `float`

The velocity, in rad/sec, to crawl at.

Returns:
float

The estimated duration of the execution of the command.

async determine_current_tai() None

Determine the current TAI time.

This is done in a separate method so a mock method can replace it in unit tests.

async exit_fault() None

Exit from fault state.

async fans(speed: float) None

Enable or disable the fans in the dome.

Parameters:
speed: `float`

The speed of the fans [%].

async go_stationary_az() float

Stop azimuth motion and engage the brakes. Also disengage the locking pins if engaged.

Returns:
float

The estimated duration of the execution of the command.

async go_stationary_el() float

Stop elevation motion and engage the brakes. Also disengage the locking pins if engaged.

Returns:
float

The estimated duration of the execution of the command.

async go_stationary_louvers() None

Stop louvers motion and engage the brakes.

async go_stationary_shutter() float

Stop shutter motion and engage the brakes.

Returns:
float

The estimated duration of the execution of the command.

async inflate(action: str) None

Inflate or deflate the inflatable seal.

Parameters:
action: `str`

ON means inflate and OFF deflate the inflatable seal.

async move_az(position: float, velocity: float) float

Move the dome.

Parameters:
position: `float`

Desired azimuth, in radians, in range [0, 2 pi)

velocity: `float`

The velocity, in rad/sec, to start crawling at once the position has been reached.

Returns:
float

The estimated duration of the execution of the command.

async move_el(position: float) float

Move the light and wind screen.

Parameters:
position: `float`

Desired elevation, in radians, in range [0, pi/2)

Returns:
duration: float

The estimated duration of the execution of the command.

async open_shutter() float

Open the shutter.

Returns:
float

The estimated duration of the execution of the command.

async park() float

Park the dome.

Returns:
float

The estimated duration of the execution of the command.

async read(n: int) bytes

Read up to n bytes.

Parameters:
nint

The number of bytes to read. If -1 then block until the other end closes its writer, then return all data seen.

Raises:
ConnectionError

If the connection is lost before, or while, reading.

async read_and_dispatch() None

Read, parse, and dispatch one item of data.

Subclasses need to implement this method such that it reads and parses data and then dispatches handling the data to a method suitable for the subclass. Methods that might be helpful include:

async read_into(struct: Structure) None

Read binary data from a stream reader into a ctypes.Structure.

Parameters:
structctypes.Structure

Structure to set.

Raises:
ConnectionError

If the connection is lost before, or while, reading.

asyncio.IncompleteReadError

If EOF is reached before n bytes can be read. Use the IncompleteReadError.partial attribute to get the partially read data.

async read_json() Any

Read JSON data.

Read the data with read_str and return the json-decoded result.

Returns:
datatyping.Any

Data decoded from JSON.

Raises:
ConnectionError

If the connection is lost before, or while, reading.

asyncio.IncompleteReadError

If EOF is reached before the complete separator is found and the internal buffer is reset.

LimitOverrunError

If the amount of data read exceeds the configured stream lmit. The data is left in the internal buffer and can be read again.

TypeError

If the data are of a type that cannot be decoded from JSON.

json.JSONDecodeError

If the data cannot be decoded from JSON.

async read_loop() None

Read incoming data and handle them.

The actual reading is deferred to the read_and_dispatch method and needs to be implemented by subclasses.

async read_str() str

Read and decode a terminated str; strip the terminator.

Read until self.terminator, strip the terminator, and decode the data as self.encoding with strict error handling.

Returns:
linestr

Line of data, as a str with the terminator stripped.

Raises:
ConnectionError

If the connection is lost before, or while, reading.

asyncio.IncompleteReadError

If EOF is reached before the complete separator is found and the internal buffer is reset.

LimitOverrunError

If the amount of data read exceeds the configured stream lmit. The data is left in the internal buffer and can be read again.

UnicodeError

If decoding fails.

async readexactly(n: int) bytes

Read exactly n bytes.

Parameters:
nint

The number of bytes to read.

Raises:
ConnectionError

If the connection is lost before, or while, reading.

asyncio.IncompleteReadError

If EOF is reached before n bytes can be read. Use the IncompleteReadError.partial attribute to get the partially read data.

async readline() bytes

Read a sequence of bytes ending with \n.

If EOF is received and \n was not found, the method returns partially read data.

Raises:
ConnectionError

If the connection is lost before, or while, reading.

async readuntil(separator: bytes = b'\n') bytes

Read one line, where “line” is a sequence of bytes ending with separator.

Read data from the stream until separator is found.

On success, the data and separator will be removed from the internal buffer (consumed). Returned data will include the separator at the end.

See also read_str, which is more convenient for most use cases.

Parameters:
separatorbytes

The desired separator. The default matches the standard library, rather than using terminator.

Raises:
ConnectionError

If the connection is lost before, or while, reading.

asyncio.IncompleteReadError

If EOF is reached before the complete separator is found and the internal buffer is reset.

LimitOverrunError

If the amount of data read exceeds the configured stream lmit. The data is left in the internal buffer and can be read again.

async request_and_send_status(llc: BaseMockStatus, llc_name: str) None

Request the status of the given Lower Level Component and write it to the requester.

Parameters:
llc: `BaseMockStatus`

The Lower Level Component status to request the status from.

llc_name: `str`

The name of the Lower Level Component.

async reset_drives_az(reset: list[int]) float

Reset one or more AZ drives.

Parameters:
reset: array of int

Desired reset action to execute on each AZ drive: 0 means don’t reset, 1 means reset.

Returns:
float

The estimated duration of the execution of the command.

Notes

This is necessary when exiting from FAULT state without going to Degraded Mode since the drives don’t reset themselves. The number of values in the reset parameter is not validated.

async reset_drives_shutter(reset: list[int]) None

Reset one or more Aperture Shutter drives.

Parameters:
reset: array of int

Desired reset action to execute on each Aperture Shutter drive: 0 means don’t reset, 1 means reset.

Notes

This is necessary when exiting from FAULT state without going to Degraded Mode since the drives don’t reset themselves. The number of values in the reset parameter is not validated.

async restore() None

Restore the default configuration of the lower level components.

async search_zero_shutter() float

Search the zero position of the Aperture Shutter, which is the closed position. This is necessary in case the ApSCS (Aperture Shutter Control system) was shutdown with the Aperture Shutter not fully open or fully closed.

Returns:
float

The estimated duration of the execution of the command.

async set_degraded_az() None

Set az operational mode to degraded (as opposed to normal).

async set_degraded_el() None

Set el operational mode to degraded (as opposed to normal).

async set_degraded_louvers() None

Set louvers operational mode to degraded (as opposed to normal).

async set_degraded_monitoring() None

Set monitoring operational mode to degraded (as opposed to normal).

async set_degraded_shutter() None

Set shutter operational mode to degraded (as opposed to normal).

async set_degraded_thermal() None

Set thermal operational mode to degraded (as opposed to normal).

async set_louvers(position: list[float]) None

Set the positions of the louvers.

Parameters:
position: array of float

An array of positions, in percentage with 0 meaning closed and 100 fully open, for each louver. A position of -1 means “do not move”.

async set_normal_az() None

Set az operational mode to normal (as opposed to degraded).

async set_normal_el() None

Set el operational mode to normal (as opposed to degraded).

async set_normal_louvers() None

Set louvers operational mode to normal (as opposed to degraded).

async set_normal_monitoring() None

Set monitoring operational mode to normal (as opposed to degraded).

async set_normal_shutter() None

Set shutter operational mode to normal (as opposed to degraded).

async set_normal_thermal() None

Set thermal operational mode to normal (as opposed to degraded).

async set_temperature(temperature: float) None

Set the preferred temperature in the dome.

Parameters:
temperature: `float`

The temperature, in degrees Celsius, to set.

async set_zero_az() float

Take the current position of the dome as zero. This is necessary as long as the racks, pinions and encoders on the drives have not been installed yet to compensate for slippage of the drives.

Returns:
float

The estimated duration of the execution of the command.

async start(**kwargs: Any) None

Start the TCP/IP server.

Parameters:
**kwargsdict [str, typing.Any]

Additional keyword arguments for asyncio.start_server, beyond host and port.

async start_or_stop_thcs_if_necessary() None
async status_amcs() None

Request the status from the AMCS lower level component and write it in reply.

async status_apscs() None

Request the status from the ApSCS lower level component and write it in reply.

async status_cbcs() None

Request the status from the CBCS lower level component and write it in reply.

async status_cscs() None

Request the status from the Calibration Screen and write it in reply.

async status_lcs() None

Request the status from the LCS lower level component and write it in reply.

async status_lwscs() None

Request the status from the LWSCS lower level component and write it in reply.

async status_moncs() None

Request the status from the MonCS lower level component and write it in reply.

async status_rad() None

Request the status from the RAD lower level component and write it in reply.

async status_thcs() None

Request the status from the ThCS lower level component and write it in reply.

async stop_az() float

Stop all dome motion.

Returns:
float

The estimated duration of the execution of the command.

async stop_el() float

Stop all light and wind screen motion.

Returns:
float

The estimated duration of the execution of the command.

async stop_louvers() None

Stop the motion of all louvers.

async stop_shutter() float

Stop the motion of the shutter.

Returns:
float

The estimated duration of the execution of the command.

async write(data: bytes) None

Write data and call drain.

Parameters:
databytes

The data to write.

Raises:
ConnectionError

If self.connected false before writing begins.

async write_from(*structs: Structure) None

Write binary data from one or more ctypes.Structures.

Parameters:
structslist [ctypes.Structure]

Structures to write.

Raises:
ConnectionError

If self.connected false before writing begins.

async write_json(data: Any) None

Write data in JSON format.

Encode the data as json and write the result with write_str.

Parameters:
dataany

The data to be written. Typically a dict, but any json-encodable data is acceptable.

Raises:
ConnectionError

If the connection is lost before, or while, reading.

UnicodeError

If encoding fails.

json.JSONEncodeError

If the data cannot be json-encoded.

async write_reply(**data: Any) None

Write the data appended with the commandId.

The non-negative, non-zero commandId is contained in the incoming data, for which this method writes a reply, and is copied as is.

Parameters:
data:

The data to write.

async write_str(line: str) None

Encode, terminate, and write a str.

Encode the str as self.encoding with strict error handling, and append self.terminator.

Parameters:
linestr

The line of data to be written.

Raises:
ConnectionError

If the connection is lost before, or while, reading.

UnicodeError

If encoding fails.

async writelines(lines: Iterable) None

Write an iterable of bytes and call drain.

Parameters:
linescollections.abc.Iterable [bytes]

The data to write, as an iterable collection of bytes.

Raises:
ConnectionError

If self.connected false before writing begins.