Expand description
Connection monitoring module (FR-010)
This module provides connection state monitoring with optional automatic reconnection support.
§Overview
The monitor module helps track the health of CAN backend connections and optionally handles automatic reconnection when connections are lost.
§Components
ConnectionMonitor: Main monitoring componentConnectionState: Current connection state (Connected, Disconnected, Reconnecting)ReconnectConfig: Configuration for automatic reconnectionMonitorConfig: Configuration loaded from TOML files
§Connection States
ConnectionState::Connected: Backend is operationalConnectionState::Disconnected: Connection lost, needs re-initializationConnectionState::Reconnecting: Auto-reconnect in progress
§Example
use canlink_hal::monitor::{ConnectionMonitor, ConnectionState, ReconnectConfig};
use std::time::Duration;
// Create monitor without auto-reconnect
let monitor = ConnectionMonitor::new(Duration::from_secs(1));
assert_eq!(monitor.state(), ConnectionState::Connected);
// Create monitor with auto-reconnect
let reconnect_config = ReconnectConfig::exponential_backoff(
5, // max retries
Duration::from_secs(1), // initial interval
2.0, // backoff multiplier
);
let monitor = ConnectionMonitor::with_reconnect(
Duration::from_secs(1),
reconnect_config,
);
assert!(monitor.auto_reconnect_enabled());§Auto-Reconnect
When auto-reconnect is enabled, the monitor will automatically attempt
to reconnect when a disconnection is detected. The reconnection behavior
is controlled by ReconnectConfig:
max_retries: Maximum reconnection attempts (0 = unlimited)retry_interval: Initial delay between attemptsbackoff_multiplier: Exponential backoff factor
Structs§
- Connection
Monitor - Connection monitor
- Monitor
Config - Monitor configuration from TOML
- Reconnect
Config - Reconnection configuration
Enums§
- Connection
State - Connection state