mirror of
https://github.com/ruvnet/RuView
synced 2026-07-28 18:21:42 +00:00
feat(desktop): v0.4.2 - Integrated sensing server with real WebSocket data
- Bundle sensing-server binary in app resources (bin/sensing-server) - Add find_server_binary() for multi-path binary discovery - Connect Sensing page to real WebSocket endpoint (ws://localhost:8765/ws/sensing) - Add DataSource type and source config for data source selection - Default to simulate mode when no ESP32 hardware present - Add ADR-055: Integrated Sensing Server architecture - Add ADR-056: Complete RuView Desktop Capabilities Reference Closes integration of sensing server as single-package distribution. Co-Authored-By: claude-flow <ruv@ruv.net>
This commit is contained in:
@@ -2,21 +2,77 @@ use std::process::{Command, Stdio};
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
use sysinfo::{Pid, ProcessesToUpdate, System};
|
||||
use tauri::State;
|
||||
use tauri::{AppHandle, Manager, State};
|
||||
|
||||
use crate::state::AppState;
|
||||
|
||||
/// Default path to the sensing server binary (relative to resources).
|
||||
const DEFAULT_SERVER_BIN: &str = "wifi-densepose-sensing-server";
|
||||
/// Default binary name for the sensing server.
|
||||
const DEFAULT_SERVER_BIN: &str = "sensing-server";
|
||||
|
||||
/// Find the sensing server binary path.
|
||||
///
|
||||
/// Search order:
|
||||
/// 1. Custom path from config.server_path
|
||||
/// 2. Bundled in app resources (macOS: Contents/Resources/bin/)
|
||||
/// 3. Next to the app executable
|
||||
/// 4. System PATH
|
||||
fn find_server_binary(app: &AppHandle, custom_path: Option<&str>) -> Result<String, String> {
|
||||
// 1. Custom path from settings
|
||||
if let Some(path) = custom_path {
|
||||
if std::path::Path::new(path).exists() {
|
||||
return Ok(path.to_string());
|
||||
}
|
||||
}
|
||||
|
||||
// 2. Bundled in resources (Tauri bundles to Contents/Resources/)
|
||||
if let Ok(resource_dir) = app.path().resource_dir() {
|
||||
let bundled = resource_dir.join("bin").join(DEFAULT_SERVER_BIN);
|
||||
if bundled.exists() {
|
||||
return Ok(bundled.to_string_lossy().to_string());
|
||||
}
|
||||
// Also check directly in resources
|
||||
let direct = resource_dir.join(DEFAULT_SERVER_BIN);
|
||||
if direct.exists() {
|
||||
return Ok(direct.to_string_lossy().to_string());
|
||||
}
|
||||
}
|
||||
|
||||
// 3. Next to the executable
|
||||
if let Ok(exe_path) = std::env::current_exe() {
|
||||
if let Some(exe_dir) = exe_path.parent() {
|
||||
let sibling = exe_dir.join(DEFAULT_SERVER_BIN);
|
||||
if sibling.exists() {
|
||||
return Ok(sibling.to_string_lossy().to_string());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 4. Check if it's in PATH
|
||||
if let Ok(output) = Command::new("which").arg(DEFAULT_SERVER_BIN).output() {
|
||||
if output.status.success() {
|
||||
let path = String::from_utf8_lossy(&output.stdout).trim().to_string();
|
||||
if !path.is_empty() {
|
||||
return Ok(path);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Err(format!(
|
||||
"Sensing server binary '{}' not found. Please build it with: cargo build --release -p wifi-densepose-sensing-server",
|
||||
DEFAULT_SERVER_BIN
|
||||
))
|
||||
}
|
||||
|
||||
/// Start the sensing server as a managed child process.
|
||||
///
|
||||
/// The server binary is looked up in the following order:
|
||||
/// 1. Settings `server_path` if set
|
||||
/// 2. Bundled resource path
|
||||
/// 3. System PATH
|
||||
/// 3. Next to executable
|
||||
/// 4. System PATH
|
||||
#[tauri::command]
|
||||
pub async fn start_server(
|
||||
app: AppHandle,
|
||||
config: ServerConfig,
|
||||
state: State<'_, AppState>,
|
||||
) -> Result<ServerStartResult, String> {
|
||||
@@ -28,10 +84,10 @@ pub async fn start_server(
|
||||
}
|
||||
}
|
||||
|
||||
// Determine server binary path
|
||||
let server_path = config.server_path
|
||||
.clone()
|
||||
.unwrap_or_else(|| DEFAULT_SERVER_BIN.to_string());
|
||||
// Find server binary
|
||||
let server_path = find_server_binary(&app, config.server_path.as_deref())?;
|
||||
|
||||
tracing::info!("Starting sensing server from: {}", server_path);
|
||||
|
||||
// Build command with configuration
|
||||
let mut cmd = Command::new(&server_path);
|
||||
@@ -52,6 +108,10 @@ pub async fn start_server(
|
||||
cmd.args(["--log-level", log_level]);
|
||||
}
|
||||
|
||||
// Set data source (default to "simulate" if not specified for demo mode)
|
||||
let source = config.source.as_deref().unwrap_or("simulate");
|
||||
cmd.args(["--source", source]);
|
||||
|
||||
// Redirect stdout/stderr to pipes for monitoring
|
||||
cmd.stdout(Stdio::piped());
|
||||
cmd.stderr(Stdio::piped());
|
||||
@@ -207,6 +267,7 @@ pub async fn server_status(state: State<'_, AppState>) -> Result<ServerStatusRes
|
||||
/// Restart the sensing server with the same or new configuration.
|
||||
#[tauri::command]
|
||||
pub async fn restart_server(
|
||||
app: AppHandle,
|
||||
config: Option<ServerConfig>,
|
||||
state: State<'_, AppState>,
|
||||
) -> Result<ServerStartResult, String> {
|
||||
@@ -222,6 +283,7 @@ pub async fn restart_server(
|
||||
log_level: None,
|
||||
bind_address: None,
|
||||
server_path: None,
|
||||
source: None, // Use default (simulate)
|
||||
}
|
||||
};
|
||||
|
||||
@@ -232,7 +294,7 @@ pub async fn restart_server(
|
||||
tokio::time::sleep(std::time::Duration::from_millis(500)).await;
|
||||
|
||||
// Start with new config
|
||||
start_server(restart_config, state).await
|
||||
start_server(app, restart_config, state).await
|
||||
}
|
||||
|
||||
/// Get server logs (last N lines from stdout/stderr).
|
||||
@@ -260,6 +322,8 @@ pub struct ServerConfig {
|
||||
pub log_level: Option<String>,
|
||||
pub bind_address: Option<String>,
|
||||
pub server_path: Option<String>,
|
||||
/// Data source: "auto", "wifi", "esp32", "simulate"
|
||||
pub source: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"$schema": "https://raw.githubusercontent.com/tauri-apps/tauri/dev/crates/tauri-config-schema/schema.json",
|
||||
"productName": "RuView Desktop",
|
||||
"version": "0.4.1",
|
||||
"version": "0.4.2",
|
||||
"identifier": "net.ruv.ruview",
|
||||
"build": {
|
||||
"frontendDist": "ui/dist",
|
||||
@@ -30,6 +30,9 @@
|
||||
"icons/128x128@2x.png",
|
||||
"icons/icon.icns",
|
||||
"icons/icon.ico"
|
||||
]
|
||||
],
|
||||
"resources": {
|
||||
"../../target/release/sensing-server": "bin/sensing-server"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "ruview-desktop-ui",
|
||||
"private": true,
|
||||
"version": "0.4.1",
|
||||
"version": "0.4.2",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
|
||||
@@ -9,6 +9,7 @@ const DEFAULT_CONFIG: ServerConfig = {
|
||||
static_dir: null,
|
||||
model_dir: null,
|
||||
log_level: "info",
|
||||
source: "simulate",
|
||||
};
|
||||
|
||||
interface UseServerOptions {
|
||||
|
||||
+233
-62
@@ -17,34 +17,58 @@ interface LogEntry {
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Mock data generators
|
||||
// WebSocket message types from sensing server
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
const MOCK_LOG_TEMPLATES: { level: LogLevel; source: string; message: string }[] = [
|
||||
{ level: "INFO", source: "sensing-server", message: "HTTP listening on 127.0.0.1:8080" },
|
||||
{ level: "INFO", source: "udp_receiver", message: "CSI frame from 192.168.1.42" },
|
||||
{ level: "WARN", source: "vital_signs", message: "Low signal quality on node 2" },
|
||||
{ level: "INFO", source: "pose_engine", message: "Activity: walking (confidence: 0.87)" },
|
||||
{ level: "ERROR", source: "ws_session", message: "Client disconnected unexpectedly" },
|
||||
{ level: "INFO", source: "udp_receiver", message: "CSI frame from 192.168.1.15" },
|
||||
{ level: "INFO", source: "pose_engine", message: "Activity: sitting (confidence: 0.93)" },
|
||||
{ level: "INFO", source: "sensing-server", message: "WebSocket client connected from 127.0.0.1" },
|
||||
{ level: "WARN", source: "mesh_sync", message: "Node 4 heartbeat delayed by 1200ms" },
|
||||
{ level: "INFO", source: "pose_engine", message: "Activity: standing (confidence: 0.91)" },
|
||||
{ level: "INFO", source: "udp_receiver", message: "CSI frame from 192.168.1.78" },
|
||||
{ level: "ERROR", source: "udp_receiver", message: "Malformed CSI payload (len=0)" },
|
||||
{ level: "INFO", source: "csi_pipeline", message: "Subcarrier FFT complete (52 bins)" },
|
||||
{ level: "WARN", source: "vital_signs", message: "Breathing rate out of range on node 5" },
|
||||
{ level: "INFO", source: "pose_engine", message: "Activity: sleeping (confidence: 0.78)" },
|
||||
];
|
||||
interface WsNodeInfo {
|
||||
node_id: number;
|
||||
rssi_dbm: number;
|
||||
position: [number, number, number];
|
||||
amplitude: number[];
|
||||
subcarrier_count: number;
|
||||
}
|
||||
|
||||
const MOCK_ACTIVITIES = [
|
||||
{ activity: "walking", confidence: 0.87 },
|
||||
{ activity: "sitting", confidence: 0.93 },
|
||||
{ activity: "standing", confidence: 0.91 },
|
||||
{ activity: "sleeping", confidence: 0.78 },
|
||||
{ activity: "exercising", confidence: 0.65 },
|
||||
];
|
||||
interface WsClassification {
|
||||
motion_level: string;
|
||||
presence: boolean;
|
||||
confidence: number;
|
||||
}
|
||||
|
||||
interface WsFeatures {
|
||||
mean_rssi: number;
|
||||
variance: number;
|
||||
motion_band_power: number;
|
||||
breathing_band_power: number;
|
||||
dominant_freq_hz: number;
|
||||
change_points: number;
|
||||
spectral_power: number;
|
||||
}
|
||||
|
||||
interface WsVitalSigns {
|
||||
breathing_rate_hz?: number;
|
||||
heart_rate_bpm?: number;
|
||||
confidence?: number;
|
||||
}
|
||||
|
||||
interface WsSensingUpdate {
|
||||
type: string;
|
||||
timestamp: number;
|
||||
source: string;
|
||||
tick: number;
|
||||
nodes: WsNodeInfo[];
|
||||
features: WsFeatures;
|
||||
classification: WsClassification;
|
||||
vital_signs?: WsVitalSigns;
|
||||
posture?: string;
|
||||
signal_quality_score?: number;
|
||||
quality_verdict?: string;
|
||||
bssid_count?: number;
|
||||
estimated_persons?: number;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Helpers
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function formatTimestamp(d: Date): string {
|
||||
const hh = String(d.getHours()).padStart(2, "0");
|
||||
@@ -56,26 +80,71 @@ function formatTimestamp(d: Date): string {
|
||||
|
||||
let nextLogId = 1;
|
||||
|
||||
function createMockLogEntry(): LogEntry {
|
||||
const template = MOCK_LOG_TEMPLATES[Math.floor(Math.random() * MOCK_LOG_TEMPLATES.length)];
|
||||
return {
|
||||
id: nextLogId++,
|
||||
timestamp: formatTimestamp(new Date()),
|
||||
level: template.level,
|
||||
source: template.source,
|
||||
message: template.message,
|
||||
};
|
||||
function createLogFromWsUpdate(update: WsSensingUpdate): LogEntry[] {
|
||||
const entries: LogEntry[] = [];
|
||||
const ts = formatTimestamp(new Date(update.timestamp * 1000));
|
||||
|
||||
// Log each node's CSI data
|
||||
for (const node of update.nodes) {
|
||||
entries.push({
|
||||
id: nextLogId++,
|
||||
timestamp: ts,
|
||||
level: "INFO",
|
||||
source: "csi_receiver",
|
||||
message: `Node ${node.node_id}: RSSI ${node.rssi_dbm.toFixed(1)} dBm, ${node.subcarrier_count} subcarriers`,
|
||||
});
|
||||
}
|
||||
|
||||
// Log classification
|
||||
if (update.classification) {
|
||||
const level: LogLevel = update.classification.confidence < 0.5 ? "WARN" : "INFO";
|
||||
entries.push({
|
||||
id: nextLogId++,
|
||||
timestamp: ts,
|
||||
level,
|
||||
source: "classifier",
|
||||
message: `Motion: ${update.classification.motion_level} (presence=${update.classification.presence}, conf=${(update.classification.confidence * 100).toFixed(0)}%)`,
|
||||
});
|
||||
}
|
||||
|
||||
// Log vital signs if present
|
||||
if (update.vital_signs) {
|
||||
const vs = update.vital_signs;
|
||||
const level: LogLevel = (vs.confidence ?? 0) < 0.5 ? "WARN" : "INFO";
|
||||
entries.push({
|
||||
id: nextLogId++,
|
||||
timestamp: ts,
|
||||
level,
|
||||
source: "vital_signs",
|
||||
message: `Breathing: ${vs.breathing_rate_hz?.toFixed(2) ?? "--"} Hz, HR: ${vs.heart_rate_bpm?.toFixed(0) ?? "--"} bpm`,
|
||||
});
|
||||
}
|
||||
|
||||
// Log quality verdict if present
|
||||
if (update.quality_verdict && update.quality_verdict !== "Permit") {
|
||||
entries.push({
|
||||
id: nextLogId++,
|
||||
timestamp: ts,
|
||||
level: update.quality_verdict === "Deny" ? "ERROR" : "WARN",
|
||||
source: "quality_gate",
|
||||
message: `Signal quality: ${update.quality_verdict} (score=${(update.signal_quality_score ?? 0).toFixed(2)})`,
|
||||
});
|
||||
}
|
||||
|
||||
return entries;
|
||||
}
|
||||
|
||||
function createMockSensingUpdate(): SensingUpdate {
|
||||
const act = MOCK_ACTIVITIES[Math.floor(Math.random() * MOCK_ACTIVITIES.length)];
|
||||
function createActivityFromWsUpdate(update: WsSensingUpdate): SensingUpdate | null {
|
||||
if (!update.classification) return null;
|
||||
|
||||
const node = update.nodes[0];
|
||||
return {
|
||||
timestamp: new Date().toISOString(),
|
||||
node_id: Math.floor(Math.random() * 6) + 1,
|
||||
subcarrier_count: 52,
|
||||
rssi: -(Math.floor(Math.random() * 40) + 30),
|
||||
activity: act.activity,
|
||||
confidence: parseFloat((act.confidence + (Math.random() * 0.1 - 0.05)).toFixed(2)),
|
||||
timestamp: new Date(update.timestamp * 1000).toISOString(),
|
||||
node_id: node?.node_id ?? 1,
|
||||
subcarrier_count: node?.subcarrier_count ?? 52,
|
||||
rssi: node?.rssi_dbm ?? -50,
|
||||
activity: update.posture ?? update.classification.motion_level,
|
||||
confidence: update.classification.confidence,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -84,7 +153,7 @@ function createMockSensingUpdate(): SensingUpdate {
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
const MAX_LOG_ENTRIES = 200;
|
||||
const LOG_INTERVAL_MS = 2000;
|
||||
const WS_RECONNECT_DELAY_MS = 3000;
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// LogViewer component (ADR-053)
|
||||
@@ -241,28 +310,119 @@ export const Sensing: React.FC = () => {
|
||||
// Activity feed state
|
||||
const [activities, setActivities] = useState<SensingUpdate[]>([]);
|
||||
|
||||
// Simulated log feed
|
||||
// WebSocket connection state
|
||||
const [wsConnected, setWsConnected] = useState(false);
|
||||
const wsRef = useRef<WebSocket | null>(null);
|
||||
const reconnectTimeoutRef = useRef<number | null>(null);
|
||||
|
||||
// Connect to real WebSocket when server is running
|
||||
useEffect(() => {
|
||||
const interval = setInterval(() => {
|
||||
if (pausedRef.current) return;
|
||||
const entry = createMockLogEntry();
|
||||
setLogEntries((prev) => {
|
||||
const next = [...prev, entry];
|
||||
return next.length > MAX_LOG_ENTRIES ? next.slice(next.length - MAX_LOG_ENTRIES) : next;
|
||||
});
|
||||
|
||||
// Also push an activity update every ~3rd tick
|
||||
if (Math.random() < 0.35) {
|
||||
setActivities((prev) => {
|
||||
const update = createMockSensingUpdate();
|
||||
const next = [update, ...prev];
|
||||
return next.slice(0, 5);
|
||||
});
|
||||
if (!isRunning || !status?.ws_port) {
|
||||
// Server not running, disconnect if connected
|
||||
if (wsRef.current) {
|
||||
wsRef.current.close();
|
||||
wsRef.current = null;
|
||||
setWsConnected(false);
|
||||
}
|
||||
}, LOG_INTERVAL_MS);
|
||||
return;
|
||||
}
|
||||
|
||||
return () => clearInterval(interval);
|
||||
}, []);
|
||||
const connect = () => {
|
||||
const wsUrl = `ws://127.0.0.1:${status.ws_port}/ws/sensing`;
|
||||
const ws = new WebSocket(wsUrl);
|
||||
|
||||
ws.onopen = () => {
|
||||
setWsConnected(true);
|
||||
setLogEntries((prev) => [
|
||||
...prev,
|
||||
{
|
||||
id: nextLogId++,
|
||||
timestamp: formatTimestamp(new Date()),
|
||||
level: "INFO",
|
||||
source: "desktop",
|
||||
message: `WebSocket connected to ${wsUrl}`,
|
||||
},
|
||||
]);
|
||||
};
|
||||
|
||||
ws.onmessage = (event) => {
|
||||
if (pausedRef.current) return;
|
||||
|
||||
try {
|
||||
const update = JSON.parse(event.data) as WsSensingUpdate;
|
||||
|
||||
// Create log entries from the update
|
||||
const entries = createLogFromWsUpdate(update);
|
||||
if (entries.length > 0) {
|
||||
setLogEntries((prev) => {
|
||||
const next = [...prev, ...entries];
|
||||
return next.length > MAX_LOG_ENTRIES ? next.slice(next.length - MAX_LOG_ENTRIES) : next;
|
||||
});
|
||||
}
|
||||
|
||||
// Create activity update
|
||||
const activity = createActivityFromWsUpdate(update);
|
||||
if (activity) {
|
||||
setActivities((prev) => {
|
||||
const next = [activity, ...prev];
|
||||
return next.slice(0, 5);
|
||||
});
|
||||
}
|
||||
} catch (err) {
|
||||
console.error("Failed to parse WebSocket message:", err);
|
||||
}
|
||||
};
|
||||
|
||||
ws.onclose = () => {
|
||||
setWsConnected(false);
|
||||
wsRef.current = null;
|
||||
|
||||
// Only add disconnect log if server is still supposed to be running
|
||||
if (isRunning) {
|
||||
setLogEntries((prev) => [
|
||||
...prev,
|
||||
{
|
||||
id: nextLogId++,
|
||||
timestamp: formatTimestamp(new Date()),
|
||||
level: "WARN",
|
||||
source: "desktop",
|
||||
message: "WebSocket disconnected, reconnecting...",
|
||||
},
|
||||
]);
|
||||
|
||||
// Attempt reconnect
|
||||
reconnectTimeoutRef.current = window.setTimeout(connect, WS_RECONNECT_DELAY_MS);
|
||||
}
|
||||
};
|
||||
|
||||
ws.onerror = () => {
|
||||
setLogEntries((prev) => [
|
||||
...prev,
|
||||
{
|
||||
id: nextLogId++,
|
||||
timestamp: formatTimestamp(new Date()),
|
||||
level: "ERROR",
|
||||
source: "desktop",
|
||||
message: "WebSocket connection error",
|
||||
},
|
||||
]);
|
||||
};
|
||||
|
||||
wsRef.current = ws;
|
||||
};
|
||||
|
||||
connect();
|
||||
|
||||
return () => {
|
||||
if (reconnectTimeoutRef.current) {
|
||||
clearTimeout(reconnectTimeoutRef.current);
|
||||
}
|
||||
if (wsRef.current) {
|
||||
wsRef.current.close();
|
||||
wsRef.current = null;
|
||||
}
|
||||
};
|
||||
}, [isRunning, status?.ws_port]);
|
||||
|
||||
const handleClearLog = useCallback(() => setLogEntries([]), []);
|
||||
const handleTogglePause = useCallback(() => setPaused((p) => !p), []);
|
||||
@@ -349,6 +509,17 @@ export const Sensing: React.FC = () => {
|
||||
{status.pid != null && <span>PID {status.pid}</span>}
|
||||
{status.http_port != null && <span>HTTP :{status.http_port}</span>}
|
||||
{status.ws_port != null && <span>WS :{status.ws_port}</span>}
|
||||
<span style={{ display: "flex", alignItems: "center", gap: 4 }}>
|
||||
<span
|
||||
style={{
|
||||
width: 6,
|
||||
height: 6,
|
||||
borderRadius: "50%",
|
||||
background: wsConnected ? "var(--status-online)" : "var(--status-warning)",
|
||||
}}
|
||||
/>
|
||||
{wsConnected ? "Live" : "Connecting..."}
|
||||
</span>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
@@ -170,6 +170,8 @@ export interface WasmModule {
|
||||
// Sensing Server
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
export type DataSource = "auto" | "wifi" | "esp32" | "simulate";
|
||||
|
||||
export interface ServerConfig {
|
||||
http_port: number;
|
||||
ws_port: number;
|
||||
@@ -177,6 +179,7 @@ export interface ServerConfig {
|
||||
static_dir: string | null;
|
||||
model_dir: string | null;
|
||||
log_level: string;
|
||||
source: DataSource;
|
||||
}
|
||||
|
||||
export interface ServerStatus {
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
// Application version - single source of truth
|
||||
export const APP_VERSION = "0.4.1";
|
||||
export const APP_VERSION = "0.4.2";
|
||||
|
||||
Reference in New Issue
Block a user