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: object

Python 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)

disconnect()[source]#

Disconnect from the CDP server.

Return type:

None

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

set(access_string, value, value_type)[source]#

Set a value on the CDP server.

Parameters:
  • access_string (str) – The access path (e.g. “vehicle.target_speed”)

  • value (float | bool | int) – The value to set

  • value_type (ValueType) – Type of the value

Return type:

None

exception perda.live.CDPException[source]#

Bases: Exception

Base exception for CDP client errors.

exception perda.live.CDPProtocolError[source]#

Bases: CDPException

Raised when there’s a protocol-level error.

exception perda.live.CDPServerError(status, message)[source]#

Bases: CDPException

Raised when the server returns an error response.

Parameters:
class perda.live.LiveAnalyzer(host, port, timeout, range_timeout)[source]#

Bases: object

Live 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:
classmethod dataserver(port=5001, timeout=5.0, range_timeout=2.0)[source]#
Return type:

LiveAnalyzer

Parameters:
  • port (int)

  • timeout (float)

  • range_timeout (float)

ensure_connected()[source]#
Return type:

None

fetch(var, time_secs=30)[source]#
Return type:

DataInstance

Parameters:
  • var (str)

  • time_secs (int)

get(access_string, value_type)[source]#
Return type:

float | bool | int

Parameters:
is_connected(refresh=False)[source]#
Return type:

bool

Parameters:

refresh (bool)

classmethod local(port=5001, timeout=5.0, range_timeout=2.0)[source]#
Return type:

LiveAnalyzer

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:
classmethod remote(host, port=5001, timeout=5.0, range_timeout=2.0)[source]#
Return type:

LiveAnalyzer

Parameters:
  • host (str)

  • port (int)

  • timeout (float)

  • range_timeout (float)

set(access_string, value, value_type)[source]#
Return type:

None

Parameters:
  • access_string (str)

  • value (float | bool | int)

  • value_type (ValueType)

class perda.live.ResponseStatus(*values)[source]#

Bases: Enum

Response 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: Enum

Value 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

cdp_client

Python client library for communicating with the Rust CDP IPC server.

live_analyzer

perda.live.live_analyzer Live data analysis using the CDP IPC server, mirroring the Analyzer interface.