MockServer¶
- class lsst.ts.cbp.MockServer(log=None)¶
Bases:
OneClientReadLoopServerMocks the CBP server.
- Parameters:
- log
logging.Logger, optional
- log
- Attributes:
Attributes Summary
Return True if self._reader and self._writer are connected.
Deprecated access to the underlying stream reader.
Deprecated access to the underlying stream server.
Deprecated access to the underlying stream writer.
Methods Summary
Close the connected client socket, if any.
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.
cmd_loop()Run the command loop.
Return the azimuth encoder status.
Return the altitude encoder status.
Return the focus encoder status.
Return the mask selection encoder status.
Return the mask rotation encoder status.
Return the altitude position.
Return the autopark value.
Return azimuth position.
do_focus()Return the focus value.
do_mask()Return the mask value.
do_new_altitude(altitude)Set the new altitude position.
do_new_azimuth(azimuth)Set the new azimuth position.
do_new_focus(focus)Set the new focus value.
do_new_mask(mask)Set the new mask value.
do_new_rotation(rotation)Set the new mask rotation value.
do_panic()Return the panic status value.
do_park([park])Park or unpark the CBP.
Return the mask rotation value.
read(n)Read up to n bytes.
Read, parse, and dispatch one item of data.
read_into(struct)Read binary data from a stream reader into a
ctypes.Structure.Read JSON data.
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.set_constrained_position(value, actuator)Set actuator to position that is silently constrained to bounds.
start(**kwargs)Start the TCP/IP server.
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_str(line)Encode, terminate, and write a str.
writelines(lines)Write an iterable of bytes and call
drain.Attributes Documentation
- 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.
- reader¶
Deprecated access to the underlying stream reader.
Use this classes’ read methods instead.
- server¶
Deprecated access to the underlying stream server.
- writer¶
Deprecated access to the underlying stream writer.
Use this classes’ write methods instead.
Methods Documentation
- async basic_close_client() None¶
Close the connected client socket, if any.
Also:
Reset
self.connected_taskto a new Future.Call connect_callback, if a client was connected.
Unlike
close_client, this does not touchself.should_be_connected.Always safe to call.
- 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_task
bool Cancel the read loop task or not? Defaults to True and should be False when called from the read loop task itself.
- cancel_read_loop_task
- async cmd_loop()¶
Run the command loop.
- Parameters:
- reader
asyncio.StreamReader - writer
asyncio.StreamWriter
- reader
- async do_aastat()¶
Return the azimuth encoder status.
- Returns:
- str
- async do_abstat()¶
Return the altitude encoder status.
- Returns:
- str
- async do_acstat()¶
Return the focus encoder status.
- Returns:
- str
- async do_adstat()¶
Return the mask selection encoder status.
- Returns:
- str
- async do_aestat()¶
Return the mask rotation encoder status.
- Returns:
- str
- async do_altitude()¶
Return the altitude position.
- Returns:
- str
- async do_autopark()¶
Return the autopark value.
- Returns:
- str
- async do_azimuth()¶
Return azimuth position.
- Returns:
- str
- async do_focus()¶
Return the focus value.
- Returns:
- str
- async do_mask()¶
Return the mask value.
- Returns:
- str
- async do_new_altitude(altitude)¶
Set the new altitude position.
- Parameters:
- altitude
float
- altitude
- Returns:
- str
- async do_new_focus(focus)¶
Set the new focus value.
- Parameters:
- focus
- Returns:
- str
- async do_new_rotation(rotation)¶
Set the new mask rotation value.
- Parameters:
- rotation
float
- rotation
- Returns:
- str
- async do_panic()¶
Return the panic status value.
- Returns:
- str
- async do_rotation()¶
Return the mask rotation value.
- Returns:
- str
- async read(n: int) bytes¶
Read up to n bytes.
- Parameters:
- n
int The number of bytes to read. If -1 then block until the other end closes its writer, then return all data seen.
- n
- Raises:
ConnectionErrorIf the connection is lost before, or while, reading.
- async read_and_dispatch()¶
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:
- struct
ctypes.Structure Structure to set.
- struct
- Raises:
ConnectionErrorIf the connection is lost before, or while, reading.
asyncio.IncompleteReadErrorIf EOF is reached before
nbytes can be read. Use theIncompleteReadError.partialattribute to get the partially read data.
- async read_json() Any¶
Read JSON data.
Read the data with
read_strand return the json-decoded result.- Returns:
- data
typing.Any Data decoded from JSON.
- data
- Raises:
ConnectionErrorIf the connection is lost before, or while, reading.
asyncio.IncompleteReadErrorIf EOF is reached before the complete separator is found and the internal buffer is reset.
LimitOverrunErrorIf the amount of data read exceeds the configured stream lmit. The data is left in the internal buffer and can be read again.
TypeErrorIf the data are of a type that cannot be decoded from JSON.
json.JSONDecodeErrorIf 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_dispatchmethod 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 asself.encodingwith strict error handling.- Returns:
- line
str Line of data, as a str with the terminator stripped.
- line
- Raises:
ConnectionErrorIf the connection is lost before, or while, reading.
asyncio.IncompleteReadErrorIf EOF is reached before the complete separator is found and the internal buffer is reset.
LimitOverrunErrorIf the amount of data read exceeds the configured stream lmit. The data is left in the internal buffer and can be read again.
UnicodeErrorIf decoding fails.
- async readexactly(n: int) bytes¶
Read exactly n bytes.
- Parameters:
- n
int The number of bytes to read.
- n
- Raises:
ConnectionErrorIf the connection is lost before, or while, reading.
asyncio.IncompleteReadErrorIf EOF is reached before
nbytes can be read. Use theIncompleteReadError.partialattribute to get the partially read data.
- async readline() bytes¶
Read a sequence of bytes ending with
\n.If EOF is received and
\nwas not found, the method returns partially read data.- Raises:
ConnectionErrorIf 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:
- separator
bytes The desired separator. The default matches the standard library, rather than using
terminator.
- separator
- Raises:
ConnectionErrorIf the connection is lost before, or while, reading.
asyncio.IncompleteReadErrorIf EOF is reached before the complete separator is found and the internal buffer is reset.
LimitOverrunErrorIf the amount of data read exceeds the configured stream lmit. The data is left in the internal buffer and can be read again.
- set_constrained_position(value, actuator)¶
Set actuator to position that is silently constrained to bounds.
- Parameters:
- value
float Desired value
- actuator
lsst.ts.simactuators.PointToPointActuator The actuator to set.
- value
- async start(**kwargs: Any) None¶
Start the TCP/IP server.
This is called automatically by the constructor, and is not intended to be called by the user. It is a public method so that subclasses can override it.
- Parameters:
- **kwargs
dict[str,typing.Any] Additional keyword arguments for
asyncio.start_server, beyond host and port.
- **kwargs
- Raises:
RuntimeErrorIf start has already been called and has successfully constructed a server.
- async write(data: bytes) None¶
Write data and call
drain.- Parameters:
- data
bytes The data to write.
- data
- Raises:
ConnectionErrorIf
self.connectedfalse before writing begins.
- async write_from(*structs: Structure) None¶
Write binary data from one or more
ctypes.Structures.- Parameters:
- structs
list[ctypes.Structure] Structures to write.
- structs
- Raises:
ConnectionErrorIf
self.connectedfalse 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:
- data
any The data to be written. Typically a dict, but any json-encodable data is acceptable.
- data
- Raises:
ConnectionErrorIf the connection is lost before, or while, reading.
UnicodeErrorIf encoding fails.
json.JSONEncodeErrorIf the data cannot be json-encoded.
- async write_str(line: str) None¶
Encode, terminate, and write a str.
Encode the str as
self.encodingwith strict error handling, and appendself.terminator.- Parameters:
- line
str The line of data to be written.
- line
- Raises:
ConnectionErrorIf the connection is lost before, or while, reading.
UnicodeErrorIf encoding fails.
- async writelines(lines: Iterable) None¶
Write an iterable of bytes and call
drain.- Parameters:
- lines
collections.abc.Iterable[bytes] The data to write, as an iterable collection of
bytes.
- lines
- Raises:
ConnectionErrorIf
self.connectedfalse before writing begins.