Skip to content

decades

frog.hardware.plugins.sensors.decades ¤

This module provides an interface to the DECADES API.

This is used to query the DECADES server for aircraft sensor data.

Attributes¤

Classes¤

Decades(host=DECADES_HOST, poll_interval=DECADES_POLL_INTERVAL, params=','.join(DEFAULT_DECADES_PARAMETERS), timeout=DEFAULT_HTTP_TIMEOUT) ¤

Bases: HTTPDevice, SensorsBase

A class for monitoring a DECADES sensor server.

Create a new Decades instance.

Parameters:

Name Type Description Default
host str

The IP address or hostname of the DECADES server

DECADES_HOST
poll_interval float

How often to poll the sensors (seconds)

DECADES_POLL_INTERVAL
params str

Comma-separated list of parameters to request from the DECADES server (leave empty for all)

join(DEFAULT_DECADES_PARAMETERS)
timeout float

The maximum time in seconds to wait for a response from the server

DEFAULT_HTTP_TIMEOUT
Source code in frog/hardware/plugins/sensors/decades.py
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
def __init__(
    self,
    host: str = DECADES_HOST,
    poll_interval: float = DECADES_POLL_INTERVAL,
    params: str = ",".join(DEFAULT_DECADES_PARAMETERS),
    timeout: float = DEFAULT_HTTP_TIMEOUT,
) -> None:
    """Create a new Decades instance.

    Args:
        host: The IP address or hostname of the DECADES server
        poll_interval: How often to poll the sensors (seconds)
        params: Comma-separated list of parameters to request from the DECADES
                server (leave empty for all)
        timeout: The maximum time in seconds to wait for a response from the server
    """
    self._url: str = DECADES_URL.format(host=host)
    self._params: list[DecadesParameter]
    """Parameters returned by the server."""

    HTTPDevice.__init__(self, timeout)
    SensorsBase.__init__(self, poll_interval)

    # Obtain full parameter list in order to parse received data
    self.obtain_parameter_list(
        frozenset(params.split(",")) if params else frozenset()
    )
Functions¤
handle_response(response) ¤

Process received sensor readings.

Parameters:

Name Type Description Default
response str

The response from the server

required
Source code in frog/hardware/plugins/sensors/decades.py
171
172
173
174
175
176
177
178
179
def handle_response(self, response: str) -> None:
    """Process received sensor readings.

    Args:
        response: The response from the server
    """
    content = json.loads(response)
    readings = tuple(self._get_decades_data(content))
    self.send_readings_message(readings)
obtain_parameter_list(params) ¤

Request the parameter list from the DECADES server and wait for response.

Source code in frog/hardware/plugins/sensors/decades.py
132
133
134
135
136
137
def obtain_parameter_list(self, params: Set[str]) -> None:
    """Request the parameter list from the DECADES server and wait for response."""
    self.make_request(
        self._url + "/params/availability",
        partial(self._on_params_received, params=params),
    )
request_readings() ¤

Request the sensor data from the DECADES server.

The HTTP request is made on a background thread.

Source code in frog/hardware/plugins/sensors/decades.py
139
140
141
142
143
144
145
146
147
148
149
150
151
def request_readings(self) -> None:
    """Request the sensor data from the DECADES server.

    The HTTP request is made on a background thread.
    """
    epoch_time = str(int(time.time()))
    url = QUrlQuery(self._url + "/livedata?")
    url.addQueryItem("frm", epoch_time)
    url.addQueryItem("to", epoch_time)
    for param in self._params:
        url.addQueryItem("para", param.name)

    self.make_request(url.toString())

DecadesError ¤

Bases: Exception

Indicates that an error occurred while querying the DECADES server.

DecadesParameter(name, readable_name, unit) dataclass ¤

Represents a parameter returned from the DECADES server.

Attributes¤
name instance-attribute ¤

Short name for the parameter.

readable_name instance-attribute ¤

Human-readable name.

unit instance-attribute ¤

Unit for the value.

Functions¤
from_dict(d) classmethod ¤

Create a DecadesParameter from a dict.

Source code in frog/hardware/plugins/sensors/decades.py
82
83
84
85
@classmethod
def from_dict(cls, d: dict[str, Any]) -> DecadesParameter:
    """Create a DecadesParameter from a dict."""
    return DecadesParameter(d["ParameterName"], d["DisplayText"], d["DisplayUnits"])
get_sensor_reading(value) ¤

Get a SensorReading object with specified value for this parameter.

Source code in frog/hardware/plugins/sensors/decades.py
78
79
80
def get_sensor_reading(self, value: float) -> SensorReading:
    """Get a SensorReading object with specified value for this parameter."""
    return SensorReading(self.readable_name, value, self.unit)