greenwave_monitor.ui_adaptor module

Greenwave monitor diagnostics helpers for UI frontends.

This module contains small data containers plus a monitor class intended to be embedded in UI processes. The greenwave_monitor_node publishes diagnostic_msgs/DiagnosticArray messages on /diagnostics. GreenwaveUiAdaptor subscribes to that topic and maintains a thread-safe, easy-to-consume view (UiDiagnosticData) per monitored topic, including the timestamp of the last update for each topic.

In addition to passively subscribing, GreenwaveUiAdaptor exposes clients for two services on the monitor node: - ManageTopic: start/stop monitoring a topic (toggle_topic_monitoring). - SetExpectedFrequency: set/clear the expected publish rate and tolerance for a topic

(set_expected_frequency). Expected rates are also cached locally in expected_frequencies as (expected_hz, tolerance_percent) so UIs can display the configured values alongside live diagnostics.

class greenwave_monitor.ui_adaptor.GreenwaveUiAdaptor(node: rclpy.node.Node, monitor_node_name: str = 'greenwave_monitor')

Bases: object

Subscribe to /diagnostics and manage topic monitoring for UI consumption.

Designed for UI frontends, this class keeps per-topic UiDiagnosticData up to date, provides a toggle for monitoring via ManageTopic, and exposes helpers to set/clear expected frequencies via SetExpectedFrequency. Service names may be discovered dynamically or constructed from an optional namespace and node name.

get_expected_frequency(topic_name: str) tuple[float, float]

Get monitoring settings for a topic. Returns (0.0, 0.0) if not set.

get_topic_diagnostics(topic_name: str) UiDiagnosticData

Get diagnostic data for a topic. Returns default values if topic not found.

set_expected_frequency(topic_name: str, expected_hz: float = 0.0, tolerance_percent: float = 0.0, clear: bool = False) tuple[bool, str]

Set or clear the expected frequency for a topic.

toggle_topic_monitoring(topic_name: str) tuple[bool, str]

Toggle monitoring for a topic.

class greenwave_monitor.ui_adaptor.UiDiagnosticData(expected_frequency: str = '-', tolerance: str = '-', pub_rate: str = '-', msg_rate: str = '-', latency: str = '-', status: str = '-', last_update: float = 0.0)

Bases: object

UI-ready snapshot of diagnostics for a monitored topic.

Fields are stored as strings for straightforward rendering in UI components. status is one of: ‘OK’ | ‘WARN’ | ‘ERROR’ | ‘STALE’ | ‘UNKNOWN’ (or ‘-’ if unset). last_update stores the epoch timestamp when diagnostics were last refreshed.

expected_frequency: str = '-'
classmethod from_status(status: diagnostic_msgs.msg.DiagnosticStatus) UiDiagnosticData

Create UiDiagnosticData from DiagnosticStatus.

last_update: float = 0.0
latency: str = '-'
msg_rate: str = '-'
pub_rate: str = '-'
status: str = '-'
tolerance: str = '-'