LightningDataClient

class lsst.ts.ess.csc.LightningDataClient(config: SimpleNamespace, topics: lsst.ts.salobj.controller.Controller | types.SimpleNamespace, log: Logger, simulation_mode: int = 0)

Bases: ControllerDataClient

Get lightning and electrical field strength data from a Raspberry Pi.

Parameters:
configtypes.SimpleNamespace

The configuration, after validation by the schema returned by get_config_schema() and conversion to a types.SimpleNamespace.

topicssalobj.Controller or types.SimpleNamespace

The telemetry topics this data client can write, as a struct with attributes such as tel_temperature.

loglogging.Logger

Logger.

simulation_modeint, optional

Simulation mode; 0 for normal operation.

Attributes Summary

connected

Methods Summary

configure()

Store device configurations.

connect()

Connect to the RPi and configure it.

descr()

Return a brief description, without the class name.

disconnect()

Disconnect from the RPi.

get_config_schema()

Get the config schema as jsonschema dict.

get_telemetry_dispatch_dict()

get_telemetry_schema()

perform_pre_read_loop_tasks()

Perform any tasks before starting the read loop.

process_efm100c_telemetry(sensor_name, ...)

Process EFM-100C electric field strength detector telemetry.

process_ld250_noise_or_status(sensor_name, ...)

process_ld250_strike(sensor_name, timestamp, ...)

process_ld250_telemetry(sensor_name, ...)

Process LD-250 lightning detector telemetry.

process_telemetry(sensor_name, timestamp, ...)

Process the sensor telemetry.

read()

Read and unmarshal a json-encoded dict.

read_data()

Read and process data from the RPi.

read_loop()

Call the read_data function in a loop and allow for max_timeouts timeouts before raising a TimeoutError.

run()

Read data from the server and publish it as ESS telemetry.

run_command(command, **parameters)

Write a command.

sleep_timer(sleep_time)

Simple timer that sleeps for the given amount of time.

start()

Call disconnect, connect, and start the run task.

stop()

Stop reading and publishing data.

Attributes Documentation

connected

Methods Documentation

configure() None

Store device configurations.

This provides easy access when processing telemetry.

async connect() None

Connect to the RPi and configure it.

Raises:
RuntimeError

If already connected.

descr() str

Return a brief description, without the class name.

This should be just enough information to distinguish one instance of this client from another. For example RPiDataClient should return something like:

f"host={self.config.host}, port={self.config.port}"
async disconnect() None

Disconnect from the RPi.

Always safe to call, though it may raise asyncio.CancelledError if the writer is currently being closed.

classmethod get_config_schema() dict[str, Any]

Get the config schema as jsonschema dict.

get_telemetry_dispatch_dict() dict[str, Callable]
classmethod get_telemetry_schema() dict[str, Any]
async perform_pre_read_loop_tasks() None

Perform any tasks before starting the read loop.

async process_efm100c_telemetry(sensor_name: str, timestamp: float, response_code: int, sensor_data: Sequence[float | str | int]) None

Process EFM-100C electric field strength detector telemetry.

Parameters:
sensor_namestr

The name of the sensor.

timestampfloat

The timestamp of the data.

response_codeint

The ResponseCode.

sensor_dataeach of type float

A Sequence of float representing the sensor telemetry data.

async process_ld250_noise_or_status(sensor_name: str, timestamp: float, response_code: int, sensor_data: Sequence[float | str | int]) None
async process_ld250_strike(sensor_name: str, timestamp: float, response_code: int, sensor_data: Sequence[float | str | int]) None
async process_ld250_telemetry(sensor_name: str, timestamp: float, response_code: int, sensor_data: Sequence[float | str | int]) None

Process LD-250 lightning detector telemetry.

Parameters:
sensor_namestr

The name of the sensor.

timestampfloat

The timestamp of the data.

response_codeint

The ResponseCode.

sensor_dataeach of type float

A Sequence of float representing the sensor telemetry data.

async process_telemetry(sensor_name: str, timestamp: float, response_code: int, sensor_data: Sequence[float | int | str]) None

Process the sensor telemetry.

Parameters:
sensor_namestr

The name of the sensor.

timestampfloat

The timestamp of the data.

response_codeint

The response code.

sensor_dataeach of type float

A Sequence of float representing the sensor telemetry data.

Raises:
RuntimeError

If the response code is common.ResponseCode.DEVICE_READ_ERROR

async read() dict

Read and unmarshal a json-encoded dict.

This may be a command acknowedgement or telemetry data.

Time out if reading takes longer than COMMUNICATE_TIMEOUT seconds.

Returns:
datadict

The read data, after json-decoding it.

Raises:
RuntimeError

In case of not being connected. In case parsing gthe JSON data fails.

async read_data() None

Read and process data from the RPi.

async read_loop() None

Call the read_data function in a loop and allow for max_timeouts timeouts before raising a TimeoutError.

async run() None

Read data from the server and publish it as ESS telemetry.

This is called once after connect and it should keep running until cancelled. See the Raises section for exceptions subclasses should raise.

Raises:
ConnectionError

If the connection to the data server is lost.

asyncio.TimeoutError

If data is not received in reasonable time.

Exception

(or any subclass) if any other serious problem occurs.

async run_command(command: str, **parameters: Any) None

Write a command. Time out if it takes too long.

Parameters:
commandstr

The command to write.

**parametersdict

Command parameters, as name=dict. For example:

configuration = {"devices": self.config.devices}
Raises:
ConnectionError

If not connected.

asyncio.TimeoutError

If it takes more than COMMUNICATE_TIMEOUT seconds to acquire the lock or write the data.

async sleep_timer(sleep_time: float) None

Simple timer that sleeps for the given amount of time.

Parameters:
sleep_timefloat

The amount of time to sleep [s].

async start() None

Call disconnect, connect, and start the run task.

Raises the same exceptions as connect. If disconnect raises, this logs the exception and continues.

async stop() None

Stop reading and publishing data.

This is alway safe to call, whether connected or not. This should raise no exceptions except asyncio.CancelledError. If disconnect raises, this logs the exception and continues.