pub struct AppState {Show 13 fields
pub port_path: Arc<Mutex<String>>,
pub baud_rate: u32,
pub serial_connected: Arc<AtomicBool>,
pub collection_running: Arc<AtomicBool>,
pub cmd_tx: Sender<String>,
pub csi_tx: Sender<Vec<u8>>,
pub log_mode_tx: Arc<Sender<LogMode>>,
pub output_mode_tx: Arc<Sender<OutputMode>>,
pub session_file_tx: Arc<Sender<Option<String>>>,
pub config: Arc<Mutex<DeviceConfig>>,
pub info_request_tx: Sender<InfoResponder>,
pub firmware_verified: Arc<AtomicBool>,
pub device_info: Arc<Mutex<Option<DeviceInfo>>>,
}Expand description
Shared application state, cheaply cloned into every route handler via Axum’s State extractor.
Fields§
§port_path: Arc<Mutex<String>>USB serial port path used to reach the ESP32 (e.g. /dev/ttyUSB0).
Stored so route handlers can open a short-lived second fd for control
operations such as RTS-triggered reset.
baud_rate: u32Baud rate negotiated at startup. The serial task and the RTS-reset handler both read this so a single source of truth governs the link.
serial_connected: Arc<AtomicBool>Whether the serial task currently has an open and healthy ESP32 link.
collection_running: Arc<AtomicBool>Best-effort flag: true after successful start, false after reset/disconnect.
cmd_tx: Sender<String>Send CLI command strings to the serial background task.
csi_tx: Sender<Vec<u8>>Broadcast raw CSI frame bytes to all connected WebSocket clients.
log_mode_tx: Arc<Sender<LogMode>>Notify the serial task of log-mode changes (affects the frame delimiter).
output_mode_tx: Arc<Sender<OutputMode>>Notify the serial task of output-mode changes (stream / dump / both).
session_file_tx: Arc<Sender<Option<String>>>Signal the serial task of the current session’s dump file path.
Some(path) → open/reuse that file; None → session ended, close file.
config: Arc<Mutex<DeviceConfig>>Cached view of the current device configuration.
info_request_tx: Sender<InfoResponder>Issue an info command on the device and capture the magic block.
The serial task synchronously consumes the responder.
firmware_verified: Arc<AtomicBool>true once the serial task (or an explicit /api/info call) has
observed a valid ESP-CSI-CLI/<version> magic block from the device.
Cleared on disconnect, on POST /api/control/reset (until the
post-reset re-verification completes), and on a failed verification.
Command endpoints refuse to send while this is false.
device_info: Arc<Mutex<Option<DeviceInfo>>>Last successfully parsed firmware identification block. None until
the first verification succeeds; cleared alongside firmware_verified.
Implementations§
Source§impl AppState
impl AppState
Sourcepub fn require_firmware(&self) -> Option<(StatusCode, Json<ApiResponse>)>
pub fn require_firmware(&self) -> Option<(StatusCode, Json<ApiResponse>)>
Returns an early-return tuple suitable for handlers when the firmware
has not yet been verified as esp-csi-cli-rs. Use this to short-circuit
any endpoint that issues a CLI command — sending commands to an
unverified device may interact with whatever bootloader/firmware is
listening in unintended ways.