perda.live#
perda.live#
Live data acquisition from the CDP IPC server.
Quick start#
from perda.live import LiveAnalyzer, ValueType
live = LiveAnalyzer.local() # running on this machine live = LiveAnalyzer.dataserver() # Penn Electric Racing dataserver live = LiveAnalyzer.remote(“10.0.0.5”) # arbitrary IP
fig = live.plot(“bms.board.glvTemp”) fig.show()
- class perda.live.CDPClient(timeout=5.0, range_timeout=2.0)[source]#
Bases:
objectPython client for communicating with the Rust CDP IPC server.
- Example usage:
client = CDPClient() client.connect(“127.0.0.1”, 5001)
# Get a single value value = client.get(“vehicle.speed”, ValueType.FLOAT)
# Get a time-series range (last 10 seconds) di = client.get_range(“vehicle.speed”, ValueType.FLOAT, time_secs=10)
# Set a value client.set(“vehicle.target_speed”, 65.0, ValueType.FLOAT)
client.disconnect()
- Parameters:
timeout (float)
range_timeout (float)
- ACCESS_STRING_SIZE = 56#
- PACKET_SIZE = 65#
- connect(host='127.0.0.1', port=5001)[source]#
Connect to the CDP server.
- Return type:
None- Parameters:
host (str)
port (int)
- get(access_string, value_type)[source]#
Get the latest value for a signal from the CDP server.
- Parameters:
access_string (
str) – The access path (e.g. “vehicle.speed”)value_type (
ValueType) – Expected type of the value
- Return type:
float|bool|int- Returns:
The requested value as float, bool, or int
- get_range(access_string, time_secs)[source]#
Request a time-series range of data from the CDP server.
The server will chunk the response into multiple UDP packets. This method collects all packets until either the expected sample count is reached or range_timeout elapses, then assembles them into a single DataInstance.
- Parameters:
access_string (
str) – The access path (e.g. “vehicle.speed”)value_type – Expected type of the value
time_secs (
int) – How many seconds of history to retrieve (u32)
- Returns:
A DataInstance with the assembled time-series data
- exception perda.live.CDPProtocolError[source]#
Bases:
CDPExceptionRaised when there’s a protocol-level error.
- exception perda.live.CDPServerError(status, message)[source]#
Bases:
CDPExceptionRaised when the server returns an error response.
- Parameters:
status (ResponseStatus)
message (str)
- class perda.live.LiveAnalyzer(host, port, timeout, range_timeout)[source]#
Bases:
objectLive data analyzer that pulls time-series data from the CDP IPC server and exposes a plotting interface analogous to
Analyzer.- Parameters:
host (str)
port (int)
timeout (float)
range_timeout (float)
- analyze_frequency(var, time_secs=30, expected_frequency_hz=None, gap_threshold_multiplier=2.0, font_config=FontConfig(large=20, medium=14, small=10), layout_config=LayoutConfig(width=1200, height=700, margin={'l': 70, 'r': 50, 't': 90, 'b': 70}, plot_bgcolor='white', title_x=0.5, title_xanchor='center', title_yanchor='top', grid_width_per_col=400, grid_height_per_row=350, grid_horizontal_spacing=0.08, grid_vertical_spacing=0.12, max_display_resolution=50), plot_config=ScatterHistogramPlotConfig(color_scatter='blue', color_line='crimson', color_histogram='blue', histogram_bins=80))[source]#
- Return type:
Figure- Parameters:
var (str)
time_secs (int)
expected_frequency_hz (float | None)
gap_threshold_multiplier (float)
font_config (FontConfig)
layout_config (LayoutConfig)
plot_config (ScatterHistogramPlotConfig)
- classmethod dataserver(port=5001, timeout=5.0, range_timeout=2.0)[source]#
- Return type:
- Parameters:
port (int)
timeout (float)
range_timeout (float)
- get(access_string, value_type)[source]#
- Return type:
float|bool|int- Parameters:
access_string (str)
value_type (ValueType)
- classmethod local(port=5001, timeout=5.0, range_timeout=2.0)[source]#
- Return type:
- Parameters:
port (int)
timeout (float)
range_timeout (float)
- plot(var_1, var_2=None, time_secs=30, title=None, y_label_1=None, y_label_2=None, show_legend=True, font_config=FontConfig(large=20, medium=14, small=10), layout_config=LayoutConfig(width=1200, height=700, margin={'l': 70, 'r': 50, 't': 90, 'b': 70}, plot_bgcolor='white', title_x=0.5, title_xanchor='center', title_yanchor='top', grid_width_per_col=400, grid_height_per_row=350, grid_horizontal_spacing=0.08, grid_vertical_spacing=0.12, max_display_resolution=50))[source]#
- Return type:
Figure- Parameters:
var_1 (str | DataInstance | List[str | DataInstance])
var_2 (str | DataInstance | List[str | DataInstance] | None)
time_secs (int)
title (str | None)
y_label_1 (str | None)
y_label_2 (str | None)
show_legend (bool)
font_config (FontConfig)
layout_config (LayoutConfig)
- class perda.live.ResponseStatus(*values)[source]#
Bases:
EnumResponse status codes from the CDP server.
- BADLY_FORMED = 6#
- COMM_ERROR = 2#
- DISCONNECTED = 5#
- GET_RANGED_SUCCESS = 7#
- GET_SUCCESS = 0#
- INCORRECT_TYPE = 4#
- INVALID_ACCESS = 3#
- SET_SUCCESS = 1#
- class perda.live.ValueType(*values)[source]#
Bases:
EnumValue types supported by the CDP IPC protocol.
- BOOL = 2#
- FLOAT = 1#
- NUMERIC = 0#
- perda.live.get_range_value(access_string, time_secs, host='127.0.0.1', port=5001, timeout=5.0, range_timeout=2.0)[source]#
Convenience function to fetch a time-series range as a DataInstance.
- Parameters:
access_string (str)
time_secs (int)
host (str)
port (int)
timeout (float)
range_timeout (float)
- perda.live.get_value(access_string, value_type, host='127.0.0.1', port=5001, timeout=5.0)[source]#
Convenience function to get a single value.
- Return type:
float|bool|int- Parameters:
access_string (str)
value_type (ValueType)
host (str)
port (int)
timeout (float)
- perda.live.set_value(access_string, value, value_type, host='127.0.0.1', port=5001, timeout=5.0)[source]#
Convenience function to set a single value.
- Return type:
None- Parameters:
access_string (str)
value (float | bool | int)
value_type (ValueType)
host (str)
port (int)
timeout (float)
Modules
Python client library for communicating with the Rust CDP IPC server. |
|
perda.live.live_analyzer Live data analysis using the CDP IPC server, mirroring the Analyzer interface. |