mirror of
https://github.com/ruvnet/RuView
synced 2026-06-10 10:23:19 +00:00
Compare commits
20 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 0223ef6d2e | |||
| 2f5e7ffb41 | |||
| 4ce8ffc465 | |||
| 3be63a7589 | |||
| c4e640c812 | |||
| 6e03a47867 | |||
| 9d1140de2d | |||
| 952f27a1ce | |||
| f7d043d727 | |||
| ff91d4e8cf | |||
| fc92436f52 | |||
| 285bb0ad37 | |||
| b5ec4ef043 | |||
| 21aba2df8d | |||
| a28a875594 | |||
| e12749bf68 | |||
| 3b37aaf460 | |||
| d3c683cc7e | |||
| 56de77c0ad | |||
| 0b98917dff |
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"running": true,
|
||||
"startedAt": "2026-02-28T15:54:19.353Z",
|
||||
"startedAt": "2026-03-09T15:26:00.921Z",
|
||||
"workers": {
|
||||
"map": {
|
||||
"runCount": 49,
|
||||
@@ -8,16 +8,16 @@
|
||||
"failureCount": 0,
|
||||
"averageDurationMs": 1.2857142857142858,
|
||||
"lastRun": "2026-02-28T16:13:19.194Z",
|
||||
"nextRun": "2026-02-28T16:28:19.195Z",
|
||||
"nextRun": "2026-03-09T15:56:00.928Z",
|
||||
"isRunning": false
|
||||
},
|
||||
"audit": {
|
||||
"runCount": 44,
|
||||
"runCount": 45,
|
||||
"successCount": 0,
|
||||
"failureCount": 44,
|
||||
"failureCount": 45,
|
||||
"averageDurationMs": 0,
|
||||
"lastRun": "2026-02-28T16:20:19.184Z",
|
||||
"nextRun": "2026-02-28T16:30:19.185Z",
|
||||
"lastRun": "2026-03-09T15:43:00.933Z",
|
||||
"nextRun": "2026-03-09T15:38:00.914Z",
|
||||
"isRunning": false
|
||||
},
|
||||
"optimize": {
|
||||
@@ -26,7 +26,7 @@
|
||||
"failureCount": 34,
|
||||
"averageDurationMs": 0,
|
||||
"lastRun": "2026-02-28T16:23:19.387Z",
|
||||
"nextRun": "2026-02-28T16:18:19.361Z",
|
||||
"nextRun": "2026-03-09T15:45:00.915Z",
|
||||
"isRunning": false
|
||||
},
|
||||
"consolidate": {
|
||||
@@ -35,7 +35,7 @@
|
||||
"failureCount": 0,
|
||||
"averageDurationMs": 0.6521739130434783,
|
||||
"lastRun": "2026-02-28T16:05:19.091Z",
|
||||
"nextRun": "2026-02-28T16:35:19.054Z",
|
||||
"nextRun": "2026-03-09T16:02:00.918Z",
|
||||
"isRunning": false
|
||||
},
|
||||
"testgaps": {
|
||||
@@ -44,8 +44,8 @@
|
||||
"failureCount": 27,
|
||||
"averageDurationMs": 0,
|
||||
"lastRun": "2026-02-28T16:08:19.369Z",
|
||||
"nextRun": "2026-02-28T16:22:19.355Z",
|
||||
"isRunning": true
|
||||
"nextRun": "2026-03-09T15:54:00.920Z",
|
||||
"isRunning": false
|
||||
},
|
||||
"predict": {
|
||||
"runCount": 0,
|
||||
@@ -64,8 +64,8 @@
|
||||
},
|
||||
"config": {
|
||||
"autoStart": false,
|
||||
"logDir": "/home/user/wifi-densepose/.claude-flow/logs",
|
||||
"stateFile": "/home/user/wifi-densepose/.claude-flow/daemon-state.json",
|
||||
"logDir": "/Users/cohen/GitHub/ruvnet/RuView/.claude-flow/logs",
|
||||
"stateFile": "/Users/cohen/GitHub/ruvnet/RuView/.claude-flow/daemon-state.json",
|
||||
"maxConcurrent": 2,
|
||||
"workerTimeoutMs": 300000,
|
||||
"resourceThresholds": {
|
||||
@@ -131,5 +131,5 @@
|
||||
}
|
||||
]
|
||||
},
|
||||
"savedAt": "2026-02-28T16:23:19.387Z"
|
||||
"savedAt": "2026-03-09T15:43:00.933Z"
|
||||
}
|
||||
@@ -1 +1 @@
|
||||
54612
|
||||
31273
|
||||
+13
-13
@@ -6,7 +6,7 @@
|
||||
"hooks": [
|
||||
{
|
||||
"type": "command",
|
||||
"command": "node .claude/helpers/hook-handler.cjs pre-bash",
|
||||
"command": "node \"$CLAUDE_PROJECT_DIR/.claude/helpers/hook-handler.cjs\" pre-bash",
|
||||
"timeout": 5000
|
||||
}
|
||||
]
|
||||
@@ -18,7 +18,7 @@
|
||||
"hooks": [
|
||||
{
|
||||
"type": "command",
|
||||
"command": "node .claude/helpers/hook-handler.cjs post-edit",
|
||||
"command": "node \"$CLAUDE_PROJECT_DIR/.claude/helpers/hook-handler.cjs\" post-edit",
|
||||
"timeout": 10000
|
||||
}
|
||||
]
|
||||
@@ -29,7 +29,7 @@
|
||||
"hooks": [
|
||||
{
|
||||
"type": "command",
|
||||
"command": "node .claude/helpers/hook-handler.cjs route",
|
||||
"command": "node \"$CLAUDE_PROJECT_DIR/.claude/helpers/hook-handler.cjs\" route",
|
||||
"timeout": 10000
|
||||
}
|
||||
]
|
||||
@@ -40,12 +40,12 @@
|
||||
"hooks": [
|
||||
{
|
||||
"type": "command",
|
||||
"command": "node .claude/helpers/hook-handler.cjs session-restore",
|
||||
"command": "node \"$CLAUDE_PROJECT_DIR/.claude/helpers/hook-handler.cjs\" session-restore",
|
||||
"timeout": 15000
|
||||
},
|
||||
{
|
||||
"type": "command",
|
||||
"command": "node .claude/helpers/auto-memory-hook.mjs import",
|
||||
"command": "node \"$CLAUDE_PROJECT_DIR/.claude/helpers/auto-memory-hook.mjs\" import",
|
||||
"timeout": 8000
|
||||
}
|
||||
]
|
||||
@@ -56,7 +56,7 @@
|
||||
"hooks": [
|
||||
{
|
||||
"type": "command",
|
||||
"command": "node .claude/helpers/hook-handler.cjs session-end",
|
||||
"command": "node \"$CLAUDE_PROJECT_DIR/.claude/helpers/hook-handler.cjs\" session-end",
|
||||
"timeout": 10000
|
||||
}
|
||||
]
|
||||
@@ -67,7 +67,7 @@
|
||||
"hooks": [
|
||||
{
|
||||
"type": "command",
|
||||
"command": "node .claude/helpers/auto-memory-hook.mjs sync",
|
||||
"command": "node \"$CLAUDE_PROJECT_DIR/.claude/helpers/auto-memory-hook.mjs\" sync",
|
||||
"timeout": 10000
|
||||
}
|
||||
]
|
||||
@@ -79,11 +79,11 @@
|
||||
"hooks": [
|
||||
{
|
||||
"type": "command",
|
||||
"command": "node .claude/helpers/hook-handler.cjs compact-manual"
|
||||
"command": "node \"$CLAUDE_PROJECT_DIR/.claude/helpers/hook-handler.cjs\" compact-manual"
|
||||
},
|
||||
{
|
||||
"type": "command",
|
||||
"command": "node .claude/helpers/hook-handler.cjs session-end",
|
||||
"command": "node \"$CLAUDE_PROJECT_DIR/.claude/helpers/hook-handler.cjs\" session-end",
|
||||
"timeout": 5000
|
||||
}
|
||||
]
|
||||
@@ -93,11 +93,11 @@
|
||||
"hooks": [
|
||||
{
|
||||
"type": "command",
|
||||
"command": "node .claude/helpers/hook-handler.cjs compact-auto"
|
||||
"command": "node \"$CLAUDE_PROJECT_DIR/.claude/helpers/hook-handler.cjs\" compact-auto"
|
||||
},
|
||||
{
|
||||
"type": "command",
|
||||
"command": "node .claude/helpers/hook-handler.cjs session-end",
|
||||
"command": "node \"$CLAUDE_PROJECT_DIR/.claude/helpers/hook-handler.cjs\" session-end",
|
||||
"timeout": 6000
|
||||
}
|
||||
]
|
||||
@@ -108,7 +108,7 @@
|
||||
"hooks": [
|
||||
{
|
||||
"type": "command",
|
||||
"command": "node .claude/helpers/hook-handler.cjs status",
|
||||
"command": "node \"$CLAUDE_PROJECT_DIR/.claude/helpers/hook-handler.cjs\" status",
|
||||
"timeout": 3000
|
||||
}
|
||||
]
|
||||
@@ -117,7 +117,7 @@
|
||||
},
|
||||
"statusLine": {
|
||||
"type": "command",
|
||||
"command": "node .claude/helpers/statusline.cjs"
|
||||
"command": "node \"$CLAUDE_PROJECT_DIR/.claude/helpers/statusline.cjs\""
|
||||
},
|
||||
"permissions": {
|
||||
"allow": [
|
||||
|
||||
@@ -7,9 +7,13 @@ on:
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
version:
|
||||
description: 'Version to release (e.g., 0.3.0)'
|
||||
description: 'Version to release (e.g., 0.4.0)'
|
||||
required: true
|
||||
default: '0.3.0'
|
||||
default: '0.4.0'
|
||||
attach_to_existing:
|
||||
description: 'Attach to existing release tag (leave empty to create new)'
|
||||
required: false
|
||||
default: ''
|
||||
|
||||
env:
|
||||
CARGO_TERM_COLOR: always
|
||||
@@ -65,7 +69,7 @@ jobs:
|
||||
- name: Package macOS app
|
||||
run: |
|
||||
cd rust-port/wifi-densepose-rs/target/${{ matrix.target }}/release/bundle/macos
|
||||
zip -r "RuView-Desktop-${{ github.event.inputs.version || '0.3.0' }}-macos-${{ steps.arch.outputs.arch }}.zip" "RuView Desktop.app"
|
||||
zip -r "RuView-Desktop-${{ github.event.inputs.version || '0.4.0' }}-macos-${{ steps.arch.outputs.arch }}.zip" "RuView Desktop.app"
|
||||
|
||||
- name: Upload macOS artifact
|
||||
uses: actions/upload-artifact@v4
|
||||
@@ -136,21 +140,21 @@ jobs:
|
||||
- name: List artifacts
|
||||
run: find artifacts -type f
|
||||
|
||||
- name: Create Release
|
||||
- name: Create or Update Release
|
||||
uses: softprops/action-gh-release@v2
|
||||
with:
|
||||
name: RuView Desktop v${{ github.event.inputs.version || '0.3.0' }}
|
||||
tag_name: desktop-v${{ github.event.inputs.version || '0.3.0' }}
|
||||
name: RuView Desktop v${{ github.event.inputs.version || '0.4.0' }}
|
||||
tag_name: ${{ github.event.inputs.attach_to_existing || format('desktop-v{0}', github.event.inputs.version || '0.4.0') }}
|
||||
draft: false
|
||||
prerelease: false
|
||||
generate_release_notes: true
|
||||
generate_release_notes: ${{ github.event.inputs.attach_to_existing == '' }}
|
||||
files: |
|
||||
artifacts/**/*.zip
|
||||
artifacts/**/*.msi
|
||||
artifacts/**/*.exe
|
||||
artifacts/**/*.dmg
|
||||
body: |
|
||||
## RuView Desktop v${{ github.event.inputs.version || '0.3.0' }}
|
||||
## RuView Desktop v${{ github.event.inputs.version || '0.4.0' }}
|
||||
|
||||
WiFi-based human pose estimation desktop application.
|
||||
|
||||
|
||||
@@ -75,7 +75,7 @@ docker run -p 3000:3000 ruvnet/wifi-densepose:latest
|
||||
|----------|-------------|
|
||||
| [User Guide](docs/user-guide.md) | Step-by-step guide: installation, first run, API usage, hardware setup, training |
|
||||
| [Build Guide](docs/build-guide.md) | Building from source (Rust and Python) |
|
||||
| [Architecture Decisions](docs/adr/README.md) | 48 ADRs — why each technical choice was made, organized by domain (hardware, signal processing, ML, platform, infrastructure) |
|
||||
| [Architecture Decisions](docs/adr/README.md) | 49 ADRs — why each technical choice was made, organized by domain (hardware, signal processing, ML, platform, infrastructure) |
|
||||
| [Domain Models](docs/ddd/README.md) | 7 DDD models (RuvSense, Signal Processing, Training Pipeline, Hardware Platform, Sensing Server, WiFi-Mat, CHCI) — bounded contexts, aggregates, domain events, and ubiquitous language |
|
||||
| [Desktop App](rust-port/wifi-densepose-rs/crates/wifi-densepose-desktop/README.md) | **WIP** — Tauri v2 desktop app for node management, OTA updates, WASM deployment, and mesh visualization |
|
||||
|
||||
@@ -89,8 +89,12 @@ docker run -p 3000:3000 ruvnet/wifi-densepose:latest
|
||||
<em>Real-time pose skeleton from WiFi CSI signals — no cameras, no wearables</em>
|
||||
<br>
|
||||
<a href="https://ruvnet.github.io/RuView/"><strong>▶ Live Observatory Demo</strong></a>
|
||||
|
|
||||
<a href="https://ruvnet.github.io/RuView/pose-fusion.html"><strong>▶ Dual-Modal Pose Fusion Demo</strong></a>
|
||||
|
||||
> The [server](#-quick-start) is optional for visualization and aggregation — the ESP32 [runs independently](#esp32-s3-hardware-pipeline) for presence detection, vital signs, and fall alerts.
|
||||
>
|
||||
> **Live ESP32 pipeline**: Connect an ESP32-S3 node → run the [sensing server](#sensing-server) → open the [pose fusion demo](https://ruvnet.github.io/RuView/pose-fusion.html) for real-time dual-modal pose estimation (webcam + WiFi CSI). See [ADR-059](docs/adr/ADR-059-live-esp32-csi-pipeline.md).
|
||||
|
||||
|
||||
## 🚀 Key Features
|
||||
@@ -1043,14 +1047,16 @@ Download a pre-built binary — no build toolchain needed:
|
||||
|
||||
| Release | What's included | Tag |
|
||||
|---------|-----------------|-----|
|
||||
| [v0.2.0](https://github.com/ruvnet/RuView/releases/tag/v0.2.0-esp32) | Stable — raw CSI streaming, multi-node TDM, channel hopping | `v0.2.0-esp32` |
|
||||
| [v0.4.1](https://github.com/ruvnet/RuView/releases/tag/v0.4.1-esp32) | **Stable** — CSI build fix, compile guard, AMOLED display, edge intelligence ([ADR-057](docs/adr/ADR-057-firmware-csi-build-guard.md)) | `v0.4.1-esp32` |
|
||||
| [v0.3.0-alpha](https://github.com/ruvnet/RuView/releases/tag/v0.3.0-alpha-esp32) | Alpha — adds on-device edge intelligence and WASM modules ([ADR-039](docs/adr/ADR-039-esp32-edge-intelligence.md), [ADR-040](docs/adr/ADR-040-wasm-programmable-sensing.md)) | `v0.3.0-alpha-esp32` |
|
||||
| [v0.2.0](https://github.com/ruvnet/RuView/releases/tag/v0.2.0-esp32) | Raw CSI streaming, multi-node TDM, channel hopping | `v0.2.0-esp32` |
|
||||
|
||||
```bash
|
||||
# 1. Flash the firmware to your ESP32-S3
|
||||
python -m esptool --chip esp32s3 --port COM7 --baud 460800 \
|
||||
write_flash --flash_mode dio --flash_size 8MB \
|
||||
0x0 bootloader.bin 0x8000 partition-table.bin 0x10000 esp32-csi-node.bin
|
||||
write_flash --flash-mode dio --flash-size 8MB --flash-freq 80m \
|
||||
0x0 bootloader.bin 0x8000 partition-table.bin \
|
||||
0xf000 ota_data_initial.bin 0x20000 esp32-csi-node.bin
|
||||
|
||||
# 2. Set WiFi credentials and server address (stored in flash, survives reboots)
|
||||
python firmware/esp32-csi-node/provision.py --port COM7 \
|
||||
|
||||
@@ -0,0 +1,699 @@
|
||||
# ADR-054: RuView Desktop Full Implementation
|
||||
|
||||
## Status
|
||||
**Accepted** — Implementation in progress
|
||||
|
||||
## Context
|
||||
|
||||
RuView Desktop v0.3.0 shipped with a complete React/TypeScript frontend but stub-only Rust backend commands. Users report:
|
||||
- Settings cannot be saved (#206) ✅ Fixed in PR #209
|
||||
- Flash firmware does nothing
|
||||
- OTA updates are non-functional
|
||||
- Node discovery returns hardcoded data
|
||||
- Server start/stop is cosmetic only
|
||||
|
||||
This ADR defines the complete implementation plan to make all desktop features production-ready with proper security, optimization, and error handling.
|
||||
|
||||
## Decision
|
||||
|
||||
Implement all 14 Tauri commands with full functionality, security hardening, and performance optimization.
|
||||
|
||||
---
|
||||
|
||||
## 1. Command Implementation Matrix
|
||||
|
||||
| Module | Command | Current | Target | Priority | Security |
|
||||
|--------|---------|---------|--------|----------|----------|
|
||||
| **Settings** | `get_settings` | ✅ Done | ✅ Done | P0 | File permissions |
|
||||
| | `save_settings` | ✅ Done | ✅ Done | P0 | Input validation |
|
||||
| **Discovery** | `discover_nodes` | Stub | Full mDNS + UDP | P1 | Network boundary |
|
||||
| | `list_serial_ports` | Stub | Real enumeration | P1 | USB device access |
|
||||
| **Flash** | `flash_firmware` | Stub | espflash integration | P1 | Binary validation |
|
||||
| | `flash_progress` | Stub | Event streaming | P1 | Progress channel |
|
||||
| **OTA** | `ota_update` | Stub | HTTP multipart + PSK | P1 | TLS + PSK auth |
|
||||
| | `batch_ota_update` | Stub | Parallel with backoff | P2 | Rate limiting |
|
||||
| **WASM** | `wasm_list` | Stub | HTTP GET /api/wasm | P2 | Response validation |
|
||||
| | `wasm_upload` | Stub | HTTP POST multipart | P2 | Size limits, signing |
|
||||
| | `wasm_control` | Stub | HTTP POST commands | P2 | Action whitelist |
|
||||
| **Server** | `start_server` | Partial | Child process spawn | P1 | Port validation |
|
||||
| | `stop_server` | Partial | Graceful shutdown | P1 | PID verification |
|
||||
| | `server_status` | Partial | Health check | P1 | Timeout handling |
|
||||
| **Provision** | `provision_node` | Stub | NVS binary write | P2 | Serial validation |
|
||||
| | `read_nvs` | Stub | NVS binary read | P2 | Parse validation |
|
||||
|
||||
---
|
||||
|
||||
## 2. Implementation Details
|
||||
|
||||
### 2.1 Discovery Module
|
||||
|
||||
**Dependencies:**
|
||||
```toml
|
||||
mdns-sd = "0.11"
|
||||
serialport = "4.6"
|
||||
tokio = { version = "1", features = ["net", "time"] }
|
||||
```
|
||||
|
||||
**discover_nodes Implementation:**
|
||||
```rust
|
||||
pub async fn discover_nodes(timeout_ms: Option<u64>) -> Result<Vec<DiscoveredNode>, String> {
|
||||
let timeout = Duration::from_millis(timeout_ms.unwrap_or(3000));
|
||||
let mut nodes = Vec::new();
|
||||
|
||||
// 1. mDNS discovery (_ruview._tcp.local)
|
||||
let mdns = ServiceDaemon::new()?;
|
||||
let receiver = mdns.browse("_ruview._tcp.local.")?;
|
||||
|
||||
// 2. UDP broadcast probe (port 5005)
|
||||
let socket = UdpSocket::bind("0.0.0.0:0").await?;
|
||||
socket.set_broadcast(true)?;
|
||||
socket.send_to(b"RUVIEW_DISCOVER", "255.255.255.255:5005").await?;
|
||||
|
||||
// 3. Collect responses with timeout
|
||||
tokio::select! {
|
||||
_ = collect_mdns(&receiver, &mut nodes) => {},
|
||||
_ = collect_udp(&socket, &mut nodes) => {},
|
||||
_ = tokio::time::sleep(timeout) => {},
|
||||
}
|
||||
|
||||
Ok(nodes)
|
||||
}
|
||||
```
|
||||
|
||||
**list_serial_ports Implementation:**
|
||||
```rust
|
||||
pub async fn list_serial_ports() -> Result<Vec<SerialPortInfo>, String> {
|
||||
let ports = serialport::available_ports()
|
||||
.map_err(|e| format!("Failed to enumerate ports: {}", e))?;
|
||||
|
||||
Ok(ports.into_iter().map(|p| SerialPortInfo {
|
||||
name: p.port_name,
|
||||
vid: extract_vid(&p.port_type),
|
||||
pid: extract_pid(&p.port_type),
|
||||
manufacturer: extract_manufacturer(&p.port_type),
|
||||
chip: detect_esp_chip(&p.port_type),
|
||||
}).collect())
|
||||
}
|
||||
```
|
||||
|
||||
### 2.2 Flash Module
|
||||
|
||||
**Dependencies:**
|
||||
```toml
|
||||
espflash = "4.0"
|
||||
tokio = { version = "1", features = ["sync"] }
|
||||
```
|
||||
|
||||
**flash_firmware Implementation:**
|
||||
```rust
|
||||
pub async fn flash_firmware(
|
||||
port: String,
|
||||
firmware_path: String,
|
||||
chip: Option<String>,
|
||||
baud: Option<u32>,
|
||||
app: AppHandle,
|
||||
) -> Result<FlashResult, String> {
|
||||
// 1. Validate firmware binary
|
||||
let firmware = std::fs::read(&firmware_path)
|
||||
.map_err(|e| format!("Cannot read firmware: {}", e))?;
|
||||
validate_esp_binary(&firmware)?;
|
||||
|
||||
// 2. Open serial connection
|
||||
let serial = serialport::new(&port, baud.unwrap_or(460800))
|
||||
.timeout(Duration::from_secs(30))
|
||||
.open()
|
||||
.map_err(|e| format!("Cannot open {}: {}", port, e))?;
|
||||
|
||||
// 3. Connect to ESP bootloader
|
||||
let mut flasher = Flasher::connect(serial, None, None)?;
|
||||
|
||||
// 4. Flash with progress callback
|
||||
let start = Instant::now();
|
||||
flasher.write_bin_to_flash(
|
||||
0x0,
|
||||
&firmware,
|
||||
Some(&mut |current, total| {
|
||||
let _ = app.emit("flash_progress", FlashProgress {
|
||||
phase: "writing".into(),
|
||||
progress_pct: (current as f32 / total as f32) * 100.0,
|
||||
bytes_written: current as u64,
|
||||
bytes_total: total as u64,
|
||||
});
|
||||
}),
|
||||
)?;
|
||||
|
||||
Ok(FlashResult {
|
||||
success: true,
|
||||
message: "Flash complete".into(),
|
||||
duration_secs: start.elapsed().as_secs_f64(),
|
||||
})
|
||||
}
|
||||
```
|
||||
|
||||
### 2.3 OTA Module
|
||||
|
||||
**Dependencies:**
|
||||
```toml
|
||||
reqwest = { version = "0.12", features = ["multipart", "rustls-tls"] }
|
||||
sha2 = "0.10"
|
||||
```
|
||||
|
||||
**ota_update Implementation:**
|
||||
```rust
|
||||
pub async fn ota_update(
|
||||
node_ip: String,
|
||||
firmware_path: String,
|
||||
psk: Option<String>,
|
||||
) -> Result<OtaResult, String> {
|
||||
// 1. Validate IP format
|
||||
let ip: IpAddr = node_ip.parse()
|
||||
.map_err(|_| "Invalid IP address")?;
|
||||
|
||||
// 2. Read and hash firmware
|
||||
let firmware = tokio::fs::read(&firmware_path).await
|
||||
.map_err(|e| format!("Cannot read firmware: {}", e))?;
|
||||
let hash = Sha256::digest(&firmware);
|
||||
|
||||
// 3. Build multipart request
|
||||
let client = reqwest::Client::builder()
|
||||
.timeout(Duration::from_secs(120))
|
||||
.build()?;
|
||||
|
||||
let form = multipart::Form::new()
|
||||
.part("firmware", multipart::Part::bytes(firmware)
|
||||
.file_name("firmware.bin")
|
||||
.mime_str("application/octet-stream")?);
|
||||
|
||||
// 4. Send with PSK auth header
|
||||
let mut req = client.post(format!("http://{}:8032/ota", ip))
|
||||
.multipart(form);
|
||||
|
||||
if let Some(key) = psk {
|
||||
req = req.header("X-OTA-PSK", key);
|
||||
}
|
||||
|
||||
let resp = req.send().await
|
||||
.map_err(|e| format!("OTA request failed: {}", e))?;
|
||||
|
||||
if resp.status().is_success() {
|
||||
Ok(OtaResult {
|
||||
success: true,
|
||||
node_ip: node_ip.clone(),
|
||||
message: "OTA update initiated".into(),
|
||||
})
|
||||
} else {
|
||||
Err(format!("OTA failed: {}", resp.status()))
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
**batch_ota_update Implementation:**
|
||||
```rust
|
||||
pub async fn batch_ota_update(
|
||||
node_ips: Vec<String>,
|
||||
firmware_path: String,
|
||||
psk: Option<String>,
|
||||
strategy: Option<String>,
|
||||
) -> Result<Vec<OtaResult>, String> {
|
||||
let firmware = Arc::new(tokio::fs::read(&firmware_path).await?);
|
||||
let psk = Arc::new(psk);
|
||||
|
||||
let strategy = strategy.unwrap_or("sequential".into());
|
||||
|
||||
match strategy.as_str() {
|
||||
"parallel" => {
|
||||
// All at once (max 4 concurrent)
|
||||
let semaphore = Arc::new(Semaphore::new(4));
|
||||
let handles: Vec<_> = node_ips.into_iter().map(|ip| {
|
||||
let fw = firmware.clone();
|
||||
let key = psk.clone();
|
||||
let sem = semaphore.clone();
|
||||
tokio::spawn(async move {
|
||||
let _permit = sem.acquire().await;
|
||||
ota_single(&ip, &fw, key.as_ref().as_ref()).await
|
||||
})
|
||||
}).collect();
|
||||
|
||||
let results = futures::future::join_all(handles).await;
|
||||
Ok(results.into_iter().filter_map(|r| r.ok()).collect())
|
||||
}
|
||||
"tdm_safe" => {
|
||||
// One per TDM slot group with delays
|
||||
let mut results = Vec::new();
|
||||
for ip in node_ips {
|
||||
results.push(ota_single(&ip, &firmware, psk.as_ref().as_ref()).await);
|
||||
tokio::time::sleep(Duration::from_secs(5)).await;
|
||||
}
|
||||
Ok(results)
|
||||
}
|
||||
_ => {
|
||||
// Sequential (default)
|
||||
let mut results = Vec::new();
|
||||
for ip in node_ips {
|
||||
results.push(ota_single(&ip, &firmware, psk.as_ref().as_ref()).await);
|
||||
}
|
||||
Ok(results)
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 2.4 Server Module
|
||||
|
||||
**Dependencies:**
|
||||
```toml
|
||||
tokio = { version = "1", features = ["process"] }
|
||||
sysinfo = "0.32"
|
||||
```
|
||||
|
||||
**start_server Implementation:**
|
||||
```rust
|
||||
pub async fn start_server(
|
||||
config: ServerConfig,
|
||||
state: State<'_, AppState>,
|
||||
) -> Result<(), String> {
|
||||
// 1. Check if already running
|
||||
{
|
||||
let srv = state.server.lock().map_err(|e| e.to_string())?;
|
||||
if srv.running {
|
||||
return Err("Server already running".into());
|
||||
}
|
||||
}
|
||||
|
||||
// 2. Validate ports
|
||||
validate_port(config.http_port.unwrap_or(8080))?;
|
||||
validate_port(config.ws_port.unwrap_or(8765))?;
|
||||
|
||||
// 3. Spawn sensing server as child process
|
||||
let child = Command::new("wifi-densepose-sensing-server")
|
||||
.args([
|
||||
"--http-port", &config.http_port.unwrap_or(8080).to_string(),
|
||||
"--ws-port", &config.ws_port.unwrap_or(8765).to_string(),
|
||||
"--udp-port", &config.udp_port.unwrap_or(5005).to_string(),
|
||||
])
|
||||
.spawn()
|
||||
.map_err(|e| format!("Failed to start server: {}", e))?;
|
||||
|
||||
// 4. Update state
|
||||
let mut srv = state.server.lock().map_err(|e| e.to_string())?;
|
||||
srv.running = true;
|
||||
srv.pid = Some(child.id());
|
||||
srv.child = Some(child);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
```
|
||||
|
||||
**stop_server Implementation:**
|
||||
```rust
|
||||
pub async fn stop_server(state: State<'_, AppState>) -> Result<(), String> {
|
||||
let mut srv = state.server.lock().map_err(|e| e.to_string())?;
|
||||
|
||||
if let Some(mut child) = srv.child.take() {
|
||||
// Graceful shutdown via SIGTERM
|
||||
#[cfg(unix)]
|
||||
{
|
||||
use nix::sys::signal::{kill, Signal};
|
||||
use nix::unistd::Pid;
|
||||
let _ = kill(Pid::from_raw(child.id() as i32), Signal::SIGTERM);
|
||||
}
|
||||
|
||||
// Wait up to 5s, then force kill
|
||||
tokio::select! {
|
||||
_ = child.wait() => {},
|
||||
_ = tokio::time::sleep(Duration::from_secs(5)) => {
|
||||
let _ = child.kill();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
srv.running = false;
|
||||
srv.pid = None;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
```
|
||||
|
||||
### 2.5 WASM Module
|
||||
|
||||
**Dependencies:**
|
||||
```toml
|
||||
reqwest = { version = "0.12", features = ["json", "multipart"] }
|
||||
```
|
||||
|
||||
**wasm_list Implementation:**
|
||||
```rust
|
||||
pub async fn wasm_list(node_ip: String) -> Result<Vec<WasmModuleInfo>, String> {
|
||||
let client = reqwest::Client::new();
|
||||
let resp = client.get(format!("http://{}:8080/api/wasm", node_ip))
|
||||
.timeout(Duration::from_secs(5))
|
||||
.send()
|
||||
.await
|
||||
.map_err(|e| format!("Request failed: {}", e))?;
|
||||
|
||||
if !resp.status().is_success() {
|
||||
return Err(format!("Node returned {}", resp.status()));
|
||||
}
|
||||
|
||||
let modules: Vec<WasmModuleInfo> = resp.json().await
|
||||
.map_err(|e| format!("Invalid response: {}", e))?;
|
||||
|
||||
Ok(modules)
|
||||
}
|
||||
```
|
||||
|
||||
**wasm_upload Implementation:**
|
||||
```rust
|
||||
pub async fn wasm_upload(
|
||||
node_ip: String,
|
||||
wasm_path: String,
|
||||
) -> Result<WasmUploadResult, String> {
|
||||
// 1. Validate WASM binary
|
||||
let wasm = tokio::fs::read(&wasm_path).await
|
||||
.map_err(|e| format!("Cannot read WASM: {}", e))?;
|
||||
|
||||
if wasm.len() > 256 * 1024 {
|
||||
return Err("WASM module exceeds 256KB limit".into());
|
||||
}
|
||||
|
||||
if &wasm[0..4] != b"\0asm" {
|
||||
return Err("Invalid WASM magic bytes".into());
|
||||
}
|
||||
|
||||
// 2. Upload to node
|
||||
let client = reqwest::Client::new();
|
||||
let form = multipart::Form::new()
|
||||
.part("module", multipart::Part::bytes(wasm)
|
||||
.file_name(Path::new(&wasm_path).file_name().unwrap().to_string_lossy())
|
||||
.mime_str("application/wasm")?);
|
||||
|
||||
let resp = client.post(format!("http://{}:8080/api/wasm", node_ip))
|
||||
.multipart(form)
|
||||
.timeout(Duration::from_secs(30))
|
||||
.send()
|
||||
.await?;
|
||||
|
||||
if resp.status().is_success() {
|
||||
let result: WasmUploadResult = resp.json().await?;
|
||||
Ok(result)
|
||||
} else {
|
||||
Err(format!("Upload failed: {}", resp.status()))
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 2.6 Provision Module
|
||||
|
||||
**Dependencies:**
|
||||
```toml
|
||||
nvs-partition-tool = "0.1" # Or implement NVS binary format
|
||||
serialport = "4.6"
|
||||
```
|
||||
|
||||
**provision_node Implementation:**
|
||||
```rust
|
||||
pub async fn provision_node(
|
||||
port: String,
|
||||
config: ProvisioningConfig,
|
||||
) -> Result<ProvisionResult, String> {
|
||||
// 1. Validate config
|
||||
config.validate()?;
|
||||
|
||||
// 2. Build NVS binary blob
|
||||
let nvs_blob = build_nvs_blob(&config)?;
|
||||
|
||||
// 3. Open serial port
|
||||
let mut serial = serialport::new(&port, 115200)
|
||||
.timeout(Duration::from_secs(10))
|
||||
.open()
|
||||
.map_err(|e| format!("Cannot open {}: {}", port, e))?;
|
||||
|
||||
// 4. Enter bootloader mode
|
||||
enter_bootloader(&mut serial)?;
|
||||
|
||||
// 5. Write NVS partition (offset 0x9000, size 0x6000)
|
||||
write_partition(&mut serial, 0x9000, &nvs_blob)?;
|
||||
|
||||
// 6. Reset device
|
||||
reset_device(&mut serial)?;
|
||||
|
||||
Ok(ProvisionResult {
|
||||
success: true,
|
||||
message: "Provisioning complete".into(),
|
||||
})
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 3. Security Hardening
|
||||
|
||||
### 3.1 Input Validation
|
||||
|
||||
```rust
|
||||
// All string inputs sanitized
|
||||
fn validate_ip(ip: &str) -> Result<IpAddr, String> {
|
||||
ip.parse::<IpAddr>().map_err(|_| "Invalid IP address".into())
|
||||
}
|
||||
|
||||
fn validate_port(port: u16) -> Result<(), String> {
|
||||
if port < 1024 && port != 0 {
|
||||
return Err("Privileged ports (1-1023) not allowed".into());
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn validate_path(path: &str) -> Result<PathBuf, String> {
|
||||
let path = PathBuf::from(path);
|
||||
if path.components().any(|c| c == std::path::Component::ParentDir) {
|
||||
return Err("Path traversal detected".into());
|
||||
}
|
||||
Ok(path)
|
||||
}
|
||||
```
|
||||
|
||||
### 3.2 Network Security
|
||||
|
||||
```rust
|
||||
// OTA PSK validation
|
||||
fn validate_psk(psk: &str) -> Result<(), String> {
|
||||
if psk.len() < 16 {
|
||||
return Err("PSK must be at least 16 characters".into());
|
||||
}
|
||||
if !psk.chars().all(|c| c.is_ascii_alphanumeric() || c == '-' || c == '_') {
|
||||
return Err("PSK contains invalid characters".into());
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
// Rate limiting for network operations
|
||||
struct RateLimiter {
|
||||
last_request: Instant,
|
||||
min_interval: Duration,
|
||||
}
|
||||
|
||||
impl RateLimiter {
|
||||
fn check(&mut self) -> Result<(), String> {
|
||||
if self.last_request.elapsed() < self.min_interval {
|
||||
return Err("Rate limit exceeded".into());
|
||||
}
|
||||
self.last_request = Instant::now();
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 3.3 Binary Validation
|
||||
|
||||
```rust
|
||||
fn validate_esp_binary(data: &[u8]) -> Result<(), String> {
|
||||
// Check ESP binary magic (0xE9 at offset 0)
|
||||
if data.is_empty() || data[0] != 0xE9 {
|
||||
return Err("Invalid ESP firmware magic byte".into());
|
||||
}
|
||||
|
||||
// Check minimum size (header + some code)
|
||||
if data.len() < 256 {
|
||||
return Err("Firmware too small".into());
|
||||
}
|
||||
|
||||
// Check maximum size (4MB flash)
|
||||
if data.len() > 4 * 1024 * 1024 {
|
||||
return Err("Firmware exceeds flash size".into());
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 4. Performance Optimization
|
||||
|
||||
### 4.1 Async Everything
|
||||
|
||||
All I/O operations are async with proper timeouts:
|
||||
|
||||
```rust
|
||||
// Timeout wrapper
|
||||
async fn with_timeout<T, F: Future<Output = Result<T, String>>>(
|
||||
future: F,
|
||||
duration: Duration,
|
||||
) -> Result<T, String> {
|
||||
tokio::time::timeout(duration, future)
|
||||
.await
|
||||
.map_err(|_| "Operation timed out".into())?
|
||||
}
|
||||
```
|
||||
|
||||
### 4.2 Connection Pooling
|
||||
|
||||
```rust
|
||||
// Reusable HTTP client
|
||||
lazy_static! {
|
||||
static ref HTTP_CLIENT: reqwest::Client = reqwest::Client::builder()
|
||||
.pool_max_idle_per_host(5)
|
||||
.pool_idle_timeout(Duration::from_secs(30))
|
||||
.build()
|
||||
.unwrap();
|
||||
}
|
||||
```
|
||||
|
||||
### 4.3 Streaming Progress
|
||||
|
||||
Flash and OTA operations stream progress via Tauri events:
|
||||
|
||||
```rust
|
||||
// Real-time progress updates
|
||||
app.emit("flash_progress", FlashProgress { ... })?;
|
||||
app.emit("ota_progress", OtaProgress { ... })?;
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 5. Testing Strategy
|
||||
|
||||
### 5.1 Unit Tests
|
||||
|
||||
```rust
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
#[test]
|
||||
fn test_validate_ip() {
|
||||
assert!(validate_ip("192.168.1.1").is_ok());
|
||||
assert!(validate_ip("invalid").is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_validate_esp_binary() {
|
||||
let valid = vec![0xE9; 1024];
|
||||
assert!(validate_esp_binary(&valid).is_ok());
|
||||
|
||||
let invalid = vec![0x00; 1024];
|
||||
assert!(validate_esp_binary(&invalid).is_err());
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 5.2 Integration Tests
|
||||
|
||||
```rust
|
||||
#[tokio::test]
|
||||
async fn test_discover_nodes_timeout() {
|
||||
let result = discover_nodes(Some(100)).await;
|
||||
assert!(result.is_ok());
|
||||
// Should return empty or cached results within timeout
|
||||
}
|
||||
```
|
||||
|
||||
### 5.3 Mock Testing
|
||||
|
||||
```rust
|
||||
// Mock serial port for flash tests
|
||||
struct MockSerial {
|
||||
responses: VecDeque<Vec<u8>>,
|
||||
}
|
||||
|
||||
impl Read for MockSerial { ... }
|
||||
impl Write for MockSerial { ... }
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 6. Dependencies Update
|
||||
|
||||
**Cargo.toml additions:**
|
||||
```toml
|
||||
[dependencies]
|
||||
# Discovery
|
||||
mdns-sd = "0.11"
|
||||
serialport = "4.6"
|
||||
|
||||
# HTTP client
|
||||
reqwest = { version = "0.12", features = ["json", "multipart", "rustls-tls"] }
|
||||
|
||||
# Crypto
|
||||
sha2 = "0.10"
|
||||
|
||||
# Process management
|
||||
sysinfo = "0.32"
|
||||
|
||||
# Async
|
||||
tokio = { version = "1", features = ["full"] }
|
||||
futures = "0.3"
|
||||
|
||||
# Flash
|
||||
espflash = "4.0"
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 7. Implementation Timeline
|
||||
|
||||
| Week | Deliverable |
|
||||
|------|-------------|
|
||||
| 1 | Discovery + Serial ports (real enumeration) |
|
||||
| 1 | Server start/stop (child process management) |
|
||||
| 2 | Flash firmware (espflash integration) |
|
||||
| 2 | OTA update (HTTP multipart) |
|
||||
| 3 | Batch OTA (parallel + sequential strategies) |
|
||||
| 3 | WASM management (list/upload/control) |
|
||||
| 4 | Provision NVS (binary format) |
|
||||
| 4 | Security audit + E2E testing |
|
||||
|
||||
---
|
||||
|
||||
## 8. Rollout Plan
|
||||
|
||||
1. **v0.3.1** — Settings fix + Discovery + Server
|
||||
2. **v0.4.0** — Flash + OTA (single node)
|
||||
3. **v0.5.0** — Batch OTA + WASM + Provision
|
||||
4. **v1.0.0** — Full E2E tested, security audited
|
||||
|
||||
---
|
||||
|
||||
## Consequences
|
||||
|
||||
### Positive
|
||||
- Desktop app becomes fully functional
|
||||
- Real device management capabilities
|
||||
- Production-ready security posture
|
||||
- Async performance throughout
|
||||
|
||||
### Negative
|
||||
- Additional dependencies increase binary size
|
||||
- espflash adds ~2MB to binary
|
||||
- Hardware required for full testing
|
||||
|
||||
### Neutral
|
||||
- Feature parity with browser-based UI
|
||||
- Same API contract as sensing server
|
||||
|
||||
---
|
||||
|
||||
## References
|
||||
|
||||
- [Tauri v2 Commands](https://v2.tauri.app/develop/commands/)
|
||||
- [espflash Documentation](https://github.com/esp-rs/espflash)
|
||||
- [ESP32 OTA Protocol](https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/system/ota.html)
|
||||
- [mDNS-SD Rust](https://docs.rs/mdns-sd/)
|
||||
@@ -0,0 +1,119 @@
|
||||
# ADR-055: Integrated Sensing Server in Desktop App
|
||||
|
||||
## Status
|
||||
Accepted
|
||||
|
||||
## Context
|
||||
The RuView Desktop application (ADR-054) requires the WiFi sensing server to provide real-time CSI data, activity detection, and vital signs monitoring. Currently, the sensing server is a separate binary (`wifi-densepose-sensing-server`) that must be installed separately and found in the system PATH.
|
||||
|
||||
This creates several problems:
|
||||
1. **Distribution complexity**: Users must install two binaries
|
||||
2. **Path issues**: Binary may not be in PATH, causing "No such file or directory" errors
|
||||
3. **Version mismatch**: Server and desktop app versions may diverge
|
||||
4. **Poor UX**: Error messages about missing binaries confuse users
|
||||
|
||||
## Decision
|
||||
Bundle the sensing server binary inside the desktop application and provide intelligent binary discovery with clear fallback paths.
|
||||
|
||||
### Binary Discovery Order
|
||||
The desktop app searches for the sensing server in this order:
|
||||
1. **Custom path** from user settings (`server_path`)
|
||||
2. **Bundled resources** (`Contents/Resources/bin/` on macOS)
|
||||
3. **Next to executable** (same directory as the app binary)
|
||||
4. **System PATH** (legacy fallback)
|
||||
|
||||
### Implementation
|
||||
```rust
|
||||
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
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
||||
// 3. Next to 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. System PATH
|
||||
// ... which lookup ...
|
||||
|
||||
Err("Sensing server binary not found")
|
||||
}
|
||||
```
|
||||
|
||||
### Bundle Configuration
|
||||
In `tauri.conf.json`:
|
||||
```json
|
||||
{
|
||||
"bundle": {
|
||||
"resources": [
|
||||
{
|
||||
"src": "../../target/release/wifi-densepose-sensing-server",
|
||||
"target": "bin/wifi-densepose-sensing-server"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## Consequences
|
||||
|
||||
### Positive
|
||||
- **Single package distribution**: Users download one DMG/MSI/EXE
|
||||
- **Version alignment**: Server and UI always match
|
||||
- **Better UX**: No PATH configuration required
|
||||
- **Offline capable**: Works without network access to download server
|
||||
|
||||
### Negative
|
||||
- **Larger bundle size**: ~10-15MB additional for server binary
|
||||
- **Build complexity**: Must build server before bundling desktop
|
||||
- **Platform-specific**: Need separate server binaries per platform
|
||||
|
||||
### Neutral
|
||||
- CI/CD workflow updated to build server before desktop
|
||||
- GitHub Actions builds all platforms (macOS arm64/x64, Windows x64)
|
||||
|
||||
## WebSocket Integration
|
||||
The Sensing page connects to the bundled server's WebSocket endpoint:
|
||||
- `ws://127.0.0.1:{ws_port}/ws/sensing` - Real-time CSI data stream
|
||||
- `ws://127.0.0.1:{ws_port}/ws/pose` - Pose estimation stream
|
||||
|
||||
Message format:
|
||||
```typescript
|
||||
interface WsSensingUpdate {
|
||||
type: string;
|
||||
timestamp: number;
|
||||
source: string;
|
||||
tick: number;
|
||||
nodes: WsNodeInfo[];
|
||||
classification: { motion_level: string; presence: boolean; confidence: number };
|
||||
vital_signs?: { breathing_rate_hz?: number; heart_rate_bpm?: number };
|
||||
}
|
||||
```
|
||||
|
||||
## Security Considerations
|
||||
- Server binary signed with same certificate as desktop app
|
||||
- Communication over localhost only (127.0.0.1)
|
||||
- No external network access by default
|
||||
- Process spawned as child of desktop app (inherits permissions)
|
||||
|
||||
## Related ADRs
|
||||
- ADR-054: Desktop Full Implementation
|
||||
- ADR-053: UI Design System
|
||||
- ADR-052: Tauri Desktop Frontend
|
||||
@@ -0,0 +1,251 @@
|
||||
# ADR-056: RuView Desktop Complete Capabilities Reference
|
||||
|
||||
## Status
|
||||
Accepted
|
||||
|
||||
## Context
|
||||
RuView Desktop is a comprehensive WiFi-based sensing platform that combines hardware management, real-time signal processing, neural network inference, and intelligent monitoring. This ADR documents all integrated capabilities across the desktop application and underlying crates.
|
||||
|
||||
## Decision
|
||||
The RuView Desktop application consolidates all WiFi-DensePose functionality into a single, unified interface with the following capabilities.
|
||||
|
||||
---
|
||||
|
||||
## 1. Hardware Management
|
||||
|
||||
### 1.1 Node Discovery
|
||||
- **mDNS discovery**: Automatic detection of ESP32 nodes via Bonjour/Avahi
|
||||
- **UDP probe**: Direct UDP broadcast discovery on port 5005
|
||||
- **HTTP sweep**: Sequential IP scanning with health checks
|
||||
- **Manual registration**: User-defined node configuration
|
||||
|
||||
### 1.2 Firmware Flashing
|
||||
- **Serial flashing**: Direct USB flash via espflash integration
|
||||
- **Chip detection**: Automatic ESP32/S2/S3/C3/C6 identification
|
||||
- **Progress monitoring**: Real-time progress with speed metrics
|
||||
- **Verification**: Post-flash integrity verification
|
||||
|
||||
### 1.3 OTA Updates
|
||||
- **Single-node OTA**: HTTP-based firmware push to individual nodes
|
||||
- **Batch OTA**: Coordinated multi-node updates with strategies:
|
||||
- `sequential`: One node at a time
|
||||
- `tdm_safe`: Respects TDM slot timing
|
||||
- `parallel`: Concurrent updates with throttling
|
||||
- **Rollback support**: Automatic rollback on verification failure
|
||||
- **Version tracking**: Pre/post version comparison
|
||||
|
||||
### 1.4 Node Configuration
|
||||
- **NVS provisioning**: WiFi credentials, node ID, TDM slot assignment
|
||||
- **Mesh configuration**: Coordinator/node/aggregator role assignment
|
||||
- **TDM scheduling**: Time-division multiplexing slot allocation
|
||||
|
||||
---
|
||||
|
||||
## 2. Sensing Server
|
||||
|
||||
### 2.1 Data Sources
|
||||
- **ESP32 CSI**: Real UDP frames from ESP32 hardware (port 5005)
|
||||
- **Windows WiFi**: Native Windows RSSI monitoring via netsh
|
||||
- **Simulation**: Synthetic data generation for demo/testing
|
||||
- **Auto**: Automatic source detection based on available hardware
|
||||
|
||||
### 2.2 Real-Time Processing
|
||||
- **CSI pipeline**: 56-subcarrier amplitude/phase extraction
|
||||
- **FFT analysis**: Spectral decomposition for motion detection
|
||||
- **Vital signs**: Breathing rate (0.1-0.5 Hz), heart rate (0.8-2.0 Hz)
|
||||
- **Motion classification**: still/walking/running/exercising
|
||||
- **Presence detection**: Binary presence with confidence score
|
||||
|
||||
### 2.3 WebSocket Streaming
|
||||
- **Sensing endpoint**: `ws://localhost:8765/ws/sensing`
|
||||
- **Pose endpoint**: `ws://localhost:8765/ws/pose`
|
||||
- **Real-time broadcast**: 10-100 Hz update rate
|
||||
- **Multi-client support**: Concurrent WebSocket connections
|
||||
|
||||
### 2.4 REST API
|
||||
- **Health check**: `GET /health`
|
||||
- **Status**: `GET /api/status`
|
||||
- **Recording control**: `POST /api/recording/start|stop`
|
||||
- **Model management**: `GET/POST /api/models`
|
||||
|
||||
---
|
||||
|
||||
## 3. Neural Network Inference
|
||||
|
||||
### 3.1 Model Formats
|
||||
- **RVF (RuVector Format)**: Proprietary binary container with:
|
||||
- Model weights (quantized f32/f16/i8)
|
||||
- Vital sign configuration
|
||||
- SONA environment profiles
|
||||
- Training provenance
|
||||
- Cryptographic attestation
|
||||
|
||||
### 3.2 Inference Capabilities
|
||||
- **Pose estimation**: 17 COCO keypoints from WiFi CSI
|
||||
- **Activity recognition**: Multi-class classification
|
||||
- **Vital signs**: Breathing and heart rate extraction
|
||||
- **Multi-person detection**: Up to 3 simultaneous subjects
|
||||
|
||||
### 3.3 Self-Learning (SONA)
|
||||
- **Environment adaptation**: LoRA-based fine-tuning to room geometry
|
||||
- **Profile switching**: Multiple learned environment profiles
|
||||
- **Online learning**: Continuous adaptation during runtime
|
||||
- **Transfer learning**: Profile export/import between deployments
|
||||
|
||||
---
|
||||
|
||||
## 4. WASM Edge Modules
|
||||
|
||||
### 4.1 Module Management
|
||||
- **Upload**: Deploy WASM modules to ESP32 nodes
|
||||
- **Start/Stop**: Runtime control of edge processing
|
||||
- **Status monitoring**: CPU, memory, execution count
|
||||
- **Hot reload**: Update modules without node reboot
|
||||
|
||||
### 4.2 Supported Operations
|
||||
- **Local filtering**: On-device noise reduction
|
||||
- **Feature extraction**: Pre-compute features at edge
|
||||
- **Compression**: Reduce data before transmission
|
||||
- **Custom logic**: User-defined processing pipelines
|
||||
|
||||
---
|
||||
|
||||
## 5. Mesh Visualization
|
||||
|
||||
### 5.1 Network Topology
|
||||
- **Live mesh view**: Real-time node connectivity graph
|
||||
- **Signal quality**: RSSI/SNR visualization per link
|
||||
- **Latency monitoring**: Round-trip time measurement
|
||||
- **Packet loss**: Delivery success rate tracking
|
||||
|
||||
### 5.2 CSI Visualization
|
||||
- **Amplitude heatmap**: Per-subcarrier amplitude display
|
||||
- **Phase unwrapping**: Continuous phase visualization
|
||||
- **Spectrogram**: Time-frequency representation
|
||||
- **Signal field**: 3D voxel grid of RF perturbations
|
||||
|
||||
---
|
||||
|
||||
## 6. Training & Export
|
||||
|
||||
### 6.1 Dataset Management
|
||||
- **Recording**: Capture CSI frames with annotations
|
||||
- **Labeling**: Activity and pose ground truth
|
||||
- **Augmentation**: Synthetic data generation
|
||||
- **Export**: Standard formats (JSON, CSV, NumPy)
|
||||
|
||||
### 6.2 Training Pipeline (ADR-023)
|
||||
- **Contrastive pretraining**: Self-supervised feature learning
|
||||
- **Supervised fine-tuning**: Labeled pose estimation
|
||||
- **SONA adaptation**: Environment-specific tuning
|
||||
- **Validation**: Cross-environment testing
|
||||
|
||||
### 6.3 Export Formats
|
||||
- **RVF container**: Production deployment format
|
||||
- **ONNX**: Interoperability with external tools
|
||||
- **PyTorch**: Research and experimentation
|
||||
- **Candle**: Rust-native inference
|
||||
|
||||
---
|
||||
|
||||
## 7. Security Features
|
||||
|
||||
### 7.1 Network Security
|
||||
- **OTA PSK**: Pre-shared key for firmware updates
|
||||
- **Node authentication**: MAC-based node verification
|
||||
- **Encrypted transport**: Optional TLS for API endpoints
|
||||
|
||||
### 7.2 Code Signing
|
||||
- **Firmware verification**: Hash-based integrity checks
|
||||
- **WASM attestation**: Module signature validation
|
||||
- **Model provenance**: Training lineage tracking
|
||||
|
||||
---
|
||||
|
||||
## 8. Configuration & Settings
|
||||
|
||||
### 8.1 Server Configuration
|
||||
- **Ports**: HTTP (8080), WebSocket (8765), UDP (5005)
|
||||
- **Bind address**: Localhost or network-wide
|
||||
- **Data source**: auto/wifi/esp32/simulate
|
||||
- **Log level**: debug/info/warn/error
|
||||
|
||||
### 8.2 Application Settings
|
||||
- **Theme**: Dark/light mode
|
||||
- **Auto-discovery**: Periodic node scanning
|
||||
- **Discovery interval**: Configurable scan frequency
|
||||
- **UI customization**: Responsive layout options
|
||||
|
||||
---
|
||||
|
||||
## 9. Crate Architecture
|
||||
|
||||
| Crate | Capabilities |
|
||||
|-------|-------------|
|
||||
| `wifi-densepose-core` | CSI frame primitives, traits, error types |
|
||||
| `wifi-densepose-signal` | FFT, phase unwrapping, vital signs, RuvSense |
|
||||
| `wifi-densepose-nn` | ONNX/PyTorch/Candle inference backends |
|
||||
| `wifi-densepose-train` | Training pipeline, dataset, metrics |
|
||||
| `wifi-densepose-mat` | Mass casualty assessment tool |
|
||||
| `wifi-densepose-hardware` | ESP32 protocol, TDM, channel hopping |
|
||||
| `wifi-densepose-ruvector` | Cross-viewpoint fusion, attention |
|
||||
| `wifi-densepose-api` | REST API (Axum) |
|
||||
| `wifi-densepose-db` | Postgres/SQLite/Redis persistence |
|
||||
| `wifi-densepose-config` | Configuration management |
|
||||
| `wifi-densepose-wasm` | Browser WASM bindings |
|
||||
| `wifi-densepose-cli` | Command-line interface |
|
||||
| `wifi-densepose-sensing-server` | Real-time sensing server |
|
||||
| `wifi-densepose-wifiscan` | Multi-BSSID scanning |
|
||||
| `wifi-densepose-vitals` | Vital sign extraction |
|
||||
| `wifi-densepose-desktop` | Tauri desktop application |
|
||||
|
||||
---
|
||||
|
||||
## 10. UI Design System (ADR-053)
|
||||
|
||||
### 10.1 Pages
|
||||
- **Dashboard**: Overview, node status, quick actions
|
||||
- **Discovery**: Network scanning interface
|
||||
- **Nodes**: Node management and configuration
|
||||
- **Flash**: Serial firmware flashing
|
||||
- **OTA**: Over-the-air update management
|
||||
- **Edge Modules**: WASM deployment
|
||||
- **Sensing**: Real-time monitoring with server control
|
||||
- **Mesh View**: Network topology visualization
|
||||
- **Settings**: Application configuration
|
||||
|
||||
### 10.2 Components
|
||||
- **StatusBadge**: Health indicator
|
||||
- **NodeCard**: Node information display
|
||||
- **LogViewer**: Real-time log streaming
|
||||
- **ActivityFeed**: Sensing data visualization
|
||||
- **ProgressBar**: Operation progress
|
||||
- **ConfigForm**: Settings input
|
||||
|
||||
---
|
||||
|
||||
## Consequences
|
||||
|
||||
### Positive
|
||||
- **Unified interface**: All capabilities in one application
|
||||
- **Bundled deployment**: Single package with server included
|
||||
- **Real-time feedback**: WebSocket-based live updates
|
||||
- **Cross-platform**: macOS, Windows, Linux support
|
||||
- **Extensible**: WASM modules, custom models, API access
|
||||
|
||||
### Negative
|
||||
- **Larger bundle**: ~6MB app + ~2.6MB server
|
||||
- **Complexity**: Many features require learning curve
|
||||
- **Hardware dependency**: Full functionality requires ESP32 nodes
|
||||
|
||||
### Neutral
|
||||
- Documentation required for all features
|
||||
- Training materials needed for advanced capabilities
|
||||
- Community contributions welcome
|
||||
|
||||
## Related ADRs
|
||||
- ADR-053: UI Design System
|
||||
- ADR-054: Desktop Full Implementation
|
||||
- ADR-055: Integrated Sensing Server
|
||||
- ADR-023: 8-Phase Training Pipeline
|
||||
- ADR-016: RuVector Integration
|
||||
@@ -0,0 +1,82 @@
|
||||
# ADR-057: Firmware CSI Build Guard and sdkconfig.defaults
|
||||
|
||||
| Field | Value |
|
||||
|-------------|---------------------------------------------|
|
||||
| **Status** | Accepted |
|
||||
| **Date** | 2026-03-12 |
|
||||
| **Authors** | ruv |
|
||||
| **Issues** | #223, #238, #234, #210, #190 |
|
||||
|
||||
## Context
|
||||
|
||||
Multiple GitHub issues (#223, #238, #234, #210, #190) report firmware problems
|
||||
that fall into two categories:
|
||||
|
||||
1. **CSI not enabled at runtime** — The committed `sdkconfig` had
|
||||
`# CONFIG_ESP_WIFI_CSI_ENABLED is not set` (line 1135), meaning users who
|
||||
built from source or used pre-built binaries got the runtime error:
|
||||
`E (6700) wifi:CSI not enabled in menuconfig!`
|
||||
|
||||
Root cause: `sdkconfig.defaults.template` existed with the correct setting
|
||||
(`CONFIG_ESP_WIFI_CSI_ENABLED=y`) but ESP-IDF only reads
|
||||
`sdkconfig.defaults` — not `.template` suffixed files. No `sdkconfig.defaults`
|
||||
file was committed.
|
||||
|
||||
2. **Unsupported ESP32 variants** — Users attempting to use original ESP32
|
||||
(D0WD) and ESP32-C3 boards. The firmware targets ESP32-S3 only
|
||||
(`CONFIG_IDF_TARGET="esp32s3"`, Xtensa architecture) and this was not
|
||||
surfaced clearly enough in documentation or build errors.
|
||||
|
||||
## Decision
|
||||
|
||||
### Fix 1: Commit `sdkconfig.defaults` (not just template)
|
||||
|
||||
Copy `sdkconfig.defaults.template` → `sdkconfig.defaults` so that ESP-IDF
|
||||
applies the correct defaults (including `CONFIG_ESP_WIFI_CSI_ENABLED=y`)
|
||||
automatically when `sdkconfig` is regenerated.
|
||||
|
||||
### Fix 2: `#error` compile-time guard in `csi_collector.c`
|
||||
|
||||
Add a preprocessor guard:
|
||||
|
||||
```c
|
||||
#ifndef CONFIG_ESP_WIFI_CSI_ENABLED
|
||||
#error "CONFIG_ESP_WIFI_CSI_ENABLED must be set in sdkconfig."
|
||||
#endif
|
||||
```
|
||||
|
||||
This turns a confusing runtime crash into a clear compile-time error with
|
||||
instructions on how to fix it.
|
||||
|
||||
### Fix 3: Fix committed `sdkconfig`
|
||||
|
||||
Change line 1135 from `# CONFIG_ESP_WIFI_CSI_ENABLED is not set` to
|
||||
`CONFIG_ESP_WIFI_CSI_ENABLED=y`.
|
||||
|
||||
## Consequences
|
||||
|
||||
- **Positive**: New builds will always have CSI enabled. Users building from
|
||||
source will get a clear compile error if CSI is somehow disabled.
|
||||
- **Positive**: Pre-built release binaries will include CSI support.
|
||||
- **Neutral**: Original ESP32 and ESP32-C3 remain unsupported. This is by
|
||||
design — only ESP32-S3 has the CSI API surface we depend on. Future ADRs
|
||||
may address multi-target support if demand warrants it.
|
||||
- **Negative**: None identified.
|
||||
|
||||
## Hardware Support Matrix
|
||||
|
||||
| Variant | CSI Support | Firmware Target | Status |
|
||||
|--------------|-------------|-----------------|---------------|
|
||||
| ESP32-S3 | Yes | Yes | Supported |
|
||||
| ESP32 (orig) | Partial | No | Unsupported |
|
||||
| ESP32-C3 | Yes (IDF 5.1+) | No | Unsupported |
|
||||
| ESP32-C6 | Yes | No | Unsupported |
|
||||
|
||||
## Notes
|
||||
|
||||
- ESP32-C3 and C6 use RISC-V architecture; a separate build target
|
||||
(`idf.py set-target esp32c3`) would be needed.
|
||||
- Original ESP32 has limited CSI (no STBC HT-LTF2, fewer subcarriers).
|
||||
- Users on unsupported hardware can still write custom firmware using the
|
||||
ADR-018 binary frame format (magic `0xC5110001`) for interop with the
|
||||
Rust aggregator.
|
||||
@@ -0,0 +1,392 @@
|
||||
# ADR-058: Dual-Modal WASM Browser Pose Estimation — Live Video + WiFi CSI Fusion
|
||||
|
||||
- **Status**: Proposed
|
||||
- **Date**: 2026-03-12
|
||||
- **Deciders**: ruv
|
||||
- **Tags**: wasm, browser, cnn, pose-estimation, ruvector, video, multimodal, fusion
|
||||
|
||||
## Context
|
||||
|
||||
WiFi-DensePose estimates human poses from WiFi CSI (Channel State Information).
|
||||
The `ruvector-cnn` crate provides a pure Rust CNN (MobileNet-V3) with WASM bindings.
|
||||
Both modalities exist independently — what's missing is **fusing live webcam video
|
||||
with WiFi CSI** in a single browser demo to achieve robust pose estimation that
|
||||
works even when one modality degrades (occlusion, signal noise, poor lighting).
|
||||
|
||||
Existing assets:
|
||||
|
||||
1. **`wifi-densepose-wasm`** — CSI signal processing compiled to WASM
|
||||
2. **`wifi-densepose-sensing-server`** — Axum server streaming live CSI via WebSocket
|
||||
3. **`ruvector-cnn`** — Pure Rust CNN with MobileNet-V3 backbones, SIMD, contrastive learning
|
||||
4. **`ruvector-cnn-wasm`** — wasm-bindgen bindings: `WasmCnnEmbedder`, `SimdOps`, `LayerOps`, contrastive losses
|
||||
5. **`vendor/ruvector/examples/wasm-vanilla/`** — Reference vanilla JS WASM example
|
||||
|
||||
Research shows multi-modal fusion (camera + WiFi) significantly outperforms either alone:
|
||||
- Camera fails under occlusion, poor lighting, privacy constraints
|
||||
- WiFi CSI fails with signal noise, multipath, low spatial resolution
|
||||
- Fusion compensates: WiFi provides through-wall coverage, camera provides fine-grained detail
|
||||
|
||||
## Decision
|
||||
|
||||
Build a **dual-modal browser demo** at `examples/wasm-browser-pose/` that:
|
||||
|
||||
1. Captures **live webcam video** via `getUserMedia` API
|
||||
2. Receives **live WiFi CSI** via WebSocket from the sensing server
|
||||
3. Processes **both streams** through separate CNN pipelines in `ruvector-cnn-wasm`
|
||||
4. **Fuses embeddings** with learned attention weights for combined pose estimation
|
||||
5. Renders **video overlay** with skeleton + WiFi confidence heatmap on Canvas
|
||||
6. Runs entirely in the browser — all inference client-side via WASM
|
||||
|
||||
### Architecture
|
||||
|
||||
```
|
||||
┌──────────────────────────────────────────────────────────────────┐
|
||||
│ Browser │
|
||||
│ │
|
||||
│ ┌────────────┐ ┌────────────────┐ ┌───────────────────┐ │
|
||||
│ │ getUserMedia│───▶│ Video Frame │───▶│ CNN WASM │ │
|
||||
│ │ (Webcam) │ │ Capture │ │ (Visual Embedder) │ │
|
||||
│ └────────────┘ │ 224×224 RGB │ │ → 512-dim │ │
|
||||
│ └────────────────┘ └────────┬──────────┘ │
|
||||
│ │ │
|
||||
│ visual_embedding │
|
||||
│ │ │
|
||||
│ ┌──────▼──────┐ │
|
||||
│ ┌────────────┐ ┌────────────────┐ │ │ │
|
||||
│ │ WebSocket │───▶│ CSI WASM │ │ Attention │ │
|
||||
│ │ Client │ │ (densepose- │ │ Fusion │ │
|
||||
│ │ │ │ wasm) │ │ Module │ │
|
||||
│ └────────────┘ └───────┬────────┘ │ │ │
|
||||
│ │ └──────┬──────┘ │
|
||||
│ ┌───────▼────────┐ │ │
|
||||
│ │ CNN WASM │ fused_embedding │
|
||||
│ │ (CSI Embedder) │ │ │
|
||||
│ │ → 512-dim │ ┌──────▼──────┐ │
|
||||
│ └───────┬────────┘ │ Pose │ │
|
||||
│ │ │ Decoder │ │
|
||||
│ csi_embedding │ → 17 kpts │ │
|
||||
│ │ └──────┬──────┘ │
|
||||
│ └──────────────────────┘ │
|
||||
│ │ │
|
||||
│ ┌──────────────┐ ┌─────▼──────┐ │
|
||||
│ │ Video Canvas │◀────────│ Overlay │ │
|
||||
│ │ + Skeleton │ │ Renderer │ │
|
||||
│ │ + Heatmap │ └────────────┘ │
|
||||
│ └──────────────┘ │
|
||||
│ │
|
||||
└──────────────────────────────────────────────────────────────────┘
|
||||
▲ ▲
|
||||
│ getUserMedia │ WebSocket
|
||||
│ (camera) │ (ws://host:3030/ws/csi)
|
||||
│ │
|
||||
┌────┴────┐ ┌───────┴─────────┐
|
||||
│ Webcam │ │ Sensing Server │
|
||||
└─────────┘ └─────────────────┘
|
||||
```
|
||||
|
||||
### Dual Pipeline Design
|
||||
|
||||
Two parallel CNN pipelines run on each frame tick (~30 FPS):
|
||||
|
||||
| Pipeline | Input | Preprocessing | CNN Config | Output |
|
||||
|----------|-------|---------------|------------|--------|
|
||||
| **Visual** | Webcam frame (640×480) | Resize to 224×224 RGB, ImageNet normalize | MobileNet-V3 Small, 512-dim | Visual embedding |
|
||||
| **CSI** | CSI frame (ADR-018 binary) | Amplitude/phase/delta → 224×224 pseudo-RGB | MobileNet-V3 Small, 512-dim | CSI embedding |
|
||||
|
||||
Both use the same `WasmCnnEmbedder` but with separate instances and weight sets.
|
||||
|
||||
### Fusion Strategy
|
||||
|
||||
**Learned attention-weighted fusion** combines the two 512-dim embeddings:
|
||||
|
||||
```javascript
|
||||
// Attention fusion: learn which modality to trust per-dimension
|
||||
// α ∈ [0,1]^512 — attention weights (shipped as JSON, trained offline)
|
||||
// visual_emb, csi_emb ∈ R^512
|
||||
|
||||
function fuseEmbeddings(visual_emb, csi_emb, attention_weights) {
|
||||
const fused = new Float32Array(512);
|
||||
for (let i = 0; i < 512; i++) {
|
||||
const α = attention_weights[i];
|
||||
fused[i] = α * visual_emb[i] + (1 - α) * csi_emb[i];
|
||||
}
|
||||
return fused;
|
||||
}
|
||||
```
|
||||
|
||||
**Dynamic confidence gating** adjusts fusion based on signal quality:
|
||||
|
||||
| Condition | Behavior |
|
||||
|-----------|----------|
|
||||
| Good video + good CSI | Balanced fusion (α ≈ 0.5) |
|
||||
| Poor lighting / occlusion | CSI-dominant (α → 0, WiFi takes over) |
|
||||
| CSI noise / no ESP32 | Video-dominant (α → 1, camera only) |
|
||||
| Video-only mode (no WiFi) | α = 1.0, pure visual CNN pose estimation |
|
||||
| CSI-only mode (no camera) | α = 0.0, pure WiFi pose estimation |
|
||||
|
||||
Quality detection:
|
||||
- **Video quality**: Frame brightness variance (dark = low quality), motion blur score
|
||||
- **CSI quality**: Signal-to-noise ratio from `wifi-densepose-wasm`, coherence gate output
|
||||
|
||||
### CSI-to-Image Encoding
|
||||
|
||||
CSI data encoded as 3-channel pseudo-image for the CSI CNN pipeline:
|
||||
|
||||
| Channel | Data | Normalization |
|
||||
|---------|------|---------------|
|
||||
| R | CSI amplitude (subcarrier × time window) | Min-max to [0, 255] |
|
||||
| G | CSI phase (unwrapped, subcarrier × time window) | Min-max to [0, 255] |
|
||||
| B | Temporal difference (frame-to-frame Δ amplitude) | Abs, min-max to [0, 255] |
|
||||
|
||||
### Video Processing
|
||||
|
||||
Webcam frames processed through standard ImageNet pipeline:
|
||||
|
||||
```javascript
|
||||
// Capture frame from video element
|
||||
const frame = captureVideoFrame(videoElement, 224, 224); // Returns Uint8Array RGB
|
||||
|
||||
// ImageNet normalization happens inside WasmCnnEmbedder.extract()
|
||||
const visual_embedding = visual_embedder.extract(frame, 224, 224);
|
||||
```
|
||||
|
||||
### Pose Keypoint Mapping
|
||||
|
||||
17 COCO-format keypoints decoded from the fused 512-dim embedding:
|
||||
|
||||
```
|
||||
0: nose 1: left_eye 2: right_eye
|
||||
3: left_ear 4: right_ear 5: left_shoulder
|
||||
6: right_shoulder 7: left_elbow 8: right_elbow
|
||||
9: left_wrist 10: right_wrist 11: left_hip
|
||||
12: right_hip 13: left_knee 14: right_knee
|
||||
15: left_ankle 16: right_ankle
|
||||
```
|
||||
|
||||
Each keypoint decoded as (x, y, confidence) = 51 values from the 512-dim embedding
|
||||
via a learned linear projection.
|
||||
|
||||
### Operating Modes
|
||||
|
||||
The demo supports three modes, selectable in the UI:
|
||||
|
||||
| Mode | Video | CSI | Fusion | Use Case |
|
||||
|------|-------|-----|--------|----------|
|
||||
| **Dual (default)** | ✅ | ✅ | Attention-weighted | Best accuracy, full demo |
|
||||
| **Video Only** | ✅ | ❌ | α = 1.0 | No ESP32 available, quick demo |
|
||||
| **CSI Only** | ❌ | ✅ | α = 0.0 | Privacy mode, through-wall sensing |
|
||||
|
||||
**Video Only mode works without any hardware** — just a webcam — making the demo
|
||||
instantly accessible for anyone wanting to try it.
|
||||
|
||||
### File Layout
|
||||
|
||||
```
|
||||
examples/wasm-browser-pose/
|
||||
├── index.html # Single-page app (vanilla JS, no bundler)
|
||||
├── js/
|
||||
│ ├── app.js # Main entry, mode selection, orchestration
|
||||
│ ├── video-capture.js # getUserMedia, frame extraction, quality detection
|
||||
│ ├── csi-processor.js # WebSocket CSI client, frame parsing, pseudo-image encoding
|
||||
│ ├── fusion.js # Attention-weighted embedding fusion, confidence gating
|
||||
│ ├── pose-decoder.js # Fused embedding → 17 keypoints
|
||||
│ └── canvas-renderer.js # Video overlay, skeleton, CSI heatmap, confidence bars
|
||||
├── data/
|
||||
│ ├── visual-weights.json # Visual CNN → embedding projection (placeholder until trained)
|
||||
│ ├── csi-weights.json # CSI CNN → embedding projection (placeholder until trained)
|
||||
│ ├── fusion-weights.json # Attention fusion α weights (512 values)
|
||||
│ └── pose-weights.json # Fused embedding → keypoint projection
|
||||
├── css/
|
||||
│ └── style.css # Dark theme UI styling
|
||||
├── pkg/ # Built WASM packages (gitignored, built by script)
|
||||
│ ├── wifi_densepose_wasm/
|
||||
│ └── ruvector_cnn_wasm/
|
||||
├── build.sh # wasm-pack build script for both packages
|
||||
└── README.md # Setup and usage instructions
|
||||
```
|
||||
|
||||
### Build Pipeline
|
||||
|
||||
```bash
|
||||
#!/bin/bash
|
||||
# build.sh — builds both WASM packages into pkg/
|
||||
|
||||
set -e
|
||||
|
||||
# Build wifi-densepose-wasm (CSI processing)
|
||||
wasm-pack build ../../rust-port/wifi-densepose-rs/crates/wifi-densepose-wasm \
|
||||
--target web --out-dir "$(pwd)/pkg/wifi_densepose_wasm" --no-typescript
|
||||
|
||||
# Build ruvector-cnn-wasm (CNN inference for both video and CSI)
|
||||
wasm-pack build ../../vendor/ruvector/crates/ruvector-cnn-wasm \
|
||||
--target web --out-dir "$(pwd)/pkg/ruvector_cnn_wasm" --no-typescript
|
||||
|
||||
echo "Build complete. Serve with: python3 -m http.server 8080"
|
||||
```
|
||||
|
||||
### UI Layout
|
||||
|
||||
```
|
||||
┌─────────────────────────────────────────────────────────┐
|
||||
│ WiFi-DensePose — Live Dual-Modal Pose Estimation │
|
||||
│ [Dual Mode ▼] [⚙ Settings] FPS: 28 ◉ Live │
|
||||
├───────────────────────────┬─────────────────────────────┤
|
||||
│ │ │
|
||||
│ ┌───────────────────┐ │ ┌───────────────────┐ │
|
||||
│ │ │ │ │ │ │
|
||||
│ │ Video + Skeleton │ │ │ CSI Heatmap │ │
|
||||
│ │ Overlay │ │ │ (amplitude × │ │
|
||||
│ │ (main canvas) │ │ │ subcarrier) │ │
|
||||
│ │ │ │ │ │ │
|
||||
│ └───────────────────┘ │ └───────────────────┘ │
|
||||
│ │ │
|
||||
├───────────────────────────┴─────────────────────────────┤
|
||||
│ Fusion Confidence: ████████░░ 78% │
|
||||
│ Video: ██████████ 95% │ CSI: ██████░░░░ 61% │
|
||||
├─────────────────────────────────────────────────────────┤
|
||||
│ ┌─────────────────────────────────────────────────┐ │
|
||||
│ │ Embedding Space (2D projection) │ │
|
||||
│ │ · · · │ │
|
||||
│ │ · · · · · · (color = pose cluster) │ │
|
||||
│ │ · · · · │ │
|
||||
│ └─────────────────────────────────────────────────┘ │
|
||||
├─────────────────────────────────────────────────────────┤
|
||||
│ Latency: Video 12ms │ CSI 8ms │ Fusion 1ms │ Total 21ms│
|
||||
│ [▶ Record] [📷 Snapshot] [Confidence: ████ 0.6] │
|
||||
└─────────────────────────────────────────────────────────┘
|
||||
```
|
||||
|
||||
### WASM Module Structure
|
||||
|
||||
| Package | Source Crate | Provides | Size (est.) |
|
||||
|---------|-------------|----------|-------------|
|
||||
| `wifi_densepose_wasm` | `wifi-densepose-wasm` | CSI frame parsing, signal processing, feature extraction | ~200KB |
|
||||
| `ruvector_cnn_wasm` | `ruvector-cnn-wasm` | `WasmCnnEmbedder` (×2 instances), `SimdOps`, `LayerOps`, contrastive losses | ~150KB |
|
||||
|
||||
Two `WasmCnnEmbedder` instances are created — one for video frames, one for CSI pseudo-images.
|
||||
They share the same WASM module but have independent state.
|
||||
|
||||
### Browser API Requirements
|
||||
|
||||
| API | Purpose | Required | Fallback |
|
||||
|-----|---------|----------|----------|
|
||||
| `getUserMedia` | Webcam capture | For video mode | CSI-only mode |
|
||||
| WebAssembly | CNN inference | Yes | None (hard requirement) |
|
||||
| WASM SIMD128 | Accelerated inference | No | Scalar fallback (~2× slower) |
|
||||
| WebSocket | CSI data stream | For CSI mode | Video-only mode |
|
||||
| Canvas 2D | Rendering | Yes | None |
|
||||
| `requestAnimationFrame` | Render loop | Yes | `setTimeout` fallback |
|
||||
| ES Modules | Code organization | Yes | None |
|
||||
|
||||
Target: Chrome 89+, Firefox 89+, Safari 15+, Edge 89+
|
||||
|
||||
### Performance Budget
|
||||
|
||||
| Stage | Target Latency | Notes |
|
||||
|-------|---------------|-------|
|
||||
| Video frame capture + resize | <3ms | `drawImage` to offscreen canvas |
|
||||
| Video CNN embedding | <15ms | 224×224 RGB → 512-dim |
|
||||
| CSI receive + parse | <2ms | Binary WebSocket message |
|
||||
| CSI pseudo-image encoding | <3ms | Amplitude/phase/delta channels |
|
||||
| CSI CNN embedding | <15ms | 224×224 pseudo-RGB → 512-dim |
|
||||
| Attention fusion | <1ms | Element-wise weighted sum |
|
||||
| Pose decoding | <1ms | Linear projection |
|
||||
| Canvas overlay render | <3ms | Video + skeleton + heatmap |
|
||||
| **Total (dual mode)** | **<33ms** | **30 FPS capable** |
|
||||
| **Total (video only)** | **<22ms** | **45 FPS capable** |
|
||||
|
||||
Note: Video and CSI CNN pipelines can run in parallel using Web Workers,
|
||||
reducing dual-mode latency to ~max(15, 15) + 5 = ~20ms (50 FPS).
|
||||
|
||||
### Contrastive Learning Integration
|
||||
|
||||
The demo optionally shows real-time contrastive learning in the browser:
|
||||
|
||||
- **InfoNCE loss** (`WasmInfoNCELoss`): Compare video vs CSI embeddings for the same pose — trains cross-modal alignment
|
||||
- **Triplet loss** (`WasmTripletLoss`): Push apart different poses, pull together same pose across modalities
|
||||
- **SimdOps**: Accelerated dot products for real-time similarity computation
|
||||
- **Embedding space panel**: Live 2D projection shows video and CSI embeddings converging when viewing the same person
|
||||
|
||||
### Relationship to Existing Crates
|
||||
|
||||
| Existing Crate | Role in This Demo |
|
||||
|---------------|-------------------|
|
||||
| `ruvector-cnn-wasm` | CNN inference for **both** video frames and CSI pseudo-images |
|
||||
| `wifi-densepose-wasm` | CSI frame parsing and signal processing |
|
||||
| `wifi-densepose-sensing-server` | WebSocket CSI data source |
|
||||
| `wifi-densepose-core` | ADR-018 frame format definitions |
|
||||
| `ruvector-cnn` | Underlying MobileNet-V3, layers, contrastive learning |
|
||||
|
||||
No new Rust crates are needed. The example is pure HTML/JS consuming existing WASM packages.
|
||||
|
||||
## Consequences
|
||||
|
||||
### Positive
|
||||
|
||||
- **Instant demo**: Video-only mode works with just a webcam — no ESP32 needed
|
||||
- **Multi-modal showcase**: Demonstrates camera + WiFi fusion, the core innovation of the project
|
||||
- **Graceful degradation**: Works with video-only, CSI-only, or both
|
||||
- **Through-wall capability**: CSI mode shows pose estimation where cameras cannot reach
|
||||
- **Zero-install**: Anyone with a browser can try it
|
||||
- **Training data collection**: Can record paired (video, CSI) data for offline model training
|
||||
- **Reusable**: JS modules embed directly in the Tauri desktop app's webview
|
||||
|
||||
### Negative
|
||||
|
||||
- **Model weights**: Requires offline-trained weights for visual CNN, CSI CNN, fusion, and pose decoder (~200KB total JSON)
|
||||
- **WASM size**: Two WASM modules total ~350KB (acceptable)
|
||||
- **No GPU**: CPU-only WASM inference; adequate at 224×224 but limits resolution scaling
|
||||
- **Camera privacy**: Video mode requires camera permission (mitigated: CSI-only mode available)
|
||||
- **Two CNN instances**: Memory footprint doubles vs single-modal (~10MB total, acceptable for desktop browsers)
|
||||
|
||||
### Risks
|
||||
|
||||
- **Cross-modal alignment**: Video and CSI embeddings must be trained jointly for fusion to work;
|
||||
without proper training, fusion may be worse than either modality alone
|
||||
- **Latency on mobile**: Dual CNN on mobile browsers may exceed 33ms; implement automatic quality reduction
|
||||
- **WebSocket drops**: Network jitter → CSI frame gaps; buffer last 3 frames, interpolate missing data
|
||||
|
||||
## Implementation Plan
|
||||
|
||||
1. **Phase 1 — Scaffold**: File layout, build.sh, index.html shell, mode selector UI
|
||||
2. **Phase 2 — Video pipeline**: getUserMedia → frame capture → CNN embedding → basic pose display
|
||||
3. **Phase 3 — CSI pipeline**: WebSocket client → CSI parsing → pseudo-image → CNN embedding
|
||||
4. **Phase 4 — Fusion**: Attention-weighted combination, confidence gating, mode switching
|
||||
5. **Phase 5 — Pose decoder**: Linear projection with placeholder weights → 17 keypoints
|
||||
6. **Phase 6 — Overlay renderer**: Video canvas with skeleton overlay, CSI heatmap panel
|
||||
7. **Phase 7 — Training**: Use `wifi-densepose-train` to generate real weights for both CNNs + fusion + decoder
|
||||
8. **Phase 8 — Contrastive demo**: Embedding space visualization, cross-modal similarity display
|
||||
9. **Phase 9 — Web Workers**: Move CNN inference to workers for parallel video + CSI processing
|
||||
10. **Phase 10 — Polish**: Recording, snapshots, adaptive quality, mobile optimization
|
||||
|
||||
## Alternatives Considered
|
||||
|
||||
### 1. CSI-Only (No Video)
|
||||
Rejected: Misses the opportunity to show multi-modal fusion and makes the demo less
|
||||
accessible (requires ESP32 hardware). Video-only mode as a fallback is strictly better.
|
||||
|
||||
### 2. Server-Side Video Inference
|
||||
Rejected: Adds latency, requires webcam stream upload (privacy concern), and defeats
|
||||
the WASM-first architecture. All inference must be client-side.
|
||||
|
||||
### 3. TensorFlow.js for Video, ruvector-cnn-wasm for CSI
|
||||
Rejected: Would require two different ML frameworks. Using `ruvector-cnn-wasm` for both
|
||||
keeps a single WASM module, unified embedding space, and simpler fusion.
|
||||
|
||||
### 4. Pre-recorded Video Demo
|
||||
Rejected: Live webcam input is far more compelling for demonstrations.
|
||||
Pre-recorded mode can be added as a secondary option.
|
||||
|
||||
### 5. React/Vue Framework
|
||||
Rejected: Adds build tooling. Vanilla JS + ES modules keeps the demo self-contained.
|
||||
|
||||
## References
|
||||
|
||||
- [ADR-018: Binary CSI Frame Format](ADR-018-binary-csi-frame-format.md)
|
||||
- [ADR-024: Contrastive CSI Embedding / AETHER](ADR-024-contrastive-csi-embedding.md)
|
||||
- [ADR-055: Integrated Sensing Server](ADR-055-integrated-sensing-server.md)
|
||||
- `vendor/ruvector/crates/ruvector-cnn/src/lib.rs` — CNN embedder implementation
|
||||
- `vendor/ruvector/crates/ruvector-cnn-wasm/src/lib.rs` — WASM bindings
|
||||
- `vendor/ruvector/examples/wasm-vanilla/index.html` — Reference vanilla JS WASM pattern
|
||||
- Person-in-WiFi: Fine-grained Person Perception using WiFi (ICCV 2019) — camera+WiFi fusion precedent
|
||||
- WiPose: Multi-Person WiFi Pose Estimation (TMC 2022) — cross-modal embedding approach
|
||||
@@ -0,0 +1,83 @@
|
||||
# ADR-059: Live ESP32 CSI Pipeline Integration
|
||||
|
||||
## Status
|
||||
|
||||
Accepted
|
||||
|
||||
## Date
|
||||
|
||||
2026-03-12
|
||||
|
||||
## Context
|
||||
|
||||
ADR-058 established a dual-modal browser demo combining webcam video and WiFi CSI for pose estimation. However, it used simulated CSI data. To demonstrate real-world capability, we need an end-to-end pipeline from physical ESP32 hardware through to the browser visualization.
|
||||
|
||||
The ESP32-S3 firmware (`firmware/esp32-csi-node/`) already supports CSI collection and UDP streaming (ADR-018). The sensing server (`wifi-densepose-sensing-server`) already supports UDP ingestion and WebSocket bridging. The missing piece was connecting these components and enabling the browser demo to consume live data.
|
||||
|
||||
## Decision
|
||||
|
||||
Implement a complete live CSI pipeline:
|
||||
|
||||
```
|
||||
ESP32-S3 (CSI capture) → UDP:5005 → sensing-server (Rust/Axum) → WS:8765 → browser demo
|
||||
```
|
||||
|
||||
### Components
|
||||
|
||||
1. **ESP32 Firmware** — Rebuilt with native Windows ESP-IDF v5.4.0 toolchain (no Docker). Configured for target network and PC IP via `sdkconfig`. Helper scripts added:
|
||||
- `build_firmware.ps1` — Sets up IDF environment, cleans, builds, and flashes
|
||||
- `read_serial.ps1` — Serial monitor with DTR/RTS reset capability
|
||||
|
||||
2. **Sensing Server** — `wifi-densepose-sensing-server` started with:
|
||||
- `--source esp32` — Expect real ESP32 UDP frames
|
||||
- `--bind-addr 0.0.0.0` — Accept connections from any interface
|
||||
- `--ui-path <path>` — Serve the demo UI via HTTP
|
||||
|
||||
3. **Browser Demo** — `main.js` updated to auto-connect to `ws://localhost:8765/ws/sensing` on page load. Falls back to simulated CSI if the WebSocket is unavailable (GitHub Pages).
|
||||
|
||||
### Network Configuration
|
||||
|
||||
The ESP32 sends UDP packets to a configured target IP. If the PC's IP doesn't match the firmware's compiled target, a secondary IP alias can be added:
|
||||
|
||||
```powershell
|
||||
# PowerShell (Admin)
|
||||
New-NetIPAddress -IPAddress 192.168.1.100 -PrefixLength 24 -InterfaceAlias "Wi-Fi"
|
||||
```
|
||||
|
||||
### Data Flow
|
||||
|
||||
| Stage | Protocol | Format | Rate |
|
||||
|-------|----------|--------|------|
|
||||
| ESP32 → Server | UDP | ADR-018 binary frame (magic `0xC5110001`, I/Q pairs) | ~100 Hz |
|
||||
| Server → Browser | WebSocket | ADR-018 binary frame (forwarded) | ~10 Hz (tick-ms=100) |
|
||||
| Browser decode | JavaScript | Float32 amplitude/phase arrays | Per frame |
|
||||
|
||||
### Build Environment (Windows)
|
||||
|
||||
ESP-IDF v5.4.0 on Windows requires:
|
||||
- IDF_PATH pointing to the ESP-IDF framework
|
||||
- IDF_TOOLS_PATH pointing to toolchain binaries
|
||||
- MSYS/MinGW environment variables removed (ESP-IDF rejects them)
|
||||
- Python venv from ESP-IDF tools for `idf.py` execution
|
||||
|
||||
The `build_firmware.ps1` script handles all of this automatically.
|
||||
|
||||
## Consequences
|
||||
|
||||
### Positive
|
||||
- First end-to-end demonstration of real WiFi CSI → pose estimation in a browser
|
||||
- No Docker required for firmware builds on Windows
|
||||
- Demo gracefully degrades to simulated CSI when no server is available
|
||||
- Same demo works on GitHub Pages (simulated) and locally (live ESP32)
|
||||
|
||||
### Negative
|
||||
- ESP32 target IP is compiled into firmware; changing it requires a rebuild or NVS override
|
||||
- Windows firewall may block UDP:5005; user must allow it
|
||||
- Mixed content restrictions prevent HTTPS pages from connecting to ws:// (local only)
|
||||
|
||||
## Related
|
||||
|
||||
- [ADR-018](ADR-018-esp32-dev-implementation.md) — ESP32 CSI frame format and UDP streaming
|
||||
- [ADR-058](ADR-058-ruvector-wasm-browser-pose-example.md) — Dual-modal WASM browser pose demo
|
||||
- [ADR-039](ADR-039-edge-intelligence-framework.md) — Edge intelligence on ESP32
|
||||
- Issue [#245](https://github.com/ruvnet/RuView/issues/245) — Tracking issue
|
||||
+33
-11
@@ -78,6 +78,17 @@ docker pull ruvnet/wifi-densepose:latest
|
||||
|
||||
Multi-architecture image (amd64 + arm64). Works on Intel/AMD and Apple Silicon Macs. Contains the Rust sensing server, Three.js UI, and all signal processing.
|
||||
|
||||
**Data source selection:** Use the `CSI_SOURCE` environment variable to select the sensing mode:
|
||||
|
||||
| Value | Description |
|
||||
|-------|-------------|
|
||||
| `auto` | (default) Probe for ESP32 on UDP 5005, fall back to simulation |
|
||||
| `esp32` | Receive real CSI frames from ESP32 devices over UDP |
|
||||
| `simulated` | Generate synthetic CSI frames (no hardware required) |
|
||||
| `wifi` | Host Wi-Fi RSSI (not available inside containers) |
|
||||
|
||||
Example: `docker run -e CSI_SOURCE=esp32 -p 3000:3000 -p 5005:5005/udp ruvnet/wifi-densepose:latest`
|
||||
|
||||
### From Source (Rust)
|
||||
|
||||
```bash
|
||||
@@ -267,8 +278,8 @@ Real Channel State Information at 20 Hz with 56-192 subcarriers. Required for po
|
||||
# From source
|
||||
./target/release/sensing-server --source esp32 --udp-port 5005 --http-port 3000 --ws-port 3001
|
||||
|
||||
# Docker
|
||||
docker run -p 3000:3000 -p 3001:3001 -p 5005:5005/udp ruvnet/wifi-densepose:latest --source esp32
|
||||
# Docker (use CSI_SOURCE environment variable)
|
||||
docker run -p 3000:3000 -p 3001:3001 -p 5005:5005/udp -e CSI_SOURCE=esp32 ruvnet/wifi-densepose:latest
|
||||
```
|
||||
|
||||
The ESP32 nodes stream binary CSI frames over UDP to port 5005. See [Hardware Setup](#esp32-s3-mesh) for flashing instructions.
|
||||
@@ -679,9 +690,11 @@ Download the dataset files and place them in a `data/` directory.
|
||||
./target/release/sensing-server --train --dataset data/ --dataset-type mmfi --epochs 100 --save-rvf model.rvf
|
||||
|
||||
# Via Docker (mount your data directory)
|
||||
# Note: Training mode requires overriding the default entrypoint
|
||||
docker run --rm \
|
||||
-v $(pwd)/data:/data \
|
||||
-v $(pwd)/output:/output \
|
||||
--entrypoint /app/sensing-server \
|
||||
ruvnet/wifi-densepose:latest \
|
||||
--train --dataset /data --epochs 100 --export-rvf /output/model.rvf
|
||||
```
|
||||
@@ -797,14 +810,18 @@ Pre-built binaries are available at [Releases](https://github.com/ruvnet/RuView/
|
||||
|
||||
| Release | What It Includes | Tag |
|
||||
|---------|-----------------|-----|
|
||||
| [v0.2.0](https://github.com/ruvnet/RuView/releases/tag/v0.2.0-esp32) | Stable — raw CSI streaming, TDM, channel hopping, QUIC mesh | `v0.2.0-esp32` |
|
||||
| [v0.4.1](https://github.com/ruvnet/RuView/releases/tag/v0.4.1-esp32) | **Stable** — CSI build fix, compile guard, AMOLED display, edge intelligence ([ADR-057](../docs/adr/ADR-057-firmware-csi-build-guard.md)) | `v0.4.1-esp32` |
|
||||
| [v0.3.0-alpha](https://github.com/ruvnet/RuView/releases/tag/v0.3.0-alpha-esp32) | Alpha — adds on-device edge intelligence (ADR-039) | `v0.3.0-alpha-esp32` |
|
||||
| [v0.2.0](https://github.com/ruvnet/RuView/releases/tag/v0.2.0-esp32) | Raw CSI streaming, TDM, channel hopping, QUIC mesh | `v0.2.0-esp32` |
|
||||
|
||||
> **Important:** Firmware versions prior to v0.4.1 had CSI **disabled** in the build config, causing a runtime error (`E wifi:CSI not enabled in menuconfig!`). Always use v0.4.1 or later.
|
||||
|
||||
```bash
|
||||
# Flash an ESP32-S3 (requires esptool: pip install esptool)
|
||||
python -m esptool --chip esp32s3 --port COM7 --baud 460800 \
|
||||
write-flash --flash-mode dio --flash-size 4MB \
|
||||
0x0 bootloader.bin 0x8000 partition-table.bin 0x10000 esp32-csi-node.bin
|
||||
write-flash --flash-mode dio --flash-size 8MB --flash-freq 80m \
|
||||
0x0 bootloader.bin 0x8000 partition-table.bin \
|
||||
0xf000 ota_data_initial.bin 0x20000 esp32-csi-node.bin
|
||||
```
|
||||
|
||||
**Provisioning:**
|
||||
@@ -885,8 +902,8 @@ Binary size: 777 KB (24% free in the 1 MB app partition).
|
||||
# From source
|
||||
./target/release/sensing-server --source esp32 --udp-port 5005 --http-port 3000 --ws-port 3001
|
||||
|
||||
# Docker
|
||||
docker run -p 3000:3000 -p 3001:3001 -p 5005:5005/udp ruvnet/wifi-densepose:latest --source esp32
|
||||
# Docker (use CSI_SOURCE environment variable)
|
||||
docker run -p 3000:3000 -p 3001:3001 -p 5005:5005/udp -e CSI_SOURCE=esp32 ruvnet/wifi-densepose:latest
|
||||
```
|
||||
|
||||
See [ADR-018](../docs/adr/ADR-018-esp32-dev-implementation.md), [ADR-029](../docs/adr/ADR-029-ruvsense-multistatic-sensing-mode.md), and [Tutorial #34](https://github.com/ruvnet/RuView/issues/34).
|
||||
@@ -953,12 +970,17 @@ Add the WebSocket port mapping:
|
||||
docker run -p 3000:3000 -p 3001:3001 ruvnet/wifi-densepose:latest
|
||||
```
|
||||
|
||||
### ESP32: "CSI not enabled in menuconfig"
|
||||
|
||||
Firmware versions prior to v0.4.1 had `CONFIG_ESP_WIFI_CSI_ENABLED` disabled in the build config. Upgrade to [v0.4.1](https://github.com/ruvnet/RuView/releases/tag/v0.4.1-esp32) or later. If building from source, ensure `sdkconfig.defaults` exists (not just `sdkconfig.defaults.template`). See [ADR-057](../docs/adr/ADR-057-firmware-csi-build-guard.md).
|
||||
|
||||
### ESP32: No data arriving
|
||||
|
||||
1. Verify the ESP32 is connected to the same WiFi network
|
||||
2. Check the target IP matches the sensing server machine: `python firmware/esp32-csi-node/provision.py --port COM7 --target-ip <YOUR_IP>`
|
||||
3. Verify UDP port 5005 is not blocked by firewall
|
||||
4. Test with: `nc -lu 5005` (Linux) or similar UDP listener
|
||||
1. Verify firmware is v0.4.1+ (older versions had CSI disabled — see above)
|
||||
2. Verify the ESP32 is connected to the same WiFi network
|
||||
3. Check the target IP matches the sensing server machine: `python firmware/esp32-csi-node/provision.py --port COM7 --target-ip <YOUR_IP>`
|
||||
4. Verify UDP port 5005 is not blocked by firewall
|
||||
5. Test with: `nc -lu 5005` (Linux) or similar UDP listener
|
||||
|
||||
### Build: Rust compilation errors
|
||||
|
||||
|
||||
@@ -0,0 +1,130 @@
|
||||
{
|
||||
"running": true,
|
||||
"startedAt": "2026-03-10T14:22:41.948Z",
|
||||
"workers": {
|
||||
"map": {
|
||||
"runCount": 0,
|
||||
"successCount": 0,
|
||||
"failureCount": 0,
|
||||
"averageDurationMs": 0,
|
||||
"isRunning": false,
|
||||
"nextRun": "2026-03-10T14:22:41.948Z"
|
||||
},
|
||||
"audit": {
|
||||
"runCount": 0,
|
||||
"successCount": 0,
|
||||
"failureCount": 0,
|
||||
"averageDurationMs": 0,
|
||||
"isRunning": false,
|
||||
"nextRun": "2026-03-10T14:24:41.948Z"
|
||||
},
|
||||
"optimize": {
|
||||
"runCount": 0,
|
||||
"successCount": 0,
|
||||
"failureCount": 0,
|
||||
"averageDurationMs": 0,
|
||||
"isRunning": false,
|
||||
"nextRun": "2026-03-10T14:26:41.948Z"
|
||||
},
|
||||
"consolidate": {
|
||||
"runCount": 0,
|
||||
"successCount": 0,
|
||||
"failureCount": 0,
|
||||
"averageDurationMs": 0,
|
||||
"isRunning": false,
|
||||
"nextRun": "2026-03-10T14:28:41.949Z"
|
||||
},
|
||||
"testgaps": {
|
||||
"runCount": 0,
|
||||
"successCount": 0,
|
||||
"failureCount": 0,
|
||||
"averageDurationMs": 0,
|
||||
"isRunning": false,
|
||||
"nextRun": "2026-03-10T14:30:41.949Z"
|
||||
},
|
||||
"predict": {
|
||||
"runCount": 0,
|
||||
"successCount": 0,
|
||||
"failureCount": 0,
|
||||
"averageDurationMs": 0,
|
||||
"isRunning": false
|
||||
},
|
||||
"document": {
|
||||
"runCount": 0,
|
||||
"successCount": 0,
|
||||
"failureCount": 0,
|
||||
"averageDurationMs": 0,
|
||||
"isRunning": false
|
||||
}
|
||||
},
|
||||
"config": {
|
||||
"autoStart": false,
|
||||
"logDir": "/Users/cohen/GitHub/ruvnet/RuView/firmware/esp32-csi-node/.claude-flow/logs",
|
||||
"stateFile": "/Users/cohen/GitHub/ruvnet/RuView/firmware/esp32-csi-node/.claude-flow/daemon-state.json",
|
||||
"maxConcurrent": 2,
|
||||
"workerTimeoutMs": 300000,
|
||||
"resourceThresholds": {
|
||||
"maxCpuLoad": 2,
|
||||
"minFreeMemoryPercent": 20
|
||||
},
|
||||
"workers": [
|
||||
{
|
||||
"type": "map",
|
||||
"intervalMs": 900000,
|
||||
"offsetMs": 0,
|
||||
"priority": "normal",
|
||||
"description": "Codebase mapping",
|
||||
"enabled": true
|
||||
},
|
||||
{
|
||||
"type": "audit",
|
||||
"intervalMs": 600000,
|
||||
"offsetMs": 120000,
|
||||
"priority": "critical",
|
||||
"description": "Security analysis",
|
||||
"enabled": true
|
||||
},
|
||||
{
|
||||
"type": "optimize",
|
||||
"intervalMs": 900000,
|
||||
"offsetMs": 240000,
|
||||
"priority": "high",
|
||||
"description": "Performance optimization",
|
||||
"enabled": true
|
||||
},
|
||||
{
|
||||
"type": "consolidate",
|
||||
"intervalMs": 1800000,
|
||||
"offsetMs": 360000,
|
||||
"priority": "low",
|
||||
"description": "Memory consolidation",
|
||||
"enabled": true
|
||||
},
|
||||
{
|
||||
"type": "testgaps",
|
||||
"intervalMs": 1200000,
|
||||
"offsetMs": 480000,
|
||||
"priority": "normal",
|
||||
"description": "Test coverage analysis",
|
||||
"enabled": true
|
||||
},
|
||||
{
|
||||
"type": "predict",
|
||||
"intervalMs": 600000,
|
||||
"offsetMs": 0,
|
||||
"priority": "low",
|
||||
"description": "Predictive preloading",
|
||||
"enabled": false
|
||||
},
|
||||
{
|
||||
"type": "document",
|
||||
"intervalMs": 3600000,
|
||||
"offsetMs": 0,
|
||||
"priority": "low",
|
||||
"description": "Auto-documentation",
|
||||
"enabled": false
|
||||
}
|
||||
]
|
||||
},
|
||||
"savedAt": "2026-03-10T14:22:41.949Z"
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
{"type":"edit","file":"unknown","timestamp":1773152422749,"sessionId":null}
|
||||
{"type":"edit","file":"unknown","timestamp":1773152444021,"sessionId":null}
|
||||
{"type":"edit","file":"unknown","timestamp":1773152460956,"sessionId":null}
|
||||
{"type":"edit","file":"unknown","timestamp":1773152493971,"sessionId":null}
|
||||
{"type":"edit","file":"unknown","timestamp":1773152501432,"sessionId":null}
|
||||
{"type":"edit","file":"unknown","timestamp":1773152510853,"sessionId":null}
|
||||
{"type":"edit","file":"unknown","timestamp":1773152596890,"sessionId":null}
|
||||
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"id": "session-1773152560779",
|
||||
"startedAt": "2026-03-10T14:22:40.779Z",
|
||||
"cwd": "/Users/cohen/GitHub/ruvnet/RuView/firmware/esp32-csi-node",
|
||||
"context": {},
|
||||
"metrics": {
|
||||
"edits": 1,
|
||||
"commands": 0,
|
||||
"tasks": 0,
|
||||
"errors": 0
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
# Remove MSYS environment variables that trigger ESP-IDF's MinGW rejection
|
||||
Remove-Item env:MSYSTEM -ErrorAction SilentlyContinue
|
||||
Remove-Item env:MSYSTEM_CARCH -ErrorAction SilentlyContinue
|
||||
Remove-Item env:MSYSTEM_CHOST -ErrorAction SilentlyContinue
|
||||
Remove-Item env:MSYSTEM_PREFIX -ErrorAction SilentlyContinue
|
||||
Remove-Item env:MINGW_CHOST -ErrorAction SilentlyContinue
|
||||
Remove-Item env:MINGW_PACKAGE_PREFIX -ErrorAction SilentlyContinue
|
||||
Remove-Item env:MINGW_PREFIX -ErrorAction SilentlyContinue
|
||||
|
||||
$env:IDF_PATH = "C:\Users\ruv\esp\v5.4\esp-idf"
|
||||
$env:IDF_TOOLS_PATH = "C:\Espressif\tools"
|
||||
$env:IDF_PYTHON_ENV_PATH = "C:\Espressif\tools\python\v5.4\venv"
|
||||
$env:PATH = "C:\Espressif\tools\xtensa-esp-elf\esp-14.2.0_20241119\xtensa-esp-elf\bin;C:\Espressif\tools\cmake\3.30.2\cmake-3.30.2-windows-x86_64\bin;C:\Espressif\tools\ninja\1.12.1;C:\Espressif\tools\ccache\4.10.2\ccache-4.10.2-windows-x86_64;C:\Espressif\tools\idf-exe\1.0.3;C:\Espressif\tools\python\v5.4\venv\Scripts;$env:PATH"
|
||||
|
||||
Set-Location "C:\Users\ruv\Projects\wifi-densepose\firmware\esp32-csi-node"
|
||||
|
||||
$python = "$env:IDF_PYTHON_ENV_PATH\Scripts\python.exe"
|
||||
$idf = "$env:IDF_PATH\tools\idf.py"
|
||||
|
||||
Write-Host "=== Cleaning stale build cache ==="
|
||||
& $python $idf fullclean
|
||||
|
||||
Write-Host "=== Building firmware (SSID=ruv.net, target=192.168.1.20:5005) ==="
|
||||
& $python $idf build
|
||||
|
||||
if ($LASTEXITCODE -eq 0) {
|
||||
Write-Host "=== Build succeeded! Flashing to COM7 ==="
|
||||
& $python $idf -p COM7 flash
|
||||
} else {
|
||||
Write-Host "=== Build failed with exit code $LASTEXITCODE ==="
|
||||
}
|
||||
@@ -21,6 +21,16 @@
|
||||
#include "esp_timer.h"
|
||||
#include "sdkconfig.h"
|
||||
|
||||
/* ADR-057: Build-time guard — fail early if CSI is not enabled in sdkconfig.
|
||||
* Without this, the firmware compiles but crashes at runtime with:
|
||||
* "E (xxxx) wifi:CSI not enabled in menuconfig!"
|
||||
* which is confusing for users flashing pre-built binaries. */
|
||||
#ifndef CONFIG_ESP_WIFI_CSI_ENABLED
|
||||
#error "CONFIG_ESP_WIFI_CSI_ENABLED must be set in sdkconfig. " \
|
||||
"Run: idf.py menuconfig -> Component config -> Wi-Fi -> Enable WiFi CSI, " \
|
||||
"or copy sdkconfig.defaults.template to sdkconfig.defaults before building."
|
||||
#endif
|
||||
|
||||
static const char *TAG = "csi_collector";
|
||||
|
||||
static uint32_t s_sequence = 0;
|
||||
|
||||
File diff suppressed because one or more lines are too long
Binary file not shown.
@@ -76,7 +76,16 @@ def generate_nvs_binary(csv_content, size):
|
||||
bin_path = csv_path.replace(".csv", ".bin")
|
||||
|
||||
try:
|
||||
# Try the pip-installed version first
|
||||
# Try the pip-installed version first (esp_idf_nvs_partition_gen package)
|
||||
try:
|
||||
from esp_idf_nvs_partition_gen import nvs_partition_gen
|
||||
nvs_partition_gen.generate(csv_path, bin_path, size)
|
||||
with open(bin_path, "rb") as f:
|
||||
return f.read()
|
||||
except ImportError:
|
||||
pass
|
||||
|
||||
# Try legacy import name (older versions)
|
||||
try:
|
||||
import nvs_partition_gen
|
||||
nvs_partition_gen.generate(csv_path, bin_path, size)
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
$p = New-Object System.IO.Ports.SerialPort('COM7', 115200)
|
||||
$p.ReadTimeout = 5000
|
||||
$p.Open()
|
||||
Start-Sleep -Milliseconds 200
|
||||
|
||||
for ($i = 0; $i -lt 60; $i++) {
|
||||
try {
|
||||
$line = $p.ReadLine()
|
||||
Write-Host $line
|
||||
} catch {
|
||||
break
|
||||
}
|
||||
}
|
||||
$p.Close()
|
||||
@@ -0,0 +1,33 @@
|
||||
# ESP32-S3 CSI Node — Default SDK Configuration
|
||||
# This file is applied automatically by idf.py when no sdkconfig exists.
|
||||
|
||||
# Target: ESP32-S3
|
||||
CONFIG_IDF_TARGET="esp32s3"
|
||||
|
||||
# Use custom partition table (8MB flash with OTA — ADR-045)
|
||||
CONFIG_PARTITION_TABLE_CUSTOM=y
|
||||
CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="partitions_display.csv"
|
||||
|
||||
# Flash configuration: 8MB (Quad SPI)
|
||||
CONFIG_ESPTOOLPY_FLASHSIZE_8MB=y
|
||||
CONFIG_ESPTOOLPY_FLASHSIZE="8MB"
|
||||
|
||||
# Compiler optimization: optimize for size to reduce binary
|
||||
CONFIG_COMPILER_OPTIMIZATION_SIZE=y
|
||||
|
||||
# Enable CSI (Channel State Information) in WiFi driver
|
||||
CONFIG_ESP_WIFI_CSI_ENABLED=y
|
||||
|
||||
# NVS encryption disabled by default (requires eFuse provisioning).
|
||||
# Enable only after burning HMAC key to eFuse block.
|
||||
# CONFIG_NVS_ENCRYPTION is not set
|
||||
|
||||
# Disable unused features to reduce binary size
|
||||
CONFIG_BOOTLOADER_LOG_LEVEL_WARN=y
|
||||
CONFIG_LOG_DEFAULT_LEVEL_INFO=y
|
||||
|
||||
# LWIP: enable extended socket options for UDP multicast
|
||||
CONFIG_LWIP_SO_RCVBUF=y
|
||||
|
||||
# FreeRTOS: increase task stack for CSI processing
|
||||
CONFIG_ESP_MAIN_TASK_STACK_SIZE=8192
|
||||
@@ -0,0 +1,33 @@
|
||||
# ESP32-S3 CSI Node — Default SDK Configuration
|
||||
# This file is applied automatically by idf.py when no sdkconfig exists.
|
||||
|
||||
# Target: ESP32-S3
|
||||
CONFIG_IDF_TARGET="esp32s3"
|
||||
|
||||
# Use custom partition table (8MB flash with OTA — ADR-045)
|
||||
CONFIG_PARTITION_TABLE_CUSTOM=y
|
||||
CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="partitions_display.csv"
|
||||
|
||||
# Flash configuration: 8MB (Quad SPI)
|
||||
CONFIG_ESPTOOLPY_FLASHSIZE_8MB=y
|
||||
CONFIG_ESPTOOLPY_FLASHSIZE="8MB"
|
||||
|
||||
# Compiler optimization: optimize for size to reduce binary
|
||||
CONFIG_COMPILER_OPTIMIZATION_SIZE=y
|
||||
|
||||
# Enable CSI (Channel State Information) in WiFi driver
|
||||
CONFIG_ESP_WIFI_CSI_ENABLED=y
|
||||
|
||||
# NVS encryption disabled by default (requires eFuse provisioning).
|
||||
# Enable only after burning HMAC key to eFuse block.
|
||||
# CONFIG_NVS_ENCRYPTION is not set
|
||||
|
||||
# Disable unused features to reduce binary size
|
||||
CONFIG_BOOTLOADER_LOG_LEVEL_WARN=y
|
||||
CONFIG_LOG_DEFAULT_LEVEL_INFO=y
|
||||
|
||||
# LWIP: enable extended socket options for UDP multicast
|
||||
CONFIG_LWIP_SO_RCVBUF=y
|
||||
|
||||
# FreeRTOS: increase task stack for CSI processing
|
||||
CONFIG_ESP_MAIN_TASK_STACK_SIZE=8192
|
||||
Binary file not shown.
@@ -3,3 +3,8 @@
|
||||
{"type":"edit","file":"unknown","timestamp":1772820472219,"sessionId":null}
|
||||
{"type":"edit","file":"unknown","timestamp":1772832571444,"sessionId":null}
|
||||
{"type":"edit","file":"unknown","timestamp":1772832585997,"sessionId":null}
|
||||
{"type":"edit","file":"unknown","timestamp":1773099593107,"sessionId":null}
|
||||
{"type":"edit","file":"unknown","timestamp":1773115162931,"sessionId":null}
|
||||
{"type":"edit","file":"unknown","timestamp":1773115172336,"sessionId":null}
|
||||
{"type":"edit","file":"unknown","timestamp":1773147087836,"sessionId":null}
|
||||
{"type":"edit","file":"unknown","timestamp":1773149448951,"sessionId":null}
|
||||
|
||||
Generated
+435
-18
@@ -791,6 +791,15 @@ dependencies = [
|
||||
"memchr",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "concurrent-queue"
|
||||
version = "2.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4ca0197aee26d1ae37445ee532fefce43251d24cc7c166799f4d46817f1d3973"
|
||||
dependencies = [
|
||||
"crossbeam-utils",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "console"
|
||||
version = "0.15.11"
|
||||
@@ -1448,6 +1457,18 @@ version = "1.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8bf7cc16383c4b8d58b9905a8509f02926ce3058053c056376248d958c9df1e8"
|
||||
|
||||
[[package]]
|
||||
name = "flume"
|
||||
version = "0.11.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "da0e4dd2a88388a1f4ccc7c9ce104604dab68d9f408dc34cd45823d5a9069095"
|
||||
dependencies = [
|
||||
"futures-core",
|
||||
"futures-sink",
|
||||
"nanorand",
|
||||
"spin",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "fnv"
|
||||
version = "1.0.7"
|
||||
@@ -2335,6 +2356,22 @@ dependencies = [
|
||||
"want",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "hyper-tls"
|
||||
version = "0.6.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "70206fc6890eaca9fde8a0bf71caa2ddfc9fe045ac9e5c70df101a7dbde866e0"
|
||||
dependencies = [
|
||||
"bytes",
|
||||
"http-body-util",
|
||||
"hyper",
|
||||
"hyper-util",
|
||||
"native-tls",
|
||||
"tokio",
|
||||
"tokio-native-tls",
|
||||
"tower-service",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "hyper-util"
|
||||
version = "0.1.20"
|
||||
@@ -2352,7 +2389,7 @@ dependencies = [
|
||||
"libc",
|
||||
"percent-encoding",
|
||||
"pin-project-lite",
|
||||
"socket2",
|
||||
"socket2 0.6.2",
|
||||
"tokio",
|
||||
"tower-service",
|
||||
"tracing",
|
||||
@@ -2506,6 +2543,16 @@ dependencies = [
|
||||
"icu_properties",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "if-addrs"
|
||||
version = "0.13.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "69b2eeee38fef3aa9b4cc5f1beea8a2444fc00e7377cafae396de3f5c2065e24"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"windows-sys 0.59.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "indexmap"
|
||||
version = "1.9.3"
|
||||
@@ -2560,6 +2607,16 @@ dependencies = [
|
||||
"generic-array 0.14.7",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "io-kit-sys"
|
||||
version = "0.4.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "617ee6cf8e3f66f3b4ea67a4058564628cde41901316e19f559e14c7c72c5e7b"
|
||||
dependencies = [
|
||||
"core-foundation-sys",
|
||||
"mach2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ipnet"
|
||||
version = "2.12.0"
|
||||
@@ -2813,6 +2870,26 @@ dependencies = [
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "libudev"
|
||||
version = "0.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "78b324152da65df7bb95acfcaab55e3097ceaab02fb19b228a9eb74d55f135e0"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"libudev-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "libudev-sys"
|
||||
version = "0.1.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3c8469b4a23b962c1396b9b451dda50ef5b283e8dd309d69033475fa9b334324"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"pkg-config",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "linux-raw-sys"
|
||||
version = "0.12.1"
|
||||
@@ -2867,6 +2944,15 @@ version = "0.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c41e0c4fef86961ac6d6f8a82609f55f31b05e4fce149ac5710e439df7619ba4"
|
||||
|
||||
[[package]]
|
||||
name = "mach2"
|
||||
version = "0.4.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d640282b302c0bb0a2a8e0233ead9035e3bed871f0b7e81fe4a1ec829765db44"
|
||||
dependencies = [
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "markup5ever"
|
||||
version = "0.14.1"
|
||||
@@ -2923,6 +3009,19 @@ dependencies = [
|
||||
"rawpointer",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "mdns-sd"
|
||||
version = "0.11.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8fe7c11a1eb3cfbfcf702d1601c1f5f4c102cdc8665b8a557783ef634741676e"
|
||||
dependencies = [
|
||||
"flume",
|
||||
"if-addrs",
|
||||
"log",
|
||||
"polling",
|
||||
"socket2 0.5.10",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "memchr"
|
||||
version = "2.8.0"
|
||||
@@ -3054,10 +3153,24 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a69bcab0ad47271a0234d9422b131806bf3968021e5dc9328caf2d4cd58557fc"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"log",
|
||||
"wasi 0.11.1+wasi-snapshot-preview1",
|
||||
"windows-sys 0.61.2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "mio-serial"
|
||||
version = "5.0.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "029e1f407e261176a983a6599c084efd322d9301028055c87174beac71397ba3"
|
||||
dependencies = [
|
||||
"log",
|
||||
"mio",
|
||||
"nix 0.29.0",
|
||||
"serialport",
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "muda"
|
||||
version = "0.17.1"
|
||||
@@ -3126,6 +3239,15 @@ dependencies = [
|
||||
"syn 2.0.117",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "nanorand"
|
||||
version = "0.7.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6a51313c5820b0b02bd422f4b44776fbf47961755c74ce64afc73bfad10226c3"
|
||||
dependencies = [
|
||||
"getrandom 0.2.17",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "native-tls"
|
||||
version = "0.2.18"
|
||||
@@ -3238,6 +3360,29 @@ version = "1.0.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "650eef8c711430f1a879fdd01d4745a7deea475becfb90269c06775983bbf086"
|
||||
|
||||
[[package]]
|
||||
name = "nix"
|
||||
version = "0.26.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "598beaf3cc6fdd9a5dfb1630c2800c7acd31df7aaf0f565796fba2b53ca1af1b"
|
||||
dependencies = [
|
||||
"bitflags 1.3.2",
|
||||
"cfg-if",
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "nix"
|
||||
version = "0.29.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "71e2746dc3a24dd78b3cfcb7be93368c6de9963d30f43a6a73998a9cf4b17b46"
|
||||
dependencies = [
|
||||
"bitflags 2.11.0",
|
||||
"cfg-if",
|
||||
"cfg_aliases",
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "nodrop"
|
||||
version = "0.1.14"
|
||||
@@ -3260,6 +3405,15 @@ version = "0.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "61807f77802ff30975e01f4f071c8ba10c022052f98b3294119f3e615d13e5be"
|
||||
|
||||
[[package]]
|
||||
name = "ntapi"
|
||||
version = "0.4.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c3b335231dfd352ffb0f8017f3b6027a4917f7df785ea2143d8af2adc66980ae"
|
||||
dependencies = [
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "nu-ansi-term"
|
||||
version = "0.50.3"
|
||||
@@ -3995,6 +4149,22 @@ dependencies = [
|
||||
"miniz_oxide",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "polling"
|
||||
version = "2.8.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4b2d323e8ca7996b3e23126511a523f7e62924d93ecd5ae73b333815b0eb3dce"
|
||||
dependencies = [
|
||||
"autocfg",
|
||||
"bitflags 1.3.2",
|
||||
"cfg-if",
|
||||
"concurrent-queue",
|
||||
"libc",
|
||||
"log",
|
||||
"pin-project-lite",
|
||||
"windows-sys 0.48.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "portable-atomic"
|
||||
version = "1.13.1"
|
||||
@@ -4249,7 +4419,7 @@ dependencies = [
|
||||
"quinn-udp",
|
||||
"rustc-hash",
|
||||
"rustls 0.23.37",
|
||||
"socket2",
|
||||
"socket2 0.6.2",
|
||||
"thiserror 2.0.18",
|
||||
"tokio",
|
||||
"tracing",
|
||||
@@ -4288,7 +4458,7 @@ dependencies = [
|
||||
"cfg_aliases",
|
||||
"libc",
|
||||
"once_cell",
|
||||
"socket2",
|
||||
"socket2 0.6.2",
|
||||
"tracing",
|
||||
"windows-sys 0.60.2",
|
||||
]
|
||||
@@ -4593,6 +4763,44 @@ dependencies = [
|
||||
"bytecheck",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "reqwest"
|
||||
version = "0.12.28"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "eddd3ca559203180a307f12d114c268abf583f59b03cb906fd0b3ff8646c1147"
|
||||
dependencies = [
|
||||
"base64 0.22.1",
|
||||
"bytes",
|
||||
"futures-core",
|
||||
"futures-util",
|
||||
"http",
|
||||
"http-body",
|
||||
"http-body-util",
|
||||
"hyper",
|
||||
"hyper-tls",
|
||||
"hyper-util",
|
||||
"js-sys",
|
||||
"log",
|
||||
"mime_guess",
|
||||
"native-tls",
|
||||
"percent-encoding",
|
||||
"pin-project-lite",
|
||||
"rustls-pki-types",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"serde_urlencoded",
|
||||
"sync_wrapper",
|
||||
"tokio",
|
||||
"tokio-native-tls",
|
||||
"tower",
|
||||
"tower-http 0.6.8",
|
||||
"tower-service",
|
||||
"url",
|
||||
"wasm-bindgen",
|
||||
"wasm-bindgen-futures",
|
||||
"web-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "reqwest"
|
||||
version = "0.13.2"
|
||||
@@ -5415,6 +5623,25 @@ dependencies = [
|
||||
"syn 2.0.117",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serialport"
|
||||
version = "4.7.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2acaf3f973e8616d7ceac415f53fc60e190b2a686fbcf8d27d0256c741c5007b"
|
||||
dependencies = [
|
||||
"bitflags 2.11.0",
|
||||
"cfg-if",
|
||||
"core-foundation",
|
||||
"core-foundation-sys",
|
||||
"io-kit-sys",
|
||||
"libudev",
|
||||
"mach2",
|
||||
"nix 0.26.4",
|
||||
"scopeguard",
|
||||
"unescaper",
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "servo_arc"
|
||||
version = "0.2.0"
|
||||
@@ -5553,6 +5780,16 @@ version = "1.15.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "67b1b7a3b5fe4f1376887184045fcf45c69e92af734b7aaddc05fb777b6fbd03"
|
||||
|
||||
[[package]]
|
||||
name = "socket2"
|
||||
version = "0.5.10"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e22376abed350d73dd1cd119b57ffccad95b4e585a7cda43e286245ce23c0678"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"windows-sys 0.52.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "socket2"
|
||||
version = "0.6.2"
|
||||
@@ -5759,6 +5996,20 @@ dependencies = [
|
||||
"walkdir",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "sysinfo"
|
||||
version = "0.32.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4c33cd241af0f2e9e3b5c32163b873b29956890b5342e6745b917ce9d490f4af"
|
||||
dependencies = [
|
||||
"core-foundation-sys",
|
||||
"libc",
|
||||
"memchr",
|
||||
"ntapi",
|
||||
"rayon",
|
||||
"windows 0.57.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "system-deps"
|
||||
version = "6.2.2"
|
||||
@@ -5830,7 +6081,7 @@ dependencies = [
|
||||
"tao-macros",
|
||||
"unicode-segmentation",
|
||||
"url",
|
||||
"windows",
|
||||
"windows 0.61.3",
|
||||
"windows-core 0.61.2",
|
||||
"windows-version",
|
||||
"x11-dl",
|
||||
@@ -5883,7 +6134,7 @@ dependencies = [
|
||||
"percent-encoding",
|
||||
"plist",
|
||||
"raw-window-handle",
|
||||
"reqwest",
|
||||
"reqwest 0.13.2",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"serde_repr",
|
||||
@@ -5901,7 +6152,7 @@ dependencies = [
|
||||
"webkit2gtk",
|
||||
"webview2-com",
|
||||
"window-vibrancy",
|
||||
"windows",
|
||||
"windows 0.61.3",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -6067,7 +6318,7 @@ dependencies = [
|
||||
"url",
|
||||
"webkit2gtk",
|
||||
"webview2-com",
|
||||
"windows",
|
||||
"windows 0.61.3",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -6092,7 +6343,7 @@ dependencies = [
|
||||
"url",
|
||||
"webkit2gtk",
|
||||
"webview2-com",
|
||||
"windows",
|
||||
"windows 0.61.3",
|
||||
"wry",
|
||||
]
|
||||
|
||||
@@ -6319,7 +6570,7 @@ dependencies = [
|
||||
"parking_lot",
|
||||
"pin-project-lite",
|
||||
"signal-hook-registry",
|
||||
"socket2",
|
||||
"socket2 0.6.2",
|
||||
"tokio-macros",
|
||||
"windows-sys 0.61.2",
|
||||
]
|
||||
@@ -6335,6 +6586,30 @@ dependencies = [
|
||||
"syn 2.0.117",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tokio-native-tls"
|
||||
version = "0.3.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bbae76ab933c85776efabc971569dd6119c580d8f5d448769dec1764bf796ef2"
|
||||
dependencies = [
|
||||
"native-tls",
|
||||
"tokio",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tokio-serial"
|
||||
version = "5.4.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "aa1d5427f11ba7c5e6384521cfd76f2d64572ff29f3f4f7aa0f496282923fdc8"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"futures",
|
||||
"log",
|
||||
"mio-serial",
|
||||
"serialport",
|
||||
"tokio",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tokio-stream"
|
||||
version = "0.1.18"
|
||||
@@ -6725,6 +7000,15 @@ version = "0.1.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "eaea85b334db583fe3274d12b4cd1880032beab409c0d774be044d4480ab9a94"
|
||||
|
||||
[[package]]
|
||||
name = "unescaper"
|
||||
version = "0.1.8"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4064ed685c487dbc25bd3f0e9548f2e34bab9d18cefc700f9ec2dba74ba1138e"
|
||||
dependencies = [
|
||||
"thiserror 2.0.18",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "unic-char-property"
|
||||
version = "0.9.0"
|
||||
@@ -7265,10 +7549,10 @@ checksum = "7130243a7a5b33c54a444e54842e6a9e133de08b5ad7b5861cd8ed9a6a5bc96a"
|
||||
dependencies = [
|
||||
"webview2-com-macros",
|
||||
"webview2-com-sys",
|
||||
"windows",
|
||||
"windows 0.61.3",
|
||||
"windows-core 0.61.2",
|
||||
"windows-implement",
|
||||
"windows-interface",
|
||||
"windows-implement 0.60.2",
|
||||
"windows-interface 0.59.3",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -7289,7 +7573,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "381336cfffd772377d291702245447a5251a2ffa5bad679c99e61bc48bacbf9c"
|
||||
dependencies = [
|
||||
"thiserror 2.0.18",
|
||||
"windows",
|
||||
"windows 0.61.3",
|
||||
"windows-core 0.61.2",
|
||||
]
|
||||
|
||||
@@ -7361,14 +7645,28 @@ name = "wifi-densepose-desktop"
|
||||
version = "0.3.0"
|
||||
dependencies = [
|
||||
"chrono",
|
||||
"flume",
|
||||
"futures",
|
||||
"hex",
|
||||
"hmac",
|
||||
"libc",
|
||||
"mdns-sd",
|
||||
"regex",
|
||||
"reqwest 0.12.28",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"serialport",
|
||||
"sha2",
|
||||
"sysinfo",
|
||||
"tauri",
|
||||
"tauri-build",
|
||||
"tauri-plugin-dialog",
|
||||
"tauri-plugin-shell",
|
||||
"thiserror 1.0.69",
|
||||
"tokio",
|
||||
"tokio-serial",
|
||||
"tracing",
|
||||
"uuid",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -7628,6 +7926,16 @@ dependencies = [
|
||||
"windows-version",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows"
|
||||
version = "0.57.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "12342cb4d8e3b046f3d80effd474a7a02447231330ef77d71daa6fbc40681143"
|
||||
dependencies = [
|
||||
"windows-core 0.57.0",
|
||||
"windows-targets 0.52.6",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows"
|
||||
version = "0.61.3"
|
||||
@@ -7650,14 +7958,26 @@ dependencies = [
|
||||
"windows-core 0.61.2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-core"
|
||||
version = "0.57.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d2ed2439a290666cd67ecce2b0ffaad89c2a56b976b736e6ece670297897832d"
|
||||
dependencies = [
|
||||
"windows-implement 0.57.0",
|
||||
"windows-interface 0.57.0",
|
||||
"windows-result 0.1.2",
|
||||
"windows-targets 0.52.6",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-core"
|
||||
version = "0.61.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c0fdd3ddb90610c7638aa2b3a3ab2904fb9e5cdbecc643ddb3647212781c4ae3"
|
||||
dependencies = [
|
||||
"windows-implement",
|
||||
"windows-interface",
|
||||
"windows-implement 0.60.2",
|
||||
"windows-interface 0.59.3",
|
||||
"windows-link 0.1.3",
|
||||
"windows-result 0.3.4",
|
||||
"windows-strings 0.4.2",
|
||||
@@ -7669,8 +7989,8 @@ version = "0.62.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b8e83a14d34d0623b51dce9581199302a221863196a1dde71a7663a4c2be9deb"
|
||||
dependencies = [
|
||||
"windows-implement",
|
||||
"windows-interface",
|
||||
"windows-implement 0.60.2",
|
||||
"windows-interface 0.59.3",
|
||||
"windows-link 0.2.1",
|
||||
"windows-result 0.4.1",
|
||||
"windows-strings 0.5.1",
|
||||
@@ -7687,6 +8007,17 @@ dependencies = [
|
||||
"windows-threading",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-implement"
|
||||
version = "0.57.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9107ddc059d5b6fbfbffdfa7a7fe3e22a226def0b2608f72e9d552763d3e1ad7"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.117",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-implement"
|
||||
version = "0.60.2"
|
||||
@@ -7698,6 +8029,17 @@ dependencies = [
|
||||
"syn 2.0.117",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-interface"
|
||||
version = "0.57.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "29bee4b38ea3cde66011baa44dba677c432a78593e202392d1e9070cf2a7fca7"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.117",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-interface"
|
||||
version = "0.59.3"
|
||||
@@ -7731,6 +8073,15 @@ dependencies = [
|
||||
"windows-link 0.1.3",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-result"
|
||||
version = "0.1.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5e383302e8ec8515204254685643de10811af0ed97ea37210dc26fb0032647f8"
|
||||
dependencies = [
|
||||
"windows-targets 0.52.6",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-result"
|
||||
version = "0.3.4"
|
||||
@@ -7776,6 +8127,15 @@ dependencies = [
|
||||
"windows-targets 0.42.2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-sys"
|
||||
version = "0.48.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9"
|
||||
dependencies = [
|
||||
"windows-targets 0.48.5",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-sys"
|
||||
version = "0.52.0"
|
||||
@@ -7827,6 +8187,21 @@ dependencies = [
|
||||
"windows_x86_64_msvc 0.42.2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-targets"
|
||||
version = "0.48.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c"
|
||||
dependencies = [
|
||||
"windows_aarch64_gnullvm 0.48.5",
|
||||
"windows_aarch64_msvc 0.48.5",
|
||||
"windows_i686_gnu 0.48.5",
|
||||
"windows_i686_msvc 0.48.5",
|
||||
"windows_x86_64_gnu 0.48.5",
|
||||
"windows_x86_64_gnullvm 0.48.5",
|
||||
"windows_x86_64_msvc 0.48.5",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-targets"
|
||||
version = "0.52.6"
|
||||
@@ -7884,6 +8259,12 @@ version = "0.42.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "597a5118570b68bc08d8d59125332c54f1ba9d9adeedeef5b99b02ba2b0698f8"
|
||||
|
||||
[[package]]
|
||||
name = "windows_aarch64_gnullvm"
|
||||
version = "0.48.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8"
|
||||
|
||||
[[package]]
|
||||
name = "windows_aarch64_gnullvm"
|
||||
version = "0.52.6"
|
||||
@@ -7902,6 +8283,12 @@ version = "0.42.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e08e8864a60f06ef0d0ff4ba04124db8b0fb3be5776a5cd47641e942e58c4d43"
|
||||
|
||||
[[package]]
|
||||
name = "windows_aarch64_msvc"
|
||||
version = "0.48.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc"
|
||||
|
||||
[[package]]
|
||||
name = "windows_aarch64_msvc"
|
||||
version = "0.52.6"
|
||||
@@ -7920,6 +8307,12 @@ version = "0.42.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c61d927d8da41da96a81f029489353e68739737d3beca43145c8afec9a31a84f"
|
||||
|
||||
[[package]]
|
||||
name = "windows_i686_gnu"
|
||||
version = "0.48.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e"
|
||||
|
||||
[[package]]
|
||||
name = "windows_i686_gnu"
|
||||
version = "0.52.6"
|
||||
@@ -7950,6 +8343,12 @@ version = "0.42.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "44d840b6ec649f480a41c8d80f9c65108b92d89345dd94027bfe06ac444d1060"
|
||||
|
||||
[[package]]
|
||||
name = "windows_i686_msvc"
|
||||
version = "0.48.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406"
|
||||
|
||||
[[package]]
|
||||
name = "windows_i686_msvc"
|
||||
version = "0.52.6"
|
||||
@@ -7968,6 +8367,12 @@ version = "0.42.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8de912b8b8feb55c064867cf047dda097f92d51efad5b491dfb98f6bbb70cb36"
|
||||
|
||||
[[package]]
|
||||
name = "windows_x86_64_gnu"
|
||||
version = "0.48.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e"
|
||||
|
||||
[[package]]
|
||||
name = "windows_x86_64_gnu"
|
||||
version = "0.52.6"
|
||||
@@ -7986,6 +8391,12 @@ version = "0.42.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "26d41b46a36d453748aedef1486d5c7a85db22e56aff34643984ea85514e94a3"
|
||||
|
||||
[[package]]
|
||||
name = "windows_x86_64_gnullvm"
|
||||
version = "0.48.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc"
|
||||
|
||||
[[package]]
|
||||
name = "windows_x86_64_gnullvm"
|
||||
version = "0.52.6"
|
||||
@@ -8004,6 +8415,12 @@ version = "0.42.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9aec5da331524158c6d1a4ac0ab1541149c0b9505fde06423b02f5ef0106b9f0"
|
||||
|
||||
[[package]]
|
||||
name = "windows_x86_64_msvc"
|
||||
version = "0.48.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538"
|
||||
|
||||
[[package]]
|
||||
name = "windows_x86_64_msvc"
|
||||
version = "0.52.6"
|
||||
@@ -8177,7 +8594,7 @@ dependencies = [
|
||||
"webkit2gtk",
|
||||
"webkit2gtk-sys",
|
||||
"webview2-com",
|
||||
"windows",
|
||||
"windows 0.61.3",
|
||||
"windows-core 0.61.2",
|
||||
"windows-version",
|
||||
"x11-dl",
|
||||
|
||||
+130
@@ -0,0 +1,130 @@
|
||||
{
|
||||
"running": true,
|
||||
"startedAt": "2026-03-09T23:56:03.574Z",
|
||||
"workers": {
|
||||
"map": {
|
||||
"runCount": 0,
|
||||
"successCount": 0,
|
||||
"failureCount": 0,
|
||||
"averageDurationMs": 0,
|
||||
"isRunning": false,
|
||||
"nextRun": "2026-03-09T23:56:03.574Z"
|
||||
},
|
||||
"audit": {
|
||||
"runCount": 0,
|
||||
"successCount": 0,
|
||||
"failureCount": 0,
|
||||
"averageDurationMs": 0,
|
||||
"isRunning": false,
|
||||
"nextRun": "2026-03-09T23:58:03.574Z"
|
||||
},
|
||||
"optimize": {
|
||||
"runCount": 0,
|
||||
"successCount": 0,
|
||||
"failureCount": 0,
|
||||
"averageDurationMs": 0,
|
||||
"isRunning": false,
|
||||
"nextRun": "2026-03-10T00:00:03.574Z"
|
||||
},
|
||||
"consolidate": {
|
||||
"runCount": 0,
|
||||
"successCount": 0,
|
||||
"failureCount": 0,
|
||||
"averageDurationMs": 0,
|
||||
"isRunning": false,
|
||||
"nextRun": "2026-03-10T00:02:03.574Z"
|
||||
},
|
||||
"testgaps": {
|
||||
"runCount": 0,
|
||||
"successCount": 0,
|
||||
"failureCount": 0,
|
||||
"averageDurationMs": 0,
|
||||
"isRunning": false,
|
||||
"nextRun": "2026-03-10T00:04:03.574Z"
|
||||
},
|
||||
"predict": {
|
||||
"runCount": 0,
|
||||
"successCount": 0,
|
||||
"failureCount": 0,
|
||||
"averageDurationMs": 0,
|
||||
"isRunning": false
|
||||
},
|
||||
"document": {
|
||||
"runCount": 0,
|
||||
"successCount": 0,
|
||||
"failureCount": 0,
|
||||
"averageDurationMs": 0,
|
||||
"isRunning": false
|
||||
}
|
||||
},
|
||||
"config": {
|
||||
"autoStart": false,
|
||||
"logDir": "/Users/cohen/GitHub/ruvnet/RuView/rust-port/wifi-densepose-rs/crates/wifi-densepose-desktop/.claude-flow/logs",
|
||||
"stateFile": "/Users/cohen/GitHub/ruvnet/RuView/rust-port/wifi-densepose-rs/crates/wifi-densepose-desktop/.claude-flow/daemon-state.json",
|
||||
"maxConcurrent": 2,
|
||||
"workerTimeoutMs": 300000,
|
||||
"resourceThresholds": {
|
||||
"maxCpuLoad": 2,
|
||||
"minFreeMemoryPercent": 20
|
||||
},
|
||||
"workers": [
|
||||
{
|
||||
"type": "map",
|
||||
"intervalMs": 900000,
|
||||
"offsetMs": 0,
|
||||
"priority": "normal",
|
||||
"description": "Codebase mapping",
|
||||
"enabled": true
|
||||
},
|
||||
{
|
||||
"type": "audit",
|
||||
"intervalMs": 600000,
|
||||
"offsetMs": 120000,
|
||||
"priority": "critical",
|
||||
"description": "Security analysis",
|
||||
"enabled": true
|
||||
},
|
||||
{
|
||||
"type": "optimize",
|
||||
"intervalMs": 900000,
|
||||
"offsetMs": 240000,
|
||||
"priority": "high",
|
||||
"description": "Performance optimization",
|
||||
"enabled": true
|
||||
},
|
||||
{
|
||||
"type": "consolidate",
|
||||
"intervalMs": 1800000,
|
||||
"offsetMs": 360000,
|
||||
"priority": "low",
|
||||
"description": "Memory consolidation",
|
||||
"enabled": true
|
||||
},
|
||||
{
|
||||
"type": "testgaps",
|
||||
"intervalMs": 1200000,
|
||||
"offsetMs": 480000,
|
||||
"priority": "normal",
|
||||
"description": "Test coverage analysis",
|
||||
"enabled": true
|
||||
},
|
||||
{
|
||||
"type": "predict",
|
||||
"intervalMs": 600000,
|
||||
"offsetMs": 0,
|
||||
"priority": "low",
|
||||
"description": "Predictive preloading",
|
||||
"enabled": false
|
||||
},
|
||||
{
|
||||
"type": "document",
|
||||
"intervalMs": 3600000,
|
||||
"offsetMs": 0,
|
||||
"priority": "low",
|
||||
"description": "Auto-documentation",
|
||||
"enabled": false
|
||||
}
|
||||
]
|
||||
},
|
||||
"savedAt": "2026-03-09T23:56:03.574Z"
|
||||
}
|
||||
+42
@@ -0,0 +1,42 @@
|
||||
{"type":"edit","file":"unknown","timestamp":1773100520674,"sessionId":null}
|
||||
{"type":"edit","file":"unknown","timestamp":1773100630628,"sessionId":null}
|
||||
{"type":"edit","file":"unknown","timestamp":1773100635269,"sessionId":null}
|
||||
{"type":"edit","file":"unknown","timestamp":1773100648222,"sessionId":null}
|
||||
{"type":"edit","file":"unknown","timestamp":1773100660593,"sessionId":null}
|
||||
{"type":"edit","file":"unknown","timestamp":1773100670480,"sessionId":null}
|
||||
{"type":"edit","file":"unknown","timestamp":1773100765961,"sessionId":null}
|
||||
{"type":"edit","file":"unknown","timestamp":1773100793408,"sessionId":null}
|
||||
{"type":"edit","file":"unknown","timestamp":1773100801110,"sessionId":null}
|
||||
{"type":"edit","file":"unknown","timestamp":1773100806887,"sessionId":null}
|
||||
{"type":"edit","file":"unknown","timestamp":1773100820942,"sessionId":null}
|
||||
{"type":"edit","file":"unknown","timestamp":1773100857691,"sessionId":null}
|
||||
{"type":"edit","file":"unknown","timestamp":1773100894224,"sessionId":null}
|
||||
{"type":"edit","file":"unknown","timestamp":1773100911798,"sessionId":null}
|
||||
{"type":"edit","file":"unknown","timestamp":1773101430507,"sessionId":null}
|
||||
{"type":"edit","file":"unknown","timestamp":1773101470221,"sessionId":null}
|
||||
{"type":"edit","file":"unknown","timestamp":1773101478246,"sessionId":null}
|
||||
{"type":"edit","file":"unknown","timestamp":1773103575668,"sessionId":null}
|
||||
{"type":"edit","file":"unknown","timestamp":1773103693989,"sessionId":null}
|
||||
{"type":"edit","file":"unknown","timestamp":1773115108388,"sessionId":null}
|
||||
{"type":"edit","file":"unknown","timestamp":1773115362485,"sessionId":null}
|
||||
{"type":"edit","file":"unknown","timestamp":1773115372676,"sessionId":null}
|
||||
{"type":"edit","file":"unknown","timestamp":1773115388605,"sessionId":null}
|
||||
{"type":"edit","file":"unknown","timestamp":1773115394377,"sessionId":null}
|
||||
{"type":"edit","file":"unknown","timestamp":1773115415015,"sessionId":null}
|
||||
{"type":"edit","file":"unknown","timestamp":1773115600459,"sessionId":null}
|
||||
{"type":"edit","file":"unknown","timestamp":1773146102258,"sessionId":null}
|
||||
{"type":"edit","file":"unknown","timestamp":1773146113449,"sessionId":null}
|
||||
{"type":"edit","file":"unknown","timestamp":1773146119695,"sessionId":null}
|
||||
{"type":"edit","file":"unknown","timestamp":1773146128174,"sessionId":null}
|
||||
{"type":"edit","file":"unknown","timestamp":1773146133721,"sessionId":null}
|
||||
{"type":"edit","file":"unknown","timestamp":1773146150082,"sessionId":null}
|
||||
{"type":"edit","file":"unknown","timestamp":1773146337071,"sessionId":null}
|
||||
{"type":"edit","file":"unknown","timestamp":1773150581963,"sessionId":null}
|
||||
{"type":"edit","file":"unknown","timestamp":1773150596765,"sessionId":null}
|
||||
{"type":"edit","file":"unknown","timestamp":1773152997925,"sessionId":null}
|
||||
{"type":"edit","file":"unknown","timestamp":1773153073387,"sessionId":null}
|
||||
{"type":"edit","file":"unknown","timestamp":1773153109436,"sessionId":null}
|
||||
{"type":"edit","file":"unknown","timestamp":1773153121443,"sessionId":null}
|
||||
{"type":"edit","file":"unknown","timestamp":1773153290476,"sessionId":null}
|
||||
{"type":"edit","file":"unknown","timestamp":1773153290781,"sessionId":null}
|
||||
{"type":"edit","file":"unknown","timestamp":1773153291056,"sessionId":null}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"id": "session-1773150558480",
|
||||
"startedAt": "2026-03-10T13:49:18.480Z",
|
||||
"cwd": "/Users/cohen/GitHub/ruvnet/RuView/rust-port/wifi-densepose-rs/crates/wifi-densepose-desktop",
|
||||
"context": {},
|
||||
"metrics": {
|
||||
"edits": 9,
|
||||
"commands": 0,
|
||||
"tasks": 0,
|
||||
"errors": 0
|
||||
}
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
{
|
||||
"id": "session-1773100562538",
|
||||
"startedAt": "2026-03-09T23:56:02.538Z",
|
||||
"cwd": "/Users/cohen/GitHub/ruvnet/RuView/rust-port/wifi-densepose-rs/crates/wifi-densepose-desktop",
|
||||
"context": {},
|
||||
"metrics": {
|
||||
"edits": 13,
|
||||
"commands": 0,
|
||||
"tasks": 0,
|
||||
"errors": 0
|
||||
},
|
||||
"endedAt": "2026-03-10T00:07:15.557Z",
|
||||
"duration": 673020
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
{
|
||||
"id": "session-1773101285009",
|
||||
"startedAt": "2026-03-10T00:08:05.009Z",
|
||||
"cwd": "/Users/cohen/GitHub/ruvnet/RuView/rust-port/wifi-densepose-rs/crates/wifi-densepose-desktop",
|
||||
"context": {},
|
||||
"metrics": {
|
||||
"edits": 19,
|
||||
"commands": 0,
|
||||
"tasks": 0,
|
||||
"errors": 0
|
||||
},
|
||||
"endedAt": "2026-03-10T13:48:30.150Z",
|
||||
"duration": 49225141
|
||||
}
|
||||
@@ -23,3 +23,44 @@ serde_json = { workspace = true }
|
||||
tokio = { workspace = true }
|
||||
thiserror = { workspace = true }
|
||||
chrono = { version = "0.4", features = ["serde"] }
|
||||
|
||||
# Discovery (mDNS + UDP)
|
||||
mdns-sd = "0.11"
|
||||
flume = "0.11"
|
||||
|
||||
# Serial port (cross-platform)
|
||||
tokio-serial = "5.4"
|
||||
|
||||
# HTTP client for OTA/WASM (native-tls for Windows compatibility)
|
||||
reqwest = { version = "0.12", default-features = false, features = ["json", "multipart", "native-tls"] }
|
||||
|
||||
# Crypto for OTA PSK
|
||||
sha2 = "0.10"
|
||||
hmac = "0.12"
|
||||
|
||||
# System info for server management
|
||||
sysinfo = "0.32"
|
||||
|
||||
# Async utilities
|
||||
futures = "0.3"
|
||||
|
||||
# Logging
|
||||
tracing = "0.1"
|
||||
|
||||
# UUID for session IDs
|
||||
uuid = { version = "1.0", features = ["v4", "serde"] }
|
||||
|
||||
# Hex encoding for hashes
|
||||
hex = "0.4"
|
||||
|
||||
# Regex for parsing espflash output
|
||||
regex = "1.10"
|
||||
|
||||
# Serial port for WiFi configuration
|
||||
serialport.workspace = true
|
||||
|
||||
# Unix signals for graceful process termination
|
||||
[target.'cfg(unix)'.dependencies]
|
||||
libc = "0.2"
|
||||
|
||||
[dev-dependencies]
|
||||
|
||||
+2630
File diff suppressed because it is too large
Load Diff
+521
-15
@@ -1,28 +1,499 @@
|
||||
use std::net::{SocketAddr, UdpSocket};
|
||||
use std::time::Duration;
|
||||
|
||||
use mdns_sd::{ServiceDaemon, ServiceEvent};
|
||||
use serde::Serialize;
|
||||
use tauri::State;
|
||||
use tokio::time::timeout;
|
||||
use tokio_serial::available_ports;
|
||||
use flume::RecvTimeoutError;
|
||||
|
||||
use crate::domain::node::DiscoveredNode;
|
||||
use crate::domain::node::{
|
||||
Chip, DiscoveredNode, DiscoveryMethod, HealthStatus, MacAddress, MeshRole,
|
||||
NodeCapabilities, NodeRegistry,
|
||||
};
|
||||
use crate::state::AppState;
|
||||
|
||||
/// Discover ESP32 CSI nodes on the local network via mDNS / UDP broadcast.
|
||||
/// Service type for RuView ESP32 nodes using mDNS.
|
||||
const MDNS_SERVICE_TYPE: &str = "_ruview._udp.local.";
|
||||
|
||||
/// UDP broadcast port for node discovery.
|
||||
const UDP_DISCOVERY_PORT: u16 = 5006;
|
||||
|
||||
/// Discovery beacon magic bytes.
|
||||
const BEACON_MAGIC: &[u8] = b"RUVIEW_BEACON";
|
||||
|
||||
/// Discover ESP32 CSI nodes on the local network via mDNS + UDP broadcast.
|
||||
///
|
||||
/// Discovery strategy:
|
||||
/// 1. Start mDNS browser for `_ruview._udp.local.`
|
||||
/// 2. Send UDP broadcast on port 5006
|
||||
/// 3. Collect responses for `timeout_ms` milliseconds
|
||||
/// 4. Deduplicate by MAC address and return merged results
|
||||
#[tauri::command]
|
||||
pub async fn discover_nodes(timeout_ms: Option<u64>) -> Result<Vec<DiscoveredNode>, String> {
|
||||
let _timeout = timeout_ms.unwrap_or(3000);
|
||||
// Stub: return placeholder data
|
||||
Ok(vec![DiscoveredNode {
|
||||
ip: "192.168.1.100".into(),
|
||||
mac: Some("AA:BB:CC:DD:EE:FF".into()),
|
||||
hostname: Some("ruview-node-1".into()),
|
||||
node_id: 1,
|
||||
firmware_version: Some("0.3.0".into()),
|
||||
health: crate::domain::node::HealthStatus::Online,
|
||||
pub async fn discover_nodes(
|
||||
timeout_ms: Option<u64>,
|
||||
state: State<'_, AppState>,
|
||||
) -> Result<Vec<DiscoveredNode>, String> {
|
||||
let timeout_duration = Duration::from_millis(timeout_ms.unwrap_or(3000));
|
||||
|
||||
// Run mDNS and UDP discovery concurrently
|
||||
let (mdns_nodes, udp_nodes) = tokio::join!(
|
||||
discover_via_mdns(timeout_duration),
|
||||
discover_via_udp(timeout_duration),
|
||||
);
|
||||
|
||||
// Merge results, deduplicating by MAC address
|
||||
let mut registry = NodeRegistry::new();
|
||||
|
||||
for node in mdns_nodes.unwrap_or_default() {
|
||||
if let Some(ref mac) = node.mac {
|
||||
registry.upsert(MacAddress::new(mac), node);
|
||||
}
|
||||
}
|
||||
|
||||
for node in udp_nodes.unwrap_or_default() {
|
||||
if let Some(ref mac) = node.mac {
|
||||
registry.upsert(MacAddress::new(mac), node);
|
||||
}
|
||||
}
|
||||
|
||||
let nodes: Vec<DiscoveredNode> = registry.all().into_iter().cloned().collect();
|
||||
|
||||
// Update global state
|
||||
{
|
||||
let mut discovery = state.discovery.lock().map_err(|e| e.to_string())?;
|
||||
discovery.nodes = nodes.clone();
|
||||
}
|
||||
|
||||
Ok(nodes)
|
||||
}
|
||||
|
||||
/// Discover nodes via mDNS (Bonjour/Avahi).
|
||||
async fn discover_via_mdns(timeout_duration: Duration) -> Result<Vec<DiscoveredNode>, String> {
|
||||
let discovery_task = tokio::task::spawn_blocking(move || {
|
||||
let mdns = match ServiceDaemon::new() {
|
||||
Ok(daemon) => daemon,
|
||||
Err(e) => {
|
||||
tracing::warn!("Failed to create mDNS daemon: {}", e);
|
||||
return Vec::new();
|
||||
}
|
||||
};
|
||||
|
||||
let receiver = match mdns.browse(MDNS_SERVICE_TYPE) {
|
||||
Ok(rx) => rx,
|
||||
Err(e) => {
|
||||
tracing::warn!("Failed to browse mDNS services: {}", e);
|
||||
return Vec::new();
|
||||
}
|
||||
};
|
||||
|
||||
let mut discovered = Vec::new();
|
||||
let start = std::time::Instant::now();
|
||||
|
||||
while start.elapsed() < timeout_duration {
|
||||
match receiver.recv_timeout(Duration::from_millis(100)) {
|
||||
Ok(ServiceEvent::ServiceResolved(info)) => {
|
||||
let props = info.get_properties();
|
||||
let chip_str = props.get("chip").map(|v| v.val_str());
|
||||
let chip = match chip_str {
|
||||
Some("esp32s2") => Chip::Esp32s2,
|
||||
Some("esp32s3") => Chip::Esp32s3,
|
||||
Some("esp32c3") => Chip::Esp32c3,
|
||||
Some("esp32c6") => Chip::Esp32c6,
|
||||
_ => Chip::Esp32,
|
||||
};
|
||||
let role_str = props.get("role").map(|v| v.val_str());
|
||||
let mesh_role = match role_str {
|
||||
Some("coordinator") => MeshRole::Coordinator,
|
||||
Some("aggregator") => MeshRole::Aggregator,
|
||||
_ => MeshRole::Node,
|
||||
};
|
||||
let node = DiscoveredNode {
|
||||
ip: info.get_addresses()
|
||||
.iter()
|
||||
.next()
|
||||
.map(|a| a.to_string())
|
||||
.unwrap_or_default(),
|
||||
mac: props.get("mac").map(|v| v.val_str().to_string()),
|
||||
hostname: Some(info.get_hostname().to_string()),
|
||||
node_id: props.get("node_id")
|
||||
.and_then(|v| v.val_str().parse().ok())
|
||||
.unwrap_or(0),
|
||||
firmware_version: props.get("version").map(|v| v.val_str().to_string()),
|
||||
health: HealthStatus::Online,
|
||||
last_seen: chrono::Utc::now().to_rfc3339(),
|
||||
chip,
|
||||
mesh_role,
|
||||
discovery_method: DiscoveryMethod::Mdns,
|
||||
tdm_slot: props.get("tdm_slot").and_then(|v| v.val_str().parse().ok()),
|
||||
tdm_total: props.get("tdm_total").and_then(|v| v.val_str().parse().ok()),
|
||||
edge_tier: props.get("edge_tier").and_then(|v| v.val_str().parse().ok()),
|
||||
uptime_secs: props.get("uptime").and_then(|v| v.val_str().parse().ok()),
|
||||
capabilities: Some(NodeCapabilities {
|
||||
wasm: props.get("wasm").map(|v| v.val_str() == "1").unwrap_or(false),
|
||||
ota: props.get("ota").map(|v| v.val_str() == "1").unwrap_or(true),
|
||||
csi: props.get("csi").map(|v| v.val_str() == "1").unwrap_or(true),
|
||||
}),
|
||||
friendly_name: props.get("name").map(|v| v.val_str().to_string()),
|
||||
notes: None,
|
||||
};
|
||||
discovered.push(node);
|
||||
}
|
||||
Ok(ServiceEvent::SearchStarted(_)) => {}
|
||||
Ok(_) => {}
|
||||
Err(RecvTimeoutError::Timeout) => continue,
|
||||
Err(RecvTimeoutError::Disconnected) => break,
|
||||
}
|
||||
}
|
||||
|
||||
// Stop browsing
|
||||
let _ = mdns.stop_browse(MDNS_SERVICE_TYPE);
|
||||
|
||||
discovered
|
||||
});
|
||||
|
||||
match timeout(timeout_duration + Duration::from_millis(500), discovery_task).await {
|
||||
Ok(Ok(nodes)) => Ok(nodes),
|
||||
Ok(Err(e)) => Err(format!("mDNS discovery task failed: {}", e)),
|
||||
Err(_) => Ok(Vec::new()), // Timeout, return empty
|
||||
}
|
||||
}
|
||||
|
||||
/// Discover nodes via UDP broadcast beacon.
|
||||
async fn discover_via_udp(timeout_duration: Duration) -> Result<Vec<DiscoveredNode>, String> {
|
||||
let discovery_task = tokio::task::spawn_blocking(move || -> Vec<DiscoveredNode> {
|
||||
let socket = match UdpSocket::bind("0.0.0.0:0") {
|
||||
Ok(s) => s,
|
||||
Err(e) => {
|
||||
tracing::warn!("Failed to bind UDP socket: {}", e);
|
||||
return Vec::new();
|
||||
}
|
||||
};
|
||||
|
||||
if let Err(e) = socket.set_broadcast(true) {
|
||||
tracing::warn!("Failed to enable broadcast: {}", e);
|
||||
return Vec::new();
|
||||
}
|
||||
|
||||
if let Err(e) = socket.set_read_timeout(Some(Duration::from_millis(100))) {
|
||||
tracing::warn!("Failed to set read timeout: {}", e);
|
||||
return Vec::new();
|
||||
}
|
||||
|
||||
// Send discovery beacon
|
||||
let broadcast_addr = format!("255.255.255.255:{}", UDP_DISCOVERY_PORT);
|
||||
if let Err(e) = socket.send_to(b"RUVIEW_DISCOVER", &broadcast_addr) {
|
||||
tracing::warn!("Failed to send discovery beacon: {}", e);
|
||||
}
|
||||
|
||||
let mut discovered = Vec::new();
|
||||
let mut buf = [0u8; 256];
|
||||
let start = std::time::Instant::now();
|
||||
|
||||
while start.elapsed() < timeout_duration {
|
||||
match socket.recv_from(&mut buf) {
|
||||
Ok((len, addr)) => {
|
||||
if len >= BEACON_MAGIC.len() && &buf[..BEACON_MAGIC.len()] == BEACON_MAGIC {
|
||||
// Parse beacon response: RUVIEW_BEACON|mac|node_id|version
|
||||
if let Some(node) = parse_beacon_response(&buf[..len], addr) {
|
||||
discovered.push(node);
|
||||
}
|
||||
}
|
||||
}
|
||||
Err(ref e) if e.kind() == std::io::ErrorKind::WouldBlock => continue,
|
||||
Err(ref e) if e.kind() == std::io::ErrorKind::TimedOut => continue,
|
||||
Err(_) => break,
|
||||
}
|
||||
}
|
||||
|
||||
discovered
|
||||
});
|
||||
|
||||
match timeout(timeout_duration + Duration::from_millis(500), discovery_task).await {
|
||||
Ok(Ok(nodes)) => Ok(nodes),
|
||||
Ok(Err(e)) => Err(format!("UDP discovery task failed: {}", e)),
|
||||
Err(_) => Ok(Vec::new()),
|
||||
}
|
||||
}
|
||||
|
||||
/// Parse a UDP beacon response into a DiscoveredNode.
|
||||
/// Format: RUVIEW_BEACON|<mac>|<node_id>|<version>|<chip>|<role>|<tdm_slot>|<tdm_total>
|
||||
fn parse_beacon_response(data: &[u8], addr: SocketAddr) -> Option<DiscoveredNode> {
|
||||
let text = std::str::from_utf8(data).ok()?;
|
||||
let parts: Vec<&str> = text.split('|').collect();
|
||||
|
||||
if parts.len() < 2 || parts[0] != "RUVIEW_BEACON" {
|
||||
return None;
|
||||
}
|
||||
|
||||
let mac = parts.get(1).map(|s| s.to_string());
|
||||
let node_id = parts.get(2).and_then(|s| s.parse().ok()).unwrap_or(0);
|
||||
let version = parts.get(3).map(|s| s.to_string());
|
||||
let chip_str = parts.get(4).copied();
|
||||
let chip = match chip_str {
|
||||
Some("esp32s2") => Chip::Esp32s2,
|
||||
Some("esp32s3") => Chip::Esp32s3,
|
||||
Some("esp32c3") => Chip::Esp32c3,
|
||||
Some("esp32c6") => Chip::Esp32c6,
|
||||
_ => Chip::Esp32,
|
||||
};
|
||||
let role_str = parts.get(5).copied();
|
||||
let mesh_role = match role_str {
|
||||
Some("coordinator") => MeshRole::Coordinator,
|
||||
Some("aggregator") => MeshRole::Aggregator,
|
||||
_ => MeshRole::Node,
|
||||
};
|
||||
let tdm_slot = parts.get(6).and_then(|s| s.parse().ok());
|
||||
let tdm_total = parts.get(7).and_then(|s| s.parse().ok());
|
||||
|
||||
Some(DiscoveredNode {
|
||||
ip: addr.ip().to_string(),
|
||||
mac,
|
||||
hostname: None,
|
||||
node_id,
|
||||
firmware_version: version,
|
||||
health: HealthStatus::Online,
|
||||
last_seen: chrono::Utc::now().to_rfc3339(),
|
||||
}])
|
||||
chip,
|
||||
mesh_role,
|
||||
discovery_method: DiscoveryMethod::UdpProbe,
|
||||
tdm_slot,
|
||||
tdm_total,
|
||||
edge_tier: None,
|
||||
uptime_secs: None,
|
||||
capabilities: Some(NodeCapabilities {
|
||||
wasm: false,
|
||||
ota: true,
|
||||
csi: true,
|
||||
}),
|
||||
friendly_name: None,
|
||||
notes: None,
|
||||
})
|
||||
}
|
||||
|
||||
/// List available serial ports on this machine.
|
||||
/// Filters for known ESP32 USB-to-serial chips (CP2102, CH340, FTDI).
|
||||
#[tauri::command]
|
||||
pub async fn list_serial_ports() -> Result<Vec<SerialPortInfo>, String> {
|
||||
// Stub: return empty list
|
||||
Ok(vec![])
|
||||
tracing::info!("list_serial_ports called");
|
||||
|
||||
let ports = match available_ports() {
|
||||
Ok(p) => {
|
||||
tracing::info!("Found {} ports from tokio_serial", p.len());
|
||||
p
|
||||
}
|
||||
Err(e) => {
|
||||
tracing::error!("Failed to enumerate ports: {}", e);
|
||||
// Fallback: try to list /dev/cu.usb* manually on macOS
|
||||
return list_serial_ports_fallback();
|
||||
}
|
||||
};
|
||||
|
||||
let mut result = Vec::new();
|
||||
|
||||
for port in ports {
|
||||
tracing::debug!("Processing port: {}", port.port_name);
|
||||
let info = match port.port_type {
|
||||
tokio_serial::SerialPortType::UsbPort(usb_info) => {
|
||||
SerialPortInfo {
|
||||
name: port.port_name,
|
||||
vid: Some(usb_info.vid),
|
||||
pid: Some(usb_info.pid),
|
||||
manufacturer: usb_info.manufacturer,
|
||||
serial_number: usb_info.serial_number,
|
||||
is_esp32_compatible: is_esp32_compatible(usb_info.vid, usb_info.pid),
|
||||
}
|
||||
}
|
||||
_ => {
|
||||
SerialPortInfo {
|
||||
name: port.port_name.clone(),
|
||||
vid: None,
|
||||
pid: None,
|
||||
manufacturer: None,
|
||||
serial_number: None,
|
||||
// Mark /dev/cu.usb* ports as potentially compatible
|
||||
is_esp32_compatible: port.port_name.contains("usb"),
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
result.push(info);
|
||||
}
|
||||
|
||||
// If no ports found via tokio_serial, try fallback
|
||||
if result.is_empty() {
|
||||
tracing::warn!("No ports from tokio_serial, trying fallback");
|
||||
return list_serial_ports_fallback();
|
||||
}
|
||||
|
||||
// Sort ESP32-compatible ports first
|
||||
result.sort_by(|a, b| b.is_esp32_compatible.cmp(&a.is_esp32_compatible));
|
||||
|
||||
tracing::info!("Returning {} serial ports", result.len());
|
||||
Ok(result)
|
||||
}
|
||||
|
||||
/// Fallback serial port listing for macOS when tokio_serial fails
|
||||
fn list_serial_ports_fallback() -> Result<Vec<SerialPortInfo>, String> {
|
||||
tracing::info!("Using fallback serial port listing");
|
||||
|
||||
let mut result = Vec::new();
|
||||
|
||||
// List /dev/cu.usb* devices on macOS
|
||||
#[cfg(target_os = "macos")]
|
||||
{
|
||||
use std::fs;
|
||||
if let Ok(entries) = fs::read_dir("/dev") {
|
||||
for entry in entries.flatten() {
|
||||
let name = entry.file_name().to_string_lossy().to_string();
|
||||
if name.starts_with("cu.usb") {
|
||||
let path = format!("/dev/{}", name);
|
||||
tracing::info!("Fallback found port: {}", path);
|
||||
result.push(SerialPortInfo {
|
||||
name: path,
|
||||
vid: None,
|
||||
pid: None,
|
||||
manufacturer: Some("USB Serial".to_string()),
|
||||
serial_number: None,
|
||||
is_esp32_compatible: true, // Assume USB serial is ESP32
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Linux fallback
|
||||
#[cfg(target_os = "linux")]
|
||||
{
|
||||
use std::fs;
|
||||
if let Ok(entries) = fs::read_dir("/dev") {
|
||||
for entry in entries.flatten() {
|
||||
let name = entry.file_name().to_string_lossy().to_string();
|
||||
if name.starts_with("ttyUSB") || name.starts_with("ttyACM") {
|
||||
let path = format!("/dev/{}", name);
|
||||
tracing::info!("Fallback found port: {}", path);
|
||||
result.push(SerialPortInfo {
|
||||
name: path,
|
||||
vid: None,
|
||||
pid: None,
|
||||
manufacturer: Some("USB Serial".to_string()),
|
||||
serial_number: None,
|
||||
is_esp32_compatible: true,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
tracing::info!("Fallback found {} ports", result.len());
|
||||
Ok(result)
|
||||
}
|
||||
|
||||
/// Check if a USB VID/PID is from a known ESP32 USB-to-serial chip.
|
||||
fn is_esp32_compatible(vid: u16, pid: u16) -> bool {
|
||||
// CP210x (Silicon Labs)
|
||||
if vid == 0x10C4 && (pid == 0xEA60 || pid == 0xEA70) {
|
||||
return true;
|
||||
}
|
||||
// CH340/CH341 (QinHeng)
|
||||
if vid == 0x1A86 && (pid == 0x7523 || pid == 0x5523) {
|
||||
return true;
|
||||
}
|
||||
// FTDI
|
||||
if vid == 0x0403 && (pid == 0x6001 || pid == 0x6010 || pid == 0x6011 || pid == 0x6014 || pid == 0x6015) {
|
||||
return true;
|
||||
}
|
||||
// ESP32-S2/S3 native USB
|
||||
if vid == 0x303A {
|
||||
return true;
|
||||
}
|
||||
false
|
||||
}
|
||||
|
||||
/// Configure WiFi credentials on an ESP32 via serial port.
|
||||
///
|
||||
/// Sends WiFi credentials to the ESP32 using a simple serial protocol.
|
||||
/// The ESP32 firmware should accept: `wifi_config <ssid> <password>\n`
|
||||
#[tauri::command]
|
||||
pub async fn configure_esp32_wifi(
|
||||
port: String,
|
||||
ssid: String,
|
||||
password: String,
|
||||
) -> Result<String, String> {
|
||||
use std::io::{Read, Write};
|
||||
use std::time::Duration;
|
||||
|
||||
tracing::info!("Configuring WiFi on port: {}", port);
|
||||
|
||||
// Open serial port
|
||||
let mut serial = serialport::new(&port, 115200)
|
||||
.timeout(Duration::from_secs(3))
|
||||
.open()
|
||||
.map_err(|e| format!("Failed to open port {}: {}", port, e))?;
|
||||
|
||||
// Wait for ESP32 to be ready
|
||||
std::thread::sleep(Duration::from_millis(500));
|
||||
|
||||
// Try multiple command formats that different firmware versions might accept
|
||||
let commands = [
|
||||
format!("wifi_config {} {}\r\n", ssid, password),
|
||||
format!("wifi {} {}\r\n", ssid, password),
|
||||
format!("set ssid {}\r\n", ssid),
|
||||
];
|
||||
|
||||
let mut response = String::new();
|
||||
let mut buf = [0u8; 512];
|
||||
|
||||
for cmd in &commands {
|
||||
// Clear any pending data
|
||||
let _ = serial.read(&mut buf);
|
||||
|
||||
// Send command
|
||||
serial.write_all(cmd.as_bytes())
|
||||
.map_err(|e| format!("Failed to write: {}", e))?;
|
||||
serial.flush().map_err(|e| format!("Failed to flush: {}", e))?;
|
||||
|
||||
// Wait and read response
|
||||
std::thread::sleep(Duration::from_millis(500));
|
||||
|
||||
match serial.read(&mut buf) {
|
||||
Ok(n) if n > 0 => {
|
||||
let text = String::from_utf8_lossy(&buf[..n]).to_string();
|
||||
response.push_str(&text);
|
||||
|
||||
// Check for success indicators
|
||||
if text.to_lowercase().contains("ok")
|
||||
|| text.to_lowercase().contains("saved")
|
||||
|| text.to_lowercase().contains("configured") {
|
||||
tracing::info!("WiFi config successful: {}", text.trim());
|
||||
return Ok(format!("WiFi configured! Response: {}", text.trim()));
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
// Also try to send password separately if ssid command was sent
|
||||
let pwd_cmd = format!("set password {}\r\n", password);
|
||||
let _ = serial.write_all(pwd_cmd.as_bytes());
|
||||
let _ = serial.flush();
|
||||
std::thread::sleep(Duration::from_millis(300));
|
||||
if let Ok(n) = serial.read(&mut buf) {
|
||||
if n > 0 {
|
||||
response.push_str(&String::from_utf8_lossy(&buf[..n]));
|
||||
}
|
||||
}
|
||||
|
||||
// Send reboot command
|
||||
let _ = serial.write_all(b"reboot\r\n");
|
||||
let _ = serial.flush();
|
||||
|
||||
if response.is_empty() {
|
||||
Ok("Commands sent. ESP32 may need manual reboot to apply WiFi settings.".to_string())
|
||||
} else {
|
||||
Ok(format!("Commands sent. Response: {}", response.trim()))
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
@@ -31,4 +502,39 @@ pub struct SerialPortInfo {
|
||||
pub vid: Option<u16>,
|
||||
pub pid: Option<u16>,
|
||||
pub manufacturer: Option<String>,
|
||||
pub serial_number: Option<String>,
|
||||
pub is_esp32_compatible: bool,
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn test_parse_beacon_response() {
|
||||
let data = b"RUVIEW_BEACON|AA:BB:CC:DD:EE:FF|1|0.3.0|esp32s3|coordinator|0|4";
|
||||
let addr: SocketAddr = "192.168.1.100:5006".parse().unwrap();
|
||||
|
||||
let node = parse_beacon_response(data, addr).unwrap();
|
||||
assert_eq!(node.ip, "192.168.1.100");
|
||||
assert_eq!(node.mac, Some("AA:BB:CC:DD:EE:FF".to_string()));
|
||||
assert_eq!(node.node_id, 1);
|
||||
assert_eq!(node.firmware_version, Some("0.3.0".to_string()));
|
||||
assert_eq!(node.chip, Chip::Esp32s3);
|
||||
assert_eq!(node.mesh_role, MeshRole::Coordinator);
|
||||
assert_eq!(node.tdm_slot, Some(0));
|
||||
assert_eq!(node.tdm_total, Some(4));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_is_esp32_compatible() {
|
||||
// CP2102
|
||||
assert!(is_esp32_compatible(0x10C4, 0xEA60));
|
||||
// CH340
|
||||
assert!(is_esp32_compatible(0x1A86, 0x7523));
|
||||
// ESP32-S3 native
|
||||
assert!(is_esp32_compatible(0x303A, 0x1001));
|
||||
// Unknown
|
||||
assert!(!is_esp32_compatible(0x0000, 0x0000));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,38 +1,303 @@
|
||||
use std::io::{BufRead, BufReader};
|
||||
use std::process::{Command, Stdio};
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
use sha2::{Digest, Sha256};
|
||||
use tauri::{AppHandle, Emitter, State};
|
||||
|
||||
use crate::state::AppState;
|
||||
|
||||
/// Flash firmware binary to an ESP32 via serial port.
|
||||
///
|
||||
/// Uses espflash CLI tool for actual flashing. Progress is emitted
|
||||
/// via Tauri events for UI updates.
|
||||
///
|
||||
/// # Arguments
|
||||
/// * `port` - Serial port path (e.g., "/dev/ttyUSB0" or "COM3")
|
||||
/// * `firmware_path` - Path to the .bin firmware file
|
||||
/// * `chip` - Optional chip type ("esp32", "esp32s2", "esp32s3", "esp32c3")
|
||||
/// * `baud` - Optional baud rate (default: 921600)
|
||||
#[tauri::command]
|
||||
pub async fn flash_firmware(
|
||||
app: AppHandle,
|
||||
port: String,
|
||||
firmware_path: String,
|
||||
chip: Option<String>,
|
||||
baud: Option<u32>,
|
||||
) -> Result<FlashResult, String> {
|
||||
let _ = (port, firmware_path, chip, baud);
|
||||
// Stub: return placeholder result
|
||||
Ok(FlashResult {
|
||||
success: true,
|
||||
message: "Stub: flash not yet implemented".into(),
|
||||
duration_secs: 0.0,
|
||||
let start_time = std::time::Instant::now();
|
||||
|
||||
// Validate firmware file exists
|
||||
let firmware_meta = std::fs::metadata(&firmware_path)
|
||||
.map_err(|e| format!("Cannot read firmware file: {}", e))?;
|
||||
|
||||
let firmware_size = firmware_meta.len();
|
||||
|
||||
// Calculate firmware SHA-256 for verification
|
||||
let firmware_hash = calculate_sha256(&firmware_path)?;
|
||||
|
||||
// Emit flash started event
|
||||
let _ = app.emit("flash-progress", FlashProgress {
|
||||
phase: "connecting".into(),
|
||||
progress_pct: 0.0,
|
||||
bytes_written: 0,
|
||||
bytes_total: firmware_size,
|
||||
message: Some(format!("Connecting to {} ...", port)),
|
||||
});
|
||||
|
||||
// Build espflash command
|
||||
let baud_rate = baud.unwrap_or(921600);
|
||||
let mut cmd = Command::new("espflash");
|
||||
cmd.arg("flash");
|
||||
cmd.args(["--port", &port]);
|
||||
cmd.args(["--baud", &baud_rate.to_string()]);
|
||||
|
||||
if let Some(ref chip_type) = chip {
|
||||
cmd.args(["--chip", chip_type]);
|
||||
}
|
||||
|
||||
// Monitor mode disabled for clean output
|
||||
cmd.arg("--no-monitor");
|
||||
|
||||
// Add firmware path
|
||||
cmd.arg(&firmware_path);
|
||||
|
||||
// Capture output for progress parsing
|
||||
cmd.stdout(Stdio::piped());
|
||||
cmd.stderr(Stdio::piped());
|
||||
|
||||
// Spawn the process
|
||||
let mut child = cmd.spawn()
|
||||
.map_err(|e| format!("Failed to start espflash: {}. Is espflash installed?", e))?;
|
||||
|
||||
let _stdout = child.stdout.take()
|
||||
.ok_or("Failed to capture stdout")?;
|
||||
let stderr = child.stderr.take()
|
||||
.ok_or("Failed to capture stderr")?;
|
||||
|
||||
// Read and parse progress from stderr (espflash outputs there)
|
||||
let app_clone = app.clone();
|
||||
let firmware_size_clone = firmware_size;
|
||||
|
||||
let progress_handle = tokio::task::spawn_blocking(move || {
|
||||
let reader = BufReader::new(stderr);
|
||||
let mut last_phase = "connecting".to_string();
|
||||
let mut last_progress = 0.0f32;
|
||||
|
||||
for line in reader.lines() {
|
||||
if let Ok(line) = line {
|
||||
// Parse espflash progress output
|
||||
if line.contains("Connecting") {
|
||||
last_phase = "connecting".to_string();
|
||||
last_progress = 5.0;
|
||||
} else if line.contains("Erasing") {
|
||||
last_phase = "erasing".to_string();
|
||||
last_progress = 20.0;
|
||||
} else if line.contains("Writing") || line.contains("Flashing") {
|
||||
last_phase = "writing".to_string();
|
||||
// Try to parse percentage from line like "[00:02:10] Writing [##########] 100%"
|
||||
if let Some(pct) = parse_progress_percentage(&line) {
|
||||
last_progress = 20.0 + (pct * 0.7); // 20-90% for writing
|
||||
}
|
||||
} else if line.contains("Hard resetting") || line.contains("Done") {
|
||||
last_phase = "verifying".to_string();
|
||||
last_progress = 95.0;
|
||||
}
|
||||
|
||||
let _ = app_clone.emit("flash-progress", FlashProgress {
|
||||
phase: last_phase.clone(),
|
||||
progress_pct: last_progress,
|
||||
bytes_written: ((last_progress / 100.0) * firmware_size_clone as f32) as u64,
|
||||
bytes_total: firmware_size_clone,
|
||||
message: Some(line),
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// Wait for completion
|
||||
let status = child.wait()
|
||||
.map_err(|e| format!("Failed to wait for espflash: {}", e))?;
|
||||
|
||||
// Wait for progress parsing to complete
|
||||
let _ = progress_handle.await;
|
||||
|
||||
let duration = start_time.elapsed().as_secs_f64();
|
||||
|
||||
if status.success() {
|
||||
// Emit completion
|
||||
let _ = app.emit("flash-progress", FlashProgress {
|
||||
phase: "completed".into(),
|
||||
progress_pct: 100.0,
|
||||
bytes_written: firmware_size,
|
||||
bytes_total: firmware_size,
|
||||
message: Some("Flash completed successfully!".into()),
|
||||
});
|
||||
|
||||
Ok(FlashResult {
|
||||
success: true,
|
||||
message: format!("Firmware flashed successfully in {:.1}s", duration),
|
||||
duration_secs: duration,
|
||||
firmware_hash: Some(firmware_hash),
|
||||
})
|
||||
} else {
|
||||
let _ = app.emit("flash-progress", FlashProgress {
|
||||
phase: "failed".into(),
|
||||
progress_pct: 0.0,
|
||||
bytes_written: 0,
|
||||
bytes_total: firmware_size,
|
||||
message: Some("Flash failed".into()),
|
||||
});
|
||||
|
||||
Err(format!("espflash exited with status: {}", status))
|
||||
}
|
||||
}
|
||||
|
||||
/// Get current flash progress (for polling-based approach).
|
||||
/// Prefer using Tauri events instead.
|
||||
#[tauri::command]
|
||||
pub async fn flash_progress(state: State<'_, AppState>) -> Result<FlashProgress, String> {
|
||||
let flash = state.flash.lock().map_err(|e| e.to_string())?;
|
||||
|
||||
Ok(FlashProgress {
|
||||
phase: flash.phase.clone(),
|
||||
progress_pct: flash.progress_pct,
|
||||
bytes_written: flash.bytes_written,
|
||||
bytes_total: flash.bytes_total,
|
||||
message: flash.message.clone(),
|
||||
})
|
||||
}
|
||||
|
||||
/// Get current flash progress (stub for polling-based approach).
|
||||
/// Verify firmware on device by reading back and comparing hash.
|
||||
#[tauri::command]
|
||||
pub async fn flash_progress() -> Result<FlashProgress, String> {
|
||||
Ok(FlashProgress {
|
||||
phase: "idle".into(),
|
||||
progress_pct: 0.0,
|
||||
bytes_written: 0,
|
||||
bytes_total: 0,
|
||||
pub async fn verify_firmware(
|
||||
_port: String,
|
||||
firmware_path: String,
|
||||
_chip: Option<String>,
|
||||
) -> Result<VerifyResult, String> {
|
||||
// Calculate expected hash
|
||||
let expected_hash = calculate_sha256(&firmware_path)?;
|
||||
|
||||
// Use espflash to read firmware back (if supported)
|
||||
// For now, we rely on espflash's built-in verification
|
||||
// A full implementation would use esptool.py read_flash
|
||||
|
||||
Ok(VerifyResult {
|
||||
verified: true,
|
||||
expected_hash,
|
||||
actual_hash: None,
|
||||
message: "Verification relies on espflash built-in verify".into(),
|
||||
})
|
||||
}
|
||||
|
||||
/// Check if espflash is installed and get version.
|
||||
#[tauri::command]
|
||||
pub async fn check_espflash() -> Result<EspflashInfo, String> {
|
||||
let output = Command::new("espflash")
|
||||
.arg("--version")
|
||||
.output()
|
||||
.map_err(|_| "espflash not found. Please install: cargo install espflash")?;
|
||||
|
||||
if output.status.success() {
|
||||
let version = String::from_utf8_lossy(&output.stdout)
|
||||
.trim()
|
||||
.to_string();
|
||||
|
||||
Ok(EspflashInfo {
|
||||
installed: true,
|
||||
version: Some(version),
|
||||
path: which_espflash().ok(),
|
||||
})
|
||||
} else {
|
||||
Err("espflash found but --version failed".into())
|
||||
}
|
||||
}
|
||||
|
||||
/// Get supported chip types for flashing.
|
||||
#[tauri::command]
|
||||
pub async fn supported_chips() -> Result<Vec<ChipInfo>, String> {
|
||||
Ok(vec![
|
||||
ChipInfo {
|
||||
id: "esp32".into(),
|
||||
name: "ESP32".into(),
|
||||
description: "Original ESP32 dual-core".into(),
|
||||
},
|
||||
ChipInfo {
|
||||
id: "esp32s2".into(),
|
||||
name: "ESP32-S2".into(),
|
||||
description: "ESP32-S2 single-core with USB OTG".into(),
|
||||
},
|
||||
ChipInfo {
|
||||
id: "esp32s3".into(),
|
||||
name: "ESP32-S3".into(),
|
||||
description: "ESP32-S3 dual-core with USB OTG and AI acceleration".into(),
|
||||
},
|
||||
ChipInfo {
|
||||
id: "esp32c3".into(),
|
||||
name: "ESP32-C3".into(),
|
||||
description: "ESP32-C3 RISC-V single-core".into(),
|
||||
},
|
||||
ChipInfo {
|
||||
id: "esp32c6".into(),
|
||||
name: "ESP32-C6".into(),
|
||||
description: "ESP32-C6 RISC-V with WiFi 6 and Thread".into(),
|
||||
},
|
||||
])
|
||||
}
|
||||
|
||||
/// Calculate SHA-256 hash of a file.
|
||||
fn calculate_sha256(path: &str) -> Result<String, String> {
|
||||
let file = std::fs::File::open(path)
|
||||
.map_err(|e| format!("Failed to open file: {}", e))?;
|
||||
|
||||
let mut reader = BufReader::new(file);
|
||||
let mut hasher = Sha256::new();
|
||||
let mut buffer = [0u8; 8192];
|
||||
|
||||
loop {
|
||||
let bytes_read = std::io::Read::read(&mut reader, &mut buffer)
|
||||
.map_err(|e| format!("Failed to read file: {}", e))?;
|
||||
|
||||
if bytes_read == 0 {
|
||||
break;
|
||||
}
|
||||
|
||||
hasher.update(&buffer[..bytes_read]);
|
||||
}
|
||||
|
||||
let hash = hasher.finalize();
|
||||
Ok(hex::encode(hash))
|
||||
}
|
||||
|
||||
/// Parse progress percentage from espflash output line.
|
||||
fn parse_progress_percentage(line: &str) -> Option<f32> {
|
||||
// Match patterns like "100%" or "[##########] 100%"
|
||||
let re = regex::Regex::new(r"(\d+)%").ok()?;
|
||||
re.captures(line)
|
||||
.and_then(|caps| caps.get(1))
|
||||
.and_then(|m| m.as_str().parse().ok())
|
||||
}
|
||||
|
||||
/// Find espflash binary path.
|
||||
fn which_espflash() -> Result<String, String> {
|
||||
let output = Command::new("which")
|
||||
.arg("espflash")
|
||||
.output()
|
||||
.map_err(|e| e.to_string())?;
|
||||
|
||||
if output.status.success() {
|
||||
Ok(String::from_utf8_lossy(&output.stdout).trim().to_string())
|
||||
} else {
|
||||
Err("espflash not in PATH".into())
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct FlashResult {
|
||||
pub success: bool,
|
||||
pub message: String,
|
||||
pub duration_secs: f64,
|
||||
pub firmware_hash: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
@@ -41,4 +306,52 @@ pub struct FlashProgress {
|
||||
pub progress_pct: f32,
|
||||
pub bytes_written: u64,
|
||||
pub bytes_total: u64,
|
||||
pub message: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub struct VerifyResult {
|
||||
pub verified: bool,
|
||||
pub expected_hash: String,
|
||||
pub actual_hash: Option<String>,
|
||||
pub message: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub struct EspflashInfo {
|
||||
pub installed: bool,
|
||||
pub version: Option<String>,
|
||||
pub path: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub struct ChipInfo {
|
||||
pub id: String,
|
||||
pub name: String,
|
||||
pub description: String,
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn test_parse_progress_percentage() {
|
||||
assert_eq!(parse_progress_percentage("[##########] 100%"), Some(100.0));
|
||||
assert_eq!(parse_progress_percentage("Writing 50%"), Some(50.0));
|
||||
assert_eq!(parse_progress_percentage("No percentage here"), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_chip_info() {
|
||||
let chips = vec![
|
||||
ChipInfo {
|
||||
id: "esp32".into(),
|
||||
name: "ESP32".into(),
|
||||
description: "Test".into(),
|
||||
},
|
||||
];
|
||||
assert_eq!(chips.len(), 1);
|
||||
assert_eq!(chips[0].id, "esp32");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,4 +3,5 @@ pub mod flash;
|
||||
pub mod ota;
|
||||
pub mod provision;
|
||||
pub mod server;
|
||||
pub mod settings;
|
||||
pub mod wasm;
|
||||
|
||||
@@ -1,36 +1,381 @@
|
||||
use std::fs::File;
|
||||
use std::io::Read;
|
||||
use std::time::Duration;
|
||||
|
||||
use hmac::{Hmac, Mac};
|
||||
use reqwest::multipart::{Form, Part};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use sha2::{Digest, Sha256};
|
||||
use tauri::{AppHandle, Emitter};
|
||||
|
||||
/// OTA update port on ESP32 nodes.
|
||||
const OTA_PORT: u16 = 8032;
|
||||
|
||||
/// OTA endpoint path.
|
||||
const OTA_PATH: &str = "/ota/upload";
|
||||
|
||||
/// Request timeout for OTA uploads.
|
||||
const OTA_TIMEOUT_SECS: u64 = 120;
|
||||
|
||||
type HmacSha256 = Hmac<Sha256>;
|
||||
|
||||
/// Push firmware to a single node via HTTP OTA (port 8032).
|
||||
///
|
||||
/// Protocol:
|
||||
/// 1. Calculate firmware SHA-256
|
||||
/// 2. Sign with PSK using HMAC-SHA256 if provided
|
||||
/// 3. POST multipart/form-data to http://<node_ip>:8032/ota/upload
|
||||
/// 4. Include signature in X-OTA-Signature header
|
||||
/// 5. Wait for reboot confirmation
|
||||
#[tauri::command]
|
||||
pub async fn ota_update(
|
||||
app: AppHandle,
|
||||
node_ip: String,
|
||||
firmware_path: String,
|
||||
psk: Option<String>,
|
||||
) -> Result<OtaResult, String> {
|
||||
let _ = (node_ip, firmware_path, psk);
|
||||
Ok(OtaResult {
|
||||
success: true,
|
||||
node_ip: "stub".into(),
|
||||
message: "Stub: OTA not yet implemented".into(),
|
||||
})
|
||||
let start_time = std::time::Instant::now();
|
||||
|
||||
// Emit progress
|
||||
let _ = app.emit("ota-progress", OtaProgress {
|
||||
node_ip: node_ip.clone(),
|
||||
phase: "preparing".into(),
|
||||
progress_pct: 0.0,
|
||||
message: Some("Reading firmware...".into()),
|
||||
});
|
||||
|
||||
// Read firmware file
|
||||
let mut file = File::open(&firmware_path)
|
||||
.map_err(|e| format!("Cannot read firmware: {}", e))?;
|
||||
|
||||
let mut firmware_data = Vec::new();
|
||||
file.read_to_end(&mut firmware_data)
|
||||
.map_err(|e| format!("Failed to read firmware: {}", e))?;
|
||||
|
||||
let firmware_size = firmware_data.len();
|
||||
|
||||
// Calculate SHA-256 hash
|
||||
let mut hasher = Sha256::new();
|
||||
hasher.update(&firmware_data);
|
||||
let firmware_hash = hex::encode(hasher.finalize());
|
||||
|
||||
// Calculate HMAC signature if PSK provided
|
||||
let signature = if let Some(ref key) = psk {
|
||||
let mut mac = HmacSha256::new_from_slice(key.as_bytes())
|
||||
.map_err(|e| format!("Invalid PSK: {}", e))?;
|
||||
mac.update(&firmware_data);
|
||||
Some(hex::encode(mac.finalize().into_bytes()))
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
// Emit progress
|
||||
let _ = app.emit("ota-progress", OtaProgress {
|
||||
node_ip: node_ip.clone(),
|
||||
phase: "uploading".into(),
|
||||
progress_pct: 10.0,
|
||||
message: Some(format!("Uploading {} bytes to {}...", firmware_size, node_ip)),
|
||||
});
|
||||
|
||||
// Build HTTP client
|
||||
let client = reqwest::Client::builder()
|
||||
.timeout(Duration::from_secs(OTA_TIMEOUT_SECS))
|
||||
.build()
|
||||
.map_err(|e| format!("Failed to create HTTP client: {}", e))?;
|
||||
|
||||
// Build multipart form
|
||||
let firmware_part = Part::bytes(firmware_data)
|
||||
.file_name("firmware.bin")
|
||||
.mime_str("application/octet-stream")
|
||||
.map_err(|e| format!("Failed to create multipart: {}", e))?;
|
||||
|
||||
let form = Form::new()
|
||||
.part("firmware", firmware_part)
|
||||
.text("sha256", firmware_hash.clone())
|
||||
.text("size", firmware_size.to_string());
|
||||
|
||||
// Build request
|
||||
let url = format!("http://{}:{}{}", node_ip, OTA_PORT, OTA_PATH);
|
||||
let mut request = client.post(&url).multipart(form);
|
||||
|
||||
// Add signature header if present
|
||||
if let Some(ref sig) = signature {
|
||||
request = request.header("X-OTA-Signature", sig);
|
||||
}
|
||||
|
||||
// Add firmware hash header
|
||||
request = request.header("X-OTA-SHA256", &firmware_hash);
|
||||
|
||||
// Send request
|
||||
let response = request.send().await
|
||||
.map_err(|e| format!("OTA upload failed: {}", e))?;
|
||||
|
||||
let status = response.status();
|
||||
let body = response.text().await.unwrap_or_default();
|
||||
|
||||
if !status.is_success() {
|
||||
let _ = app.emit("ota-progress", OtaProgress {
|
||||
node_ip: node_ip.clone(),
|
||||
phase: "failed".into(),
|
||||
progress_pct: 0.0,
|
||||
message: Some(format!("HTTP {}: {}", status, body)),
|
||||
});
|
||||
|
||||
return Err(format!("OTA failed with HTTP {}: {}", status, body));
|
||||
}
|
||||
|
||||
// Emit progress - upload complete
|
||||
let _ = app.emit("ota-progress", OtaProgress {
|
||||
node_ip: node_ip.clone(),
|
||||
phase: "rebooting".into(),
|
||||
progress_pct: 80.0,
|
||||
message: Some("Waiting for node reboot...".into()),
|
||||
});
|
||||
|
||||
// Wait for node to come back online
|
||||
let reboot_ok = wait_for_reboot(&client, &node_ip, Duration::from_secs(30)).await;
|
||||
|
||||
let duration = start_time.elapsed().as_secs_f64();
|
||||
|
||||
if reboot_ok {
|
||||
let _ = app.emit("ota-progress", OtaProgress {
|
||||
node_ip: node_ip.clone(),
|
||||
phase: "completed".into(),
|
||||
progress_pct: 100.0,
|
||||
message: Some(format!("OTA completed in {:.1}s", duration)),
|
||||
});
|
||||
|
||||
Ok(OtaResult {
|
||||
success: true,
|
||||
node_ip,
|
||||
message: format!("OTA completed successfully in {:.1}s", duration),
|
||||
firmware_hash: Some(firmware_hash),
|
||||
duration_secs: Some(duration),
|
||||
})
|
||||
} else {
|
||||
let _ = app.emit("ota-progress", OtaProgress {
|
||||
node_ip: node_ip.clone(),
|
||||
phase: "warning".into(),
|
||||
progress_pct: 90.0,
|
||||
message: Some("Node may not have rebooted successfully".into()),
|
||||
});
|
||||
|
||||
Ok(OtaResult {
|
||||
success: true,
|
||||
node_ip,
|
||||
message: "OTA uploaded but reboot confirmation timed out".into(),
|
||||
firmware_hash: Some(firmware_hash),
|
||||
duration_secs: Some(duration),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
/// Push firmware to multiple nodes with rolling update strategy.
|
||||
///
|
||||
/// Strategy options:
|
||||
/// - Sequential: One node at a time
|
||||
/// - Parallel: All nodes simultaneously (max_concurrent)
|
||||
/// - TdmSafe: Respects TDM slots to avoid disruption
|
||||
#[tauri::command]
|
||||
pub async fn batch_ota_update(
|
||||
app: AppHandle,
|
||||
node_ips: Vec<String>,
|
||||
firmware_path: String,
|
||||
psk: Option<String>,
|
||||
) -> Result<Vec<OtaResult>, String> {
|
||||
let _ = (firmware_path, psk);
|
||||
Ok(node_ips
|
||||
.into_iter()
|
||||
.map(|ip| OtaResult {
|
||||
success: true,
|
||||
node_ip: ip,
|
||||
message: "Stub: batch OTA not yet implemented".into(),
|
||||
})
|
||||
.collect())
|
||||
strategy: Option<String>,
|
||||
max_concurrent: Option<usize>,
|
||||
) -> Result<BatchOtaResult, String> {
|
||||
let start_time = std::time::Instant::now();
|
||||
let total_nodes = node_ips.len();
|
||||
let strategy = strategy.unwrap_or_else(|| "sequential".into());
|
||||
let max_concurrent = max_concurrent.unwrap_or(1);
|
||||
|
||||
let _ = app.emit("batch-ota-progress", BatchOtaProgress {
|
||||
phase: "starting".into(),
|
||||
total: total_nodes,
|
||||
completed: 0,
|
||||
failed: 0,
|
||||
current_node: None,
|
||||
});
|
||||
|
||||
let mut results = Vec::new();
|
||||
let mut completed = 0;
|
||||
let mut failed = 0;
|
||||
|
||||
match strategy.as_str() {
|
||||
"parallel" => {
|
||||
// Parallel execution with semaphore
|
||||
// Parallel OTA with semaphore
|
||||
|
||||
let semaphore = std::sync::Arc::new(tokio::sync::Semaphore::new(max_concurrent));
|
||||
let firmware_path = std::sync::Arc::new(firmware_path);
|
||||
let psk = std::sync::Arc::new(psk);
|
||||
let app = std::sync::Arc::new(app.clone());
|
||||
|
||||
let tasks: Vec<_> = node_ips.into_iter().map(|ip| {
|
||||
let sem = semaphore.clone();
|
||||
let fw_path = firmware_path.clone();
|
||||
let psk_clone = psk.clone();
|
||||
let app_clone = app.clone();
|
||||
|
||||
async move {
|
||||
let _permit = sem.acquire().await.unwrap();
|
||||
ota_update(
|
||||
(*app_clone).clone(),
|
||||
ip,
|
||||
(*fw_path).clone(),
|
||||
(*psk_clone).clone(),
|
||||
).await
|
||||
}
|
||||
}).collect();
|
||||
|
||||
let task_results = futures::future::join_all(tasks).await;
|
||||
|
||||
for result in task_results {
|
||||
match result {
|
||||
Ok(r) => {
|
||||
if r.success {
|
||||
completed += 1;
|
||||
} else {
|
||||
failed += 1;
|
||||
}
|
||||
results.push(r);
|
||||
}
|
||||
Err(e) => {
|
||||
failed += 1;
|
||||
results.push(OtaResult {
|
||||
success: false,
|
||||
node_ip: "unknown".into(),
|
||||
message: e,
|
||||
firmware_hash: None,
|
||||
duration_secs: None,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
_ => {
|
||||
// Sequential execution (default)
|
||||
for ip in node_ips {
|
||||
let _ = app.emit("batch-ota-progress", BatchOtaProgress {
|
||||
phase: "updating".into(),
|
||||
total: total_nodes,
|
||||
completed,
|
||||
failed,
|
||||
current_node: Some(ip.clone()),
|
||||
});
|
||||
|
||||
match ota_update(
|
||||
app.clone(),
|
||||
ip.clone(),
|
||||
firmware_path.clone(),
|
||||
psk.clone(),
|
||||
).await {
|
||||
Ok(r) => {
|
||||
if r.success {
|
||||
completed += 1;
|
||||
} else {
|
||||
failed += 1;
|
||||
}
|
||||
results.push(r);
|
||||
}
|
||||
Err(e) => {
|
||||
failed += 1;
|
||||
results.push(OtaResult {
|
||||
success: false,
|
||||
node_ip: ip,
|
||||
message: e,
|
||||
firmware_hash: None,
|
||||
duration_secs: None,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let duration = start_time.elapsed().as_secs_f64();
|
||||
|
||||
let _ = app.emit("batch-ota-progress", BatchOtaProgress {
|
||||
phase: "completed".into(),
|
||||
total: total_nodes,
|
||||
completed,
|
||||
failed,
|
||||
current_node: None,
|
||||
});
|
||||
|
||||
Ok(BatchOtaResult {
|
||||
total: total_nodes,
|
||||
completed,
|
||||
failed,
|
||||
results,
|
||||
duration_secs: duration,
|
||||
})
|
||||
}
|
||||
|
||||
/// Check if a node's OTA endpoint is accessible.
|
||||
#[tauri::command]
|
||||
pub async fn check_ota_endpoint(node_ip: String) -> Result<OtaEndpointInfo, String> {
|
||||
let client = reqwest::Client::builder()
|
||||
.timeout(Duration::from_secs(5))
|
||||
.build()
|
||||
.map_err(|e| format!("Failed to create HTTP client: {}", e))?;
|
||||
|
||||
let url = format!("http://{}:{}/ota/status", node_ip, OTA_PORT);
|
||||
|
||||
match client.get(&url).send().await {
|
||||
Ok(response) => {
|
||||
if response.status().is_success() {
|
||||
let body = response.text().await.unwrap_or_default();
|
||||
|
||||
// Try to parse as JSON
|
||||
let version = serde_json::from_str::<serde_json::Value>(&body)
|
||||
.ok()
|
||||
.and_then(|v| v.get("version").and_then(|v| v.as_str().map(|s| s.to_string())));
|
||||
|
||||
Ok(OtaEndpointInfo {
|
||||
reachable: true,
|
||||
ota_supported: true,
|
||||
current_version: version,
|
||||
psk_required: false, // Would need to check headers
|
||||
})
|
||||
} else {
|
||||
Ok(OtaEndpointInfo {
|
||||
reachable: true,
|
||||
ota_supported: response.status() != reqwest::StatusCode::NOT_FOUND,
|
||||
current_version: None,
|
||||
psk_required: response.status() == reqwest::StatusCode::UNAUTHORIZED,
|
||||
})
|
||||
}
|
||||
}
|
||||
Err(_) => Ok(OtaEndpointInfo {
|
||||
reachable: false,
|
||||
ota_supported: false,
|
||||
current_version: None,
|
||||
psk_required: false,
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
||||
/// Wait for a node to come back online after OTA reboot.
|
||||
async fn wait_for_reboot(client: &reqwest::Client, node_ip: &str, timeout: Duration) -> bool {
|
||||
let url = format!("http://{}:{}/ota/status", node_ip, OTA_PORT);
|
||||
let start = std::time::Instant::now();
|
||||
|
||||
// First wait for node to go down
|
||||
tokio::time::sleep(Duration::from_secs(2)).await;
|
||||
|
||||
// Then poll for it to come back
|
||||
while start.elapsed() < timeout {
|
||||
if let Ok(response) = client.get(&url).send().await {
|
||||
if response.status().is_success() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
tokio::time::sleep(Duration::from_millis(500)).await;
|
||||
}
|
||||
|
||||
false
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
@@ -38,4 +383,66 @@ pub struct OtaResult {
|
||||
pub success: bool,
|
||||
pub node_ip: String,
|
||||
pub message: String,
|
||||
pub firmware_hash: Option<String>,
|
||||
pub duration_secs: Option<f64>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub struct OtaProgress {
|
||||
pub node_ip: String,
|
||||
pub phase: String,
|
||||
pub progress_pct: f32,
|
||||
pub message: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub struct BatchOtaResult {
|
||||
pub total: usize,
|
||||
pub completed: usize,
|
||||
pub failed: usize,
|
||||
pub results: Vec<OtaResult>,
|
||||
pub duration_secs: f64,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub struct BatchOtaProgress {
|
||||
pub phase: String,
|
||||
pub total: usize,
|
||||
pub completed: usize,
|
||||
pub failed: usize,
|
||||
pub current_node: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub struct OtaEndpointInfo {
|
||||
pub reachable: bool,
|
||||
pub ota_supported: bool,
|
||||
pub current_version: Option<String>,
|
||||
pub psk_required: bool,
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn test_hmac_signature() {
|
||||
let data = b"test firmware data";
|
||||
let psk = "secret_key";
|
||||
|
||||
let mut mac = HmacSha256::new_from_slice(psk.as_bytes()).unwrap();
|
||||
mac.update(data);
|
||||
let signature = hex::encode(mac.finalize().into_bytes());
|
||||
|
||||
assert_eq!(signature.len(), 64); // SHA-256 = 32 bytes = 64 hex chars
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_sha256_hash() {
|
||||
let mut hasher = Sha256::new();
|
||||
hasher.update(b"test data");
|
||||
let hash = hex::encode(hasher.finalize());
|
||||
|
||||
assert_eq!(hash.len(), 64);
|
||||
}
|
||||
}
|
||||
|
||||
+485
-7
@@ -1,29 +1,507 @@
|
||||
use std::time::Duration;
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
use sha2::{Digest, Sha256};
|
||||
|
||||
use crate::domain::config::ProvisioningConfig;
|
||||
|
||||
/// Serial baud rate for provisioning communication.
|
||||
const PROVISION_BAUD: u32 = 115200;
|
||||
|
||||
/// Timeout for serial operations.
|
||||
const SERIAL_TIMEOUT_MS: u64 = 5000;
|
||||
|
||||
/// NVS partition name (reserved for future use).
|
||||
#[allow(dead_code)]
|
||||
const NVS_PARTITION: &str = "nvs";
|
||||
|
||||
/// Magic bytes for provisioning protocol.
|
||||
const PROVISION_MAGIC: &[u8] = b"RUVIEW_NVS";
|
||||
|
||||
/// Provision NVS configuration to an ESP32 via serial port.
|
||||
///
|
||||
/// Protocol:
|
||||
/// 1. Open serial port at 115200 baud
|
||||
/// 2. Send provisioning magic bytes
|
||||
/// 3. Wait for acknowledgment
|
||||
/// 4. Send NVS binary blob
|
||||
/// 5. Wait for checksum confirmation
|
||||
#[tauri::command]
|
||||
pub async fn provision_node(
|
||||
port: String,
|
||||
config: ProvisioningConfig,
|
||||
) -> Result<ProvisionResult, String> {
|
||||
let _ = (port, config);
|
||||
Ok(ProvisionResult {
|
||||
success: true,
|
||||
message: "Stub: provisioning not yet implemented".into(),
|
||||
})
|
||||
// Validate configuration
|
||||
config.validate()?;
|
||||
|
||||
// Serialize config to NVS binary format
|
||||
let nvs_data = serialize_nvs_config(&config)?;
|
||||
let nvs_size = nvs_data.len();
|
||||
|
||||
// Calculate checksum
|
||||
let mut hasher = Sha256::new();
|
||||
hasher.update(&nvs_data);
|
||||
let checksum = hex::encode(&hasher.finalize()[..8]); // First 8 bytes
|
||||
|
||||
// Open serial port
|
||||
let port_settings = tokio_serial::SerialPortBuilderExt::open_native_async(
|
||||
tokio_serial::new(&port, PROVISION_BAUD)
|
||||
.timeout(Duration::from_millis(SERIAL_TIMEOUT_MS))
|
||||
).map_err(|e| format!("Failed to open serial port: {}", e))?;
|
||||
|
||||
let (mut reader, mut writer) = tokio::io::split(port_settings);
|
||||
|
||||
// Send magic bytes + size header
|
||||
let header = ProvisionHeader {
|
||||
magic: PROVISION_MAGIC.try_into().unwrap(),
|
||||
version: 1,
|
||||
size: nvs_size as u32,
|
||||
};
|
||||
|
||||
let header_bytes = bincode_header(&header);
|
||||
tokio::io::AsyncWriteExt::write_all(&mut writer, &header_bytes).await
|
||||
.map_err(|e| format!("Failed to send header: {}", e))?;
|
||||
|
||||
// Wait for ACK
|
||||
let mut ack_buf = [0u8; 4];
|
||||
tokio::time::timeout(
|
||||
Duration::from_millis(SERIAL_TIMEOUT_MS),
|
||||
tokio::io::AsyncReadExt::read_exact(&mut reader, &mut ack_buf)
|
||||
).await
|
||||
.map_err(|_| "Timeout waiting for device acknowledgment")?
|
||||
.map_err(|e| format!("Failed to read ACK: {}", e))?;
|
||||
|
||||
if &ack_buf != b"ACK\n" {
|
||||
return Err(format!("Invalid ACK response: {:?}", ack_buf));
|
||||
}
|
||||
|
||||
// Send NVS data in chunks
|
||||
const CHUNK_SIZE: usize = 256;
|
||||
for chunk in nvs_data.chunks(CHUNK_SIZE) {
|
||||
tokio::io::AsyncWriteExt::write_all(&mut writer, chunk).await
|
||||
.map_err(|e| format!("Failed to send data chunk: {}", e))?;
|
||||
|
||||
// Small delay between chunks for device processing
|
||||
tokio::time::sleep(Duration::from_millis(10)).await;
|
||||
}
|
||||
|
||||
// Send checksum
|
||||
tokio::io::AsyncWriteExt::write_all(&mut writer, checksum.as_bytes()).await
|
||||
.map_err(|e| format!("Failed to send checksum: {}", e))?;
|
||||
|
||||
tokio::io::AsyncWriteExt::write_all(&mut writer, b"\n").await
|
||||
.map_err(|e| format!("Failed to send newline: {}", e))?;
|
||||
|
||||
// Wait for confirmation
|
||||
let mut confirm_buf = [0u8; 32];
|
||||
let confirm_len = tokio::time::timeout(
|
||||
Duration::from_millis(SERIAL_TIMEOUT_MS * 2),
|
||||
tokio::io::AsyncReadExt::read(&mut reader, &mut confirm_buf)
|
||||
).await
|
||||
.map_err(|_| "Timeout waiting for confirmation")?
|
||||
.map_err(|e| format!("Failed to read confirmation: {}", e))?;
|
||||
|
||||
let confirm_str = String::from_utf8_lossy(&confirm_buf[..confirm_len]);
|
||||
|
||||
if confirm_str.contains("OK") {
|
||||
Ok(ProvisionResult {
|
||||
success: true,
|
||||
message: format!("Provisioned {} bytes to NVS successfully", nvs_size),
|
||||
checksum: Some(checksum),
|
||||
})
|
||||
} else if confirm_str.contains("ERR") {
|
||||
Err(format!("Device reported error: {}", confirm_str.trim()))
|
||||
} else {
|
||||
Err(format!("Unexpected response: {}", confirm_str.trim()))
|
||||
}
|
||||
}
|
||||
|
||||
/// Read current NVS configuration from a connected ESP32.
|
||||
#[tauri::command]
|
||||
pub async fn read_nvs(port: String) -> Result<ProvisioningConfig, String> {
|
||||
let _ = port;
|
||||
Ok(ProvisioningConfig::default())
|
||||
// Open serial port
|
||||
let port_settings = tokio_serial::SerialPortBuilderExt::open_native_async(
|
||||
tokio_serial::new(&port, PROVISION_BAUD)
|
||||
.timeout(Duration::from_millis(SERIAL_TIMEOUT_MS))
|
||||
).map_err(|e| format!("Failed to open serial port: {}", e))?;
|
||||
|
||||
let (mut reader, mut writer) = tokio::io::split(port_settings);
|
||||
|
||||
// Send read command
|
||||
tokio::io::AsyncWriteExt::write_all(&mut writer, b"RUVIEW_NVS_READ\n").await
|
||||
.map_err(|e| format!("Failed to send read command: {}", e))?;
|
||||
|
||||
// Read size header
|
||||
let mut size_buf = [0u8; 4];
|
||||
tokio::time::timeout(
|
||||
Duration::from_millis(SERIAL_TIMEOUT_MS),
|
||||
tokio::io::AsyncReadExt::read_exact(&mut reader, &mut size_buf)
|
||||
).await
|
||||
.map_err(|_| "Timeout waiting for NVS size")?
|
||||
.map_err(|e| format!("Failed to read size: {}", e))?;
|
||||
|
||||
let nvs_size = u32::from_le_bytes(size_buf) as usize;
|
||||
|
||||
if nvs_size == 0 || nvs_size > 4096 {
|
||||
return Err(format!("Invalid NVS size: {}", nvs_size));
|
||||
}
|
||||
|
||||
// Read NVS data
|
||||
let mut nvs_data = vec![0u8; nvs_size];
|
||||
tokio::time::timeout(
|
||||
Duration::from_millis(SERIAL_TIMEOUT_MS * 2),
|
||||
tokio::io::AsyncReadExt::read_exact(&mut reader, &mut nvs_data)
|
||||
).await
|
||||
.map_err(|_| "Timeout reading NVS data")?
|
||||
.map_err(|e| format!("Failed to read NVS data: {}", e))?;
|
||||
|
||||
// Parse NVS data to config
|
||||
deserialize_nvs_config(&nvs_data)
|
||||
}
|
||||
|
||||
/// Erase NVS partition on a connected ESP32.
|
||||
#[tauri::command]
|
||||
pub async fn erase_nvs(port: String) -> Result<ProvisionResult, String> {
|
||||
// Open serial port
|
||||
let port_settings = tokio_serial::SerialPortBuilderExt::open_native_async(
|
||||
tokio_serial::new(&port, PROVISION_BAUD)
|
||||
.timeout(Duration::from_millis(SERIAL_TIMEOUT_MS))
|
||||
).map_err(|e| format!("Failed to open serial port: {}", e))?;
|
||||
|
||||
let (mut reader, mut writer) = tokio::io::split(port_settings);
|
||||
|
||||
// Send erase command
|
||||
tokio::io::AsyncWriteExt::write_all(&mut writer, b"RUVIEW_NVS_ERASE\n").await
|
||||
.map_err(|e| format!("Failed to send erase command: {}", e))?;
|
||||
|
||||
// Wait for confirmation
|
||||
let mut confirm_buf = [0u8; 32];
|
||||
let confirm_len = tokio::time::timeout(
|
||||
Duration::from_millis(SERIAL_TIMEOUT_MS * 3), // Erase takes longer
|
||||
tokio::io::AsyncReadExt::read(&mut reader, &mut confirm_buf)
|
||||
).await
|
||||
.map_err(|_| "Timeout waiting for erase confirmation")?
|
||||
.map_err(|e| format!("Failed to read confirmation: {}", e))?;
|
||||
|
||||
let confirm_str = String::from_utf8_lossy(&confirm_buf[..confirm_len]);
|
||||
|
||||
if confirm_str.contains("OK") {
|
||||
Ok(ProvisionResult {
|
||||
success: true,
|
||||
message: "NVS partition erased successfully".into(),
|
||||
checksum: None,
|
||||
})
|
||||
} else {
|
||||
Err(format!("Erase failed: {}", confirm_str.trim()))
|
||||
}
|
||||
}
|
||||
|
||||
/// Validate provisioning configuration without applying.
|
||||
#[tauri::command]
|
||||
pub async fn validate_config(config: ProvisioningConfig) -> Result<ValidationResult, String> {
|
||||
match config.validate() {
|
||||
Ok(()) => {
|
||||
let nvs_data = serialize_nvs_config(&config)?;
|
||||
Ok(ValidationResult {
|
||||
valid: true,
|
||||
message: None,
|
||||
estimated_size: nvs_data.len(),
|
||||
})
|
||||
}
|
||||
Err(e) => Ok(ValidationResult {
|
||||
valid: false,
|
||||
message: Some(e),
|
||||
estimated_size: 0,
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
||||
/// Generate mesh provisioning configs for multiple nodes.
|
||||
#[tauri::command]
|
||||
pub async fn generate_mesh_configs(
|
||||
base_config: ProvisioningConfig,
|
||||
node_count: u8,
|
||||
) -> Result<Vec<MeshNodeConfig>, String> {
|
||||
if node_count == 0 || node_count > 32 {
|
||||
return Err("Node count must be 1-32".into());
|
||||
}
|
||||
|
||||
let mut configs = Vec::new();
|
||||
|
||||
for i in 0..node_count {
|
||||
let mut node_config = base_config.clone();
|
||||
node_config.node_id = Some(i);
|
||||
node_config.tdm_slot = Some(i);
|
||||
node_config.tdm_total = Some(node_count);
|
||||
|
||||
configs.push(MeshNodeConfig {
|
||||
node_id: i,
|
||||
tdm_slot: i,
|
||||
config: node_config,
|
||||
});
|
||||
}
|
||||
|
||||
Ok(configs)
|
||||
}
|
||||
|
||||
/// Serialize ProvisioningConfig to NVS binary format.
|
||||
/// Format: key-value pairs with length prefixes
|
||||
fn serialize_nvs_config(config: &ProvisioningConfig) -> Result<Vec<u8>, String> {
|
||||
let mut data = Vec::new();
|
||||
|
||||
// Inline helpers to avoid closure borrow issues
|
||||
fn write_str(data: &mut Vec<u8>, key: &str, value: &str) {
|
||||
// Key length (1 byte) + key + value length (2 bytes) + value
|
||||
data.push(key.len() as u8);
|
||||
data.extend_from_slice(key.as_bytes());
|
||||
data.extend_from_slice(&(value.len() as u16).to_le_bytes());
|
||||
data.extend_from_slice(value.as_bytes());
|
||||
}
|
||||
|
||||
fn write_u8(data: &mut Vec<u8>, key: &str, value: u8) {
|
||||
data.push(key.len() as u8);
|
||||
data.extend_from_slice(key.as_bytes());
|
||||
data.extend_from_slice(&1u16.to_le_bytes());
|
||||
data.push(value);
|
||||
}
|
||||
|
||||
fn write_u16(data: &mut Vec<u8>, key: &str, value: u16) {
|
||||
data.push(key.len() as u8);
|
||||
data.extend_from_slice(key.as_bytes());
|
||||
data.extend_from_slice(&2u16.to_le_bytes());
|
||||
data.extend_from_slice(&value.to_le_bytes());
|
||||
}
|
||||
|
||||
// Serialize each field
|
||||
if let Some(ref ssid) = config.wifi_ssid {
|
||||
write_str(&mut data, "wifi_ssid", ssid);
|
||||
}
|
||||
if let Some(ref pass) = config.wifi_password {
|
||||
write_str(&mut data, "wifi_pass", pass);
|
||||
}
|
||||
if let Some(ref ip) = config.target_ip {
|
||||
write_str(&mut data, "target_ip", ip);
|
||||
}
|
||||
if let Some(port) = config.target_port {
|
||||
write_u16(&mut data, "target_port", port);
|
||||
}
|
||||
if let Some(id) = config.node_id {
|
||||
write_u8(&mut data, "node_id", id);
|
||||
}
|
||||
if let Some(slot) = config.tdm_slot {
|
||||
write_u8(&mut data, "tdm_slot", slot);
|
||||
}
|
||||
if let Some(total) = config.tdm_total {
|
||||
write_u8(&mut data, "tdm_total", total);
|
||||
}
|
||||
if let Some(tier) = config.edge_tier {
|
||||
write_u8(&mut data, "edge_tier", tier);
|
||||
}
|
||||
if let Some(thresh) = config.presence_thresh {
|
||||
write_u16(&mut data, "presence_th", thresh);
|
||||
}
|
||||
if let Some(thresh) = config.fall_thresh {
|
||||
write_u16(&mut data, "fall_th", thresh);
|
||||
}
|
||||
if let Some(window) = config.vital_window {
|
||||
write_u16(&mut data, "vital_win", window);
|
||||
}
|
||||
if let Some(interval) = config.vital_interval_ms {
|
||||
write_u16(&mut data, "vital_int", interval);
|
||||
}
|
||||
if let Some(count) = config.top_k_count {
|
||||
write_u8(&mut data, "top_k", count);
|
||||
}
|
||||
if let Some(hops) = config.hop_count {
|
||||
write_u8(&mut data, "hop_count", hops);
|
||||
}
|
||||
if let Some(ref channels) = config.channel_list {
|
||||
let ch_str: String = channels.iter()
|
||||
.map(|c| c.to_string())
|
||||
.collect::<Vec<_>>()
|
||||
.join(",");
|
||||
write_str(&mut data, "channels", &ch_str);
|
||||
}
|
||||
if let Some(duty) = config.power_duty {
|
||||
write_u8(&mut data, "power_duty", duty);
|
||||
}
|
||||
if let Some(max) = config.wasm_max_modules {
|
||||
write_u8(&mut data, "wasm_max", max);
|
||||
}
|
||||
if let Some(verify) = config.wasm_verify {
|
||||
write_u8(&mut data, "wasm_verify", if verify { 1 } else { 0 });
|
||||
}
|
||||
if let Some(ref psk) = config.ota_psk {
|
||||
write_str(&mut data, "ota_psk", psk);
|
||||
}
|
||||
|
||||
// End marker
|
||||
data.push(0);
|
||||
|
||||
Ok(data)
|
||||
}
|
||||
|
||||
/// Deserialize NVS binary data to ProvisioningConfig.
|
||||
fn deserialize_nvs_config(data: &[u8]) -> Result<ProvisioningConfig, String> {
|
||||
let mut config = ProvisioningConfig::default();
|
||||
let mut pos = 0;
|
||||
|
||||
while pos < data.len() {
|
||||
// Read key length
|
||||
let key_len = data[pos] as usize;
|
||||
pos += 1;
|
||||
|
||||
if key_len == 0 {
|
||||
break; // End marker
|
||||
}
|
||||
|
||||
if pos + key_len > data.len() {
|
||||
return Err("Invalid NVS data: truncated key".into());
|
||||
}
|
||||
|
||||
let key = std::str::from_utf8(&data[pos..pos + key_len])
|
||||
.map_err(|_| "Invalid key encoding")?;
|
||||
pos += key_len;
|
||||
|
||||
if pos + 2 > data.len() {
|
||||
return Err("Invalid NVS data: truncated value length".into());
|
||||
}
|
||||
|
||||
let value_len = u16::from_le_bytes([data[pos], data[pos + 1]]) as usize;
|
||||
pos += 2;
|
||||
|
||||
if pos + value_len > data.len() {
|
||||
return Err("Invalid NVS data: truncated value".into());
|
||||
}
|
||||
|
||||
let value_bytes = &data[pos..pos + value_len];
|
||||
pos += value_len;
|
||||
|
||||
// Parse based on key
|
||||
match key {
|
||||
"wifi_ssid" => config.wifi_ssid = Some(String::from_utf8_lossy(value_bytes).to_string()),
|
||||
"wifi_pass" => config.wifi_password = Some(String::from_utf8_lossy(value_bytes).to_string()),
|
||||
"target_ip" => config.target_ip = Some(String::from_utf8_lossy(value_bytes).to_string()),
|
||||
"target_port" if value_len == 2 => {
|
||||
config.target_port = Some(u16::from_le_bytes([value_bytes[0], value_bytes[1]]));
|
||||
}
|
||||
"node_id" if value_len == 1 => config.node_id = Some(value_bytes[0]),
|
||||
"tdm_slot" if value_len == 1 => config.tdm_slot = Some(value_bytes[0]),
|
||||
"tdm_total" if value_len == 1 => config.tdm_total = Some(value_bytes[0]),
|
||||
"edge_tier" if value_len == 1 => config.edge_tier = Some(value_bytes[0]),
|
||||
"presence_th" if value_len == 2 => {
|
||||
config.presence_thresh = Some(u16::from_le_bytes([value_bytes[0], value_bytes[1]]));
|
||||
}
|
||||
"fall_th" if value_len == 2 => {
|
||||
config.fall_thresh = Some(u16::from_le_bytes([value_bytes[0], value_bytes[1]]));
|
||||
}
|
||||
"vital_win" if value_len == 2 => {
|
||||
config.vital_window = Some(u16::from_le_bytes([value_bytes[0], value_bytes[1]]));
|
||||
}
|
||||
"vital_int" if value_len == 2 => {
|
||||
config.vital_interval_ms = Some(u16::from_le_bytes([value_bytes[0], value_bytes[1]]));
|
||||
}
|
||||
"top_k" if value_len == 1 => config.top_k_count = Some(value_bytes[0]),
|
||||
"hop_count" if value_len == 1 => config.hop_count = Some(value_bytes[0]),
|
||||
"channels" => {
|
||||
let ch_str = String::from_utf8_lossy(value_bytes);
|
||||
config.channel_list = Some(
|
||||
ch_str.split(',')
|
||||
.filter_map(|s| s.trim().parse().ok())
|
||||
.collect()
|
||||
);
|
||||
}
|
||||
"power_duty" if value_len == 1 => config.power_duty = Some(value_bytes[0]),
|
||||
"wasm_max" if value_len == 1 => config.wasm_max_modules = Some(value_bytes[0]),
|
||||
"wasm_verify" if value_len == 1 => config.wasm_verify = Some(value_bytes[0] != 0),
|
||||
"ota_psk" => config.ota_psk = Some(String::from_utf8_lossy(value_bytes).to_string()),
|
||||
_ => {} // Ignore unknown keys
|
||||
}
|
||||
}
|
||||
|
||||
Ok(config)
|
||||
}
|
||||
|
||||
/// Binary header for provisioning protocol.
|
||||
#[repr(C, packed)]
|
||||
struct ProvisionHeader {
|
||||
magic: [u8; 10],
|
||||
version: u8,
|
||||
size: u32,
|
||||
}
|
||||
|
||||
fn bincode_header(header: &ProvisionHeader) -> Vec<u8> {
|
||||
let mut bytes = Vec::with_capacity(15);
|
||||
bytes.extend_from_slice(&header.magic);
|
||||
bytes.push(header.version);
|
||||
bytes.extend_from_slice(&header.size.to_le_bytes());
|
||||
bytes
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct ProvisionResult {
|
||||
pub success: bool,
|
||||
pub message: String,
|
||||
pub checksum: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub struct ValidationResult {
|
||||
pub valid: bool,
|
||||
pub message: Option<String>,
|
||||
pub estimated_size: usize,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub struct MeshNodeConfig {
|
||||
pub node_id: u8,
|
||||
pub tdm_slot: u8,
|
||||
pub config: ProvisioningConfig,
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn test_serialize_deserialize_config() {
|
||||
let config = ProvisioningConfig {
|
||||
wifi_ssid: Some("TestNetwork".into()),
|
||||
wifi_password: Some("password123".into()),
|
||||
node_id: Some(1),
|
||||
tdm_slot: Some(0),
|
||||
tdm_total: Some(4),
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
let serialized = serialize_nvs_config(&config).unwrap();
|
||||
let deserialized = deserialize_nvs_config(&serialized).unwrap();
|
||||
|
||||
assert_eq!(deserialized.wifi_ssid, config.wifi_ssid);
|
||||
assert_eq!(deserialized.node_id, config.node_id);
|
||||
assert_eq!(deserialized.tdm_slot, config.tdm_slot);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_config_validation() {
|
||||
let mut config = ProvisioningConfig::default();
|
||||
config.tdm_slot = Some(5);
|
||||
config.tdm_total = Some(4);
|
||||
|
||||
let result = config.validate();
|
||||
assert!(result.is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_provision_header() {
|
||||
let header = ProvisionHeader {
|
||||
magic: *b"RUVIEW_NVS",
|
||||
version: 1,
|
||||
size: 256,
|
||||
};
|
||||
|
||||
let bytes = bincode_header(&header);
|
||||
assert_eq!(bytes.len(), 15);
|
||||
assert_eq!(&bytes[0..10], b"RUVIEW_NVS");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,39 +1,344 @@
|
||||
use std::process::{Command, Stdio};
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
use tauri::State;
|
||||
use sysinfo::{Pid, ProcessesToUpdate, System};
|
||||
use tauri::{AppHandle, Manager, State};
|
||||
|
||||
use crate::state::AppState;
|
||||
|
||||
/// 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. Next to executable
|
||||
/// 4. System PATH
|
||||
#[tauri::command]
|
||||
pub async fn start_server(
|
||||
app: AppHandle,
|
||||
config: ServerConfig,
|
||||
state: State<'_, AppState>,
|
||||
) -> Result<(), String> {
|
||||
let _ = config;
|
||||
let mut srv = state.server.lock().map_err(|e| e.to_string())?;
|
||||
srv.running = true;
|
||||
srv.pid = Some(0); // Stub PID
|
||||
Ok(())
|
||||
) -> Result<ServerStartResult, String> {
|
||||
// Check if already running
|
||||
{
|
||||
let srv = state.server.lock().map_err(|e| e.to_string())?;
|
||||
if srv.running {
|
||||
return Err("Server is already running".into());
|
||||
}
|
||||
}
|
||||
|
||||
// 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);
|
||||
|
||||
if let Some(port) = config.http_port {
|
||||
cmd.args(["--http-port", &port.to_string()]);
|
||||
}
|
||||
if let Some(port) = config.ws_port {
|
||||
cmd.args(["--ws-port", &port.to_string()]);
|
||||
}
|
||||
if let Some(port) = config.udp_port {
|
||||
cmd.args(["--udp-port", &port.to_string()]);
|
||||
}
|
||||
if let Some(ref bind_addr) = config.bind_address {
|
||||
cmd.args(["--bind", bind_addr]);
|
||||
}
|
||||
if let Some(ref log_level) = config.log_level {
|
||||
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());
|
||||
|
||||
// Spawn the child process
|
||||
let child = cmd.spawn()
|
||||
.map_err(|e| format!("Failed to start server: {}. Is '{}' installed?", e, server_path))?;
|
||||
|
||||
let pid = child.id();
|
||||
|
||||
// Store the child process in state
|
||||
{
|
||||
let mut srv = state.server.lock().map_err(|e| e.to_string())?;
|
||||
srv.running = true;
|
||||
srv.pid = Some(pid);
|
||||
srv.http_port = config.http_port;
|
||||
srv.ws_port = config.ws_port;
|
||||
srv.udp_port = config.udp_port;
|
||||
srv.child = Some(child);
|
||||
}
|
||||
|
||||
tracing::info!("Started sensing server with PID {}", pid);
|
||||
|
||||
Ok(ServerStartResult {
|
||||
pid,
|
||||
http_port: config.http_port,
|
||||
ws_port: config.ws_port,
|
||||
udp_port: config.udp_port,
|
||||
})
|
||||
}
|
||||
|
||||
/// Stop the managed sensing server process.
|
||||
///
|
||||
/// First attempts graceful termination (SIGTERM), then SIGKILL after timeout.
|
||||
#[tauri::command]
|
||||
pub async fn stop_server(state: State<'_, AppState>) -> Result<(), String> {
|
||||
let mut srv = state.server.lock().map_err(|e| e.to_string())?;
|
||||
srv.running = false;
|
||||
srv.pid = None;
|
||||
// Extract child process and take ownership for killing
|
||||
let (child_id, mut child_process) = {
|
||||
let mut srv = state.server.lock().map_err(|e| e.to_string())?;
|
||||
if !srv.running {
|
||||
return Err("Server is not running".into());
|
||||
}
|
||||
let pid = srv.pid;
|
||||
let child = srv.child.take(); // Take ownership of child
|
||||
(pid, child)
|
||||
};
|
||||
|
||||
let child_id = match child_id {
|
||||
Some(id) => id,
|
||||
None => return Err("No server process found".into()),
|
||||
};
|
||||
|
||||
tracing::info!("Stopping sensing server with PID {}", child_id);
|
||||
|
||||
// First try graceful termination via SIGTERM
|
||||
#[cfg(unix)]
|
||||
{
|
||||
unsafe {
|
||||
// Kill the process group (negative PID) to kill all children too
|
||||
let _ = libc::kill(-(child_id as i32), libc::SIGTERM);
|
||||
// Also kill the main process directly
|
||||
let _ = libc::kill(child_id as i32, libc::SIGTERM);
|
||||
}
|
||||
}
|
||||
|
||||
// Wait briefly for graceful shutdown
|
||||
tokio::time::sleep(std::time::Duration::from_millis(500)).await;
|
||||
|
||||
// Check if still running
|
||||
let still_running = {
|
||||
let mut sys = System::new();
|
||||
let pid = Pid::from_u32(child_id);
|
||||
sys.refresh_processes(ProcessesToUpdate::Some(&[pid]), true);
|
||||
sys.process(pid).is_some()
|
||||
};
|
||||
|
||||
// Force kill if still running
|
||||
if still_running {
|
||||
tracing::warn!("Server still running after SIGTERM, sending SIGKILL");
|
||||
|
||||
#[cfg(unix)]
|
||||
{
|
||||
unsafe {
|
||||
// SIGKILL the process group and main process
|
||||
let _ = libc::kill(-(child_id as i32), libc::SIGKILL);
|
||||
let _ = libc::kill(child_id as i32, libc::SIGKILL);
|
||||
}
|
||||
}
|
||||
|
||||
// Also use the child handle if available
|
||||
if let Some(ref mut child) = child_process {
|
||||
let _ = child.kill();
|
||||
}
|
||||
}
|
||||
|
||||
// Wait for process to actually terminate
|
||||
if let Some(ref mut child) = child_process {
|
||||
let _ = child.wait();
|
||||
}
|
||||
|
||||
// Final verification and cleanup
|
||||
tokio::time::sleep(std::time::Duration::from_millis(200)).await;
|
||||
|
||||
// Clear state
|
||||
{
|
||||
let mut srv = state.server.lock().map_err(|e| e.to_string())?;
|
||||
srv.running = false;
|
||||
srv.pid = None;
|
||||
srv.http_port = None;
|
||||
srv.ws_port = None;
|
||||
srv.udp_port = None;
|
||||
srv.child = None;
|
||||
}
|
||||
|
||||
// Verify process is dead
|
||||
let still_alive = {
|
||||
let mut sys = System::new();
|
||||
let pid = Pid::from_u32(child_id);
|
||||
sys.refresh_processes(ProcessesToUpdate::Some(&[pid]), true);
|
||||
sys.process(pid).is_some()
|
||||
};
|
||||
|
||||
if still_alive {
|
||||
tracing::error!("Failed to kill server process {}", child_id);
|
||||
return Err(format!("Failed to stop server process {}", child_id));
|
||||
}
|
||||
|
||||
tracing::info!("Stopped sensing server");
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Get sensing server status.
|
||||
/// Get sensing server status including resource usage.
|
||||
#[tauri::command]
|
||||
pub async fn server_status(state: State<'_, AppState>) -> Result<ServerStatusResponse, String> {
|
||||
let srv = state.server.lock().map_err(|e| e.to_string())?;
|
||||
|
||||
if !srv.running || srv.pid.is_none() {
|
||||
return Ok(ServerStatusResponse {
|
||||
running: false,
|
||||
pid: None,
|
||||
http_port: None,
|
||||
ws_port: None,
|
||||
udp_port: None,
|
||||
memory_mb: None,
|
||||
cpu_percent: None,
|
||||
uptime_secs: None,
|
||||
});
|
||||
}
|
||||
|
||||
let pid = srv.pid.unwrap();
|
||||
let mut sys = System::new();
|
||||
let sysinfo_pid = Pid::from_u32(pid);
|
||||
sys.refresh_processes(ProcessesToUpdate::Some(&[sysinfo_pid]), true);
|
||||
|
||||
let (memory_mb, cpu_percent) = sys.process(sysinfo_pid)
|
||||
.map(|proc| {
|
||||
let mem = proc.memory() as f64 / 1024.0 / 1024.0;
|
||||
let cpu = proc.cpu_usage();
|
||||
(Some(mem), Some(cpu))
|
||||
})
|
||||
.unwrap_or((None, None));
|
||||
|
||||
// Calculate uptime if we have start time
|
||||
let uptime_secs = srv.start_time.map(|start| {
|
||||
std::time::Instant::now().duration_since(start).as_secs()
|
||||
});
|
||||
|
||||
Ok(ServerStatusResponse {
|
||||
running: srv.running,
|
||||
pid: srv.pid,
|
||||
http_port: None,
|
||||
ws_port: None,
|
||||
pid: Some(pid),
|
||||
http_port: srv.http_port,
|
||||
ws_port: srv.ws_port,
|
||||
udp_port: srv.udp_port,
|
||||
memory_mb,
|
||||
cpu_percent,
|
||||
uptime_secs,
|
||||
})
|
||||
}
|
||||
|
||||
/// 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> {
|
||||
// Get current config if no new config provided
|
||||
let restart_config = if let Some(cfg) = config {
|
||||
cfg
|
||||
} else {
|
||||
let srv = state.server.lock().map_err(|e| e.to_string())?;
|
||||
ServerConfig {
|
||||
http_port: srv.http_port,
|
||||
ws_port: srv.ws_port,
|
||||
udp_port: srv.udp_port,
|
||||
log_level: None,
|
||||
bind_address: None,
|
||||
server_path: None,
|
||||
source: None, // Use default (simulate)
|
||||
}
|
||||
};
|
||||
|
||||
// Stop existing server
|
||||
let _ = stop_server(state.clone()).await;
|
||||
|
||||
// Brief delay to ensure port is released
|
||||
tokio::time::sleep(std::time::Duration::from_millis(500)).await;
|
||||
|
||||
// Start with new config
|
||||
start_server(app, restart_config, state).await
|
||||
}
|
||||
|
||||
/// Get server logs (last N lines from stdout/stderr).
|
||||
#[tauri::command]
|
||||
pub async fn server_logs(
|
||||
_lines: Option<usize>,
|
||||
state: State<'_, AppState>,
|
||||
) -> Result<ServerLogsResponse, String> {
|
||||
let _srv = state.server.lock().map_err(|e| e.to_string())?;
|
||||
|
||||
// For now, return empty logs - full implementation would capture stdout/stderr
|
||||
// to ring buffer during process lifetime
|
||||
Ok(ServerLogsResponse {
|
||||
stdout: Vec::new(),
|
||||
stderr: Vec::new(),
|
||||
truncated: false,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -43,6 +348,18 @@ pub struct ServerConfig {
|
||||
pub ws_port: Option<u16>,
|
||||
pub udp_port: Option<u16>,
|
||||
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)]
|
||||
pub struct ServerStartResult {
|
||||
pub pid: u32,
|
||||
pub http_port: Option<u16>,
|
||||
pub ws_port: Option<u16>,
|
||||
pub udp_port: Option<u16>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
@@ -51,4 +368,36 @@ pub struct ServerStatusResponse {
|
||||
pub pid: Option<u32>,
|
||||
pub http_port: Option<u16>,
|
||||
pub ws_port: Option<u16>,
|
||||
pub udp_port: Option<u16>,
|
||||
pub memory_mb: Option<f64>,
|
||||
pub cpu_percent: Option<f32>,
|
||||
pub uptime_secs: Option<u64>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub struct ServerLogsResponse {
|
||||
pub stdout: Vec<String>,
|
||||
pub stderr: Vec<String>,
|
||||
pub truncated: bool,
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn test_server_config_default() {
|
||||
let config = ServerConfig {
|
||||
http_port: Some(8080),
|
||||
ws_port: Some(8765),
|
||||
udp_port: Some(5005),
|
||||
log_level: None,
|
||||
bind_address: None,
|
||||
server_path: None,
|
||||
source: Some("simulate".to_string()),
|
||||
};
|
||||
|
||||
assert_eq!(config.http_port, Some(8080));
|
||||
assert_eq!(config.ws_port, Some(8765));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,101 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::fs;
|
||||
use std::path::PathBuf;
|
||||
use tauri::{AppHandle, Manager};
|
||||
|
||||
/// Application settings that persist across restarts.
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct AppSettings {
|
||||
pub server_http_port: u16,
|
||||
pub server_ws_port: u16,
|
||||
pub server_udp_port: u16,
|
||||
pub bind_address: String,
|
||||
pub ui_path: String,
|
||||
pub ota_psk: String,
|
||||
pub auto_discover: bool,
|
||||
pub discover_interval_ms: u32,
|
||||
pub theme: String,
|
||||
}
|
||||
|
||||
impl Default for AppSettings {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
server_http_port: 8080,
|
||||
server_ws_port: 8765,
|
||||
server_udp_port: 5005,
|
||||
bind_address: "127.0.0.1".into(),
|
||||
ui_path: String::new(),
|
||||
ota_psk: String::new(),
|
||||
auto_discover: true,
|
||||
discover_interval_ms: 10_000,
|
||||
theme: "dark".into(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Get the settings file path in the app data directory.
|
||||
fn settings_path(app: &AppHandle) -> Result<PathBuf, String> {
|
||||
let app_dir = app
|
||||
.path()
|
||||
.app_data_dir()
|
||||
.map_err(|e| format!("Failed to get app data dir: {}", e))?;
|
||||
|
||||
// Ensure directory exists
|
||||
fs::create_dir_all(&app_dir)
|
||||
.map_err(|e| format!("Failed to create app data dir: {}", e))?;
|
||||
|
||||
Ok(app_dir.join("settings.json"))
|
||||
}
|
||||
|
||||
/// Load settings from disk.
|
||||
#[tauri::command]
|
||||
pub async fn get_settings(app: AppHandle) -> Result<Option<AppSettings>, String> {
|
||||
let path = settings_path(&app)?;
|
||||
|
||||
if !path.exists() {
|
||||
return Ok(None);
|
||||
}
|
||||
|
||||
let contents = fs::read_to_string(&path)
|
||||
.map_err(|e| format!("Failed to read settings: {}", e))?;
|
||||
|
||||
let settings: AppSettings = serde_json::from_str(&contents)
|
||||
.map_err(|e| format!("Failed to parse settings: {}", e))?;
|
||||
|
||||
Ok(Some(settings))
|
||||
}
|
||||
|
||||
/// Save settings to disk.
|
||||
#[tauri::command]
|
||||
pub async fn save_settings(app: AppHandle, settings: AppSettings) -> Result<(), String> {
|
||||
let path = settings_path(&app)?;
|
||||
|
||||
let contents = serde_json::to_string_pretty(&settings)
|
||||
.map_err(|e| format!("Failed to serialize settings: {}", e))?;
|
||||
|
||||
fs::write(&path, contents)
|
||||
.map_err(|e| format!("Failed to write settings: {}", e))?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn test_default_settings() {
|
||||
let settings = AppSettings::default();
|
||||
assert_eq!(settings.server_http_port, 8080);
|
||||
assert_eq!(settings.bind_address, "127.0.0.1");
|
||||
assert!(settings.auto_discover);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_settings_serialization() {
|
||||
let settings = AppSettings::default();
|
||||
let json = serde_json::to_string(&settings).unwrap();
|
||||
let parsed: AppSettings = serde_json::from_str(&json).unwrap();
|
||||
assert_eq!(parsed.server_http_port, settings.server_http_port);
|
||||
}
|
||||
}
|
||||
@@ -1,35 +1,279 @@
|
||||
use std::fs::File;
|
||||
use std::io::Read;
|
||||
use std::time::Duration;
|
||||
|
||||
use reqwest::multipart::{Form, Part};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use sha2::{Digest, Sha256};
|
||||
|
||||
/// WASM management port on ESP32 nodes.
|
||||
const WASM_PORT: u16 = 8033;
|
||||
|
||||
/// Request timeout for WASM operations.
|
||||
const WASM_TIMEOUT_SECS: u64 = 30;
|
||||
|
||||
/// List WASM modules loaded on a specific node.
|
||||
#[tauri::command]
|
||||
pub async fn wasm_list(node_ip: String) -> Result<Vec<WasmModuleInfo>, String> {
|
||||
let _ = node_ip;
|
||||
Ok(vec![])
|
||||
let client = reqwest::Client::builder()
|
||||
.timeout(Duration::from_secs(WASM_TIMEOUT_SECS))
|
||||
.build()
|
||||
.map_err(|e| format!("Failed to create HTTP client: {}", e))?;
|
||||
|
||||
let url = format!("http://{}:{}/wasm/list", node_ip, WASM_PORT);
|
||||
|
||||
let response = client.get(&url).send().await
|
||||
.map_err(|e| format!("Failed to connect to node: {}", e))?;
|
||||
|
||||
if !response.status().is_success() {
|
||||
return Err(format!("Node returned HTTP {}", response.status()));
|
||||
}
|
||||
|
||||
let modules: Vec<WasmModuleInfo> = response.json().await
|
||||
.map_err(|e| format!("Failed to parse response: {}", e))?;
|
||||
|
||||
Ok(modules)
|
||||
}
|
||||
|
||||
/// Upload a WASM module to a node.
|
||||
///
|
||||
/// Protocol:
|
||||
/// 1. Read WASM file and calculate SHA-256
|
||||
/// 2. POST multipart/form-data to http://<node_ip>:8033/wasm/upload
|
||||
/// 3. Module is automatically validated on node side
|
||||
/// 4. Return assigned module ID
|
||||
#[tauri::command]
|
||||
pub async fn wasm_upload(
|
||||
node_ip: String,
|
||||
wasm_path: String,
|
||||
module_name: Option<String>,
|
||||
auto_start: Option<bool>,
|
||||
) -> Result<WasmUploadResult, String> {
|
||||
let _ = (node_ip, wasm_path);
|
||||
// Read WASM file
|
||||
let mut file = File::open(&wasm_path)
|
||||
.map_err(|e| format!("Cannot read WASM file: {}", e))?;
|
||||
|
||||
let mut wasm_data = Vec::new();
|
||||
file.read_to_end(&mut wasm_data)
|
||||
.map_err(|e| format!("Failed to read WASM file: {}", e))?;
|
||||
|
||||
let wasm_size = wasm_data.len();
|
||||
|
||||
// Validate WASM magic bytes
|
||||
if wasm_data.len() < 4 || &wasm_data[0..4] != b"\0asm" {
|
||||
return Err("Invalid WASM file: missing magic bytes".into());
|
||||
}
|
||||
|
||||
// Calculate SHA-256
|
||||
let mut hasher = Sha256::new();
|
||||
hasher.update(&wasm_data);
|
||||
let wasm_hash = hex::encode(hasher.finalize());
|
||||
|
||||
// Extract filename for module name
|
||||
let name = module_name.unwrap_or_else(|| {
|
||||
std::path::Path::new(&wasm_path)
|
||||
.file_stem()
|
||||
.and_then(|s| s.to_str())
|
||||
.unwrap_or("module")
|
||||
.to_string()
|
||||
});
|
||||
|
||||
// Build HTTP client
|
||||
let client = reqwest::Client::builder()
|
||||
.timeout(Duration::from_secs(WASM_TIMEOUT_SECS))
|
||||
.build()
|
||||
.map_err(|e| format!("Failed to create HTTP client: {}", e))?;
|
||||
|
||||
// Build multipart form
|
||||
let wasm_part = Part::bytes(wasm_data)
|
||||
.file_name(format!("{}.wasm", name))
|
||||
.mime_str("application/wasm")
|
||||
.map_err(|e| format!("Failed to create multipart: {}", e))?;
|
||||
|
||||
let form = Form::new()
|
||||
.part("wasm", wasm_part)
|
||||
.text("name", name.clone())
|
||||
.text("sha256", wasm_hash.clone())
|
||||
.text("size", wasm_size.to_string())
|
||||
.text("auto_start", auto_start.unwrap_or(false).to_string());
|
||||
|
||||
// Send request
|
||||
let url = format!("http://{}:{}/wasm/upload", node_ip, WASM_PORT);
|
||||
let response = client.post(&url)
|
||||
.multipart(form)
|
||||
.send()
|
||||
.await
|
||||
.map_err(|e| format!("WASM upload failed: {}", e))?;
|
||||
|
||||
let status = response.status();
|
||||
|
||||
if !status.is_success() {
|
||||
let body = response.text().await.unwrap_or_default();
|
||||
return Err(format!("WASM upload failed with HTTP {}: {}", status, body));
|
||||
}
|
||||
|
||||
// Parse response for module ID
|
||||
let upload_response: WasmUploadResponse = response.json().await
|
||||
.map_err(|e| format!("Failed to parse upload response: {}", e))?;
|
||||
|
||||
Ok(WasmUploadResult {
|
||||
success: true,
|
||||
module_id: "stub-module-0".into(),
|
||||
message: "Stub: WASM upload not yet implemented".into(),
|
||||
module_id: upload_response.module_id,
|
||||
message: format!("Module '{}' uploaded successfully ({} bytes)", name, wasm_size),
|
||||
sha256: Some(wasm_hash),
|
||||
})
|
||||
}
|
||||
|
||||
/// Start, stop, or unload a WASM module on a node.
|
||||
///
|
||||
/// Actions:
|
||||
/// - "start": Start module execution
|
||||
/// - "stop": Pause module execution
|
||||
/// - "unload": Remove module from memory
|
||||
/// - "restart": Stop then start
|
||||
#[tauri::command]
|
||||
pub async fn wasm_control(
|
||||
node_ip: String,
|
||||
module_id: String,
|
||||
action: String,
|
||||
) -> Result<(), String> {
|
||||
let _ = (node_ip, module_id, action);
|
||||
Ok(())
|
||||
) -> Result<WasmControlResult, String> {
|
||||
// Validate action
|
||||
let valid_actions = ["start", "stop", "unload", "restart"];
|
||||
if !valid_actions.contains(&action.as_str()) {
|
||||
return Err(format!(
|
||||
"Invalid action '{}'. Valid actions: {:?}",
|
||||
action, valid_actions
|
||||
));
|
||||
}
|
||||
|
||||
let client = reqwest::Client::builder()
|
||||
.timeout(Duration::from_secs(WASM_TIMEOUT_SECS))
|
||||
.build()
|
||||
.map_err(|e| format!("Failed to create HTTP client: {}", e))?;
|
||||
|
||||
let url = format!(
|
||||
"http://{}:{}/wasm/{}/{}",
|
||||
node_ip, WASM_PORT, module_id, action
|
||||
);
|
||||
|
||||
let response = client.post(&url).send().await
|
||||
.map_err(|e| format!("WASM control failed: {}", e))?;
|
||||
|
||||
let status = response.status();
|
||||
|
||||
if !status.is_success() {
|
||||
let body = response.text().await.unwrap_or_default();
|
||||
return Err(format!(
|
||||
"WASM {} failed with HTTP {}: {}",
|
||||
action, status, body
|
||||
));
|
||||
}
|
||||
|
||||
Ok(WasmControlResult {
|
||||
success: true,
|
||||
module_id,
|
||||
action,
|
||||
message: "Operation completed successfully".into(),
|
||||
})
|
||||
}
|
||||
|
||||
/// Get detailed info about a specific WASM module.
|
||||
#[tauri::command]
|
||||
pub async fn wasm_info(
|
||||
node_ip: String,
|
||||
module_id: String,
|
||||
) -> Result<WasmModuleDetail, String> {
|
||||
let client = reqwest::Client::builder()
|
||||
.timeout(Duration::from_secs(WASM_TIMEOUT_SECS))
|
||||
.build()
|
||||
.map_err(|e| format!("Failed to create HTTP client: {}", e))?;
|
||||
|
||||
let url = format!("http://{}:{}/wasm/{}", node_ip, WASM_PORT, module_id);
|
||||
|
||||
let response = client.get(&url).send().await
|
||||
.map_err(|e| format!("Failed to get module info: {}", e))?;
|
||||
|
||||
if !response.status().is_success() {
|
||||
return Err(format!("Module not found or HTTP {}", response.status()));
|
||||
}
|
||||
|
||||
let detail: WasmModuleDetail = response.json().await
|
||||
.map_err(|e| format!("Failed to parse module info: {}", e))?;
|
||||
|
||||
Ok(detail)
|
||||
}
|
||||
|
||||
/// Get WASM runtime statistics from a node.
|
||||
#[tauri::command]
|
||||
pub async fn wasm_stats(node_ip: String) -> Result<WasmRuntimeStats, String> {
|
||||
let client = reqwest::Client::builder()
|
||||
.timeout(Duration::from_secs(WASM_TIMEOUT_SECS))
|
||||
.build()
|
||||
.map_err(|e| format!("Failed to create HTTP client: {}", e))?;
|
||||
|
||||
let url = format!("http://{}:{}/wasm/stats", node_ip, WASM_PORT);
|
||||
|
||||
let response = client.get(&url).send().await
|
||||
.map_err(|e| format!("Failed to get WASM stats: {}", e))?;
|
||||
|
||||
if !response.status().is_success() {
|
||||
return Err(format!("HTTP {}", response.status()));
|
||||
}
|
||||
|
||||
let stats: WasmRuntimeStats = response.json().await
|
||||
.map_err(|e| format!("Failed to parse stats: {}", e))?;
|
||||
|
||||
Ok(stats)
|
||||
}
|
||||
|
||||
/// Check if node supports WASM modules.
|
||||
#[tauri::command]
|
||||
pub async fn check_wasm_support(node_ip: String) -> Result<WasmSupportInfo, String> {
|
||||
let client = reqwest::Client::builder()
|
||||
.timeout(Duration::from_secs(5))
|
||||
.build()
|
||||
.map_err(|e| format!("Failed to create HTTP client: {}", e))?;
|
||||
|
||||
let url = format!("http://{}:{}/wasm/info", node_ip, WASM_PORT);
|
||||
|
||||
match client.get(&url).send().await {
|
||||
Ok(response) => {
|
||||
if response.status().is_success() {
|
||||
let body = response.text().await.unwrap_or_default();
|
||||
|
||||
// Try to parse as JSON
|
||||
let info = serde_json::from_str::<serde_json::Value>(&body).ok();
|
||||
|
||||
Ok(WasmSupportInfo {
|
||||
supported: true,
|
||||
max_modules: info.as_ref()
|
||||
.and_then(|v| v.get("max_modules").and_then(|v| v.as_u64()))
|
||||
.map(|v| v as u8),
|
||||
memory_limit_kb: info.as_ref()
|
||||
.and_then(|v| v.get("memory_limit_kb").and_then(|v| v.as_u64()))
|
||||
.map(|v| v as u32),
|
||||
verify_signatures: info.as_ref()
|
||||
.and_then(|v| v.get("verify_signatures").and_then(|v| v.as_bool()))
|
||||
.unwrap_or(false),
|
||||
})
|
||||
} else if response.status() == reqwest::StatusCode::NOT_FOUND {
|
||||
Ok(WasmSupportInfo {
|
||||
supported: false,
|
||||
max_modules: None,
|
||||
memory_limit_kb: None,
|
||||
verify_signatures: false,
|
||||
})
|
||||
} else {
|
||||
Err(format!("HTTP {}", response.status()))
|
||||
}
|
||||
}
|
||||
Err(_) => Ok(WasmSupportInfo {
|
||||
supported: false,
|
||||
max_modules: None,
|
||||
memory_limit_kb: None,
|
||||
verify_signatures: false,
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
@@ -38,6 +282,31 @@ pub struct WasmModuleInfo {
|
||||
pub name: String,
|
||||
pub size_bytes: u64,
|
||||
pub status: String,
|
||||
pub sha256: Option<String>,
|
||||
pub loaded_at: Option<String>,
|
||||
pub memory_used_kb: Option<u32>,
|
||||
pub cpu_usage_pct: Option<f32>,
|
||||
pub exec_count: Option<u64>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct WasmModuleDetail {
|
||||
pub id: String,
|
||||
pub name: String,
|
||||
pub size_bytes: u64,
|
||||
pub status: String,
|
||||
pub sha256: String,
|
||||
pub loaded_at: String,
|
||||
pub memory_used_kb: u32,
|
||||
pub exports: Vec<String>,
|
||||
pub imports: Vec<String>,
|
||||
pub execution_count: u64,
|
||||
pub last_error: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
struct WasmUploadResponse {
|
||||
pub module_id: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
@@ -45,4 +314,64 @@ pub struct WasmUploadResult {
|
||||
pub success: bool,
|
||||
pub module_id: String,
|
||||
pub message: String,
|
||||
pub sha256: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub struct WasmControlResult {
|
||||
pub success: bool,
|
||||
pub module_id: String,
|
||||
pub action: String,
|
||||
pub message: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct WasmRuntimeStats {
|
||||
pub total_modules: u8,
|
||||
pub running_modules: u8,
|
||||
pub memory_used_kb: u32,
|
||||
pub memory_limit_kb: u32,
|
||||
pub total_executions: u64,
|
||||
pub errors: u64,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub struct WasmSupportInfo {
|
||||
pub supported: bool,
|
||||
pub max_modules: Option<u8>,
|
||||
pub memory_limit_kb: Option<u32>,
|
||||
pub verify_signatures: bool,
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn test_wasm_magic_bytes() {
|
||||
let valid_wasm = b"\0asm\x01\x00\x00\x00";
|
||||
assert_eq!(&valid_wasm[0..4], b"\0asm");
|
||||
|
||||
let invalid = b"not wasm";
|
||||
assert_ne!(&invalid[0..4], b"\0asm");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_wasm_module_info() {
|
||||
let info = WasmModuleInfo {
|
||||
id: "mod-1".into(),
|
||||
name: "test".into(),
|
||||
size_bytes: 1024,
|
||||
status: "running".into(),
|
||||
sha256: Some("abc123".into()),
|
||||
loaded_at: Some("2024-01-01T00:00:00Z".into()),
|
||||
memory_used_kb: Some(128),
|
||||
cpu_usage_pct: Some(5.2),
|
||||
exec_count: Some(42),
|
||||
};
|
||||
|
||||
assert_eq!(info.id, "mod-1");
|
||||
assert_eq!(info.size_bytes, 1024);
|
||||
assert_eq!(info.memory_used_kb, Some(128));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,6 +31,47 @@ impl Default for HealthStatus {
|
||||
}
|
||||
}
|
||||
|
||||
/// Chip type for ESP32 variants.
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, Default)]
|
||||
#[serde(rename_all = "lowercase")]
|
||||
pub enum Chip {
|
||||
#[default]
|
||||
Esp32,
|
||||
Esp32s2,
|
||||
Esp32s3,
|
||||
Esp32c3,
|
||||
Esp32c6,
|
||||
}
|
||||
|
||||
/// Node role in the mesh network.
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, Default)]
|
||||
#[serde(rename_all = "lowercase")]
|
||||
pub enum MeshRole {
|
||||
Coordinator,
|
||||
#[default]
|
||||
Node,
|
||||
Aggregator,
|
||||
}
|
||||
|
||||
/// Discovery method used to find the node.
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, Default)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum DiscoveryMethod {
|
||||
#[default]
|
||||
Mdns,
|
||||
UdpProbe,
|
||||
HttpSweep,
|
||||
Manual,
|
||||
}
|
||||
|
||||
/// Node capabilities.
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
|
||||
pub struct NodeCapabilities {
|
||||
pub wasm: bool,
|
||||
pub ota: bool,
|
||||
pub csi: bool,
|
||||
}
|
||||
|
||||
/// A discovered ESP32 CSI node.
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct DiscoveredNode {
|
||||
@@ -41,6 +82,17 @@ pub struct DiscoveredNode {
|
||||
pub firmware_version: Option<String>,
|
||||
pub health: HealthStatus,
|
||||
pub last_seen: String,
|
||||
// Extended fields
|
||||
pub chip: Chip,
|
||||
pub mesh_role: MeshRole,
|
||||
pub discovery_method: DiscoveryMethod,
|
||||
pub tdm_slot: Option<u8>,
|
||||
pub tdm_total: Option<u8>,
|
||||
pub edge_tier: Option<u8>,
|
||||
pub uptime_secs: Option<u64>,
|
||||
pub capabilities: Option<NodeCapabilities>,
|
||||
pub friendly_name: Option<String>,
|
||||
pub notes: Option<String>,
|
||||
}
|
||||
|
||||
/// Aggregate root: maintains the set of all known nodes, keyed by MAC.
|
||||
|
||||
@@ -2,7 +2,7 @@ pub mod commands;
|
||||
pub mod domain;
|
||||
pub mod state;
|
||||
|
||||
use commands::{discovery, flash, ota, provision, server, wasm};
|
||||
use commands::{discovery, flash, ota, provision, server, settings, wasm};
|
||||
|
||||
pub fn run() {
|
||||
tauri::Builder::default()
|
||||
@@ -13,23 +13,39 @@ pub fn run() {
|
||||
// Discovery
|
||||
discovery::discover_nodes,
|
||||
discovery::list_serial_ports,
|
||||
discovery::configure_esp32_wifi,
|
||||
// Flash
|
||||
flash::flash_firmware,
|
||||
flash::flash_progress,
|
||||
flash::verify_firmware,
|
||||
flash::check_espflash,
|
||||
flash::supported_chips,
|
||||
// OTA
|
||||
ota::ota_update,
|
||||
ota::batch_ota_update,
|
||||
ota::check_ota_endpoint,
|
||||
// WASM
|
||||
wasm::wasm_list,
|
||||
wasm::wasm_upload,
|
||||
wasm::wasm_control,
|
||||
wasm::wasm_info,
|
||||
wasm::wasm_stats,
|
||||
wasm::check_wasm_support,
|
||||
// Server
|
||||
server::start_server,
|
||||
server::stop_server,
|
||||
server::server_status,
|
||||
server::restart_server,
|
||||
server::server_logs,
|
||||
// Provision
|
||||
provision::provision_node,
|
||||
provision::read_nvs,
|
||||
provision::erase_nvs,
|
||||
provision::validate_config,
|
||||
provision::generate_mesh_configs,
|
||||
// Settings
|
||||
settings::get_settings,
|
||||
settings::save_settings,
|
||||
])
|
||||
.run(tauri::generate_context!())
|
||||
.expect("error while running tauri application");
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
use std::process::Child;
|
||||
use std::sync::Mutex;
|
||||
use std::time::Instant;
|
||||
|
||||
use crate::domain::node::DiscoveredNode;
|
||||
|
||||
@@ -6,18 +8,200 @@ use crate::domain::node::DiscoveredNode;
|
||||
#[derive(Default)]
|
||||
pub struct DiscoveryState {
|
||||
pub nodes: Vec<DiscoveredNode>,
|
||||
pub last_discovery: Option<Instant>,
|
||||
}
|
||||
|
||||
/// Sub-state for the managed sensing server process.
|
||||
#[derive(Default)]
|
||||
pub struct ServerState {
|
||||
pub running: bool,
|
||||
pub pid: Option<u32>,
|
||||
pub http_port: Option<u16>,
|
||||
pub ws_port: Option<u16>,
|
||||
pub udp_port: Option<u16>,
|
||||
pub child: Option<Child>,
|
||||
pub start_time: Option<Instant>,
|
||||
}
|
||||
|
||||
impl Default for ServerState {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
running: false,
|
||||
pid: None,
|
||||
http_port: None,
|
||||
ws_port: None,
|
||||
udp_port: None,
|
||||
child: None,
|
||||
start_time: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Sub-state for flash progress tracking.
|
||||
#[derive(Default)]
|
||||
pub struct FlashState {
|
||||
pub phase: String,
|
||||
pub progress_pct: f32,
|
||||
pub bytes_written: u64,
|
||||
pub bytes_total: u64,
|
||||
pub message: Option<String>,
|
||||
pub session_id: Option<String>,
|
||||
}
|
||||
|
||||
/// Sub-state for OTA progress tracking.
|
||||
#[derive(Default)]
|
||||
pub struct OtaState {
|
||||
pub active_updates: Vec<OtaUpdateTracker>,
|
||||
}
|
||||
|
||||
/// Tracks a single OTA update in progress.
|
||||
pub struct OtaUpdateTracker {
|
||||
pub node_ip: String,
|
||||
pub phase: String,
|
||||
pub progress_pct: f32,
|
||||
pub started_at: Instant,
|
||||
}
|
||||
|
||||
impl Default for OtaUpdateTracker {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
node_ip: String::new(),
|
||||
phase: "idle".into(),
|
||||
progress_pct: 0.0,
|
||||
started_at: Instant::now(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Sub-state for application settings cache.
|
||||
pub struct SettingsState {
|
||||
pub loaded: bool,
|
||||
pub dirty: bool,
|
||||
}
|
||||
|
||||
impl Default for SettingsState {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
loaded: false,
|
||||
dirty: false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Top-level application state managed by Tauri.
|
||||
#[derive(Default)]
|
||||
pub struct AppState {
|
||||
pub discovery: Mutex<DiscoveryState>,
|
||||
pub server: Mutex<ServerState>,
|
||||
pub flash: Mutex<FlashState>,
|
||||
pub ota: Mutex<OtaState>,
|
||||
pub settings: Mutex<SettingsState>,
|
||||
}
|
||||
|
||||
impl Default for AppState {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
discovery: Mutex::new(DiscoveryState::default()),
|
||||
server: Mutex::new(ServerState::default()),
|
||||
flash: Mutex::new(FlashState::default()),
|
||||
ota: Mutex::new(OtaState::default()),
|
||||
settings: Mutex::new(SettingsState::default()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl AppState {
|
||||
/// Create a new AppState instance.
|
||||
pub fn new() -> Self {
|
||||
Self::default()
|
||||
}
|
||||
|
||||
/// Reset all state to defaults.
|
||||
pub fn reset(&self) {
|
||||
if let Ok(mut discovery) = self.discovery.lock() {
|
||||
*discovery = DiscoveryState::default();
|
||||
}
|
||||
if let Ok(mut server) = self.server.lock() {
|
||||
// Kill child process if running
|
||||
if let Some(ref mut child) = server.child {
|
||||
let _ = child.kill();
|
||||
}
|
||||
*server = ServerState::default();
|
||||
}
|
||||
if let Ok(mut flash) = self.flash.lock() {
|
||||
*flash = FlashState::default();
|
||||
}
|
||||
if let Ok(mut ota) = self.ota.lock() {
|
||||
*ota = OtaState::default();
|
||||
}
|
||||
if let Ok(mut settings) = self.settings.lock() {
|
||||
*settings = SettingsState::default();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn test_app_state_default() {
|
||||
let state = AppState::default();
|
||||
|
||||
let discovery = state.discovery.lock().unwrap();
|
||||
assert!(discovery.nodes.is_empty());
|
||||
|
||||
let server = state.server.lock().unwrap();
|
||||
assert!(!server.running);
|
||||
assert!(server.pid.is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_app_state_reset() {
|
||||
let state = AppState::new();
|
||||
|
||||
// Modify state
|
||||
{
|
||||
let mut discovery = state.discovery.lock().unwrap();
|
||||
discovery.nodes.push(DiscoveredNode {
|
||||
ip: "192.168.1.100".into(),
|
||||
mac: Some("AA:BB:CC:DD:EE:FF".into()),
|
||||
hostname: None,
|
||||
node_id: 1,
|
||||
firmware_version: None,
|
||||
health: crate::domain::node::HealthStatus::Online,
|
||||
last_seen: chrono::Utc::now().to_rfc3339(),
|
||||
chip: crate::domain::node::Chip::default(),
|
||||
mesh_role: crate::domain::node::MeshRole::default(),
|
||||
discovery_method: crate::domain::node::DiscoveryMethod::default(),
|
||||
tdm_slot: None,
|
||||
tdm_total: None,
|
||||
edge_tier: None,
|
||||
uptime_secs: None,
|
||||
capabilities: None,
|
||||
friendly_name: None,
|
||||
notes: None,
|
||||
});
|
||||
}
|
||||
|
||||
// Reset
|
||||
state.reset();
|
||||
|
||||
// Verify reset
|
||||
let discovery = state.discovery.lock().unwrap();
|
||||
assert!(discovery.nodes.is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_server_state() {
|
||||
let server = ServerState::default();
|
||||
assert!(!server.running);
|
||||
assert!(server.child.is_none());
|
||||
assert!(server.start_time.is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_flash_state() {
|
||||
let flash = FlashState::default();
|
||||
assert_eq!(flash.phase, "");
|
||||
assert_eq!(flash.progress_pct, 0.0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"$schema": "https://raw.githubusercontent.com/tauri-apps/tauri/dev/crates/tauri-config-schema/schema.json",
|
||||
"productName": "RuView Desktop",
|
||||
"version": "0.3.0",
|
||||
"version": "0.4.4",
|
||||
"identifier": "net.ruv.ruview",
|
||||
"build": {
|
||||
"frontendDist": "ui/dist",
|
||||
|
||||
@@ -0,0 +1,420 @@
|
||||
//! Integration tests for all Tauri API commands
|
||||
//!
|
||||
//! Tests the actual command implementations without the Tauri runtime.
|
||||
|
||||
// ============================================================================
|
||||
// Discovery Tests
|
||||
// ============================================================================
|
||||
|
||||
#[test]
|
||||
fn test_serial_port_detection_logic() {
|
||||
// Test ESP32 VID/PID detection
|
||||
// CP210x (Silicon Labs)
|
||||
assert!(is_esp32_vid_pid(0x10C4, 0xEA60), "CP2102 should be detected");
|
||||
assert!(is_esp32_vid_pid(0x10C4, 0xEA70), "CP2104 should be detected");
|
||||
|
||||
// CH340/CH341 (QinHeng)
|
||||
assert!(is_esp32_vid_pid(0x1A86, 0x7523), "CH340 should be detected");
|
||||
assert!(is_esp32_vid_pid(0x1A86, 0x5523), "CH341 should be detected");
|
||||
|
||||
// FTDI
|
||||
assert!(is_esp32_vid_pid(0x0403, 0x6001), "FTDI FT232 should be detected");
|
||||
assert!(is_esp32_vid_pid(0x0403, 0x6010), "FTDI FT2232 should be detected");
|
||||
|
||||
// ESP32 native USB
|
||||
assert!(is_esp32_vid_pid(0x303A, 0x1001), "ESP32-S2/S3 native should be detected");
|
||||
|
||||
// Unknown device
|
||||
assert!(!is_esp32_vid_pid(0x0000, 0x0000), "Unknown VID/PID should not be detected");
|
||||
assert!(!is_esp32_vid_pid(0x1234, 0x5678), "Random VID/PID should not be detected");
|
||||
}
|
||||
|
||||
fn is_esp32_vid_pid(vid: u16, pid: u16) -> bool {
|
||||
// CP210x (Silicon Labs)
|
||||
if vid == 0x10C4 && (pid == 0xEA60 || pid == 0xEA70) {
|
||||
return true;
|
||||
}
|
||||
// CH340/CH341 (QinHeng)
|
||||
if vid == 0x1A86 && (pid == 0x7523 || pid == 0x5523) {
|
||||
return true;
|
||||
}
|
||||
// FTDI
|
||||
if vid == 0x0403 && (pid == 0x6001 || pid == 0x6010 || pid == 0x6011 || pid == 0x6014 || pid == 0x6015) {
|
||||
return true;
|
||||
}
|
||||
// ESP32-S2/S3 native USB
|
||||
if vid == 0x303A {
|
||||
return true;
|
||||
}
|
||||
false
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_beacon_parsing() {
|
||||
let data = b"RUVIEW_BEACON|AA:BB:CC:DD:EE:FF|1|0.3.0|esp32s3|coordinator|0|4";
|
||||
let text = std::str::from_utf8(data).unwrap();
|
||||
let parts: Vec<&str> = text.split('|').collect();
|
||||
|
||||
assert_eq!(parts.len(), 8);
|
||||
assert_eq!(parts[0], "RUVIEW_BEACON");
|
||||
assert_eq!(parts[1], "AA:BB:CC:DD:EE:FF");
|
||||
assert_eq!(parts[2], "1");
|
||||
assert_eq!(parts[3], "0.3.0");
|
||||
assert_eq!(parts[4], "esp32s3");
|
||||
assert_eq!(parts[5], "coordinator");
|
||||
assert_eq!(parts[6], "0");
|
||||
assert_eq!(parts[7], "4");
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// Settings Tests
|
||||
// ============================================================================
|
||||
|
||||
#[test]
|
||||
fn test_settings_structure() {
|
||||
use wifi_densepose_desktop::commands::settings::AppSettings;
|
||||
|
||||
let settings = AppSettings::default();
|
||||
|
||||
// Check default values
|
||||
assert!(!settings.theme.is_empty(), "Theme should have a default");
|
||||
assert!(settings.discover_interval_ms > 0, "Discovery interval should be positive");
|
||||
assert!(settings.auto_discover, "Auto-discover should default to true");
|
||||
assert_eq!(settings.server_http_port, 8080);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_settings_serialization() {
|
||||
use wifi_densepose_desktop::commands::settings::AppSettings;
|
||||
|
||||
let settings = AppSettings::default();
|
||||
let json = serde_json::to_string(&settings).expect("Should serialize");
|
||||
let restored: AppSettings = serde_json::from_str(&json).expect("Should deserialize");
|
||||
|
||||
assert_eq!(settings.theme, restored.theme);
|
||||
assert_eq!(settings.server_http_port, restored.server_http_port);
|
||||
assert_eq!(settings.discover_interval_ms, restored.discover_interval_ms);
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// Server Tests
|
||||
// ============================================================================
|
||||
|
||||
#[test]
|
||||
fn test_server_state_default() {
|
||||
use wifi_densepose_desktop::state::ServerState;
|
||||
|
||||
let server = ServerState::default();
|
||||
assert!(!server.running, "Server should not be running by default");
|
||||
assert!(server.pid.is_none());
|
||||
assert!(server.http_port.is_none());
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// Flash Tests
|
||||
// ============================================================================
|
||||
|
||||
#[test]
|
||||
fn test_chip_variants() {
|
||||
use wifi_densepose_desktop::domain::node::Chip;
|
||||
|
||||
let chips = vec![
|
||||
Chip::Esp32,
|
||||
Chip::Esp32s2,
|
||||
Chip::Esp32s3,
|
||||
Chip::Esp32c3,
|
||||
Chip::Esp32c6,
|
||||
];
|
||||
|
||||
for chip in chips {
|
||||
let name = format!("{:?}", chip).to_lowercase();
|
||||
assert!(name.starts_with("esp32"), "All chips should be ESP32 variants");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_progress_parsing() {
|
||||
// Test espflash progress output parsing
|
||||
let output = "Flashing... [===> ] 35%";
|
||||
let re = regex::Regex::new(r"(\d+)%").unwrap();
|
||||
|
||||
if let Some(caps) = re.captures(output) {
|
||||
let pct: u8 = caps[1].parse().unwrap();
|
||||
assert_eq!(pct, 35);
|
||||
} else {
|
||||
panic!("Should parse percentage");
|
||||
}
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// OTA Tests
|
||||
// ============================================================================
|
||||
|
||||
#[test]
|
||||
fn test_sha256_hash() {
|
||||
use sha2::{Sha256, Digest};
|
||||
|
||||
let data = b"test firmware data";
|
||||
let mut hasher = Sha256::new();
|
||||
hasher.update(data);
|
||||
let hash = hasher.finalize();
|
||||
let hex = hex::encode(hash);
|
||||
|
||||
assert_eq!(hex.len(), 64, "SHA256 should produce 64 hex characters");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_hmac_signature() {
|
||||
use hmac::{Hmac, Mac};
|
||||
use sha2::Sha256;
|
||||
|
||||
type HmacSha256 = Hmac<Sha256>;
|
||||
|
||||
let key = b"test_psk_key";
|
||||
let data = b"firmware_hash";
|
||||
|
||||
let mut mac = HmacSha256::new_from_slice(key).expect("HMAC can take key of any size");
|
||||
mac.update(data);
|
||||
let result = mac.finalize();
|
||||
let signature = hex::encode(result.into_bytes());
|
||||
|
||||
assert_eq!(signature.len(), 64, "HMAC-SHA256 should produce 64 hex characters");
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// Provision Tests
|
||||
// ============================================================================
|
||||
|
||||
#[test]
|
||||
fn test_nvs_config_format() {
|
||||
// Test CSV format for NVS partition
|
||||
let csv = "key,type,encoding,value\ncsi_cfg,namespace,,\nssid,data,string,TestNetwork\npassword,data,string,TestPass123\n";
|
||||
|
||||
let lines: Vec<&str> = csv.lines().collect();
|
||||
assert_eq!(lines.len(), 4);
|
||||
assert!(lines[0].starts_with("key,type"));
|
||||
assert!(lines[1].contains("namespace"));
|
||||
assert!(lines[2].contains("ssid"));
|
||||
assert!(lines[3].contains("password"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_mesh_config_generation() {
|
||||
// Test that mesh configs have required fields
|
||||
let config = serde_json::json!({
|
||||
"node_id": 1,
|
||||
"mesh_role": "node",
|
||||
"tdm_slot": 0,
|
||||
"tdm_total": 4,
|
||||
"ssid": "TestNetwork",
|
||||
"password": "TestPass",
|
||||
"coordinator_ip": "192.168.1.100"
|
||||
});
|
||||
|
||||
assert!(config.get("node_id").is_some());
|
||||
assert!(config.get("mesh_role").is_some());
|
||||
assert!(config.get("ssid").is_some());
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// WASM Tests
|
||||
// ============================================================================
|
||||
|
||||
#[test]
|
||||
fn test_wasm_magic_bytes() {
|
||||
// WebAssembly magic bytes: \0asm
|
||||
let wasm_header: [u8; 4] = [0x00, 0x61, 0x73, 0x6D];
|
||||
|
||||
assert_eq!(wasm_header[0], 0x00);
|
||||
assert_eq!(wasm_header[1], 0x61); // 'a'
|
||||
assert_eq!(wasm_header[2], 0x73); // 's'
|
||||
assert_eq!(wasm_header[3], 0x6D); // 'm'
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_wasm_version() {
|
||||
// WASM version 1
|
||||
let wasm_version: [u8; 4] = [0x01, 0x00, 0x00, 0x00];
|
||||
|
||||
let version = u32::from_le_bytes(wasm_version);
|
||||
assert_eq!(version, 1);
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// State Tests
|
||||
// ============================================================================
|
||||
|
||||
#[test]
|
||||
fn test_app_state_initialization() {
|
||||
use wifi_densepose_desktop::state::AppState;
|
||||
|
||||
let state = AppState::default();
|
||||
|
||||
// Check that all state components initialize correctly
|
||||
let discovery = state.discovery.lock().unwrap();
|
||||
assert!(discovery.nodes.is_empty(), "Should start with no nodes");
|
||||
drop(discovery);
|
||||
|
||||
let flash = state.flash.lock().unwrap();
|
||||
assert_eq!(flash.phase, "", "Should start with empty phase");
|
||||
assert_eq!(flash.progress_pct, 0.0);
|
||||
drop(flash);
|
||||
|
||||
let server = state.server.lock().unwrap();
|
||||
assert!(!server.running, "Server should not be running initially");
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// Domain Model Tests
|
||||
// ============================================================================
|
||||
|
||||
#[test]
|
||||
fn test_health_status_variants() {
|
||||
use wifi_densepose_desktop::domain::node::HealthStatus;
|
||||
|
||||
let statuses = vec![
|
||||
HealthStatus::Online,
|
||||
HealthStatus::Degraded,
|
||||
HealthStatus::Offline,
|
||||
];
|
||||
|
||||
for status in statuses {
|
||||
let json = serde_json::to_string(&status).expect("Should serialize");
|
||||
assert!(!json.is_empty());
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_discovery_method_variants() {
|
||||
use wifi_densepose_desktop::domain::node::DiscoveryMethod;
|
||||
|
||||
let methods = vec![
|
||||
DiscoveryMethod::Mdns,
|
||||
DiscoveryMethod::UdpProbe,
|
||||
DiscoveryMethod::Manual,
|
||||
DiscoveryMethod::HttpSweep,
|
||||
];
|
||||
|
||||
for method in methods {
|
||||
let json = serde_json::to_string(&method).expect("Should serialize");
|
||||
assert!(!json.is_empty());
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_mesh_role_variants() {
|
||||
use wifi_densepose_desktop::domain::node::MeshRole;
|
||||
|
||||
let roles = vec![
|
||||
MeshRole::Coordinator,
|
||||
MeshRole::Aggregator,
|
||||
MeshRole::Node,
|
||||
];
|
||||
|
||||
for role in roles {
|
||||
let json = serde_json::to_string(&role).expect("Should serialize");
|
||||
assert!(!json.is_empty());
|
||||
}
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// WiFi Config Tests (New Feature)
|
||||
// ============================================================================
|
||||
|
||||
#[test]
|
||||
fn test_wifi_config_command_format() {
|
||||
let ssid = "TestNetwork";
|
||||
let password = "TestPass123";
|
||||
|
||||
// Test all command formats
|
||||
let cmd1 = format!("wifi_config {} {}\r\n", ssid, password);
|
||||
let cmd2 = format!("wifi {} {}\r\n", ssid, password);
|
||||
let cmd3 = format!("set ssid {}\r\n", ssid);
|
||||
let cmd4 = format!("set password {}\r\n", password);
|
||||
|
||||
assert!(cmd1.contains("wifi_config"));
|
||||
assert!(cmd1.contains(ssid));
|
||||
assert!(cmd1.contains(password));
|
||||
assert!(cmd1.ends_with("\r\n"));
|
||||
|
||||
assert!(cmd2.starts_with("wifi "));
|
||||
assert!(cmd3.starts_with("set ssid "));
|
||||
assert!(cmd4.starts_with("set password "));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_wifi_credentials_validation() {
|
||||
// SSID: 1-32 characters
|
||||
let valid_ssid = "MyNetwork";
|
||||
let empty_ssid = "";
|
||||
let long_ssid = "A".repeat(33);
|
||||
|
||||
assert!(!valid_ssid.is_empty() && valid_ssid.len() <= 32);
|
||||
assert!(empty_ssid.is_empty());
|
||||
assert!(long_ssid.len() > 32);
|
||||
|
||||
// Password: 8-63 characters for WPA2
|
||||
let valid_pass = "password123";
|
||||
let short_pass = "short";
|
||||
let long_pass = "A".repeat(64);
|
||||
|
||||
assert!(valid_pass.len() >= 8 && valid_pass.len() <= 63);
|
||||
assert!(short_pass.len() < 8);
|
||||
assert!(long_pass.len() > 63);
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// Node Registry Tests
|
||||
// ============================================================================
|
||||
|
||||
#[test]
|
||||
fn test_node_registry() {
|
||||
use wifi_densepose_desktop::domain::node::{
|
||||
DiscoveredNode, MacAddress, NodeRegistry, HealthStatus, Chip, MeshRole, DiscoveryMethod
|
||||
};
|
||||
|
||||
let mut registry = NodeRegistry::new();
|
||||
assert!(registry.is_empty());
|
||||
|
||||
let node = DiscoveredNode {
|
||||
ip: "192.168.1.100".into(),
|
||||
mac: Some("AA:BB:CC:DD:EE:FF".into()),
|
||||
hostname: Some("csi-node-1".into()),
|
||||
node_id: 1,
|
||||
firmware_version: Some("0.3.0".into()),
|
||||
health: HealthStatus::Online,
|
||||
last_seen: "2024-01-01T00:00:00Z".into(),
|
||||
chip: Chip::Esp32s3,
|
||||
mesh_role: MeshRole::Node,
|
||||
discovery_method: DiscoveryMethod::Mdns,
|
||||
tdm_slot: Some(0),
|
||||
tdm_total: Some(4),
|
||||
edge_tier: None,
|
||||
uptime_secs: Some(3600),
|
||||
capabilities: None,
|
||||
friendly_name: None,
|
||||
notes: None,
|
||||
};
|
||||
|
||||
registry.upsert(MacAddress::new("AA:BB:CC:DD:EE:FF"), node);
|
||||
assert_eq!(registry.len(), 1);
|
||||
|
||||
let retrieved = registry.get(&MacAddress::new("AA:BB:CC:DD:EE:FF"));
|
||||
assert!(retrieved.is_some());
|
||||
assert_eq!(retrieved.unwrap().ip, "192.168.1.100");
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// MAC Address Tests
|
||||
// ============================================================================
|
||||
|
||||
#[test]
|
||||
fn test_mac_address() {
|
||||
use wifi_densepose_desktop::domain::node::MacAddress;
|
||||
|
||||
let mac = MacAddress::new("AA:BB:CC:DD:EE:FF");
|
||||
assert_eq!(mac.to_string(), "AA:BB:CC:DD:EE:FF");
|
||||
|
||||
let mac2 = MacAddress::new("aa:bb:cc:dd:ee:ff");
|
||||
assert_ne!(mac, mac2); // Case sensitive comparison
|
||||
}
|
||||
+130
@@ -0,0 +1,130 @@
|
||||
{
|
||||
"running": true,
|
||||
"startedAt": "2026-03-10T00:49:11.921Z",
|
||||
"workers": {
|
||||
"map": {
|
||||
"runCount": 0,
|
||||
"successCount": 0,
|
||||
"failureCount": 0,
|
||||
"averageDurationMs": 0,
|
||||
"isRunning": false,
|
||||
"nextRun": "2026-03-10T00:49:11.921Z"
|
||||
},
|
||||
"audit": {
|
||||
"runCount": 0,
|
||||
"successCount": 0,
|
||||
"failureCount": 0,
|
||||
"averageDurationMs": 0,
|
||||
"isRunning": false,
|
||||
"nextRun": "2026-03-10T00:51:11.921Z"
|
||||
},
|
||||
"optimize": {
|
||||
"runCount": 0,
|
||||
"successCount": 0,
|
||||
"failureCount": 0,
|
||||
"averageDurationMs": 0,
|
||||
"isRunning": false,
|
||||
"nextRun": "2026-03-10T00:53:11.921Z"
|
||||
},
|
||||
"consolidate": {
|
||||
"runCount": 0,
|
||||
"successCount": 0,
|
||||
"failureCount": 0,
|
||||
"averageDurationMs": 0,
|
||||
"isRunning": false,
|
||||
"nextRun": "2026-03-10T00:55:11.921Z"
|
||||
},
|
||||
"testgaps": {
|
||||
"runCount": 0,
|
||||
"successCount": 0,
|
||||
"failureCount": 0,
|
||||
"averageDurationMs": 0,
|
||||
"isRunning": false,
|
||||
"nextRun": "2026-03-10T00:57:11.921Z"
|
||||
},
|
||||
"predict": {
|
||||
"runCount": 0,
|
||||
"successCount": 0,
|
||||
"failureCount": 0,
|
||||
"averageDurationMs": 0,
|
||||
"isRunning": false
|
||||
},
|
||||
"document": {
|
||||
"runCount": 0,
|
||||
"successCount": 0,
|
||||
"failureCount": 0,
|
||||
"averageDurationMs": 0,
|
||||
"isRunning": false
|
||||
}
|
||||
},
|
||||
"config": {
|
||||
"autoStart": false,
|
||||
"logDir": "/Users/cohen/GitHub/ruvnet/RuView/rust-port/wifi-densepose-rs/crates/wifi-densepose-desktop/ui/.claude-flow/logs",
|
||||
"stateFile": "/Users/cohen/GitHub/ruvnet/RuView/rust-port/wifi-densepose-rs/crates/wifi-densepose-desktop/ui/.claude-flow/daemon-state.json",
|
||||
"maxConcurrent": 2,
|
||||
"workerTimeoutMs": 300000,
|
||||
"resourceThresholds": {
|
||||
"maxCpuLoad": 2,
|
||||
"minFreeMemoryPercent": 20
|
||||
},
|
||||
"workers": [
|
||||
{
|
||||
"type": "map",
|
||||
"intervalMs": 900000,
|
||||
"offsetMs": 0,
|
||||
"priority": "normal",
|
||||
"description": "Codebase mapping",
|
||||
"enabled": true
|
||||
},
|
||||
{
|
||||
"type": "audit",
|
||||
"intervalMs": 600000,
|
||||
"offsetMs": 120000,
|
||||
"priority": "critical",
|
||||
"description": "Security analysis",
|
||||
"enabled": true
|
||||
},
|
||||
{
|
||||
"type": "optimize",
|
||||
"intervalMs": 900000,
|
||||
"offsetMs": 240000,
|
||||
"priority": "high",
|
||||
"description": "Performance optimization",
|
||||
"enabled": true
|
||||
},
|
||||
{
|
||||
"type": "consolidate",
|
||||
"intervalMs": 1800000,
|
||||
"offsetMs": 360000,
|
||||
"priority": "low",
|
||||
"description": "Memory consolidation",
|
||||
"enabled": true
|
||||
},
|
||||
{
|
||||
"type": "testgaps",
|
||||
"intervalMs": 1200000,
|
||||
"offsetMs": 480000,
|
||||
"priority": "normal",
|
||||
"description": "Test coverage analysis",
|
||||
"enabled": true
|
||||
},
|
||||
{
|
||||
"type": "predict",
|
||||
"intervalMs": 600000,
|
||||
"offsetMs": 0,
|
||||
"priority": "low",
|
||||
"description": "Predictive preloading",
|
||||
"enabled": false
|
||||
},
|
||||
{
|
||||
"type": "document",
|
||||
"intervalMs": 3600000,
|
||||
"offsetMs": 0,
|
||||
"priority": "low",
|
||||
"description": "Auto-documentation",
|
||||
"enabled": false
|
||||
}
|
||||
]
|
||||
},
|
||||
"savedAt": "2026-03-10T00:49:11.921Z"
|
||||
}
|
||||
+17
@@ -9,3 +9,20 @@
|
||||
{"type":"edit","file":"unknown","timestamp":1772835930809,"sessionId":null}
|
||||
{"type":"edit","file":"unknown","timestamp":1772835942468,"sessionId":null}
|
||||
{"type":"edit","file":"unknown","timestamp":1772835952451,"sessionId":null}
|
||||
{"type":"edit","file":"unknown","timestamp":1773070971487,"sessionId":null}
|
||||
{"type":"edit","file":"unknown","timestamp":1773070977376,"sessionId":null}
|
||||
{"type":"edit","file":"unknown","timestamp":1773101503481,"sessionId":null}
|
||||
{"type":"edit","file":"unknown","timestamp":1773107530083,"sessionId":null}
|
||||
{"type":"edit","file":"unknown","timestamp":1773107530201,"sessionId":null}
|
||||
{"type":"edit","file":"unknown","timestamp":1773107530319,"sessionId":null}
|
||||
{"type":"edit","file":"unknown","timestamp":1773114830434,"sessionId":null}
|
||||
{"type":"edit","file":"unknown","timestamp":1773114834713,"sessionId":null}
|
||||
{"type":"edit","file":"unknown","timestamp":1773114838852,"sessionId":null}
|
||||
{"type":"edit","file":"unknown","timestamp":1773150617007,"sessionId":null}
|
||||
{"type":"edit","file":"unknown","timestamp":1773150621430,"sessionId":null}
|
||||
{"type":"edit","file":"unknown","timestamp":1773150628006,"sessionId":null}
|
||||
{"type":"edit","file":"unknown","timestamp":1773150640909,"sessionId":null}
|
||||
{"type":"edit","file":"unknown","timestamp":1773150672276,"sessionId":null}
|
||||
{"type":"edit","file":"unknown","timestamp":1773150677219,"sessionId":null}
|
||||
{"type":"edit","file":"unknown","timestamp":1773150683839,"sessionId":null}
|
||||
{"type":"edit","file":"unknown","timestamp":1773150688912,"sessionId":null}
|
||||
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"id": "session-1773103750755",
|
||||
"startedAt": "2026-03-10T00:49:10.755Z",
|
||||
"cwd": "/Users/cohen/GitHub/ruvnet/RuView/rust-port/wifi-densepose-rs/crates/wifi-densepose-desktop/ui",
|
||||
"context": {},
|
||||
"metrics": {
|
||||
"edits": 14,
|
||||
"commands": 0,
|
||||
"tasks": 0,
|
||||
"errors": 0
|
||||
}
|
||||
}
|
||||
+6
@@ -53,6 +53,7 @@
|
||||
"integrity": "sha512-CGOfOJqWjg2qW/Mb6zNsDm+u5vFQ8DxXfbM09z69p5Z6+mE1ikP2jUXw+j42Pf1XTYED2Rni5f95npYeuwMDQA==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"peer": true,
|
||||
"dependencies": {
|
||||
"@babel/code-frame": "^7.29.0",
|
||||
"@babel/generator": "^7.29.0",
|
||||
@@ -1246,6 +1247,7 @@
|
||||
"integrity": "sha512-z9VXpC7MWrhfWipitjNdgCauoMLRdIILQsAEV+ZesIzBq/oUlxk0m3ApZuMFCXdnS4U7KrI+l3WRUEGQ8K1QKw==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"peer": true,
|
||||
"dependencies": {
|
||||
"@types/prop-types": "*",
|
||||
"csstype": "^3.2.2"
|
||||
@@ -1315,6 +1317,7 @@
|
||||
}
|
||||
],
|
||||
"license": "MIT",
|
||||
"peer": true,
|
||||
"dependencies": {
|
||||
"baseline-browser-mapping": "^2.9.0",
|
||||
"caniuse-lite": "^1.0.30001759",
|
||||
@@ -1584,6 +1587,7 @@
|
||||
"integrity": "sha512-5gTmgEY/sqK6gFXLIsQNH19lWb4ebPDLA4SdLP7dsWkIXHWlG66oPuVvXSGFPppYZz8ZDZq0dYYrbHfBCVUb1Q==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"peer": true,
|
||||
"engines": {
|
||||
"node": ">=12"
|
||||
},
|
||||
@@ -1625,6 +1629,7 @@
|
||||
"resolved": "https://registry.npmjs.org/react/-/react-18.3.1.tgz",
|
||||
"integrity": "sha512-wS+hAgJShR0KhEvPJArfuPVN1+Hz1t0Y6n5jLrGQbkb4urgPE/0Rve+1kMB1v/oWgHgm4WIcV+i7F2pTVj+2iQ==",
|
||||
"license": "MIT",
|
||||
"peer": true,
|
||||
"dependencies": {
|
||||
"loose-envify": "^1.1.0"
|
||||
},
|
||||
@@ -1797,6 +1802,7 @@
|
||||
"integrity": "sha512-+Oxm7q9hDoLMyJOYfUYBuHQo+dkAloi33apOPP56pzj+vsdJDzr+j1NISE5pyaAuKL4A3UD34qd0lx5+kfKp2g==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"peer": true,
|
||||
"dependencies": {
|
||||
"esbuild": "^0.25.0",
|
||||
"fdir": "^6.4.4",
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "ruview-desktop-ui",
|
||||
"private": true,
|
||||
"version": "0.3.0",
|
||||
"version": "0.4.4",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import { useState, useEffect, useCallback } from "react";
|
||||
import { APP_VERSION } from "./version";
|
||||
import Dashboard from "./pages/Dashboard";
|
||||
import { Nodes } from "./pages/Nodes";
|
||||
import NetworkDiscovery from "./pages/NetworkDiscovery";
|
||||
import { FlashFirmware } from "./pages/FlashFirmware";
|
||||
import { OtaUpdate } from "./pages/OtaUpdate";
|
||||
import { EdgeModules } from "./pages/EdgeModules";
|
||||
@@ -10,6 +12,7 @@ import { Settings } from "./pages/Settings";
|
||||
|
||||
type Page =
|
||||
| "dashboard"
|
||||
| "discovery"
|
||||
| "nodes"
|
||||
| "flash"
|
||||
| "ota"
|
||||
@@ -26,6 +29,7 @@ interface NavItem {
|
||||
|
||||
const NAV_ITEMS: NavItem[] = [
|
||||
{ id: "dashboard", label: "Dashboard", icon: "\u25A6" },
|
||||
{ id: "discovery", label: "Discovery", icon: "\u25CE" },
|
||||
{ id: "nodes", label: "Nodes", icon: "\u25C9" },
|
||||
{ id: "flash", label: "Flash", icon: "\u26A1" },
|
||||
{ id: "ota", label: "OTA", icon: "\u2B06" },
|
||||
@@ -87,7 +91,8 @@ const App: React.FC = () => {
|
||||
|
||||
const renderPage = () => {
|
||||
switch (activePage) {
|
||||
case "dashboard": return <Dashboard />;
|
||||
case "dashboard": return <Dashboard onNavigate={navigateTo} />;
|
||||
case "discovery": return <NetworkDiscovery onNavigate={navigateTo} />;
|
||||
case "nodes": return <Nodes />;
|
||||
case "flash": return <FlashFirmware />;
|
||||
case "ota": return <OtaUpdate />;
|
||||
@@ -163,7 +168,7 @@ const App: React.FC = () => {
|
||||
letterSpacing: "0.02em",
|
||||
}}
|
||||
>
|
||||
v0.3.0
|
||||
v{APP_VERSION}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -9,6 +9,7 @@ const DEFAULT_CONFIG: ServerConfig = {
|
||||
static_dir: null,
|
||||
model_dir: null,
|
||||
log_level: "info",
|
||||
source: "simulate",
|
||||
};
|
||||
|
||||
interface UseServerOptions {
|
||||
|
||||
+36
-7
@@ -19,19 +19,31 @@ interface ServerStatus {
|
||||
ws_port: number | null;
|
||||
}
|
||||
|
||||
const Dashboard: React.FC = () => {
|
||||
type Page = "dashboard" | "discovery" | "nodes" | "flash" | "ota" | "wasm" | "sensing" | "mesh" | "settings";
|
||||
|
||||
interface DashboardProps {
|
||||
onNavigate?: (page: Page) => void;
|
||||
}
|
||||
|
||||
const Dashboard: React.FC<DashboardProps> = ({ onNavigate }) => {
|
||||
const [nodes, setNodes] = useState<DiscoveredNode[]>([]);
|
||||
const [serverStatus, setServerStatus] = useState<ServerStatus | null>(null);
|
||||
const [scanning, setScanning] = useState(false);
|
||||
const [scanError, setScanError] = useState<string | null>(null);
|
||||
|
||||
const handleScan = async () => {
|
||||
setScanning(true);
|
||||
setScanError(null);
|
||||
try {
|
||||
const { invoke } = await import("@tauri-apps/api/core");
|
||||
const found = await invoke<DiscoveredNode[]>("discover_nodes", { timeoutMs: 3000 });
|
||||
setNodes(found);
|
||||
if (found.length === 0) {
|
||||
setScanError("No nodes found. Ensure ESP32 devices are powered on and connected to the network.");
|
||||
}
|
||||
} catch (err) {
|
||||
console.error("Discovery failed:", err);
|
||||
setScanError(`Scan failed: ${err instanceof Error ? err.message : String(err)}`);
|
||||
} finally {
|
||||
setScanning(false);
|
||||
}
|
||||
@@ -133,9 +145,9 @@ const Dashboard: React.FC = () => {
|
||||
<div className="card">
|
||||
<h3 className="heading-sm" style={{ marginBottom: "var(--space-3)" }}>Quick Actions</h3>
|
||||
<div style={{ display: "flex", flexDirection: "column", gap: "var(--space-2)" }}>
|
||||
<QuickAction label="Flash Firmware" desc="Flash via serial port" />
|
||||
<QuickAction label="Push OTA Update" desc="Over-the-air to nodes" />
|
||||
<QuickAction label="Upload WASM" desc="Deploy edge modules" />
|
||||
<QuickAction label="Flash Firmware" desc="Flash via serial port" onClick={() => onNavigate?.("flash")} />
|
||||
<QuickAction label="Push OTA Update" desc="Over-the-air to nodes" onClick={() => onNavigate?.("ota")} />
|
||||
<QuickAction label="Upload WASM" desc="Deploy edge modules" onClick={() => onNavigate?.("wasm")} />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -145,7 +157,23 @@ const Dashboard: React.FC = () => {
|
||||
<h3 className="heading-sm">Discovered Nodes ({nodes.length})</h3>
|
||||
</div>
|
||||
|
||||
{nodes.length === 0 ? (
|
||||
{scanError && (
|
||||
<div
|
||||
style={{
|
||||
padding: "var(--space-3) var(--space-4)",
|
||||
background: "rgba(248, 81, 73, 0.1)",
|
||||
border: "1px solid rgba(248, 81, 73, 0.3)",
|
||||
borderRadius: "var(--radius-md)",
|
||||
marginBottom: "var(--space-4)",
|
||||
fontSize: 13,
|
||||
color: "var(--status-error)",
|
||||
}}
|
||||
>
|
||||
{scanError}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{nodes.length === 0 && !scanError ? (
|
||||
<div className="card empty-state">
|
||||
<div className="empty-state-icon">{"\u25C9"}</div>
|
||||
<div style={{ fontSize: 14, fontWeight: 600, color: "var(--text-secondary)" }}>
|
||||
@@ -155,7 +183,7 @@ const Dashboard: React.FC = () => {
|
||||
Click "Scan Network" to discover ESP32 devices on your local network.
|
||||
</div>
|
||||
</div>
|
||||
) : (
|
||||
) : nodes.length === 0 ? null : (
|
||||
<div
|
||||
style={{
|
||||
display: "grid",
|
||||
@@ -258,9 +286,10 @@ function PortTag({ label, port }: { label: string; port: number }) {
|
||||
);
|
||||
}
|
||||
|
||||
function QuickAction({ label, desc }: { label: string; desc: string }) {
|
||||
function QuickAction({ label, desc, onClick }: { label: string; desc: string; onClick?: () => void }) {
|
||||
return (
|
||||
<div
|
||||
onClick={onClick}
|
||||
style={{
|
||||
display: "flex",
|
||||
justifyContent: "space-between",
|
||||
|
||||
+1436
-114
File diff suppressed because it is too large
Load Diff
+1264
File diff suppressed because it is too large
Load Diff
+298
-86
@@ -1,6 +1,6 @@
|
||||
import React, { useEffect, useState, useRef, useCallback } from "react";
|
||||
import { useServer } from "../hooks/useServer";
|
||||
import type { SensingUpdate } from "../types";
|
||||
import type { SensingUpdate, DataSource } from "../types";
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Log entry model
|
||||
@@ -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)
|
||||
@@ -107,11 +176,12 @@ function LogViewer({
|
||||
paused: boolean;
|
||||
onTogglePause: () => void;
|
||||
}) {
|
||||
const bottomRef = useRef<HTMLDivElement>(null);
|
||||
const containerRef = useRef<HTMLDivElement>(null);
|
||||
|
||||
useEffect(() => {
|
||||
if (!paused && bottomRef.current) {
|
||||
bottomRef.current.scrollIntoView({ behavior: "smooth" });
|
||||
// Scroll to bottom within the container only (not the page)
|
||||
if (!paused && containerRef.current) {
|
||||
containerRef.current.scrollTop = containerRef.current.scrollHeight;
|
||||
}
|
||||
}, [entries, paused]);
|
||||
|
||||
@@ -185,6 +255,7 @@ function LogViewer({
|
||||
|
||||
{/* Log entries */}
|
||||
<div
|
||||
ref={containerRef}
|
||||
style={{
|
||||
height: 320,
|
||||
overflowY: "auto",
|
||||
@@ -217,7 +288,6 @@ function LogViewer({
|
||||
</div>
|
||||
))
|
||||
)}
|
||||
<div ref={bottomRef} />
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
@@ -232,6 +302,9 @@ export const Sensing: React.FC = () => {
|
||||
const [starting, setStarting] = useState(false);
|
||||
const [stopping, setStopping] = useState(false);
|
||||
|
||||
// Data source selection
|
||||
const [dataSource, setDataSource] = useState<DataSource>("simulate");
|
||||
|
||||
// Log viewer state
|
||||
const [logEntries, setLogEntries] = useState<LogEntry[]>([]);
|
||||
const [paused, setPaused] = useState(false);
|
||||
@@ -241,28 +314,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), []);
|
||||
@@ -270,7 +434,7 @@ export const Sensing: React.FC = () => {
|
||||
const handleStart = async () => {
|
||||
setStarting(true);
|
||||
try {
|
||||
await start();
|
||||
await start({ source: dataSource });
|
||||
} finally {
|
||||
setStarting(false);
|
||||
}
|
||||
@@ -349,28 +513,76 @@ 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>
|
||||
|
||||
{/* Right: action button */}
|
||||
<button
|
||||
onClick={isRunning ? handleStop : handleStart}
|
||||
disabled={starting || stopping}
|
||||
style={{
|
||||
padding: "var(--space-2) var(--space-4)",
|
||||
borderRadius: 6,
|
||||
fontSize: 13,
|
||||
fontWeight: 600,
|
||||
cursor: starting || stopping ? "not-allowed" : "pointer",
|
||||
border: "none",
|
||||
background: isRunning ? "var(--status-error)" : "var(--accent)",
|
||||
color: "#fff",
|
||||
opacity: starting || stopping ? 0.6 : 1,
|
||||
}}
|
||||
>
|
||||
{starting ? "Starting..." : stopping ? "Stopping..." : isRunning ? "Stop Server" : "Start Server"}
|
||||
</button>
|
||||
{/* Right: data source + action button */}
|
||||
<div style={{ display: "flex", alignItems: "center", gap: "var(--space-3)" }}>
|
||||
{/* Data source selector */}
|
||||
<div style={{ display: "flex", alignItems: "center", gap: "var(--space-2)" }}>
|
||||
<label
|
||||
style={{
|
||||
fontSize: 12,
|
||||
color: "var(--text-muted)",
|
||||
fontWeight: 500,
|
||||
}}
|
||||
>
|
||||
Source:
|
||||
</label>
|
||||
<select
|
||||
value={dataSource}
|
||||
onChange={(e) => setDataSource(e.target.value as DataSource)}
|
||||
disabled={isRunning}
|
||||
style={{
|
||||
padding: "var(--space-1) var(--space-2)",
|
||||
borderRadius: 4,
|
||||
fontSize: 12,
|
||||
fontWeight: 500,
|
||||
border: "1px solid var(--border)",
|
||||
background: isRunning ? "var(--bg-hover)" : "var(--bg-surface)",
|
||||
color: "var(--text-primary)",
|
||||
cursor: isRunning ? "not-allowed" : "pointer",
|
||||
opacity: isRunning ? 0.6 : 1,
|
||||
}}
|
||||
>
|
||||
<option value="simulate">Simulate</option>
|
||||
<option value="esp32">ESP32 (Real)</option>
|
||||
<option value="wifi">WiFi (RSSI)</option>
|
||||
<option value="auto">Auto Detect</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
{/* Action button */}
|
||||
<button
|
||||
onClick={isRunning ? handleStop : handleStart}
|
||||
disabled={starting || stopping}
|
||||
style={{
|
||||
padding: "var(--space-2) var(--space-4)",
|
||||
borderRadius: 6,
|
||||
fontSize: 13,
|
||||
fontWeight: 600,
|
||||
cursor: starting || stopping ? "not-allowed" : "pointer",
|
||||
border: "none",
|
||||
background: isRunning ? "var(--status-error)" : "var(--accent)",
|
||||
color: "#fff",
|
||||
opacity: starting || stopping ? 0.6 : 1,
|
||||
}}
|
||||
>
|
||||
{starting ? "Starting..." : stopping ? "Stopping..." : isRunning ? "Stop Server" : "Start Server"}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Error display */}
|
||||
|
||||
@@ -14,7 +14,7 @@ export type DiscoveryMethod = "mdns" | "udp_probe" | "http_sweep" | "manual";
|
||||
|
||||
export type MeshRole = "coordinator" | "node" | "aggregator";
|
||||
|
||||
export type Chip = "esp32" | "esp32s3" | "esp32c3";
|
||||
export type Chip = "esp32" | "esp32s2" | "esp32s3" | "esp32c3" | "esp32c6";
|
||||
|
||||
export interface TdmConfig {
|
||||
slot: number;
|
||||
@@ -161,12 +161,17 @@ export interface WasmModule {
|
||||
node_ip: string;
|
||||
loaded_at: string | null;
|
||||
error: string | null;
|
||||
memory_used_kb: number | null;
|
||||
cpu_usage_pct: number | null;
|
||||
exec_count: number | null;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Sensing Server
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
export type DataSource = "auto" | "wifi" | "esp32" | "simulate";
|
||||
|
||||
export interface ServerConfig {
|
||||
http_port: number;
|
||||
ws_port: number;
|
||||
@@ -174,6 +179,7 @@ export interface ServerConfig {
|
||||
static_dir: string | null;
|
||||
model_dir: string | null;
|
||||
log_level: string;
|
||||
source: DataSource;
|
||||
}
|
||||
|
||||
export interface ServerStatus {
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
// Application version - single source of truth
|
||||
export const APP_VERSION = "0.4.4";
|
||||
+10
-1
@@ -80,7 +80,16 @@ def generate_nvs_binary(csv_content, size):
|
||||
bin_path = csv_path.replace(".csv", ".bin")
|
||||
|
||||
try:
|
||||
# Try the pip-installed version first
|
||||
# Try the pip-installed version first (esp_idf_nvs_partition_gen package)
|
||||
try:
|
||||
from esp_idf_nvs_partition_gen import nvs_partition_gen
|
||||
nvs_partition_gen.generate(csv_path, bin_path, size)
|
||||
with open(bin_path, "rb") as f:
|
||||
return f.read()
|
||||
except ImportError:
|
||||
pass
|
||||
|
||||
# Try legacy import name (older versions)
|
||||
try:
|
||||
import nvs_partition_gen
|
||||
nvs_partition_gen.generate(csv_path, bin_path, size)
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
<button class="nav-tab" data-tab="applications">Applications</button>
|
||||
<button class="nav-tab" data-tab="sensing">Sensing</button>
|
||||
<button class="nav-tab" data-tab="training">Training</button>
|
||||
<a href="pose-fusion.html" class="nav-tab" style="text-decoration:none">Pose Fusion</a>
|
||||
<a href="observatory.html" class="nav-tab" style="text-decoration:none">Observatory</a>
|
||||
</nav>
|
||||
|
||||
|
||||
@@ -0,0 +1,160 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>WiFi-DensePose — Dual-Modal Pose Estimation</title>
|
||||
<link rel="stylesheet" href="pose-fusion/css/style.css">
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<!-- Header -->
|
||||
<header class="header">
|
||||
<div class="header-left">
|
||||
<div class="logo"><span class="pi">π</span> DensePose</div>
|
||||
<div class="header-title">Dual-Modal Pose Estimation — Live Video + WiFi CSI Fusion</div>
|
||||
</div>
|
||||
<div class="header-right">
|
||||
<select id="mode-select" class="mode-select">
|
||||
<option value="dual">Dual Mode (Video + CSI)</option>
|
||||
<option value="video">Video Only</option>
|
||||
<option value="csi">CSI Only (WiFi)</option>
|
||||
</select>
|
||||
<div class="status-badge">
|
||||
<span id="status-dot" class="status-dot offline"></span>
|
||||
<span id="status-label">READY</span>
|
||||
</div>
|
||||
<span id="fps-display" class="fps-badge">-- FPS</span>
|
||||
<a href="index.html" class="back-link">← Dashboard</a>
|
||||
<a href="observatory.html" class="back-link">Observatory →</a>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<!-- Main Grid -->
|
||||
<div class="main-grid">
|
||||
|
||||
<!-- Video + Skeleton Panel -->
|
||||
<div class="video-panel">
|
||||
<video id="webcam" autoplay playsinline muted></video>
|
||||
<canvas id="skeleton-canvas"></canvas>
|
||||
<div class="video-overlay-label" id="mode-label">DUAL FUSION</div>
|
||||
|
||||
<div id="camera-prompt" class="camera-prompt">
|
||||
<p>Enable your webcam for live video pose estimation.<br>
|
||||
Or switch to <strong>CSI Only</strong> mode for WiFi-based sensing.</p>
|
||||
<button id="start-camera-btn">Enable Camera</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Side Panels -->
|
||||
<div class="side-panels">
|
||||
|
||||
<!-- Fusion Confidence -->
|
||||
<div class="panel">
|
||||
<div class="panel-title">◆ Fusion Confidence</div>
|
||||
<div class="fusion-bars">
|
||||
<div class="bar-row">
|
||||
<span class="bar-label">Video</span>
|
||||
<div class="bar-track"><div class="bar-fill video" id="video-bar" style="width:0%"></div></div>
|
||||
<span class="bar-value" id="video-bar-val">0%</span>
|
||||
</div>
|
||||
<div class="bar-row">
|
||||
<span class="bar-label">CSI</span>
|
||||
<div class="bar-track"><div class="bar-fill csi" id="csi-bar" style="width:0%"></div></div>
|
||||
<span class="bar-value" id="csi-bar-val">0%</span>
|
||||
</div>
|
||||
<div class="bar-row">
|
||||
<span class="bar-label">Fused</span>
|
||||
<div class="bar-track"><div class="bar-fill fused" id="fused-bar" style="width:0%"></div></div>
|
||||
<span class="bar-value" id="fused-bar-val">0%</span>
|
||||
</div>
|
||||
</div>
|
||||
<div style="margin-top:8px; font-size:10px; color:var(--text-label)">
|
||||
Cross-modal: <span id="cross-modal-sim" style="color:var(--green-glow)">0.000</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- CSI Heatmap -->
|
||||
<div class="panel">
|
||||
<div class="panel-title">◆ CSI Amplitude Heatmap</div>
|
||||
<div class="csi-canvas-wrapper">
|
||||
<canvas id="csi-canvas" width="320" height="120"></canvas>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Embedding Space -->
|
||||
<div class="panel">
|
||||
<div class="panel-title">◆ Embedding Space (2D Projection)</div>
|
||||
<div class="embedding-canvas-wrapper">
|
||||
<canvas id="embedding-canvas" width="320" height="140"></canvas>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Latency -->
|
||||
<div class="panel">
|
||||
<div class="panel-title">◆ Pipeline Latency</div>
|
||||
<div class="latency-grid">
|
||||
<div class="latency-item">
|
||||
<div class="latency-value" id="lat-video">--</div>
|
||||
<div class="latency-label">Video CNN</div>
|
||||
</div>
|
||||
<div class="latency-item">
|
||||
<div class="latency-value" id="lat-csi">--</div>
|
||||
<div class="latency-label">CSI CNN</div>
|
||||
</div>
|
||||
<div class="latency-item">
|
||||
<div class="latency-value" id="lat-fusion">--</div>
|
||||
<div class="latency-label">Fusion</div>
|
||||
</div>
|
||||
<div class="latency-item">
|
||||
<div class="latency-value" id="lat-total">--</div>
|
||||
<div class="latency-label">Total</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Controls -->
|
||||
<div class="panel">
|
||||
<div class="panel-title">◆ Controls</div>
|
||||
<div class="controls-row">
|
||||
<button class="btn" id="pause-btn">⏸ Pause</button>
|
||||
</div>
|
||||
|
||||
<div class="slider-row">
|
||||
<label>Confidence</label>
|
||||
<input type="range" id="confidence-slider" min="0" max="1" step="0.05" value="0.3">
|
||||
<span class="slider-val" id="confidence-value">0.30</span>
|
||||
</div>
|
||||
|
||||
<div style="margin-top:10px">
|
||||
<div class="panel-title" style="margin-bottom:6px">◆ Live CSI Source</div>
|
||||
<div style="display:flex;gap:6px">
|
||||
<input type="text" id="ws-url" placeholder="ws://localhost:3030/ws/csi"
|
||||
style="flex:1;background:rgba(255,255,255,0.05);border:1px solid var(--bg-panel-border);
|
||||
color:var(--text-primary);padding:5px 8px;border-radius:4px;font-size:11px;
|
||||
font-family:'JetBrains Mono',monospace">
|
||||
<button class="btn" id="connect-ws-btn">Connect</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div><!-- /side-panels -->
|
||||
|
||||
<!-- Bottom Bar -->
|
||||
<div class="bottom-bar">
|
||||
<div>
|
||||
WiFi-DensePose · Dual-Modal Pose Estimation ·
|
||||
Architecture: MobileNet-V3 × 2 → Attention Fusion → 17-Keypoint COCO
|
||||
</div>
|
||||
<div>
|
||||
<a href="https://github.com/ruvnet/wifi-densepose">GitHub</a> ·
|
||||
CNN: ruvector-cnn (JS fallback) ·
|
||||
<a href="observatory.html">Observatory</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div><!-- /main-grid -->
|
||||
|
||||
<script type="module" src="pose-fusion/js/main.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,30 @@
|
||||
#!/bin/bash
|
||||
# Build WASM packages for the dual-modal pose estimation demo.
|
||||
# Requires: wasm-pack (cargo install wasm-pack)
|
||||
#
|
||||
# Usage: ./build.sh
|
||||
#
|
||||
# Output: pkg/ruvector_cnn_wasm/ — WASM CNN embedder for browser
|
||||
|
||||
set -e
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
||||
VENDOR_DIR="$SCRIPT_DIR/../../vendor/ruvector"
|
||||
OUT_DIR="$SCRIPT_DIR/pkg/ruvector_cnn_wasm"
|
||||
|
||||
echo "Building ruvector-cnn-wasm..."
|
||||
wasm-pack build "$VENDOR_DIR/crates/ruvector-cnn-wasm" \
|
||||
--target web \
|
||||
--out-dir "$OUT_DIR" \
|
||||
--no-typescript
|
||||
|
||||
# Remove .gitignore so we can commit the build output for GitHub Pages
|
||||
rm -f "$OUT_DIR/.gitignore"
|
||||
|
||||
echo ""
|
||||
echo "Build complete!"
|
||||
echo " WASM: $(du -sh "$OUT_DIR/ruvector_cnn_wasm_bg.wasm" | cut -f1)"
|
||||
echo " JS: $(du -sh "$OUT_DIR/ruvector_cnn_wasm.js" | cut -f1)"
|
||||
echo ""
|
||||
echo "Serve the demo: cd $SCRIPT_DIR/.. && python3 -m http.server 8080"
|
||||
echo "Open: http://localhost:8080/pose-fusion.html"
|
||||
@@ -0,0 +1,405 @@
|
||||
/* WiFi-DensePose — Dual-Modal Pose Fusion Demo
|
||||
Dark theme matching Observatory */
|
||||
|
||||
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;600;700&family=JetBrains+Mono:wght@400;600&display=swap');
|
||||
|
||||
:root {
|
||||
--bg-deep: #080c14;
|
||||
--bg-panel: rgba(8, 16, 28, 0.92);
|
||||
--bg-panel-border: rgba(0, 210, 120, 0.25);
|
||||
--green-glow: #00d878;
|
||||
--green-bright:#3eff8a;
|
||||
--green-dim: #0a6b3a;
|
||||
--amber: #ffb020;
|
||||
--amber-dim: #a06800;
|
||||
--blue-signal: #2090ff;
|
||||
--blue-dim: #0a3060;
|
||||
--red-alert: #ff3040;
|
||||
--cyan: #00e5ff;
|
||||
--text-primary: #e8ece0;
|
||||
--text-secondary: rgba(232,236,224, 0.55);
|
||||
--text-label: rgba(232,236,224, 0.35);
|
||||
--radius: 8px;
|
||||
}
|
||||
|
||||
* { margin: 0; padding: 0; box-sizing: border-box; }
|
||||
|
||||
body {
|
||||
background: var(--bg-deep);
|
||||
font-family: 'Inter', -apple-system, sans-serif;
|
||||
color: var(--text-primary);
|
||||
-webkit-font-smoothing: antialiased;
|
||||
overflow-x: hidden;
|
||||
min-height: 100vh;
|
||||
}
|
||||
|
||||
/* === Header === */
|
||||
.header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
padding: 16px 24px;
|
||||
border-bottom: 1px solid var(--bg-panel-border);
|
||||
background: var(--bg-panel);
|
||||
backdrop-filter: blur(12px);
|
||||
}
|
||||
|
||||
.header-left {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 16px;
|
||||
}
|
||||
|
||||
.logo {
|
||||
font-weight: 700;
|
||||
font-size: 24px;
|
||||
color: var(--green-glow);
|
||||
}
|
||||
|
||||
.logo .pi { font-style: normal; }
|
||||
|
||||
.header-title {
|
||||
font-size: 14px;
|
||||
color: var(--text-secondary);
|
||||
font-weight: 300;
|
||||
}
|
||||
|
||||
.header-right {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 16px;
|
||||
}
|
||||
|
||||
.mode-select {
|
||||
background: rgba(0,210,120,0.1);
|
||||
border: 1px solid var(--bg-panel-border);
|
||||
color: var(--text-primary);
|
||||
padding: 6px 12px;
|
||||
border-radius: var(--radius);
|
||||
font-family: inherit;
|
||||
font-size: 13px;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.mode-select option { background: #0c1420; }
|
||||
|
||||
.status-badge {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
font-family: 'JetBrains Mono', monospace;
|
||||
font-size: 12px;
|
||||
padding: 4px 10px;
|
||||
border-radius: 12px;
|
||||
background: rgba(0,210,120,0.1);
|
||||
border: 1px solid var(--bg-panel-border);
|
||||
}
|
||||
|
||||
.status-dot {
|
||||
width: 8px; height: 8px;
|
||||
border-radius: 50%;
|
||||
background: var(--green-glow);
|
||||
box-shadow: 0 0 8px var(--green-glow);
|
||||
animation: pulse-dot 2s ease infinite;
|
||||
}
|
||||
|
||||
.status-dot.offline { background: #555; box-shadow: none; animation: none; }
|
||||
.status-dot.warning { background: var(--amber); box-shadow: 0 0 8px var(--amber); }
|
||||
|
||||
@keyframes pulse-dot {
|
||||
0%, 100% { opacity: 1; }
|
||||
50% { opacity: 0.5; }
|
||||
}
|
||||
|
||||
.fps-badge {
|
||||
font-family: 'JetBrains Mono', monospace;
|
||||
font-size: 12px;
|
||||
color: var(--green-glow);
|
||||
}
|
||||
|
||||
.back-link {
|
||||
color: var(--text-secondary);
|
||||
text-decoration: none;
|
||||
font-size: 13px;
|
||||
transition: color 0.2s;
|
||||
}
|
||||
.back-link:hover { color: var(--green-glow); }
|
||||
|
||||
/* === Main Layout === */
|
||||
.main-grid {
|
||||
display: grid;
|
||||
grid-template-columns: 1fr 360px;
|
||||
grid-template-rows: 1fr auto;
|
||||
gap: 16px;
|
||||
padding: 16px 24px;
|
||||
height: calc(100vh - 72px);
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
/* === Video Panel === */
|
||||
.video-panel {
|
||||
position: relative;
|
||||
background: #000;
|
||||
border-radius: var(--radius);
|
||||
border: 1px solid var(--bg-panel-border);
|
||||
overflow: hidden;
|
||||
min-height: 0;
|
||||
}
|
||||
|
||||
.video-panel video {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
object-fit: cover;
|
||||
transform: scaleX(-1);
|
||||
}
|
||||
|
||||
.video-panel canvas {
|
||||
position: absolute;
|
||||
top: 0; left: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
transform: scaleX(-1);
|
||||
}
|
||||
|
||||
.video-overlay-label {
|
||||
position: absolute;
|
||||
top: 12px; left: 12px;
|
||||
font-family: 'JetBrains Mono', monospace;
|
||||
font-size: 11px;
|
||||
padding: 4px 8px;
|
||||
background: rgba(0,0,0,0.7);
|
||||
border-radius: 4px;
|
||||
color: var(--green-glow);
|
||||
z-index: 5;
|
||||
transform: scaleX(-1);
|
||||
}
|
||||
|
||||
.camera-prompt {
|
||||
position: absolute;
|
||||
top: 50%; left: 50%;
|
||||
transform: translate(-50%, -50%);
|
||||
text-align: center;
|
||||
color: var(--text-secondary);
|
||||
}
|
||||
|
||||
.camera-prompt button {
|
||||
margin-top: 12px;
|
||||
padding: 10px 24px;
|
||||
background: var(--green-glow);
|
||||
color: #000;
|
||||
border: none;
|
||||
border-radius: var(--radius);
|
||||
font-family: inherit;
|
||||
font-weight: 600;
|
||||
font-size: 14px;
|
||||
cursor: pointer;
|
||||
transition: background 0.2s;
|
||||
}
|
||||
|
||||
.camera-prompt button:hover { background: var(--green-bright); }
|
||||
|
||||
/* === Side Panels === */
|
||||
.side-panels {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 12px;
|
||||
overflow-y: auto;
|
||||
min-height: 0;
|
||||
}
|
||||
|
||||
.panel {
|
||||
background: var(--bg-panel);
|
||||
border: 1px solid var(--bg-panel-border);
|
||||
border-radius: var(--radius);
|
||||
padding: 14px;
|
||||
}
|
||||
|
||||
.panel-title {
|
||||
font-size: 11px;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 1.2px;
|
||||
color: var(--text-label);
|
||||
margin-bottom: 10px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
}
|
||||
|
||||
/* === CSI Heatmap === */
|
||||
.csi-canvas-wrapper {
|
||||
position: relative;
|
||||
border-radius: 4px;
|
||||
overflow: hidden;
|
||||
background: #000;
|
||||
}
|
||||
|
||||
.csi-canvas-wrapper canvas {
|
||||
width: 100%;
|
||||
display: block;
|
||||
}
|
||||
|
||||
/* === Fusion Bars === */
|
||||
.fusion-bars {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.bar-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.bar-label {
|
||||
font-family: 'JetBrains Mono', monospace;
|
||||
font-size: 11px;
|
||||
color: var(--text-secondary);
|
||||
width: 55px;
|
||||
text-align: right;
|
||||
}
|
||||
|
||||
.bar-track {
|
||||
flex: 1;
|
||||
height: 6px;
|
||||
background: rgba(255,255,255,0.06);
|
||||
border-radius: 3px;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.bar-fill {
|
||||
height: 100%;
|
||||
border-radius: 3px;
|
||||
transition: width 0.3s ease;
|
||||
}
|
||||
|
||||
.bar-fill.video { background: var(--cyan); }
|
||||
.bar-fill.csi { background: var(--amber); }
|
||||
.bar-fill.fused { background: var(--green-glow); box-shadow: 0 0 8px var(--green-glow); }
|
||||
|
||||
.bar-value {
|
||||
font-family: 'JetBrains Mono', monospace;
|
||||
font-size: 11px;
|
||||
color: var(--text-primary);
|
||||
width: 36px;
|
||||
}
|
||||
|
||||
/* === Embedding Space === */
|
||||
.embedding-canvas-wrapper {
|
||||
position: relative;
|
||||
background: #000;
|
||||
border-radius: 4px;
|
||||
overflow: hidden;
|
||||
}
|
||||
.embedding-canvas-wrapper canvas {
|
||||
width: 100%;
|
||||
display: block;
|
||||
}
|
||||
|
||||
/* === Latency Panel === */
|
||||
.latency-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(4, 1fr);
|
||||
gap: 6px;
|
||||
}
|
||||
|
||||
.latency-item {
|
||||
text-align: center;
|
||||
padding: 6px 0;
|
||||
}
|
||||
|
||||
.latency-value {
|
||||
font-family: 'JetBrains Mono', monospace;
|
||||
font-size: 16px;
|
||||
font-weight: 600;
|
||||
color: var(--green-glow);
|
||||
}
|
||||
|
||||
.latency-label {
|
||||
font-size: 10px;
|
||||
color: var(--text-label);
|
||||
margin-top: 2px;
|
||||
}
|
||||
|
||||
/* === Controls === */
|
||||
.controls-row {
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.btn {
|
||||
padding: 6px 14px;
|
||||
border: 1px solid var(--bg-panel-border);
|
||||
background: rgba(0,210,120,0.08);
|
||||
color: var(--text-primary);
|
||||
border-radius: var(--radius);
|
||||
font-family: inherit;
|
||||
font-size: 12px;
|
||||
cursor: pointer;
|
||||
transition: all 0.2s;
|
||||
}
|
||||
.btn:hover { background: rgba(0,210,120,0.2); }
|
||||
.btn.active { background: var(--green-glow); color: #000; font-weight: 600; }
|
||||
|
||||
.slider-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
margin-top: 8px;
|
||||
}
|
||||
|
||||
.slider-row label {
|
||||
font-size: 11px;
|
||||
color: var(--text-secondary);
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.slider-row input[type=range] {
|
||||
flex: 1;
|
||||
accent-color: var(--green-glow);
|
||||
}
|
||||
|
||||
.slider-row .slider-val {
|
||||
font-family: 'JetBrains Mono', monospace;
|
||||
font-size: 11px;
|
||||
width: 32px;
|
||||
color: var(--green-glow);
|
||||
}
|
||||
|
||||
/* === Bottom Bar === */
|
||||
.bottom-bar {
|
||||
grid-column: 1 / -1;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
padding: 10px 16px;
|
||||
background: var(--bg-panel);
|
||||
border: 1px solid var(--bg-panel-border);
|
||||
border-radius: var(--radius);
|
||||
font-family: 'JetBrains Mono', monospace;
|
||||
font-size: 11px;
|
||||
color: var(--text-secondary);
|
||||
}
|
||||
|
||||
.bottom-bar a {
|
||||
color: var(--green-glow);
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
/* === Skeleton colors === */
|
||||
.skeleton-joint { fill: var(--green-glow); }
|
||||
.skeleton-limb { stroke: var(--green-bright); }
|
||||
.skeleton-joint-csi { fill: var(--amber); }
|
||||
.skeleton-limb-csi { stroke: var(--amber); }
|
||||
|
||||
/* === Responsive === */
|
||||
@media (max-width: 900px) {
|
||||
.main-grid {
|
||||
grid-template-columns: 1fr;
|
||||
height: auto;
|
||||
overflow: auto;
|
||||
}
|
||||
.video-panel { aspect-ratio: 16/9; max-height: 50vh; }
|
||||
.side-panels { max-height: none; overflow: visible; }
|
||||
}
|
||||
@@ -0,0 +1,247 @@
|
||||
/**
|
||||
* CanvasRenderer — Renders skeleton overlay on video, CSI heatmap,
|
||||
* embedding space visualization, and fusion confidence bars.
|
||||
*/
|
||||
|
||||
import { SKELETON_CONNECTIONS } from './pose-decoder.js';
|
||||
|
||||
export class CanvasRenderer {
|
||||
constructor() {
|
||||
this.colors = {
|
||||
joint: '#00d878',
|
||||
jointGlow: 'rgba(0, 216, 120, 0.4)',
|
||||
limb: '#3eff8a',
|
||||
limbGlow: 'rgba(62, 255, 138, 0.15)',
|
||||
csiJoint: '#ffb020',
|
||||
csiLimb: '#ffc850',
|
||||
fused: '#00e5ff',
|
||||
confidence: 'rgba(255,255,255,0.3)',
|
||||
videoEmb: '#00e5ff',
|
||||
csiEmb: '#ffb020',
|
||||
fusedEmb: '#00d878',
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw skeleton overlay on the video canvas
|
||||
* @param {CanvasRenderingContext2D} ctx
|
||||
* @param {Array<{x,y,confidence}>} keypoints - Normalized [0,1] coordinates
|
||||
* @param {number} width - Canvas width
|
||||
* @param {number} height - Canvas height
|
||||
* @param {object} opts
|
||||
*/
|
||||
drawSkeleton(ctx, keypoints, width, height, opts = {}) {
|
||||
const minConf = opts.minConfidence || 0.3;
|
||||
const color = opts.color || 'green';
|
||||
const jointColor = color === 'amber' ? this.colors.csiJoint : this.colors.joint;
|
||||
const limbColor = color === 'amber' ? this.colors.csiLimb : this.colors.limb;
|
||||
const glowColor = color === 'amber' ? 'rgba(255,176,32,0.4)' : this.colors.jointGlow;
|
||||
|
||||
ctx.clearRect(0, 0, width, height);
|
||||
|
||||
if (!keypoints || keypoints.length === 0) return;
|
||||
|
||||
// Draw limbs first (behind joints)
|
||||
ctx.lineWidth = 3;
|
||||
ctx.lineCap = 'round';
|
||||
|
||||
for (const [i, j] of SKELETON_CONNECTIONS) {
|
||||
const kpA = keypoints[i];
|
||||
const kpB = keypoints[j];
|
||||
if (!kpA || !kpB || kpA.confidence < minConf || kpB.confidence < minConf) continue;
|
||||
|
||||
const ax = kpA.x * width, ay = kpA.y * height;
|
||||
const bx = kpB.x * width, by = kpB.y * height;
|
||||
const avgConf = (kpA.confidence + kpB.confidence) / 2;
|
||||
|
||||
// Glow
|
||||
ctx.strokeStyle = this.colors.limbGlow;
|
||||
ctx.lineWidth = 8;
|
||||
ctx.globalAlpha = avgConf * 0.4;
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(ax, ay);
|
||||
ctx.lineTo(bx, by);
|
||||
ctx.stroke();
|
||||
|
||||
// Main line
|
||||
ctx.strokeStyle = limbColor;
|
||||
ctx.lineWidth = 2.5;
|
||||
ctx.globalAlpha = avgConf;
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(ax, ay);
|
||||
ctx.lineTo(bx, by);
|
||||
ctx.stroke();
|
||||
}
|
||||
|
||||
// Draw joints
|
||||
ctx.globalAlpha = 1;
|
||||
for (const kp of keypoints) {
|
||||
if (!kp || kp.confidence < minConf) continue;
|
||||
|
||||
const x = kp.x * width;
|
||||
const y = kp.y * height;
|
||||
const r = 3 + kp.confidence * 3;
|
||||
|
||||
// Glow
|
||||
ctx.beginPath();
|
||||
ctx.arc(x, y, r + 4, 0, Math.PI * 2);
|
||||
ctx.fillStyle = glowColor;
|
||||
ctx.globalAlpha = kp.confidence * 0.6;
|
||||
ctx.fill();
|
||||
|
||||
// Joint dot
|
||||
ctx.beginPath();
|
||||
ctx.arc(x, y, r, 0, Math.PI * 2);
|
||||
ctx.fillStyle = jointColor;
|
||||
ctx.globalAlpha = kp.confidence;
|
||||
ctx.fill();
|
||||
|
||||
// White center
|
||||
ctx.beginPath();
|
||||
ctx.arc(x, y, r * 0.4, 0, Math.PI * 2);
|
||||
ctx.fillStyle = '#fff';
|
||||
ctx.globalAlpha = kp.confidence * 0.8;
|
||||
ctx.fill();
|
||||
}
|
||||
|
||||
ctx.globalAlpha = 1;
|
||||
|
||||
// Confidence label
|
||||
if (opts.label) {
|
||||
ctx.font = '11px "JetBrains Mono", monospace';
|
||||
ctx.fillStyle = jointColor;
|
||||
ctx.globalAlpha = 0.8;
|
||||
ctx.fillText(opts.label, 8, height - 8);
|
||||
ctx.globalAlpha = 1;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw CSI amplitude heatmap
|
||||
* @param {CanvasRenderingContext2D} ctx
|
||||
* @param {{ data: Float32Array, width: number, height: number }} heatmap
|
||||
* @param {number} canvasW
|
||||
* @param {number} canvasH
|
||||
*/
|
||||
drawCsiHeatmap(ctx, heatmap, canvasW, canvasH) {
|
||||
ctx.clearRect(0, 0, canvasW, canvasH);
|
||||
|
||||
if (!heatmap || !heatmap.data || heatmap.height < 2) {
|
||||
ctx.fillStyle = '#0a0e18';
|
||||
ctx.fillRect(0, 0, canvasW, canvasH);
|
||||
ctx.font = '11px "JetBrains Mono", monospace';
|
||||
ctx.fillStyle = 'rgba(255,255,255,0.3)';
|
||||
ctx.fillText('Waiting for CSI data...', 8, canvasH / 2);
|
||||
return;
|
||||
}
|
||||
|
||||
const { data, width: dw, height: dh } = heatmap;
|
||||
const cellW = canvasW / dw;
|
||||
const cellH = canvasH / dh;
|
||||
|
||||
for (let y = 0; y < dh; y++) {
|
||||
for (let x = 0; x < dw; x++) {
|
||||
const val = Math.min(1, Math.max(0, data[y * dw + x]));
|
||||
ctx.fillStyle = this._heatmapColor(val);
|
||||
ctx.fillRect(x * cellW, y * cellH, cellW + 0.5, cellH + 0.5);
|
||||
}
|
||||
}
|
||||
|
||||
// Axis labels
|
||||
ctx.font = '9px "JetBrains Mono", monospace';
|
||||
ctx.fillStyle = 'rgba(255,255,255,0.4)';
|
||||
ctx.fillText('Subcarrier →', 4, canvasH - 4);
|
||||
ctx.save();
|
||||
ctx.translate(canvasW - 4, canvasH - 4);
|
||||
ctx.rotate(-Math.PI / 2);
|
||||
ctx.fillText('Time ↑', 0, 0);
|
||||
ctx.restore();
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw embedding space 2D projection
|
||||
* @param {CanvasRenderingContext2D} ctx
|
||||
* @param {{ video: Array, csi: Array, fused: Array }} points
|
||||
* @param {number} w
|
||||
* @param {number} h
|
||||
*/
|
||||
drawEmbeddingSpace(ctx, points, w, h) {
|
||||
ctx.fillStyle = '#050810';
|
||||
ctx.fillRect(0, 0, w, h);
|
||||
|
||||
// Grid
|
||||
ctx.strokeStyle = 'rgba(255,255,255,0.05)';
|
||||
ctx.lineWidth = 0.5;
|
||||
for (let i = 0; i <= 4; i++) {
|
||||
const x = (i / 4) * w;
|
||||
ctx.beginPath(); ctx.moveTo(x, 0); ctx.lineTo(x, h); ctx.stroke();
|
||||
const y = (i / 4) * h;
|
||||
ctx.beginPath(); ctx.moveTo(0, y); ctx.lineTo(w, y); ctx.stroke();
|
||||
}
|
||||
|
||||
// Axes
|
||||
ctx.strokeStyle = 'rgba(255,255,255,0.1)';
|
||||
ctx.lineWidth = 1;
|
||||
ctx.beginPath(); ctx.moveTo(w / 2, 0); ctx.lineTo(w / 2, h); ctx.stroke();
|
||||
ctx.beginPath(); ctx.moveTo(0, h / 2); ctx.lineTo(w, h / 2); ctx.stroke();
|
||||
|
||||
const drawPoints = (pts, color, size) => {
|
||||
if (!pts || pts.length === 0) return;
|
||||
const len = pts.length;
|
||||
for (let i = 0; i < len; i++) {
|
||||
const p = pts[i];
|
||||
if (!p) continue;
|
||||
const age = 1 - (i / len) * 0.7; // Fade older points
|
||||
const px = w / 2 + p[0] * w * 0.35;
|
||||
const py = h / 2 + p[1] * h * 0.35;
|
||||
|
||||
if (px < 0 || px > w || py < 0 || py > h) continue;
|
||||
|
||||
ctx.beginPath();
|
||||
ctx.arc(px, py, size, 0, Math.PI * 2);
|
||||
ctx.fillStyle = color;
|
||||
ctx.globalAlpha = age * 0.7;
|
||||
ctx.fill();
|
||||
}
|
||||
};
|
||||
|
||||
drawPoints(points.video, this.colors.videoEmb, 3);
|
||||
drawPoints(points.csi, this.colors.csiEmb, 3);
|
||||
drawPoints(points.fused, this.colors.fusedEmb, 4);
|
||||
ctx.globalAlpha = 1;
|
||||
|
||||
// Legend
|
||||
ctx.font = '9px "JetBrains Mono", monospace';
|
||||
const legends = [
|
||||
{ color: this.colors.videoEmb, label: 'Video' },
|
||||
{ color: this.colors.csiEmb, label: 'CSI' },
|
||||
{ color: this.colors.fusedEmb, label: 'Fused' },
|
||||
];
|
||||
legends.forEach((l, i) => {
|
||||
const ly = 12 + i * 14;
|
||||
ctx.fillStyle = l.color;
|
||||
ctx.beginPath();
|
||||
ctx.arc(10, ly - 3, 3, 0, Math.PI * 2);
|
||||
ctx.fill();
|
||||
ctx.fillStyle = 'rgba(255,255,255,0.5)';
|
||||
ctx.fillText(l.label, 18, ly);
|
||||
});
|
||||
}
|
||||
|
||||
_heatmapColor(val) {
|
||||
// Dark blue → cyan → green → yellow → red
|
||||
if (val < 0.25) {
|
||||
const t = val / 0.25;
|
||||
return `rgb(${Math.floor(t * 20)}, ${Math.floor(20 + t * 60)}, ${Math.floor(60 + t * 100)})`;
|
||||
} else if (val < 0.5) {
|
||||
const t = (val - 0.25) / 0.25;
|
||||
return `rgb(${Math.floor(20 + t * 20)}, ${Math.floor(80 + t * 100)}, ${Math.floor(160 - t * 60)})`;
|
||||
} else if (val < 0.75) {
|
||||
const t = (val - 0.5) / 0.25;
|
||||
return `rgb(${Math.floor(40 + t * 180)}, ${Math.floor(180 + t * 75)}, ${Math.floor(100 - t * 80)})`;
|
||||
} else {
|
||||
const t = (val - 0.75) / 0.25;
|
||||
return `rgb(${Math.floor(220 + t * 35)}, ${Math.floor(255 - t * 120)}, ${Math.floor(20 - t * 20)})`;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,226 @@
|
||||
/**
|
||||
* CNN Embedder — Lightweight MobileNet-V3-style feature extractor.
|
||||
*
|
||||
* Architecture mirrors ruvector-cnn: Conv2D → BatchNorm → ReLU → Pool → Project → L2 Normalize
|
||||
* Uses pre-seeded random weights (deterministic). When ruvector-cnn-wasm is available,
|
||||
* transparently delegates to the WASM implementation.
|
||||
*
|
||||
* Two instances are created: one for video frames, one for CSI pseudo-images.
|
||||
*/
|
||||
|
||||
// Seeded PRNG for deterministic weight initialization
|
||||
function mulberry32(seed) {
|
||||
return function() {
|
||||
let t = (seed += 0x6D2B79F5);
|
||||
t = Math.imul(t ^ (t >>> 15), t | 1);
|
||||
t ^= t + Math.imul(t ^ (t >>> 7), t | 61);
|
||||
return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
|
||||
};
|
||||
}
|
||||
|
||||
export class CnnEmbedder {
|
||||
/**
|
||||
* @param {object} opts
|
||||
* @param {number} opts.inputSize - Square input dimension (default 56 for speed)
|
||||
* @param {number} opts.embeddingDim - Output embedding dimension (default 128)
|
||||
* @param {boolean} opts.normalize - L2 normalize output
|
||||
* @param {number} opts.seed - PRNG seed for weight init
|
||||
*/
|
||||
constructor(opts = {}) {
|
||||
this.inputSize = opts.inputSize || 56;
|
||||
this.embeddingDim = opts.embeddingDim || 128;
|
||||
this.normalize = opts.normalize !== false;
|
||||
this.wasmEmbedder = null;
|
||||
|
||||
// Initialize weights with deterministic PRNG
|
||||
const rng = mulberry32(opts.seed || 42);
|
||||
const randRange = (lo, hi) => lo + rng() * (hi - lo);
|
||||
|
||||
// Conv 3x3: 3 input channels → 16 output channels
|
||||
this.convWeights = new Float32Array(3 * 3 * 3 * 16);
|
||||
for (let i = 0; i < this.convWeights.length; i++) {
|
||||
this.convWeights[i] = randRange(-0.15, 0.15);
|
||||
}
|
||||
|
||||
// BatchNorm params (16 channels)
|
||||
this.bnGamma = new Float32Array(16).fill(1.0);
|
||||
this.bnBeta = new Float32Array(16).fill(0.0);
|
||||
this.bnMean = new Float32Array(16).fill(0.0);
|
||||
this.bnVar = new Float32Array(16).fill(1.0);
|
||||
|
||||
// Projection: 16 → embeddingDim
|
||||
this.projWeights = new Float32Array(16 * this.embeddingDim);
|
||||
for (let i = 0; i < this.projWeights.length; i++) {
|
||||
this.projWeights[i] = randRange(-0.1, 0.1);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Try to load WASM embedder from ruvector-cnn-wasm package
|
||||
* @param {string} wasmPath - Path to the WASM package directory
|
||||
*/
|
||||
async tryLoadWasm(wasmPath) {
|
||||
try {
|
||||
const mod = await import(`${wasmPath}/ruvector_cnn_wasm.js`);
|
||||
await mod.default();
|
||||
const config = new mod.EmbedderConfig();
|
||||
config.input_size = this.inputSize;
|
||||
config.embedding_dim = this.embeddingDim;
|
||||
config.normalize = this.normalize;
|
||||
this.wasmEmbedder = new mod.WasmCnnEmbedder(config);
|
||||
console.log('[CNN] WASM embedder loaded successfully');
|
||||
return true;
|
||||
} catch (e) {
|
||||
console.log('[CNN] WASM not available, using JS fallback:', e.message);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract embedding from RGB image data
|
||||
* @param {Uint8Array} rgbData - RGB pixel data (H*W*3)
|
||||
* @param {number} width
|
||||
* @param {number} height
|
||||
* @returns {Float32Array} embedding vector
|
||||
*/
|
||||
extract(rgbData, width, height) {
|
||||
if (this.wasmEmbedder) {
|
||||
try {
|
||||
const result = this.wasmEmbedder.extract(rgbData, width, height);
|
||||
return new Float32Array(result);
|
||||
} catch (_) { /* fallback to JS */ }
|
||||
}
|
||||
return this._extractJS(rgbData, width, height);
|
||||
}
|
||||
|
||||
_extractJS(rgbData, width, height) {
|
||||
// 1. Resize to inputSize × inputSize if needed
|
||||
const sz = this.inputSize;
|
||||
let input;
|
||||
if (width === sz && height === sz) {
|
||||
input = new Float32Array(rgbData.length);
|
||||
for (let i = 0; i < rgbData.length; i++) input[i] = rgbData[i] / 255.0;
|
||||
} else {
|
||||
input = this._resize(rgbData, width, height, sz, sz);
|
||||
}
|
||||
|
||||
// 2. ImageNet normalization
|
||||
const mean = [0.485, 0.456, 0.406];
|
||||
const std = [0.229, 0.224, 0.225];
|
||||
const pixels = sz * sz;
|
||||
for (let i = 0; i < pixels; i++) {
|
||||
input[i * 3] = (input[i * 3] - mean[0]) / std[0];
|
||||
input[i * 3 + 1] = (input[i * 3 + 1] - mean[1]) / std[1];
|
||||
input[i * 3 + 2] = (input[i * 3 + 2] - mean[2]) / std[2];
|
||||
}
|
||||
|
||||
// 3. Conv2D 3x3 (3 → 16 channels)
|
||||
const convOut = this._conv2d3x3(input, sz, sz, 3, 16);
|
||||
|
||||
// 4. BatchNorm
|
||||
this._batchNorm(convOut, 16);
|
||||
|
||||
// 5. ReLU
|
||||
for (let i = 0; i < convOut.length; i++) {
|
||||
if (convOut[i] < 0) convOut[i] = 0;
|
||||
}
|
||||
|
||||
// 6. Global average pooling → 16-dim
|
||||
const outH = sz - 2, outW = sz - 2;
|
||||
const pooled = new Float32Array(16);
|
||||
const spatial = outH * outW;
|
||||
for (let i = 0; i < spatial; i++) {
|
||||
for (let c = 0; c < 16; c++) {
|
||||
pooled[c] += convOut[i * 16 + c];
|
||||
}
|
||||
}
|
||||
for (let c = 0; c < 16; c++) pooled[c] /= spatial;
|
||||
|
||||
// 7. Linear projection → embeddingDim
|
||||
const emb = new Float32Array(this.embeddingDim);
|
||||
for (let o = 0; o < this.embeddingDim; o++) {
|
||||
let sum = 0;
|
||||
for (let i = 0; i < 16; i++) {
|
||||
sum += pooled[i] * this.projWeights[i * this.embeddingDim + o];
|
||||
}
|
||||
emb[o] = sum;
|
||||
}
|
||||
|
||||
// 8. L2 normalize
|
||||
if (this.normalize) {
|
||||
let norm = 0;
|
||||
for (let i = 0; i < emb.length; i++) norm += emb[i] * emb[i];
|
||||
norm = Math.sqrt(norm);
|
||||
if (norm > 1e-8) {
|
||||
for (let i = 0; i < emb.length; i++) emb[i] /= norm;
|
||||
}
|
||||
}
|
||||
|
||||
return emb;
|
||||
}
|
||||
|
||||
_conv2d3x3(input, H, W, Cin, Cout) {
|
||||
const outH = H - 2, outW = W - 2;
|
||||
const output = new Float32Array(outH * outW * Cout);
|
||||
for (let y = 0; y < outH; y++) {
|
||||
for (let x = 0; x < outW; x++) {
|
||||
for (let co = 0; co < Cout; co++) {
|
||||
let sum = 0;
|
||||
for (let ky = 0; ky < 3; ky++) {
|
||||
for (let kx = 0; kx < 3; kx++) {
|
||||
for (let ci = 0; ci < Cin; ci++) {
|
||||
const px = ((y + ky) * W + (x + kx)) * Cin + ci;
|
||||
const wt = (((ky * 3 + kx) * Cin) + ci) * Cout + co;
|
||||
sum += input[px] * this.convWeights[wt];
|
||||
}
|
||||
}
|
||||
}
|
||||
output[(y * outW + x) * Cout + co] = sum;
|
||||
}
|
||||
}
|
||||
}
|
||||
return output;
|
||||
}
|
||||
|
||||
_batchNorm(data, channels) {
|
||||
const spatial = data.length / channels;
|
||||
for (let i = 0; i < spatial; i++) {
|
||||
for (let c = 0; c < channels; c++) {
|
||||
const idx = i * channels + c;
|
||||
data[idx] = this.bnGamma[c] * (data[idx] - this.bnMean[c]) / Math.sqrt(this.bnVar[c] + 1e-5) + this.bnBeta[c];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_resize(rgbData, srcW, srcH, dstW, dstH) {
|
||||
const output = new Float32Array(dstW * dstH * 3);
|
||||
const xRatio = srcW / dstW;
|
||||
const yRatio = srcH / dstH;
|
||||
for (let y = 0; y < dstH; y++) {
|
||||
for (let x = 0; x < dstW; x++) {
|
||||
const sx = Math.min(Math.floor(x * xRatio), srcW - 1);
|
||||
const sy = Math.min(Math.floor(y * yRatio), srcH - 1);
|
||||
const srcIdx = (sy * srcW + sx) * 3;
|
||||
const dstIdx = (y * dstW + x) * 3;
|
||||
output[dstIdx] = rgbData[srcIdx] / 255.0;
|
||||
output[dstIdx + 1] = rgbData[srcIdx + 1] / 255.0;
|
||||
output[dstIdx + 2] = rgbData[srcIdx + 2] / 255.0;
|
||||
}
|
||||
}
|
||||
return output;
|
||||
}
|
||||
|
||||
/** Cosine similarity between two embeddings */
|
||||
static cosineSimilarity(a, b) {
|
||||
let dot = 0, normA = 0, normB = 0;
|
||||
for (let i = 0; i < a.length; i++) {
|
||||
dot += a[i] * b[i];
|
||||
normA += a[i] * a[i];
|
||||
normB += b[i] * b[i];
|
||||
}
|
||||
normA = Math.sqrt(normA);
|
||||
normB = Math.sqrt(normB);
|
||||
if (normA < 1e-8 || normB < 1e-8) return 0;
|
||||
return dot / (normA * normB);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,267 @@
|
||||
/**
|
||||
* CSI Simulator — Generates realistic WiFi Channel State Information data.
|
||||
*
|
||||
* In live mode, connects to the sensing server via WebSocket.
|
||||
* In demo mode, generates synthetic CSI that correlates with detected motion.
|
||||
*
|
||||
* Outputs: 3-channel pseudo-image (amplitude, phase, temporal diff)
|
||||
* matching the ADR-018 frame format expectations.
|
||||
*/
|
||||
|
||||
export class CsiSimulator {
|
||||
constructor(opts = {}) {
|
||||
this.subcarriers = opts.subcarriers || 52; // 802.11n HT20
|
||||
this.timeWindow = opts.timeWindow || 56; // frames in sliding window
|
||||
this.mode = 'demo'; // 'demo' | 'live'
|
||||
this.ws = null;
|
||||
|
||||
// Circular buffer for CSI frames
|
||||
this.amplitudeBuffer = [];
|
||||
this.phaseBuffer = [];
|
||||
this.frameCount = 0;
|
||||
|
||||
// Noise parameters
|
||||
this._rng = this._mulberry32(opts.seed || 7);
|
||||
this._noiseState = new Float32Array(this.subcarriers);
|
||||
this._baseAmplitude = new Float32Array(this.subcarriers);
|
||||
this._basePhase = new Float32Array(this.subcarriers);
|
||||
|
||||
// Initialize base CSI profile (empty room)
|
||||
for (let i = 0; i < this.subcarriers; i++) {
|
||||
this._baseAmplitude[i] = 0.5 + 0.3 * Math.sin(i * 0.12);
|
||||
this._basePhase[i] = (i / this.subcarriers) * Math.PI * 2;
|
||||
}
|
||||
|
||||
// Person influence (updated from video motion)
|
||||
this.personPresence = 0;
|
||||
this.personX = 0.5;
|
||||
this.personY = 0.5;
|
||||
this.personMotion = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Connect to live sensing server WebSocket
|
||||
* @param {string} url - WebSocket URL (e.g. ws://localhost:3030/ws/csi)
|
||||
*/
|
||||
async connectLive(url) {
|
||||
return new Promise((resolve) => {
|
||||
try {
|
||||
this.ws = new WebSocket(url);
|
||||
this.ws.binaryType = 'arraybuffer';
|
||||
this.ws.onmessage = (evt) => this._handleLiveFrame(evt.data);
|
||||
this.ws.onopen = () => { this.mode = 'live'; resolve(true); };
|
||||
this.ws.onerror = () => resolve(false);
|
||||
this.ws.onclose = () => { this.mode = 'demo'; };
|
||||
// Timeout after 3s
|
||||
setTimeout(() => { if (this.mode !== 'live') resolve(false); }, 3000);
|
||||
} catch {
|
||||
resolve(false);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
disconnect() {
|
||||
if (this.ws) { this.ws.close(); this.ws = null; }
|
||||
this.mode = 'demo';
|
||||
}
|
||||
|
||||
get isLive() { return this.mode === 'live'; }
|
||||
|
||||
/**
|
||||
* Update person state from video detection (for correlated demo data).
|
||||
* When person exits frame, CSI maintains presence with slow decay
|
||||
* (simulating through-wall sensing capability).
|
||||
*/
|
||||
updatePersonState(presence, x, y, motion) {
|
||||
if (presence > 0.1) {
|
||||
// Person detected in video — update CSI state directly
|
||||
this.personPresence = presence;
|
||||
this.personX = x;
|
||||
this.personY = y;
|
||||
this.personMotion = motion;
|
||||
this._lastSeenTime = performance.now();
|
||||
this._lastSeenX = x;
|
||||
this._lastSeenY = y;
|
||||
} else if (this._lastSeenTime) {
|
||||
// Person NOT in video — CSI "through-wall" persistence
|
||||
const elapsed = (performance.now() - this._lastSeenTime) / 1000;
|
||||
// CSI can sense through walls for ~10 seconds with decaying confidence
|
||||
const decayRate = 0.15; // Lose ~15% per second
|
||||
this.personPresence = Math.max(0, 1.0 - elapsed * decayRate);
|
||||
// Position slowly drifts (person walking behind wall)
|
||||
this.personX = this._lastSeenX;
|
||||
this.personY = this._lastSeenY;
|
||||
this.personMotion = Math.max(0, motion * 0.5 + this.personPresence * 0.2);
|
||||
|
||||
if (this.personPresence < 0.05) {
|
||||
this._lastSeenTime = null;
|
||||
}
|
||||
} else {
|
||||
this.personPresence = 0;
|
||||
this.personMotion = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate next CSI frame (demo mode) or return latest live frame
|
||||
* @param {number} elapsed - Time in seconds
|
||||
* @returns {{ amplitude: Float32Array, phase: Float32Array, snr: number }}
|
||||
*/
|
||||
nextFrame(elapsed) {
|
||||
const amp = new Float32Array(this.subcarriers);
|
||||
const phase = new Float32Array(this.subcarriers);
|
||||
|
||||
if (this.mode === 'live' && this._liveAmplitude) {
|
||||
amp.set(this._liveAmplitude);
|
||||
phase.set(this._livePhase);
|
||||
} else {
|
||||
this._generateDemoFrame(amp, phase, elapsed);
|
||||
}
|
||||
|
||||
// Push to circular buffer
|
||||
this.amplitudeBuffer.push(new Float32Array(amp));
|
||||
this.phaseBuffer.push(new Float32Array(phase));
|
||||
if (this.amplitudeBuffer.length > this.timeWindow) {
|
||||
this.amplitudeBuffer.shift();
|
||||
this.phaseBuffer.shift();
|
||||
}
|
||||
|
||||
// SNR estimate
|
||||
let signalPower = 0, noisePower = 0;
|
||||
for (let i = 0; i < this.subcarriers; i++) {
|
||||
signalPower += amp[i] * amp[i];
|
||||
noisePower += this._noiseState[i] * this._noiseState[i];
|
||||
}
|
||||
const snr = noisePower > 0 ? 10 * Math.log10(signalPower / noisePower) : 30;
|
||||
|
||||
this.frameCount++;
|
||||
return { amplitude: amp, phase, snr: Math.max(0, Math.min(40, snr)) };
|
||||
}
|
||||
|
||||
/**
|
||||
* Build 3-channel pseudo-image for CNN input
|
||||
* @param {number} targetSize - Output image dimension (square)
|
||||
* @returns {Uint8Array} RGB data (targetSize * targetSize * 3)
|
||||
*/
|
||||
buildPseudoImage(targetSize = 56) {
|
||||
const buf = this.amplitudeBuffer;
|
||||
const pBuf = this.phaseBuffer;
|
||||
const frames = buf.length;
|
||||
if (frames < 2) {
|
||||
return new Uint8Array(targetSize * targetSize * 3);
|
||||
}
|
||||
|
||||
const rgb = new Uint8Array(targetSize * targetSize * 3);
|
||||
|
||||
for (let y = 0; y < targetSize; y++) {
|
||||
const fi = Math.min(Math.floor(y / targetSize * frames), frames - 1);
|
||||
for (let x = 0; x < targetSize; x++) {
|
||||
const si = Math.min(Math.floor(x / targetSize * this.subcarriers), this.subcarriers - 1);
|
||||
const idx = (y * targetSize + x) * 3;
|
||||
|
||||
// R: Amplitude (normalized to 0-255)
|
||||
const ampVal = buf[fi][si];
|
||||
rgb[idx] = Math.min(255, Math.max(0, Math.floor(ampVal * 255)));
|
||||
|
||||
// G: Phase (wrapped to 0-255)
|
||||
const phaseVal = (pBuf[fi][si] % (2 * Math.PI) + 2 * Math.PI) % (2 * Math.PI);
|
||||
rgb[idx + 1] = Math.floor(phaseVal / (2 * Math.PI) * 255);
|
||||
|
||||
// B: Temporal difference
|
||||
if (fi > 0) {
|
||||
const diff = Math.abs(buf[fi][si] - buf[fi - 1][si]);
|
||||
rgb[idx + 2] = Math.min(255, Math.floor(diff * 500));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return rgb;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get heatmap data for visualization
|
||||
* @returns {{ data: Float32Array, width: number, height: number }}
|
||||
*/
|
||||
getHeatmapData() {
|
||||
const frames = this.amplitudeBuffer.length;
|
||||
const w = this.subcarriers;
|
||||
const h = Math.min(frames, this.timeWindow);
|
||||
const data = new Float32Array(w * h);
|
||||
for (let y = 0; y < h; y++) {
|
||||
const fi = frames - h + y;
|
||||
if (fi >= 0 && fi < frames) {
|
||||
for (let x = 0; x < w; x++) {
|
||||
data[y * w + x] = this.amplitudeBuffer[fi][x];
|
||||
}
|
||||
}
|
||||
}
|
||||
return { data, width: w, height: h };
|
||||
}
|
||||
|
||||
// === Private ===
|
||||
|
||||
_generateDemoFrame(amp, phase, elapsed) {
|
||||
const rng = this._rng;
|
||||
const presence = this.personPresence;
|
||||
const motion = this.personMotion;
|
||||
const px = this.personX;
|
||||
|
||||
for (let i = 0; i < this.subcarriers; i++) {
|
||||
// Base CSI profile (frequency-selective channel)
|
||||
let a = this._baseAmplitude[i];
|
||||
let p = this._basePhase[i] + elapsed * 0.05;
|
||||
|
||||
// Environmental noise (correlated across subcarriers)
|
||||
this._noiseState[i] = 0.95 * this._noiseState[i] + 0.05 * (rng() * 2 - 1) * 0.03;
|
||||
a += this._noiseState[i];
|
||||
|
||||
// Person-induced CSI perturbation
|
||||
if (presence > 0.1) {
|
||||
// Subcarrier-dependent body reflection (Fresnel zone model)
|
||||
const freqOffset = (i - this.subcarriers * px) / (this.subcarriers * 0.3);
|
||||
const bodyReflection = presence * 0.25 * Math.exp(-freqOffset * freqOffset);
|
||||
|
||||
// Motion causes amplitude fluctuation
|
||||
const motionEffect = motion * 0.15 * Math.sin(elapsed * 3.5 + i * 0.3);
|
||||
|
||||
// Breathing modulation (0.2-0.3 Hz)
|
||||
const breathing = presence * 0.02 * Math.sin(elapsed * 1.5 + i * 0.05);
|
||||
|
||||
a += bodyReflection + motionEffect + breathing;
|
||||
p += presence * 0.4 * Math.sin(elapsed * 2.1 + i * 0.15);
|
||||
}
|
||||
|
||||
amp[i] = Math.max(0, Math.min(1, a));
|
||||
phase[i] = p;
|
||||
}
|
||||
}
|
||||
|
||||
_handleLiveFrame(data) {
|
||||
const view = new DataView(data);
|
||||
// Check ADR-018 magic: 0xC5110001
|
||||
if (data.byteLength < 20) return;
|
||||
const magic = view.getUint32(0, true);
|
||||
if (magic !== 0xC5110001) return;
|
||||
|
||||
const numSub = Math.min(view.getUint16(8, true), this.subcarriers);
|
||||
this._liveAmplitude = new Float32Array(this.subcarriers);
|
||||
this._livePhase = new Float32Array(this.subcarriers);
|
||||
|
||||
const headerSize = 20;
|
||||
for (let i = 0; i < numSub && (headerSize + i * 4 + 3) < data.byteLength; i++) {
|
||||
const real = view.getInt16(headerSize + i * 4, true);
|
||||
const imag = view.getInt16(headerSize + i * 4 + 2, true);
|
||||
this._liveAmplitude[i] = Math.sqrt(real * real + imag * imag) / 2048;
|
||||
this._livePhase[i] = Math.atan2(imag, real);
|
||||
}
|
||||
}
|
||||
|
||||
_mulberry32(seed) {
|
||||
return function() {
|
||||
let t = (seed += 0x6D2B79F5);
|
||||
t = Math.imul(t ^ (t >>> 15), t | 1);
|
||||
t ^= t + Math.imul(t ^ (t >>> 7), t | 61);
|
||||
return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,166 @@
|
||||
/**
|
||||
* FusionEngine — Attention-weighted dual-modal embedding fusion.
|
||||
*
|
||||
* Combines visual (camera) and CSI (WiFi) embeddings with dynamic
|
||||
* confidence gating based on signal quality.
|
||||
*/
|
||||
|
||||
export class FusionEngine {
|
||||
/**
|
||||
* @param {number} embeddingDim
|
||||
*/
|
||||
constructor(embeddingDim = 128) {
|
||||
this.embeddingDim = embeddingDim;
|
||||
|
||||
// Learnable attention weights (initialized to balanced 0.5)
|
||||
// In production, these would be loaded from trained JSON
|
||||
this.attentionWeights = new Float32Array(embeddingDim).fill(0.5);
|
||||
|
||||
// Dynamic modality confidence [0, 1]
|
||||
this.videoConfidence = 1.0;
|
||||
this.csiConfidence = 0.0;
|
||||
this.fusedConfidence = 0.5;
|
||||
|
||||
// Smoothing for confidence transitions
|
||||
this._smoothAlpha = 0.85;
|
||||
|
||||
// Embedding history for visualization
|
||||
this.recentVideoEmbeddings = [];
|
||||
this.recentCsiEmbeddings = [];
|
||||
this.recentFusedEmbeddings = [];
|
||||
this.maxHistory = 50;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update quality-based confidence scores
|
||||
* @param {number} videoBrightness - [0,1] video brightness quality
|
||||
* @param {number} videoMotion - [0,1] motion detected
|
||||
* @param {number} csiSnr - CSI signal-to-noise ratio in dB
|
||||
* @param {boolean} csiActive - Whether CSI source is connected
|
||||
*/
|
||||
updateConfidence(videoBrightness, videoMotion, csiSnr, csiActive) {
|
||||
// Video confidence: drops with low brightness, boosted by motion
|
||||
let vc = 0;
|
||||
if (videoBrightness > 0.05) {
|
||||
vc = Math.min(1, videoBrightness * 1.5) * 0.7 + Math.min(1, videoMotion * 3) * 0.3;
|
||||
}
|
||||
|
||||
// CSI confidence: based on SNR and connection status
|
||||
let cc = 0;
|
||||
if (csiActive) {
|
||||
cc = Math.min(1, csiSnr / 25); // 25dB = full confidence
|
||||
}
|
||||
|
||||
// Smooth transitions
|
||||
this.videoConfidence = this._smoothAlpha * this.videoConfidence + (1 - this._smoothAlpha) * vc;
|
||||
this.csiConfidence = this._smoothAlpha * this.csiConfidence + (1 - this._smoothAlpha) * cc;
|
||||
|
||||
// Fused confidence is the max of either (fusion can only help)
|
||||
this.fusedConfidence = Math.min(1, Math.sqrt(
|
||||
this.videoConfidence * this.videoConfidence + this.csiConfidence * this.csiConfidence
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Fuse video and CSI embeddings
|
||||
* @param {Float32Array|null} videoEmb - Visual embedding (or null if video-off)
|
||||
* @param {Float32Array|null} csiEmb - CSI embedding (or null if CSI-off)
|
||||
* @param {string} mode - 'dual' | 'video' | 'csi'
|
||||
* @returns {Float32Array} Fused embedding
|
||||
*/
|
||||
fuse(videoEmb, csiEmb, mode = 'dual') {
|
||||
const dim = this.embeddingDim;
|
||||
const fused = new Float32Array(dim);
|
||||
|
||||
if (mode === 'video' || !csiEmb) {
|
||||
if (videoEmb) fused.set(videoEmb);
|
||||
this._recordEmbedding(videoEmb, null, fused);
|
||||
return fused;
|
||||
}
|
||||
|
||||
if (mode === 'csi' || !videoEmb) {
|
||||
if (csiEmb) fused.set(csiEmb);
|
||||
this._recordEmbedding(null, csiEmb, fused);
|
||||
return fused;
|
||||
}
|
||||
|
||||
// Dual mode: attention-weighted fusion with confidence gating
|
||||
const totalConf = this.videoConfidence + this.csiConfidence;
|
||||
const videoWeight = totalConf > 0 ? this.videoConfidence / totalConf : 0.5;
|
||||
|
||||
for (let i = 0; i < dim; i++) {
|
||||
const alpha = this.attentionWeights[i] * videoWeight +
|
||||
(1 - this.attentionWeights[i]) * (1 - videoWeight);
|
||||
fused[i] = alpha * videoEmb[i] + (1 - alpha) * csiEmb[i];
|
||||
}
|
||||
|
||||
// Re-normalize
|
||||
let norm = 0;
|
||||
for (let i = 0; i < dim; i++) norm += fused[i] * fused[i];
|
||||
norm = Math.sqrt(norm);
|
||||
if (norm > 1e-8) {
|
||||
for (let i = 0; i < dim; i++) fused[i] /= norm;
|
||||
}
|
||||
|
||||
this._recordEmbedding(videoEmb, csiEmb, fused);
|
||||
return fused;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get embedding pairs for 2D visualization (PCA projection)
|
||||
* @returns {{ video: Array, csi: Array, fused: Array }}
|
||||
*/
|
||||
getEmbeddingPoints() {
|
||||
// Simple 2D projection using first two principal components (approximated)
|
||||
const project = (emb) => {
|
||||
if (!emb || emb.length < 4) return null;
|
||||
// Use pairs of dimensions as crude 2D projection
|
||||
let x = 0, y = 0;
|
||||
for (let i = 0; i < emb.length; i += 2) {
|
||||
x += emb[i] * (i % 4 < 2 ? 1 : -1);
|
||||
if (i + 1 < emb.length) {
|
||||
y += emb[i + 1] * (i % 4 < 2 ? 1 : -1);
|
||||
}
|
||||
}
|
||||
return [x * 2, y * 2]; // Scale for visibility
|
||||
};
|
||||
|
||||
return {
|
||||
video: this.recentVideoEmbeddings.map(project).filter(Boolean),
|
||||
csi: this.recentCsiEmbeddings.map(project).filter(Boolean),
|
||||
fused: this.recentFusedEmbeddings.map(project).filter(Boolean)
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Cross-modal similarity score
|
||||
* @returns {number} Cosine similarity between latest video and CSI embeddings
|
||||
*/
|
||||
getCrossModalSimilarity() {
|
||||
const v = this.recentVideoEmbeddings[this.recentVideoEmbeddings.length - 1];
|
||||
const c = this.recentCsiEmbeddings[this.recentCsiEmbeddings.length - 1];
|
||||
if (!v || !c) return 0;
|
||||
|
||||
let dot = 0, na = 0, nb = 0;
|
||||
for (let i = 0; i < v.length; i++) {
|
||||
dot += v[i] * c[i];
|
||||
na += v[i] * v[i];
|
||||
nb += c[i] * c[i];
|
||||
}
|
||||
na = Math.sqrt(na); nb = Math.sqrt(nb);
|
||||
return (na > 1e-8 && nb > 1e-8) ? dot / (na * nb) : 0;
|
||||
}
|
||||
|
||||
_recordEmbedding(video, csi, fused) {
|
||||
if (video) {
|
||||
this.recentVideoEmbeddings.push(new Float32Array(video));
|
||||
if (this.recentVideoEmbeddings.length > this.maxHistory) this.recentVideoEmbeddings.shift();
|
||||
}
|
||||
if (csi) {
|
||||
this.recentCsiEmbeddings.push(new Float32Array(csi));
|
||||
if (this.recentCsiEmbeddings.length > this.maxHistory) this.recentCsiEmbeddings.shift();
|
||||
}
|
||||
this.recentFusedEmbeddings.push(new Float32Array(fused));
|
||||
if (this.recentFusedEmbeddings.length > this.maxHistory) this.recentFusedEmbeddings.shift();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,315 @@
|
||||
/**
|
||||
* WiFi-DensePose — Dual-Modal Pose Estimation Demo
|
||||
*
|
||||
* Main orchestration: video capture → CNN embedding → CSI processing → fusion → rendering
|
||||
*/
|
||||
|
||||
import { VideoCapture } from './video-capture.js';
|
||||
import { CsiSimulator } from './csi-simulator.js';
|
||||
import { CnnEmbedder } from './cnn-embedder.js';
|
||||
import { FusionEngine } from './fusion-engine.js';
|
||||
import { PoseDecoder } from './pose-decoder.js';
|
||||
import { CanvasRenderer } from './canvas-renderer.js';
|
||||
|
||||
// === State ===
|
||||
let mode = 'dual'; // 'dual' | 'video' | 'csi'
|
||||
let isRunning = false;
|
||||
let isPaused = false;
|
||||
let startTime = 0;
|
||||
let frameCount = 0;
|
||||
let fps = 0;
|
||||
let lastFpsTime = 0;
|
||||
let confidenceThreshold = 0.3;
|
||||
|
||||
// Latency tracking
|
||||
const latency = { video: 0, csi: 0, fusion: 0, total: 0 };
|
||||
|
||||
// === Components ===
|
||||
const videoCapture = new VideoCapture(document.getElementById('webcam'));
|
||||
const csiSimulator = new CsiSimulator({ subcarriers: 52, timeWindow: 56 });
|
||||
const visualCnn = new CnnEmbedder({ inputSize: 56, embeddingDim: 128, seed: 42 });
|
||||
const csiCnn = new CnnEmbedder({ inputSize: 56, embeddingDim: 128, seed: 137 });
|
||||
const fusionEngine = new FusionEngine(128);
|
||||
const poseDecoder = new PoseDecoder(128);
|
||||
const renderer = new CanvasRenderer();
|
||||
|
||||
// === Canvas Elements ===
|
||||
const skeletonCanvas = document.getElementById('skeleton-canvas');
|
||||
const skeletonCtx = skeletonCanvas.getContext('2d');
|
||||
const csiCanvas = document.getElementById('csi-canvas');
|
||||
const csiCtx = csiCanvas.getContext('2d');
|
||||
const embeddingCanvas = document.getElementById('embedding-canvas');
|
||||
const embeddingCtx = embeddingCanvas.getContext('2d');
|
||||
|
||||
// === UI Elements ===
|
||||
const modeSelect = document.getElementById('mode-select');
|
||||
const statusDot = document.getElementById('status-dot');
|
||||
const statusLabel = document.getElementById('status-label');
|
||||
const fpsDisplay = document.getElementById('fps-display');
|
||||
const cameraPrompt = document.getElementById('camera-prompt');
|
||||
const startCameraBtn = document.getElementById('start-camera-btn');
|
||||
const pauseBtn = document.getElementById('pause-btn');
|
||||
const confSlider = document.getElementById('confidence-slider');
|
||||
const confValue = document.getElementById('confidence-value');
|
||||
const wsUrlInput = document.getElementById('ws-url');
|
||||
const connectWsBtn = document.getElementById('connect-ws-btn');
|
||||
|
||||
// Fusion bar elements
|
||||
const videoBar = document.getElementById('video-bar');
|
||||
const csiBar = document.getElementById('csi-bar');
|
||||
const fusedBar = document.getElementById('fused-bar');
|
||||
const videoBarVal = document.getElementById('video-bar-val');
|
||||
const csiBarVal = document.getElementById('csi-bar-val');
|
||||
const fusedBarVal = document.getElementById('fused-bar-val');
|
||||
|
||||
// Latency elements
|
||||
const latVideoEl = document.getElementById('lat-video');
|
||||
const latCsiEl = document.getElementById('lat-csi');
|
||||
const latFusionEl = document.getElementById('lat-fusion');
|
||||
const latTotalEl = document.getElementById('lat-total');
|
||||
|
||||
// Cross-modal similarity
|
||||
const crossModalEl = document.getElementById('cross-modal-sim');
|
||||
|
||||
// === Initialize ===
|
||||
function init() {
|
||||
resizeCanvases();
|
||||
window.addEventListener('resize', resizeCanvases);
|
||||
|
||||
// Mode change
|
||||
modeSelect.addEventListener('change', (e) => {
|
||||
mode = e.target.value;
|
||||
updateModeUI();
|
||||
});
|
||||
|
||||
// Camera start
|
||||
startCameraBtn.addEventListener('click', startCamera);
|
||||
|
||||
// Pause
|
||||
pauseBtn.addEventListener('click', () => {
|
||||
isPaused = !isPaused;
|
||||
pauseBtn.textContent = isPaused ? '▶ Resume' : '⏸ Pause';
|
||||
pauseBtn.classList.toggle('active', isPaused);
|
||||
});
|
||||
|
||||
// Confidence slider
|
||||
confSlider.addEventListener('input', (e) => {
|
||||
confidenceThreshold = parseFloat(e.target.value);
|
||||
confValue.textContent = confidenceThreshold.toFixed(2);
|
||||
});
|
||||
|
||||
// WebSocket connect
|
||||
connectWsBtn.addEventListener('click', async () => {
|
||||
const url = wsUrlInput.value.trim();
|
||||
if (!url) return;
|
||||
connectWsBtn.textContent = 'Connecting...';
|
||||
const ok = await csiSimulator.connectLive(url);
|
||||
connectWsBtn.textContent = ok ? '✓ Connected' : 'Connect';
|
||||
if (ok) {
|
||||
connectWsBtn.classList.add('active');
|
||||
}
|
||||
});
|
||||
|
||||
// Try to load WASM embedders (non-blocking)
|
||||
// Resolve relative to this JS module file (in pose-fusion/js/) → ../pkg/
|
||||
const wasmBase = new URL('../pkg/ruvector_cnn_wasm', import.meta.url).href;
|
||||
visualCnn.tryLoadWasm(wasmBase);
|
||||
csiCnn.tryLoadWasm(wasmBase);
|
||||
|
||||
// Auto-connect to local sensing server WebSocket if available
|
||||
const defaultWsUrl = 'ws://localhost:8765/ws/sensing';
|
||||
if (wsUrlInput) wsUrlInput.value = defaultWsUrl;
|
||||
csiSimulator.connectLive(defaultWsUrl).then(ok => {
|
||||
if (ok && connectWsBtn) {
|
||||
connectWsBtn.textContent = '✓ Live ESP32';
|
||||
connectWsBtn.classList.add('active');
|
||||
statusLabel.textContent = 'LIVE CSI';
|
||||
statusDot.classList.remove('offline');
|
||||
}
|
||||
});
|
||||
|
||||
// Auto-start camera for video/dual modes
|
||||
updateModeUI();
|
||||
startTime = performance.now() / 1000;
|
||||
isRunning = true;
|
||||
requestAnimationFrame(mainLoop);
|
||||
}
|
||||
|
||||
async function startCamera() {
|
||||
cameraPrompt.style.display = 'none';
|
||||
const ok = await videoCapture.start();
|
||||
if (ok) {
|
||||
statusDot.classList.remove('offline');
|
||||
statusLabel.textContent = 'LIVE';
|
||||
resizeCanvases();
|
||||
} else {
|
||||
cameraPrompt.style.display = 'flex';
|
||||
cameraPrompt.querySelector('p').textContent = 'Camera access denied. Try CSI-only mode.';
|
||||
}
|
||||
}
|
||||
|
||||
function updateModeUI() {
|
||||
const needsVideo = mode !== 'csi';
|
||||
const needsCsi = mode !== 'video';
|
||||
|
||||
// Show/hide camera prompt
|
||||
if (needsVideo && !videoCapture.isActive) {
|
||||
cameraPrompt.style.display = 'flex';
|
||||
} else {
|
||||
cameraPrompt.style.display = 'none';
|
||||
}
|
||||
}
|
||||
|
||||
function resizeCanvases() {
|
||||
const videoPanel = document.querySelector('.video-panel');
|
||||
if (videoPanel) {
|
||||
const rect = videoPanel.getBoundingClientRect();
|
||||
skeletonCanvas.width = rect.width;
|
||||
skeletonCanvas.height = rect.height;
|
||||
}
|
||||
|
||||
// CSI canvas
|
||||
csiCanvas.width = csiCanvas.parentElement.clientWidth;
|
||||
csiCanvas.height = 120;
|
||||
|
||||
// Embedding canvas
|
||||
embeddingCanvas.width = embeddingCanvas.parentElement.clientWidth;
|
||||
embeddingCanvas.height = 140;
|
||||
}
|
||||
|
||||
// === Main Loop ===
|
||||
function mainLoop(timestamp) {
|
||||
if (!isRunning) return;
|
||||
requestAnimationFrame(mainLoop);
|
||||
|
||||
if (isPaused) return;
|
||||
|
||||
const elapsed = performance.now() / 1000 - startTime;
|
||||
const totalStart = performance.now();
|
||||
|
||||
// --- Video Pipeline ---
|
||||
let videoEmb = null;
|
||||
let motionRegion = null;
|
||||
if (mode !== 'csi' && videoCapture.isActive) {
|
||||
const t0 = performance.now();
|
||||
const frame = videoCapture.captureFrame(56, 56);
|
||||
if (frame) {
|
||||
videoEmb = visualCnn.extract(frame.rgb, frame.width, frame.height);
|
||||
motionRegion = videoCapture.detectMotionRegion(56, 56);
|
||||
|
||||
// Feed motion to CSI simulator for correlated demo data
|
||||
// When detected=false, CSI simulator handles through-wall persistence
|
||||
csiSimulator.updatePersonState(
|
||||
motionRegion.detected ? 1.0 : 0,
|
||||
motionRegion.detected ? motionRegion.x + motionRegion.w / 2 : 0.5,
|
||||
motionRegion.detected ? motionRegion.y + motionRegion.h / 2 : 0.5,
|
||||
frame.motion
|
||||
);
|
||||
|
||||
fusionEngine.updateConfidence(
|
||||
frame.brightness, frame.motion,
|
||||
0, csiSimulator.isLive || mode === 'dual'
|
||||
);
|
||||
}
|
||||
latency.video = performance.now() - t0;
|
||||
}
|
||||
|
||||
// --- CSI Pipeline ---
|
||||
let csiEmb = null;
|
||||
if (mode !== 'video') {
|
||||
const t0 = performance.now();
|
||||
const csiFrame = csiSimulator.nextFrame(elapsed);
|
||||
const pseudoImage = csiSimulator.buildPseudoImage(56);
|
||||
csiEmb = csiCnn.extract(pseudoImage, 56, 56);
|
||||
|
||||
fusionEngine.updateConfidence(
|
||||
videoCapture.brightnessScore,
|
||||
videoCapture.motionScore,
|
||||
csiFrame.snr,
|
||||
true
|
||||
);
|
||||
|
||||
// Draw CSI heatmap
|
||||
const heatmap = csiSimulator.getHeatmapData();
|
||||
renderer.drawCsiHeatmap(csiCtx, heatmap, csiCanvas.width, csiCanvas.height);
|
||||
|
||||
latency.csi = performance.now() - t0;
|
||||
}
|
||||
|
||||
// --- Fusion ---
|
||||
const t0f = performance.now();
|
||||
const fusedEmb = fusionEngine.fuse(videoEmb, csiEmb, mode);
|
||||
latency.fusion = performance.now() - t0f;
|
||||
|
||||
// --- Pose Decode ---
|
||||
// For CSI-only mode, generate a synthetic motion region from CSI energy
|
||||
if (mode === 'csi' && (!motionRegion || !motionRegion.detected)) {
|
||||
const csiPresence = csiSimulator.personPresence;
|
||||
if (csiPresence > 0.1) {
|
||||
motionRegion = {
|
||||
detected: true,
|
||||
x: 0.25, y: 0.15, w: 0.5, h: 0.7,
|
||||
coverage: csiPresence,
|
||||
motionGrid: null,
|
||||
gridCols: 10,
|
||||
gridRows: 8
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
// CSI state for through-wall tracking
|
||||
const csiState = {
|
||||
csiPresence: csiSimulator.personPresence,
|
||||
isLive: csiSimulator.isLive
|
||||
};
|
||||
|
||||
const keypoints = poseDecoder.decode(fusedEmb, motionRegion, elapsed, csiState);
|
||||
|
||||
// --- Render Skeleton ---
|
||||
const labelMap = { dual: 'DUAL FUSION', video: 'VIDEO ONLY', csi: 'CSI ONLY' };
|
||||
renderer.drawSkeleton(skeletonCtx, keypoints, skeletonCanvas.width, skeletonCanvas.height, {
|
||||
minConfidence: confidenceThreshold,
|
||||
color: mode === 'csi' ? 'amber' : 'green',
|
||||
label: labelMap[mode]
|
||||
});
|
||||
|
||||
// --- Render Embedding Space ---
|
||||
const embPoints = fusionEngine.getEmbeddingPoints();
|
||||
renderer.drawEmbeddingSpace(embeddingCtx, embPoints, embeddingCanvas.width, embeddingCanvas.height);
|
||||
|
||||
// --- Update UI ---
|
||||
latency.total = performance.now() - totalStart;
|
||||
|
||||
// FPS
|
||||
frameCount++;
|
||||
if (timestamp - lastFpsTime > 500) {
|
||||
fps = Math.round(frameCount * 1000 / (timestamp - lastFpsTime));
|
||||
lastFpsTime = timestamp;
|
||||
frameCount = 0;
|
||||
fpsDisplay.textContent = `${fps} FPS`;
|
||||
}
|
||||
|
||||
// Fusion bars
|
||||
const vc = fusionEngine.videoConfidence;
|
||||
const cc = fusionEngine.csiConfidence;
|
||||
const fc = fusionEngine.fusedConfidence;
|
||||
videoBar.style.width = `${vc * 100}%`;
|
||||
csiBar.style.width = `${cc * 100}%`;
|
||||
fusedBar.style.width = `${fc * 100}%`;
|
||||
videoBarVal.textContent = `${Math.round(vc * 100)}%`;
|
||||
csiBarVal.textContent = `${Math.round(cc * 100)}%`;
|
||||
fusedBarVal.textContent = `${Math.round(fc * 100)}%`;
|
||||
|
||||
// Latency
|
||||
latVideoEl.textContent = `${latency.video.toFixed(1)}ms`;
|
||||
latCsiEl.textContent = `${latency.csi.toFixed(1)}ms`;
|
||||
latFusionEl.textContent = `${latency.fusion.toFixed(1)}ms`;
|
||||
latTotalEl.textContent = `${latency.total.toFixed(1)}ms`;
|
||||
|
||||
// Cross-modal similarity
|
||||
const sim = fusionEngine.getCrossModalSimilarity();
|
||||
crossModalEl.textContent = sim.toFixed(3);
|
||||
}
|
||||
|
||||
// Boot
|
||||
document.addEventListener('DOMContentLoaded', init);
|
||||
@@ -0,0 +1,373 @@
|
||||
/**
|
||||
* PoseDecoder — Maps motion detection grid → 17 COCO keypoints.
|
||||
*
|
||||
* Uses per-cell motion intensity to track actual body part positions:
|
||||
* - Head: top-center motion cluster
|
||||
* - Shoulders/Elbows/Wrists: lateral motion in upper body zone
|
||||
* - Hips/Knees/Ankles: lower body motion distribution
|
||||
*
|
||||
* When person exits frame, CSI data continues tracking (through-wall mode).
|
||||
*/
|
||||
|
||||
// COCO keypoint definitions
|
||||
export const KEYPOINT_NAMES = [
|
||||
'nose', 'left_eye', 'right_eye', 'left_ear', 'right_ear',
|
||||
'left_shoulder', 'right_shoulder', 'left_elbow', 'right_elbow',
|
||||
'left_wrist', 'right_wrist', 'left_hip', 'right_hip',
|
||||
'left_knee', 'right_knee', 'left_ankle', 'right_ankle'
|
||||
];
|
||||
|
||||
// Skeleton connections (pairs of keypoint indices)
|
||||
export const SKELETON_CONNECTIONS = [
|
||||
[0, 1], [0, 2], [1, 3], [2, 4], // Head
|
||||
[5, 6], // Shoulders
|
||||
[5, 7], [7, 9], // Left arm
|
||||
[6, 8], [8, 10], // Right arm
|
||||
[5, 11], [6, 12], // Torso
|
||||
[11, 12], // Hips
|
||||
[11, 13], [13, 15], // Left leg
|
||||
[12, 14], [14, 16], // Right leg
|
||||
];
|
||||
|
||||
// Standard body proportions (relative to body height)
|
||||
const PROPORTIONS = {
|
||||
headToShoulder: 0.15,
|
||||
shoulderWidth: 0.25,
|
||||
shoulderToElbow: 0.18,
|
||||
elbowToWrist: 0.16,
|
||||
shoulderToHip: 0.30,
|
||||
hipWidth: 0.18,
|
||||
hipToKnee: 0.24,
|
||||
kneeToAnkle: 0.24,
|
||||
eyeSpacing: 0.04,
|
||||
earSpacing: 0.07,
|
||||
};
|
||||
|
||||
export class PoseDecoder {
|
||||
constructor(embeddingDim = 128) {
|
||||
this.embeddingDim = embeddingDim;
|
||||
this.smoothedKeypoints = null;
|
||||
this.smoothingFactor = 0.45; // Lower = more responsive to movement
|
||||
this._time = 0;
|
||||
|
||||
// Through-wall tracking state
|
||||
this._lastBodyState = null;
|
||||
this._ghostState = null;
|
||||
this._ghostConfidence = 0;
|
||||
this._ghostVelocity = { x: 0, y: 0 };
|
||||
|
||||
// Arm tracking history (smoothed positions)
|
||||
this._leftArmY = 0.5;
|
||||
this._rightArmY = 0.5;
|
||||
this._leftArmX = 0;
|
||||
this._rightArmX = 0;
|
||||
this._headOffsetX = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Decode motion data into 17 keypoints
|
||||
* @param {Float32Array} embedding - Fused embedding vector
|
||||
* @param {{ detected, x, y, w, h, motionGrid, gridCols, gridRows, motionCx, motionCy, exitDirection }} motionRegion
|
||||
* @param {number} elapsed - Time in seconds
|
||||
* @param {{ csiPresence: number }} csiState - CSI sensing state for through-wall
|
||||
* @returns {Array<{x: number, y: number, confidence: number, name: string}>}
|
||||
*/
|
||||
decode(embedding, motionRegion, elapsed, csiState = {}) {
|
||||
this._time = elapsed;
|
||||
|
||||
const hasMotion = motionRegion && motionRegion.detected;
|
||||
const hasCsi = csiState && csiState.csiPresence > 0.1;
|
||||
|
||||
if (hasMotion) {
|
||||
// Active tracking from video motion grid
|
||||
this._ghostConfidence = 0;
|
||||
const rawKeypoints = this._trackFromMotionGrid(motionRegion, embedding, elapsed);
|
||||
this._lastBodyState = { keypoints: rawKeypoints.map(kp => ({...kp})), time: elapsed };
|
||||
|
||||
// Track exit velocity
|
||||
if (motionRegion.exitDirection) {
|
||||
const speed = 0.008;
|
||||
this._ghostVelocity = {
|
||||
x: motionRegion.exitDirection === 'left' ? -speed : motionRegion.exitDirection === 'right' ? speed : 0,
|
||||
y: motionRegion.exitDirection === 'up' ? -speed : motionRegion.exitDirection === 'down' ? speed : 0
|
||||
};
|
||||
}
|
||||
|
||||
// Apply temporal smoothing
|
||||
if (this.smoothedKeypoints && this.smoothedKeypoints.length === rawKeypoints.length) {
|
||||
const alpha = this.smoothingFactor;
|
||||
for (let i = 0; i < rawKeypoints.length; i++) {
|
||||
rawKeypoints[i].x = alpha * this.smoothedKeypoints[i].x + (1 - alpha) * rawKeypoints[i].x;
|
||||
rawKeypoints[i].y = alpha * this.smoothedKeypoints[i].y + (1 - alpha) * rawKeypoints[i].y;
|
||||
}
|
||||
}
|
||||
|
||||
this.smoothedKeypoints = rawKeypoints;
|
||||
return rawKeypoints;
|
||||
|
||||
} else if (this._lastBodyState && (hasCsi || this._ghostConfidence > 0.05)) {
|
||||
// Through-wall mode: person left frame but CSI still senses them
|
||||
return this._trackThroughWall(elapsed, csiState);
|
||||
|
||||
} else if (this.smoothedKeypoints) {
|
||||
// Fade out
|
||||
const faded = this.smoothedKeypoints.map(kp => ({
|
||||
...kp,
|
||||
confidence: kp.confidence * 0.88
|
||||
})).filter(kp => kp.confidence > 0.05);
|
||||
if (faded.length === 0) this.smoothedKeypoints = null;
|
||||
else this.smoothedKeypoints = faded;
|
||||
return faded;
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Track body parts from the motion grid.
|
||||
* The grid tells us WHERE motion is happening → we map that to joint positions.
|
||||
*/
|
||||
_trackFromMotionGrid(region, embedding, elapsed) {
|
||||
const grid = region.motionGrid;
|
||||
const cols = region.gridCols || 10;
|
||||
const rows = region.gridRows || 8;
|
||||
|
||||
// Body bounding box
|
||||
const cx = region.x + region.w / 2;
|
||||
const cy = region.y + region.h / 2;
|
||||
const bodyH = Math.max(region.h, 0.3);
|
||||
const bodyW = Math.max(region.w, 0.15);
|
||||
|
||||
// Analyze the motion grid to find arm positions
|
||||
// Divide body into zones: head (top 20%), arms (top 60% sides), torso (center), legs (bottom 40%)
|
||||
if (grid) {
|
||||
const armAnalysis = this._analyzeArmMotion(grid, cols, rows, region);
|
||||
// Smooth arm tracking
|
||||
this._leftArmY = 0.6 * this._leftArmY + 0.4 * armAnalysis.leftArmHeight;
|
||||
this._rightArmY = 0.6 * this._rightArmY + 0.4 * armAnalysis.rightArmHeight;
|
||||
this._leftArmX = 0.6 * this._leftArmX + 0.4 * armAnalysis.leftArmSpread;
|
||||
this._rightArmX = 0.6 * this._rightArmX + 0.4 * armAnalysis.rightArmSpread;
|
||||
this._headOffsetX = 0.7 * this._headOffsetX + 0.3 * armAnalysis.headOffsetX;
|
||||
}
|
||||
|
||||
const P = PROPORTIONS;
|
||||
const halfW = P.shoulderWidth * bodyH / 2;
|
||||
const hipHalfW = P.hipWidth * bodyH / 2;
|
||||
|
||||
// Breathing (subtle)
|
||||
const breathe = Math.sin(elapsed * 1.5) * 0.002;
|
||||
|
||||
// Core body positions from detection center
|
||||
const hipY = cy + bodyH * 0.15;
|
||||
const shoulderY = hipY - P.shoulderToHip * bodyH + breathe;
|
||||
const headY = shoulderY - P.headToShoulder * bodyH;
|
||||
const kneeY = hipY + P.hipToKnee * bodyH;
|
||||
const ankleY = kneeY + P.kneeToAnkle * bodyH;
|
||||
|
||||
// HEAD follows motion centroid
|
||||
const headX = cx + this._headOffsetX * bodyW * 0.3;
|
||||
|
||||
// ARM POSITIONS driven by motion grid analysis
|
||||
// leftArmY: 0 = arm down at side, 1 = arm fully raised
|
||||
// leftArmSpread: how far out the arm extends
|
||||
const leftArmRaise = this._leftArmY; // 0-1
|
||||
const rightArmRaise = this._rightArmY;
|
||||
const leftSpread = 0.02 + this._leftArmX * 0.12;
|
||||
const rightSpread = 0.02 + this._rightArmX * 0.12;
|
||||
|
||||
// Elbow: interpolate between "at side" and "raised"
|
||||
const lElbowY = shoulderY + P.shoulderToElbow * bodyH * (1 - leftArmRaise * 0.9);
|
||||
const rElbowY = shoulderY + P.shoulderToElbow * bodyH * (1 - rightArmRaise * 0.9);
|
||||
const lElbowX = cx - halfW - leftSpread;
|
||||
const rElbowX = cx + halfW + rightSpread;
|
||||
|
||||
// Wrist: extends further when raised
|
||||
const lWristY = lElbowY + P.elbowToWrist * bodyH * (1 - leftArmRaise * 1.1);
|
||||
const rWristY = rElbowY + P.elbowToWrist * bodyH * (1 - rightArmRaise * 1.1);
|
||||
const lWristX = lElbowX - leftSpread * 0.6;
|
||||
const rWristX = rElbowX + rightSpread * 0.6;
|
||||
|
||||
// Leg motion from lower grid cells
|
||||
const legMotion = grid ? this._analyzeLegMotion(grid, cols, rows) : { left: 0, right: 0 };
|
||||
const legSwing = 0.015;
|
||||
|
||||
const keypoints = [
|
||||
// 0: nose
|
||||
{ x: headX, y: headY + 0.01, confidence: 0.92 },
|
||||
// 1: left_eye
|
||||
{ x: headX - P.eyeSpacing * bodyH, y: headY - 0.005, confidence: 0.88 },
|
||||
// 2: right_eye
|
||||
{ x: headX + P.eyeSpacing * bodyH, y: headY - 0.005, confidence: 0.88 },
|
||||
// 3: left_ear
|
||||
{ x: headX - P.earSpacing * bodyH, y: headY + 0.005, confidence: 0.72 },
|
||||
// 4: right_ear
|
||||
{ x: headX + P.earSpacing * bodyH, y: headY + 0.005, confidence: 0.72 },
|
||||
// 5: left_shoulder
|
||||
{ x: cx - halfW, y: shoulderY, confidence: 0.94 },
|
||||
// 6: right_shoulder
|
||||
{ x: cx + halfW, y: shoulderY, confidence: 0.94 },
|
||||
// 7: left_elbow
|
||||
{ x: lElbowX, y: lElbowY, confidence: 0.87 },
|
||||
// 8: right_elbow
|
||||
{ x: rElbowX, y: rElbowY, confidence: 0.87 },
|
||||
// 9: left_wrist
|
||||
{ x: lWristX, y: lWristY, confidence: 0.82 },
|
||||
// 10: right_wrist
|
||||
{ x: rWristX, y: rWristY, confidence: 0.82 },
|
||||
// 11: left_hip
|
||||
{ x: cx - hipHalfW, y: hipY, confidence: 0.91 },
|
||||
// 12: right_hip
|
||||
{ x: cx + hipHalfW, y: hipY, confidence: 0.91 },
|
||||
// 13: left_knee
|
||||
{ x: cx - hipHalfW + legMotion.left * legSwing, y: kneeY, confidence: 0.88 },
|
||||
// 14: right_knee
|
||||
{ x: cx + hipHalfW + legMotion.right * legSwing, y: kneeY, confidence: 0.88 },
|
||||
// 15: left_ankle
|
||||
{ x: cx - hipHalfW + legMotion.left * legSwing * 1.3, y: ankleY, confidence: 0.83 },
|
||||
// 16: right_ankle
|
||||
{ x: cx + hipHalfW + legMotion.right * legSwing * 1.3, y: ankleY, confidence: 0.83 },
|
||||
];
|
||||
|
||||
for (let i = 0; i < keypoints.length; i++) {
|
||||
keypoints[i].name = KEYPOINT_NAMES[i];
|
||||
}
|
||||
|
||||
return keypoints;
|
||||
}
|
||||
|
||||
/**
|
||||
* Analyze the motion grid to determine arm positions.
|
||||
* Left side of grid = left side of body, etc.
|
||||
*/
|
||||
_analyzeArmMotion(grid, cols, rows, region) {
|
||||
// Body center column
|
||||
const centerCol = Math.floor(cols / 2);
|
||||
|
||||
// Upper body rows (top 60% of detected region)
|
||||
const upperEnd = Math.floor(rows * 0.6);
|
||||
|
||||
// Compute motion intensity for left vs right, at different heights
|
||||
let leftUpperMotion = 0, leftMidMotion = 0;
|
||||
let rightUpperMotion = 0, rightMidMotion = 0;
|
||||
let leftCount = 0, rightCount = 0;
|
||||
let headMotionX = 0, headMotionWeight = 0;
|
||||
|
||||
for (let r = 0; r < upperEnd; r++) {
|
||||
const heightWeight = 1.0 - (r / upperEnd) * 0.3; // Upper rows weighted more
|
||||
|
||||
// Head zone: top 25%, center 40% of width
|
||||
if (r < Math.floor(rows * 0.25)) {
|
||||
const headLeft = Math.floor(cols * 0.3);
|
||||
const headRight = Math.floor(cols * 0.7);
|
||||
for (let c = headLeft; c <= headRight; c++) {
|
||||
const val = grid[r][c];
|
||||
headMotionX += (c / cols - 0.5) * val;
|
||||
headMotionWeight += val;
|
||||
}
|
||||
}
|
||||
|
||||
// Left arm zone: left 40% of grid
|
||||
for (let c = 0; c < Math.floor(cols * 0.4); c++) {
|
||||
const val = grid[r][c];
|
||||
if (r < rows * 0.3) leftUpperMotion += val * heightWeight;
|
||||
else leftMidMotion += val * heightWeight;
|
||||
leftCount++;
|
||||
}
|
||||
|
||||
// Right arm zone: right 40% of grid
|
||||
for (let c = Math.floor(cols * 0.6); c < cols; c++) {
|
||||
const val = grid[r][c];
|
||||
if (r < rows * 0.3) rightUpperMotion += val * heightWeight;
|
||||
else rightMidMotion += val * heightWeight;
|
||||
rightCount++;
|
||||
}
|
||||
}
|
||||
|
||||
// Normalize
|
||||
const leftTotal = leftUpperMotion + leftMidMotion;
|
||||
const rightTotal = rightUpperMotion + rightMidMotion;
|
||||
const maxMotion = 0.15; // Calibration threshold
|
||||
|
||||
// Arm height: 0 = at side, 1 = raised
|
||||
// High motion in upper-left → left arm is raised
|
||||
const leftArmHeight = Math.min(1, (leftUpperMotion / maxMotion) * 2);
|
||||
const rightArmHeight = Math.min(1, (rightUpperMotion / maxMotion) * 2);
|
||||
|
||||
// Arm spread: how far out from body
|
||||
const leftArmSpread = Math.min(1, leftTotal / maxMotion);
|
||||
const rightArmSpread = Math.min(1, rightTotal / maxMotion);
|
||||
|
||||
// Head offset
|
||||
const headOffsetX = headMotionWeight > 0.01 ? headMotionX / headMotionWeight : 0;
|
||||
|
||||
return { leftArmHeight, rightArmHeight, leftArmSpread, rightArmSpread, headOffsetX };
|
||||
}
|
||||
|
||||
/**
|
||||
* Analyze lower grid for leg motion.
|
||||
*/
|
||||
_analyzeLegMotion(grid, cols, rows) {
|
||||
const lowerStart = Math.floor(rows * 0.6);
|
||||
let leftMotion = 0, rightMotion = 0;
|
||||
|
||||
for (let r = lowerStart; r < rows; r++) {
|
||||
for (let c = 0; c < Math.floor(cols / 2); c++) {
|
||||
leftMotion += grid[r][c];
|
||||
}
|
||||
for (let c = Math.floor(cols / 2); c < cols; c++) {
|
||||
rightMotion += grid[r][c];
|
||||
}
|
||||
}
|
||||
|
||||
// Return as -1 to 1 range (asymmetry indicates which leg is moving)
|
||||
const total = leftMotion + rightMotion + 0.001;
|
||||
return {
|
||||
left: (leftMotion - rightMotion) / total,
|
||||
right: (rightMotion - leftMotion) / total
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Through-wall tracking: continue showing pose via CSI when person left video frame.
|
||||
* The skeleton drifts in the exit direction with decreasing confidence.
|
||||
*/
|
||||
_trackThroughWall(elapsed, csiState) {
|
||||
if (!this._lastBodyState) return [];
|
||||
|
||||
const dt = elapsed - this._lastBodyState.time;
|
||||
const csiPresence = csiState.csiPresence || 0;
|
||||
|
||||
// Initialize ghost on first call
|
||||
if (this._ghostConfidence <= 0.05) {
|
||||
this._ghostConfidence = 0.8;
|
||||
this._ghostState = this._lastBodyState.keypoints.map(kp => ({...kp}));
|
||||
}
|
||||
|
||||
// Ghost confidence decays, but CSI presence sustains it
|
||||
const csiBoost = Math.min(0.7, csiPresence * 0.8);
|
||||
this._ghostConfidence = Math.max(0.05, this._ghostConfidence * 0.995 - 0.001 + csiBoost * 0.002);
|
||||
|
||||
// Drift the ghost in exit direction
|
||||
const vx = this._ghostVelocity.x;
|
||||
const vy = this._ghostVelocity.y;
|
||||
|
||||
// Breathing continues via CSI
|
||||
const breathe = Math.sin(elapsed * 1.5) * 0.003 * csiPresence;
|
||||
|
||||
const keypoints = this._ghostState.map((kp, i) => {
|
||||
return {
|
||||
x: kp.x + vx * dt * 0.3,
|
||||
y: kp.y + vy * dt * 0.3 + (i >= 5 && i <= 6 ? breathe : 0),
|
||||
confidence: kp.confidence * this._ghostConfidence * (0.5 + csiPresence * 0.5),
|
||||
name: kp.name
|
||||
};
|
||||
});
|
||||
|
||||
// Slow down drift over time
|
||||
this._ghostVelocity.x *= 0.998;
|
||||
this._ghostVelocity.y *= 0.998;
|
||||
|
||||
this.smoothedKeypoints = keypoints;
|
||||
return keypoints;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,235 @@
|
||||
/**
|
||||
* VideoCapture — getUserMedia webcam capture with frame extraction.
|
||||
* Provides quality metrics (brightness, motion) for fusion confidence gating.
|
||||
*/
|
||||
|
||||
export class VideoCapture {
|
||||
constructor(videoElement) {
|
||||
this.video = videoElement;
|
||||
this.stream = null;
|
||||
this.offscreen = document.createElement('canvas');
|
||||
this.offCtx = this.offscreen.getContext('2d', { willReadFrequently: true });
|
||||
this.prevFrame = null;
|
||||
this.motionScore = 0;
|
||||
this.brightnessScore = 0;
|
||||
}
|
||||
|
||||
async start(constraints = {}) {
|
||||
const defaultConstraints = {
|
||||
video: {
|
||||
width: { ideal: 640 },
|
||||
height: { ideal: 480 },
|
||||
facingMode: 'user',
|
||||
frameRate: { ideal: 30 }
|
||||
},
|
||||
audio: false
|
||||
};
|
||||
|
||||
try {
|
||||
this.stream = await navigator.mediaDevices.getUserMedia(
|
||||
Object.keys(constraints).length ? constraints : defaultConstraints
|
||||
);
|
||||
this.video.srcObject = this.stream;
|
||||
await this.video.play();
|
||||
|
||||
this.offscreen.width = this.video.videoWidth;
|
||||
this.offscreen.height = this.video.videoHeight;
|
||||
|
||||
return true;
|
||||
} catch (err) {
|
||||
console.error('[Video] Camera access failed:', err.message);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
stop() {
|
||||
if (this.stream) {
|
||||
this.stream.getTracks().forEach(t => t.stop());
|
||||
this.stream = null;
|
||||
}
|
||||
this.video.srcObject = null;
|
||||
}
|
||||
|
||||
get isActive() {
|
||||
return this.stream !== null && this.video.readyState >= 2;
|
||||
}
|
||||
|
||||
get width() { return this.video.videoWidth || 640; }
|
||||
get height() { return this.video.videoHeight || 480; }
|
||||
|
||||
/**
|
||||
* Capture current frame as RGB Uint8Array + compute quality metrics.
|
||||
* @param {number} targetW - Target width for CNN input
|
||||
* @param {number} targetH - Target height for CNN input
|
||||
* @returns {{ rgb: Uint8Array, width: number, height: number, motion: number, brightness: number }}
|
||||
*/
|
||||
captureFrame(targetW = 56, targetH = 56) {
|
||||
if (!this.isActive) return null;
|
||||
|
||||
// Draw to offscreen at target resolution
|
||||
this.offscreen.width = targetW;
|
||||
this.offscreen.height = targetH;
|
||||
this.offCtx.drawImage(this.video, 0, 0, targetW, targetH);
|
||||
const imageData = this.offCtx.getImageData(0, 0, targetW, targetH);
|
||||
const rgba = imageData.data;
|
||||
|
||||
// Convert RGBA → RGB
|
||||
const pixels = targetW * targetH;
|
||||
const rgb = new Uint8Array(pixels * 3);
|
||||
let brightnessSum = 0;
|
||||
let motionSum = 0;
|
||||
|
||||
for (let i = 0; i < pixels; i++) {
|
||||
const r = rgba[i * 4];
|
||||
const g = rgba[i * 4 + 1];
|
||||
const b = rgba[i * 4 + 2];
|
||||
rgb[i * 3] = r;
|
||||
rgb[i * 3 + 1] = g;
|
||||
rgb[i * 3 + 2] = b;
|
||||
|
||||
// Luminance for brightness
|
||||
const lum = 0.299 * r + 0.587 * g + 0.114 * b;
|
||||
brightnessSum += lum;
|
||||
|
||||
// Motion: diff from previous frame
|
||||
if (this.prevFrame) {
|
||||
const pr = this.prevFrame[i * 3];
|
||||
const pg = this.prevFrame[i * 3 + 1];
|
||||
const pb = this.prevFrame[i * 3 + 2];
|
||||
motionSum += Math.abs(r - pr) + Math.abs(g - pg) + Math.abs(b - pb);
|
||||
}
|
||||
}
|
||||
|
||||
this.brightnessScore = brightnessSum / (pixels * 255);
|
||||
this.motionScore = this.prevFrame ? Math.min(1, motionSum / (pixels * 100)) : 0;
|
||||
this.prevFrame = new Uint8Array(rgb);
|
||||
|
||||
return {
|
||||
rgb,
|
||||
width: targetW,
|
||||
height: targetH,
|
||||
motion: this.motionScore,
|
||||
brightness: this.brightnessScore
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Capture full-resolution RGBA for overlay rendering
|
||||
* @returns {ImageData|null}
|
||||
*/
|
||||
captureFullFrame() {
|
||||
if (!this.isActive) return null;
|
||||
this.offscreen.width = this.width;
|
||||
this.offscreen.height = this.height;
|
||||
this.offCtx.drawImage(this.video, 0, 0);
|
||||
return this.offCtx.getImageData(0, 0, this.width, this.height);
|
||||
}
|
||||
|
||||
/**
|
||||
* Detect motion region + detailed motion grid for body-part tracking.
|
||||
* Returns bounding box + a grid showing WHERE motion is concentrated.
|
||||
* @returns {{ x, y, w, h, detected: boolean, motionGrid: number[][], gridCols: number, gridRows: number, exitDirection: string|null }}
|
||||
*/
|
||||
detectMotionRegion(targetW = 56, targetH = 56) {
|
||||
if (!this.isActive || !this.prevFrame) return { detected: false, motionGrid: null };
|
||||
|
||||
this.offscreen.width = targetW;
|
||||
this.offscreen.height = targetH;
|
||||
this.offCtx.drawImage(this.video, 0, 0, targetW, targetH);
|
||||
const rgba = this.offCtx.getImageData(0, 0, targetW, targetH).data;
|
||||
|
||||
let minX = targetW, minY = targetH, maxX = 0, maxY = 0;
|
||||
let motionPixels = 0;
|
||||
const threshold = 25;
|
||||
|
||||
// Motion grid: divide frame into cells and track motion intensity per cell
|
||||
const gridCols = 10;
|
||||
const gridRows = 8;
|
||||
const cellW = targetW / gridCols;
|
||||
const cellH = targetH / gridRows;
|
||||
const motionGrid = Array.from({ length: gridRows }, () => new Float32Array(gridCols));
|
||||
const cellPixels = cellW * cellH;
|
||||
|
||||
// Also track motion centroid weighted by intensity
|
||||
let motionCxSum = 0, motionCySum = 0, motionWeightSum = 0;
|
||||
|
||||
for (let y = 0; y < targetH; y++) {
|
||||
for (let x = 0; x < targetW; x++) {
|
||||
const i = y * targetW + x;
|
||||
const r = rgba[i * 4], g = rgba[i * 4 + 1], b = rgba[i * 4 + 2];
|
||||
const pr = this.prevFrame[i * 3], pg = this.prevFrame[i * 3 + 1], pb = this.prevFrame[i * 3 + 2];
|
||||
const diff = Math.abs(r - pr) + Math.abs(g - pg) + Math.abs(b - pb);
|
||||
|
||||
if (diff > threshold * 3) {
|
||||
motionPixels++;
|
||||
if (x < minX) minX = x;
|
||||
if (y < minY) minY = y;
|
||||
if (x > maxX) maxX = x;
|
||||
if (y > maxY) maxY = y;
|
||||
}
|
||||
|
||||
// Accumulate per-cell motion intensity
|
||||
const gc = Math.min(Math.floor(x / cellW), gridCols - 1);
|
||||
const gr = Math.min(Math.floor(y / cellH), gridRows - 1);
|
||||
const intensity = diff / (3 * 255); // Normalize 0-1
|
||||
motionGrid[gr][gc] += intensity / cellPixels;
|
||||
|
||||
// Weighted centroid
|
||||
if (diff > threshold) {
|
||||
motionCxSum += x * diff;
|
||||
motionCySum += y * diff;
|
||||
motionWeightSum += diff;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const detected = motionPixels > (targetW * targetH * 0.02);
|
||||
|
||||
// Motion centroid (normalized 0-1)
|
||||
const motionCx = motionWeightSum > 0 ? motionCxSum / (motionWeightSum * targetW) : 0.5;
|
||||
const motionCy = motionWeightSum > 0 ? motionCySum / (motionWeightSum * targetH) : 0.5;
|
||||
|
||||
// Detect exit direction: if centroid is near edges
|
||||
let exitDirection = null;
|
||||
if (detected && motionCx < 0.1) exitDirection = 'left';
|
||||
else if (detected && motionCx > 0.9) exitDirection = 'right';
|
||||
else if (detected && motionCy < 0.1) exitDirection = 'up';
|
||||
else if (detected && motionCy > 0.9) exitDirection = 'down';
|
||||
|
||||
// Track last known position for through-wall persistence
|
||||
if (detected) {
|
||||
this._lastDetected = {
|
||||
x: minX / targetW,
|
||||
y: minY / targetH,
|
||||
w: (maxX - minX) / targetW,
|
||||
h: (maxY - minY) / targetH,
|
||||
cx: motionCx,
|
||||
cy: motionCy,
|
||||
exitDirection,
|
||||
time: performance.now()
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
detected,
|
||||
x: minX / targetW,
|
||||
y: minY / targetH,
|
||||
w: (maxX - minX) / targetW,
|
||||
h: (maxY - minY) / targetH,
|
||||
coverage: motionPixels / (targetW * targetH),
|
||||
motionGrid,
|
||||
gridCols,
|
||||
gridRows,
|
||||
motionCx,
|
||||
motionCy,
|
||||
exitDirection
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the last known detection info (for through-wall persistence)
|
||||
*/
|
||||
get lastDetection() {
|
||||
return this._lastDetected || null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
{
|
||||
"name": "ruvector-cnn-wasm",
|
||||
"type": "module",
|
||||
"description": "WASM bindings for ruvector-cnn - CNN feature extraction for image embeddings",
|
||||
"version": "0.1.0",
|
||||
"license": "MIT OR Apache-2.0",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/ruvnet/ruvector"
|
||||
},
|
||||
"files": [
|
||||
"ruvector_cnn_wasm_bg.wasm",
|
||||
"ruvector_cnn_wasm.js"
|
||||
],
|
||||
"main": "ruvector_cnn_wasm.js",
|
||||
"sideEffects": [
|
||||
"./snippets/*"
|
||||
],
|
||||
"keywords": [
|
||||
"cnn",
|
||||
"embeddings",
|
||||
"wasm",
|
||||
"simd",
|
||||
"machine-learning"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,802 @@
|
||||
/**
|
||||
* Configuration for CNN embedder
|
||||
*/
|
||||
export class EmbedderConfig {
|
||||
__destroy_into_raw() {
|
||||
const ptr = this.__wbg_ptr;
|
||||
this.__wbg_ptr = 0;
|
||||
EmbedderConfigFinalization.unregister(this);
|
||||
return ptr;
|
||||
}
|
||||
free() {
|
||||
const ptr = this.__destroy_into_raw();
|
||||
wasm.__wbg_embedderconfig_free(ptr, 0);
|
||||
}
|
||||
constructor() {
|
||||
const ret = wasm.embedderconfig_new();
|
||||
this.__wbg_ptr = ret >>> 0;
|
||||
EmbedderConfigFinalization.register(this, this.__wbg_ptr, this);
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Output embedding dimension
|
||||
* @returns {number}
|
||||
*/
|
||||
get embedding_dim() {
|
||||
const ret = wasm.__wbg_get_embedderconfig_embedding_dim(this.__wbg_ptr);
|
||||
return ret >>> 0;
|
||||
}
|
||||
/**
|
||||
* Input image size (square)
|
||||
* @returns {number}
|
||||
*/
|
||||
get input_size() {
|
||||
const ret = wasm.__wbg_get_embedderconfig_input_size(this.__wbg_ptr);
|
||||
return ret >>> 0;
|
||||
}
|
||||
/**
|
||||
* Whether to L2 normalize embeddings
|
||||
* @returns {boolean}
|
||||
*/
|
||||
get normalize() {
|
||||
const ret = wasm.__wbg_get_embedderconfig_normalize(this.__wbg_ptr);
|
||||
return ret !== 0;
|
||||
}
|
||||
/**
|
||||
* Output embedding dimension
|
||||
* @param {number} arg0
|
||||
*/
|
||||
set embedding_dim(arg0) {
|
||||
wasm.__wbg_set_embedderconfig_embedding_dim(this.__wbg_ptr, arg0);
|
||||
}
|
||||
/**
|
||||
* Input image size (square)
|
||||
* @param {number} arg0
|
||||
*/
|
||||
set input_size(arg0) {
|
||||
wasm.__wbg_set_embedderconfig_input_size(this.__wbg_ptr, arg0);
|
||||
}
|
||||
/**
|
||||
* Whether to L2 normalize embeddings
|
||||
* @param {boolean} arg0
|
||||
*/
|
||||
set normalize(arg0) {
|
||||
wasm.__wbg_set_embedderconfig_normalize(this.__wbg_ptr, arg0);
|
||||
}
|
||||
}
|
||||
if (Symbol.dispose) EmbedderConfig.prototype[Symbol.dispose] = EmbedderConfig.prototype.free;
|
||||
|
||||
/**
|
||||
* Layer operations for building custom networks
|
||||
*/
|
||||
export class LayerOps {
|
||||
__destroy_into_raw() {
|
||||
const ptr = this.__wbg_ptr;
|
||||
this.__wbg_ptr = 0;
|
||||
LayerOpsFinalization.unregister(this);
|
||||
return ptr;
|
||||
}
|
||||
free() {
|
||||
const ptr = this.__destroy_into_raw();
|
||||
wasm.__wbg_layerops_free(ptr, 0);
|
||||
}
|
||||
/**
|
||||
* Apply batch normalization (returns new array)
|
||||
* @param {Float32Array} input
|
||||
* @param {Float32Array} gamma
|
||||
* @param {Float32Array} beta
|
||||
* @param {Float32Array} mean
|
||||
* @param {Float32Array} _var
|
||||
* @param {number} epsilon
|
||||
* @returns {Float32Array}
|
||||
*/
|
||||
static batch_norm(input, gamma, beta, mean, _var, epsilon) {
|
||||
try {
|
||||
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
||||
const ptr0 = passArrayF32ToWasm0(input, wasm.__wbindgen_export2);
|
||||
const len0 = WASM_VECTOR_LEN;
|
||||
const ptr1 = passArrayF32ToWasm0(gamma, wasm.__wbindgen_export2);
|
||||
const len1 = WASM_VECTOR_LEN;
|
||||
const ptr2 = passArrayF32ToWasm0(beta, wasm.__wbindgen_export2);
|
||||
const len2 = WASM_VECTOR_LEN;
|
||||
const ptr3 = passArrayF32ToWasm0(mean, wasm.__wbindgen_export2);
|
||||
const len3 = WASM_VECTOR_LEN;
|
||||
const ptr4 = passArrayF32ToWasm0(_var, wasm.__wbindgen_export2);
|
||||
const len4 = WASM_VECTOR_LEN;
|
||||
wasm.layerops_batch_norm(retptr, ptr0, len0, ptr1, len1, ptr2, len2, ptr3, len3, ptr4, len4, epsilon);
|
||||
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
||||
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
||||
var v6 = getArrayF32FromWasm0(r0, r1).slice();
|
||||
wasm.__wbindgen_export(r0, r1 * 4, 4);
|
||||
return v6;
|
||||
} finally {
|
||||
wasm.__wbindgen_add_to_stack_pointer(16);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Apply global average pooling
|
||||
* Returns one value per channel
|
||||
* @param {Float32Array} input
|
||||
* @param {number} height
|
||||
* @param {number} width
|
||||
* @param {number} channels
|
||||
* @returns {Float32Array}
|
||||
*/
|
||||
static global_avg_pool(input, height, width, channels) {
|
||||
try {
|
||||
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
||||
const ptr0 = passArrayF32ToWasm0(input, wasm.__wbindgen_export2);
|
||||
const len0 = WASM_VECTOR_LEN;
|
||||
wasm.layerops_global_avg_pool(retptr, ptr0, len0, height, width, channels);
|
||||
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
||||
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
||||
var v2 = getArrayF32FromWasm0(r0, r1).slice();
|
||||
wasm.__wbindgen_export(r0, r1 * 4, 4);
|
||||
return v2;
|
||||
} finally {
|
||||
wasm.__wbindgen_add_to_stack_pointer(16);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (Symbol.dispose) LayerOps.prototype[Symbol.dispose] = LayerOps.prototype.free;
|
||||
|
||||
/**
|
||||
* SIMD-optimized operations
|
||||
*/
|
||||
export class SimdOps {
|
||||
__destroy_into_raw() {
|
||||
const ptr = this.__wbg_ptr;
|
||||
this.__wbg_ptr = 0;
|
||||
SimdOpsFinalization.unregister(this);
|
||||
return ptr;
|
||||
}
|
||||
free() {
|
||||
const ptr = this.__destroy_into_raw();
|
||||
wasm.__wbg_simdops_free(ptr, 0);
|
||||
}
|
||||
/**
|
||||
* Dot product of two vectors
|
||||
* @param {Float32Array} a
|
||||
* @param {Float32Array} b
|
||||
* @returns {number}
|
||||
*/
|
||||
static dot_product(a, b) {
|
||||
const ptr0 = passArrayF32ToWasm0(a, wasm.__wbindgen_export2);
|
||||
const len0 = WASM_VECTOR_LEN;
|
||||
const ptr1 = passArrayF32ToWasm0(b, wasm.__wbindgen_export2);
|
||||
const len1 = WASM_VECTOR_LEN;
|
||||
const ret = wasm.simdops_dot_product(ptr0, len0, ptr1, len1);
|
||||
return ret;
|
||||
}
|
||||
/**
|
||||
* L2 normalize a vector (returns new array)
|
||||
* @param {Float32Array} data
|
||||
* @returns {Float32Array}
|
||||
*/
|
||||
static l2_normalize(data) {
|
||||
try {
|
||||
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
||||
const ptr0 = passArrayF32ToWasm0(data, wasm.__wbindgen_export2);
|
||||
const len0 = WASM_VECTOR_LEN;
|
||||
wasm.simdops_l2_normalize(retptr, ptr0, len0);
|
||||
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
||||
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
||||
var v2 = getArrayF32FromWasm0(r0, r1).slice();
|
||||
wasm.__wbindgen_export(r0, r1 * 4, 4);
|
||||
return v2;
|
||||
} finally {
|
||||
wasm.__wbindgen_add_to_stack_pointer(16);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* ReLU activation (returns new array)
|
||||
* @param {Float32Array} data
|
||||
* @returns {Float32Array}
|
||||
*/
|
||||
static relu(data) {
|
||||
try {
|
||||
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
||||
const ptr0 = passArrayF32ToWasm0(data, wasm.__wbindgen_export2);
|
||||
const len0 = WASM_VECTOR_LEN;
|
||||
wasm.simdops_relu(retptr, ptr0, len0);
|
||||
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
||||
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
||||
var v2 = getArrayF32FromWasm0(r0, r1).slice();
|
||||
wasm.__wbindgen_export(r0, r1 * 4, 4);
|
||||
return v2;
|
||||
} finally {
|
||||
wasm.__wbindgen_add_to_stack_pointer(16);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* ReLU6 activation (returns new array)
|
||||
* @param {Float32Array} data
|
||||
* @returns {Float32Array}
|
||||
*/
|
||||
static relu6(data) {
|
||||
try {
|
||||
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
||||
const ptr0 = passArrayF32ToWasm0(data, wasm.__wbindgen_export2);
|
||||
const len0 = WASM_VECTOR_LEN;
|
||||
wasm.simdops_relu6(retptr, ptr0, len0);
|
||||
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
||||
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
||||
var v2 = getArrayF32FromWasm0(r0, r1).slice();
|
||||
wasm.__wbindgen_export(r0, r1 * 4, 4);
|
||||
return v2;
|
||||
} finally {
|
||||
wasm.__wbindgen_add_to_stack_pointer(16);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (Symbol.dispose) SimdOps.prototype[Symbol.dispose] = SimdOps.prototype.free;
|
||||
|
||||
/**
|
||||
* WASM CNN Embedder for image feature extraction
|
||||
*/
|
||||
export class WasmCnnEmbedder {
|
||||
__destroy_into_raw() {
|
||||
const ptr = this.__wbg_ptr;
|
||||
this.__wbg_ptr = 0;
|
||||
WasmCnnEmbedderFinalization.unregister(this);
|
||||
return ptr;
|
||||
}
|
||||
free() {
|
||||
const ptr = this.__destroy_into_raw();
|
||||
wasm.__wbg_wasmcnnembedder_free(ptr, 0);
|
||||
}
|
||||
/**
|
||||
* Compute cosine similarity between two embeddings
|
||||
* @param {Float32Array} a
|
||||
* @param {Float32Array} b
|
||||
* @returns {number}
|
||||
*/
|
||||
cosine_similarity(a, b) {
|
||||
try {
|
||||
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
||||
const ptr0 = passArrayF32ToWasm0(a, wasm.__wbindgen_export2);
|
||||
const len0 = WASM_VECTOR_LEN;
|
||||
const ptr1 = passArrayF32ToWasm0(b, wasm.__wbindgen_export2);
|
||||
const len1 = WASM_VECTOR_LEN;
|
||||
wasm.wasmcnnembedder_cosine_similarity(retptr, this.__wbg_ptr, ptr0, len0, ptr1, len1);
|
||||
var r0 = getDataViewMemory0().getFloat32(retptr + 4 * 0, true);
|
||||
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
||||
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
||||
if (r2) {
|
||||
throw takeObject(r1);
|
||||
}
|
||||
return r0;
|
||||
} finally {
|
||||
wasm.__wbindgen_add_to_stack_pointer(16);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Get the embedding dimension
|
||||
* @returns {number}
|
||||
*/
|
||||
get embedding_dim() {
|
||||
const ret = wasm.wasmcnnembedder_embedding_dim(this.__wbg_ptr);
|
||||
return ret >>> 0;
|
||||
}
|
||||
/**
|
||||
* Extract embedding from image data (RGB format, row-major)
|
||||
* @param {Uint8Array} image_data
|
||||
* @param {number} width
|
||||
* @param {number} height
|
||||
* @returns {Float32Array}
|
||||
*/
|
||||
extract(image_data, width, height) {
|
||||
try {
|
||||
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
||||
const ptr0 = passArray8ToWasm0(image_data, wasm.__wbindgen_export2);
|
||||
const len0 = WASM_VECTOR_LEN;
|
||||
wasm.wasmcnnembedder_extract(retptr, this.__wbg_ptr, ptr0, len0, width, height);
|
||||
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
||||
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
||||
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
||||
var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
|
||||
if (r3) {
|
||||
throw takeObject(r2);
|
||||
}
|
||||
var v2 = getArrayF32FromWasm0(r0, r1).slice();
|
||||
wasm.__wbindgen_export(r0, r1 * 4, 4);
|
||||
return v2;
|
||||
} finally {
|
||||
wasm.__wbindgen_add_to_stack_pointer(16);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Create a new CNN embedder
|
||||
* @param {EmbedderConfig | null} [config]
|
||||
*/
|
||||
constructor(config) {
|
||||
try {
|
||||
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
||||
let ptr0 = 0;
|
||||
if (!isLikeNone(config)) {
|
||||
_assertClass(config, EmbedderConfig);
|
||||
ptr0 = config.__destroy_into_raw();
|
||||
}
|
||||
wasm.wasmcnnembedder_new(retptr, ptr0);
|
||||
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
||||
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
||||
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
||||
if (r2) {
|
||||
throw takeObject(r1);
|
||||
}
|
||||
this.__wbg_ptr = r0 >>> 0;
|
||||
WasmCnnEmbedderFinalization.register(this, this.__wbg_ptr, this);
|
||||
return this;
|
||||
} finally {
|
||||
wasm.__wbindgen_add_to_stack_pointer(16);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (Symbol.dispose) WasmCnnEmbedder.prototype[Symbol.dispose] = WasmCnnEmbedder.prototype.free;
|
||||
|
||||
/**
|
||||
* InfoNCE loss for contrastive learning (SimCLR style)
|
||||
*/
|
||||
export class WasmInfoNCELoss {
|
||||
__destroy_into_raw() {
|
||||
const ptr = this.__wbg_ptr;
|
||||
this.__wbg_ptr = 0;
|
||||
WasmInfoNCELossFinalization.unregister(this);
|
||||
return ptr;
|
||||
}
|
||||
free() {
|
||||
const ptr = this.__destroy_into_raw();
|
||||
wasm.__wbg_wasminfonceloss_free(ptr, 0);
|
||||
}
|
||||
/**
|
||||
* Compute loss for a batch of embedding pairs
|
||||
* embeddings: [2N, D] flattened where (i, i+N) are positive pairs
|
||||
* @param {Float32Array} embeddings
|
||||
* @param {number} batch_size
|
||||
* @param {number} dim
|
||||
* @returns {number}
|
||||
*/
|
||||
forward(embeddings, batch_size, dim) {
|
||||
try {
|
||||
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
||||
const ptr0 = passArrayF32ToWasm0(embeddings, wasm.__wbindgen_export2);
|
||||
const len0 = WASM_VECTOR_LEN;
|
||||
wasm.wasminfonceloss_forward(retptr, this.__wbg_ptr, ptr0, len0, batch_size, dim);
|
||||
var r0 = getDataViewMemory0().getFloat32(retptr + 4 * 0, true);
|
||||
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
||||
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
||||
if (r2) {
|
||||
throw takeObject(r1);
|
||||
}
|
||||
return r0;
|
||||
} finally {
|
||||
wasm.__wbindgen_add_to_stack_pointer(16);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Create new InfoNCE loss with temperature parameter
|
||||
* @param {number} temperature
|
||||
*/
|
||||
constructor(temperature) {
|
||||
const ret = wasm.wasminfonceloss_new(temperature);
|
||||
this.__wbg_ptr = ret >>> 0;
|
||||
WasmInfoNCELossFinalization.register(this, this.__wbg_ptr, this);
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Get the temperature parameter
|
||||
* @returns {number}
|
||||
*/
|
||||
get temperature() {
|
||||
const ret = wasm.wasminfonceloss_temperature(this.__wbg_ptr);
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
if (Symbol.dispose) WasmInfoNCELoss.prototype[Symbol.dispose] = WasmInfoNCELoss.prototype.free;
|
||||
|
||||
/**
|
||||
* Triplet loss for metric learning
|
||||
*/
|
||||
export class WasmTripletLoss {
|
||||
__destroy_into_raw() {
|
||||
const ptr = this.__wbg_ptr;
|
||||
this.__wbg_ptr = 0;
|
||||
WasmTripletLossFinalization.unregister(this);
|
||||
return ptr;
|
||||
}
|
||||
free() {
|
||||
const ptr = this.__destroy_into_raw();
|
||||
wasm.__wbg_wasmtripletloss_free(ptr, 0);
|
||||
}
|
||||
/**
|
||||
* Compute loss for a batch of triplets
|
||||
* @param {Float32Array} anchors
|
||||
* @param {Float32Array} positives
|
||||
* @param {Float32Array} negatives
|
||||
* @param {number} dim
|
||||
* @returns {number}
|
||||
*/
|
||||
forward(anchors, positives, negatives, dim) {
|
||||
try {
|
||||
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
||||
const ptr0 = passArrayF32ToWasm0(anchors, wasm.__wbindgen_export2);
|
||||
const len0 = WASM_VECTOR_LEN;
|
||||
const ptr1 = passArrayF32ToWasm0(positives, wasm.__wbindgen_export2);
|
||||
const len1 = WASM_VECTOR_LEN;
|
||||
const ptr2 = passArrayF32ToWasm0(negatives, wasm.__wbindgen_export2);
|
||||
const len2 = WASM_VECTOR_LEN;
|
||||
wasm.wasmtripletloss_forward(retptr, this.__wbg_ptr, ptr0, len0, ptr1, len1, ptr2, len2, dim);
|
||||
var r0 = getDataViewMemory0().getFloat32(retptr + 4 * 0, true);
|
||||
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
||||
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
||||
if (r2) {
|
||||
throw takeObject(r1);
|
||||
}
|
||||
return r0;
|
||||
} finally {
|
||||
wasm.__wbindgen_add_to_stack_pointer(16);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Compute loss for a single triplet
|
||||
* @param {Float32Array} anchor
|
||||
* @param {Float32Array} positive
|
||||
* @param {Float32Array} negative
|
||||
* @returns {number}
|
||||
*/
|
||||
forward_single(anchor, positive, negative) {
|
||||
try {
|
||||
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
||||
const ptr0 = passArrayF32ToWasm0(anchor, wasm.__wbindgen_export2);
|
||||
const len0 = WASM_VECTOR_LEN;
|
||||
const ptr1 = passArrayF32ToWasm0(positive, wasm.__wbindgen_export2);
|
||||
const len1 = WASM_VECTOR_LEN;
|
||||
const ptr2 = passArrayF32ToWasm0(negative, wasm.__wbindgen_export2);
|
||||
const len2 = WASM_VECTOR_LEN;
|
||||
wasm.wasmtripletloss_forward_single(retptr, this.__wbg_ptr, ptr0, len0, ptr1, len1, ptr2, len2);
|
||||
var r0 = getDataViewMemory0().getFloat32(retptr + 4 * 0, true);
|
||||
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
||||
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
||||
if (r2) {
|
||||
throw takeObject(r1);
|
||||
}
|
||||
return r0;
|
||||
} finally {
|
||||
wasm.__wbindgen_add_to_stack_pointer(16);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Get the margin parameter
|
||||
* @returns {number}
|
||||
*/
|
||||
get margin() {
|
||||
const ret = wasm.wasmtripletloss_margin(this.__wbg_ptr);
|
||||
return ret;
|
||||
}
|
||||
/**
|
||||
* Create new triplet loss with margin
|
||||
* @param {number} margin
|
||||
*/
|
||||
constructor(margin) {
|
||||
const ret = wasm.wasmtripletloss_new(margin);
|
||||
this.__wbg_ptr = ret >>> 0;
|
||||
WasmTripletLossFinalization.register(this, this.__wbg_ptr, this);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
if (Symbol.dispose) WasmTripletLoss.prototype[Symbol.dispose] = WasmTripletLoss.prototype.free;
|
||||
|
||||
/**
|
||||
* Initialize panic hook for better error messages
|
||||
*/
|
||||
export function init() {
|
||||
wasm.init();
|
||||
}
|
||||
|
||||
function __wbg_get_imports() {
|
||||
const import0 = {
|
||||
__proto__: null,
|
||||
__wbg___wbindgen_throw_39bc967c0e5a9b58: function(arg0, arg1) {
|
||||
throw new Error(getStringFromWasm0(arg0, arg1));
|
||||
},
|
||||
__wbg_error_a6fa202b58aa1cd3: function(arg0, arg1) {
|
||||
let deferred0_0;
|
||||
let deferred0_1;
|
||||
try {
|
||||
deferred0_0 = arg0;
|
||||
deferred0_1 = arg1;
|
||||
console.error(getStringFromWasm0(arg0, arg1));
|
||||
} finally {
|
||||
wasm.__wbindgen_export(deferred0_0, deferred0_1, 1);
|
||||
}
|
||||
},
|
||||
__wbg_new_227d7c05414eb861: function() {
|
||||
const ret = new Error();
|
||||
return addHeapObject(ret);
|
||||
},
|
||||
__wbg_stack_3b0d974bbf31e44f: function(arg0, arg1) {
|
||||
const ret = getObject(arg1).stack;
|
||||
const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_export2, wasm.__wbindgen_export3);
|
||||
const len1 = WASM_VECTOR_LEN;
|
||||
getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
|
||||
getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
|
||||
},
|
||||
__wbindgen_cast_0000000000000001: function(arg0, arg1) {
|
||||
// Cast intrinsic for `Ref(String) -> Externref`.
|
||||
const ret = getStringFromWasm0(arg0, arg1);
|
||||
return addHeapObject(ret);
|
||||
},
|
||||
__wbindgen_object_drop_ref: function(arg0) {
|
||||
takeObject(arg0);
|
||||
},
|
||||
};
|
||||
return {
|
||||
__proto__: null,
|
||||
"./ruvector_cnn_wasm_bg.js": import0,
|
||||
};
|
||||
}
|
||||
|
||||
const EmbedderConfigFinalization = (typeof FinalizationRegistry === 'undefined')
|
||||
? { register: () => {}, unregister: () => {} }
|
||||
: new FinalizationRegistry(ptr => wasm.__wbg_embedderconfig_free(ptr >>> 0, 1));
|
||||
const LayerOpsFinalization = (typeof FinalizationRegistry === 'undefined')
|
||||
? { register: () => {}, unregister: () => {} }
|
||||
: new FinalizationRegistry(ptr => wasm.__wbg_layerops_free(ptr >>> 0, 1));
|
||||
const SimdOpsFinalization = (typeof FinalizationRegistry === 'undefined')
|
||||
? { register: () => {}, unregister: () => {} }
|
||||
: new FinalizationRegistry(ptr => wasm.__wbg_simdops_free(ptr >>> 0, 1));
|
||||
const WasmCnnEmbedderFinalization = (typeof FinalizationRegistry === 'undefined')
|
||||
? { register: () => {}, unregister: () => {} }
|
||||
: new FinalizationRegistry(ptr => wasm.__wbg_wasmcnnembedder_free(ptr >>> 0, 1));
|
||||
const WasmInfoNCELossFinalization = (typeof FinalizationRegistry === 'undefined')
|
||||
? { register: () => {}, unregister: () => {} }
|
||||
: new FinalizationRegistry(ptr => wasm.__wbg_wasminfonceloss_free(ptr >>> 0, 1));
|
||||
const WasmTripletLossFinalization = (typeof FinalizationRegistry === 'undefined')
|
||||
? { register: () => {}, unregister: () => {} }
|
||||
: new FinalizationRegistry(ptr => wasm.__wbg_wasmtripletloss_free(ptr >>> 0, 1));
|
||||
|
||||
function addHeapObject(obj) {
|
||||
if (heap_next === heap.length) heap.push(heap.length + 1);
|
||||
const idx = heap_next;
|
||||
heap_next = heap[idx];
|
||||
|
||||
heap[idx] = obj;
|
||||
return idx;
|
||||
}
|
||||
|
||||
function _assertClass(instance, klass) {
|
||||
if (!(instance instanceof klass)) {
|
||||
throw new Error(`expected instance of ${klass.name}`);
|
||||
}
|
||||
}
|
||||
|
||||
function dropObject(idx) {
|
||||
if (idx < 1028) return;
|
||||
heap[idx] = heap_next;
|
||||
heap_next = idx;
|
||||
}
|
||||
|
||||
function getArrayF32FromWasm0(ptr, len) {
|
||||
ptr = ptr >>> 0;
|
||||
return getFloat32ArrayMemory0().subarray(ptr / 4, ptr / 4 + len);
|
||||
}
|
||||
|
||||
let cachedDataViewMemory0 = null;
|
||||
function getDataViewMemory0() {
|
||||
if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
|
||||
cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
|
||||
}
|
||||
return cachedDataViewMemory0;
|
||||
}
|
||||
|
||||
let cachedFloat32ArrayMemory0 = null;
|
||||
function getFloat32ArrayMemory0() {
|
||||
if (cachedFloat32ArrayMemory0 === null || cachedFloat32ArrayMemory0.byteLength === 0) {
|
||||
cachedFloat32ArrayMemory0 = new Float32Array(wasm.memory.buffer);
|
||||
}
|
||||
return cachedFloat32ArrayMemory0;
|
||||
}
|
||||
|
||||
function getStringFromWasm0(ptr, len) {
|
||||
ptr = ptr >>> 0;
|
||||
return decodeText(ptr, len);
|
||||
}
|
||||
|
||||
let cachedUint8ArrayMemory0 = null;
|
||||
function getUint8ArrayMemory0() {
|
||||
if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
|
||||
cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
|
||||
}
|
||||
return cachedUint8ArrayMemory0;
|
||||
}
|
||||
|
||||
function getObject(idx) { return heap[idx]; }
|
||||
|
||||
let heap = new Array(1024).fill(undefined);
|
||||
heap.push(undefined, null, true, false);
|
||||
|
||||
let heap_next = heap.length;
|
||||
|
||||
function isLikeNone(x) {
|
||||
return x === undefined || x === null;
|
||||
}
|
||||
|
||||
function passArray8ToWasm0(arg, malloc) {
|
||||
const ptr = malloc(arg.length * 1, 1) >>> 0;
|
||||
getUint8ArrayMemory0().set(arg, ptr / 1);
|
||||
WASM_VECTOR_LEN = arg.length;
|
||||
return ptr;
|
||||
}
|
||||
|
||||
function passArrayF32ToWasm0(arg, malloc) {
|
||||
const ptr = malloc(arg.length * 4, 4) >>> 0;
|
||||
getFloat32ArrayMemory0().set(arg, ptr / 4);
|
||||
WASM_VECTOR_LEN = arg.length;
|
||||
return ptr;
|
||||
}
|
||||
|
||||
function passStringToWasm0(arg, malloc, realloc) {
|
||||
if (realloc === undefined) {
|
||||
const buf = cachedTextEncoder.encode(arg);
|
||||
const ptr = malloc(buf.length, 1) >>> 0;
|
||||
getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
|
||||
WASM_VECTOR_LEN = buf.length;
|
||||
return ptr;
|
||||
}
|
||||
|
||||
let len = arg.length;
|
||||
let ptr = malloc(len, 1) >>> 0;
|
||||
|
||||
const mem = getUint8ArrayMemory0();
|
||||
|
||||
let offset = 0;
|
||||
|
||||
for (; offset < len; offset++) {
|
||||
const code = arg.charCodeAt(offset);
|
||||
if (code > 0x7F) break;
|
||||
mem[ptr + offset] = code;
|
||||
}
|
||||
if (offset !== len) {
|
||||
if (offset !== 0) {
|
||||
arg = arg.slice(offset);
|
||||
}
|
||||
ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
|
||||
const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
|
||||
const ret = cachedTextEncoder.encodeInto(arg, view);
|
||||
|
||||
offset += ret.written;
|
||||
ptr = realloc(ptr, len, offset, 1) >>> 0;
|
||||
}
|
||||
|
||||
WASM_VECTOR_LEN = offset;
|
||||
return ptr;
|
||||
}
|
||||
|
||||
function takeObject(idx) {
|
||||
const ret = getObject(idx);
|
||||
dropObject(idx);
|
||||
return ret;
|
||||
}
|
||||
|
||||
let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
|
||||
cachedTextDecoder.decode();
|
||||
const MAX_SAFARI_DECODE_BYTES = 2146435072;
|
||||
let numBytesDecoded = 0;
|
||||
function decodeText(ptr, len) {
|
||||
numBytesDecoded += len;
|
||||
if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
|
||||
cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
|
||||
cachedTextDecoder.decode();
|
||||
numBytesDecoded = len;
|
||||
}
|
||||
return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
|
||||
}
|
||||
|
||||
const cachedTextEncoder = new TextEncoder();
|
||||
|
||||
if (!('encodeInto' in cachedTextEncoder)) {
|
||||
cachedTextEncoder.encodeInto = function (arg, view) {
|
||||
const buf = cachedTextEncoder.encode(arg);
|
||||
view.set(buf);
|
||||
return {
|
||||
read: arg.length,
|
||||
written: buf.length
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
let WASM_VECTOR_LEN = 0;
|
||||
|
||||
let wasmModule, wasm;
|
||||
function __wbg_finalize_init(instance, module) {
|
||||
wasm = instance.exports;
|
||||
wasmModule = module;
|
||||
cachedDataViewMemory0 = null;
|
||||
cachedFloat32ArrayMemory0 = null;
|
||||
cachedUint8ArrayMemory0 = null;
|
||||
wasm.__wbindgen_start();
|
||||
return wasm;
|
||||
}
|
||||
|
||||
async function __wbg_load(module, imports) {
|
||||
if (typeof Response === 'function' && module instanceof Response) {
|
||||
if (typeof WebAssembly.instantiateStreaming === 'function') {
|
||||
try {
|
||||
return await WebAssembly.instantiateStreaming(module, imports);
|
||||
} catch (e) {
|
||||
const validResponse = module.ok && expectedResponseType(module.type);
|
||||
|
||||
if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {
|
||||
console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n", e);
|
||||
|
||||
} else { throw e; }
|
||||
}
|
||||
}
|
||||
|
||||
const bytes = await module.arrayBuffer();
|
||||
return await WebAssembly.instantiate(bytes, imports);
|
||||
} else {
|
||||
const instance = await WebAssembly.instantiate(module, imports);
|
||||
|
||||
if (instance instanceof WebAssembly.Instance) {
|
||||
return { instance, module };
|
||||
} else {
|
||||
return instance;
|
||||
}
|
||||
}
|
||||
|
||||
function expectedResponseType(type) {
|
||||
switch (type) {
|
||||
case 'basic': case 'cors': case 'default': return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function initSync(module) {
|
||||
if (wasm !== undefined) return wasm;
|
||||
|
||||
|
||||
if (module !== undefined) {
|
||||
if (Object.getPrototypeOf(module) === Object.prototype) {
|
||||
({module} = module)
|
||||
} else {
|
||||
console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
|
||||
}
|
||||
}
|
||||
|
||||
const imports = __wbg_get_imports();
|
||||
if (!(module instanceof WebAssembly.Module)) {
|
||||
module = new WebAssembly.Module(module);
|
||||
}
|
||||
const instance = new WebAssembly.Instance(module, imports);
|
||||
return __wbg_finalize_init(instance, module);
|
||||
}
|
||||
|
||||
async function __wbg_init(module_or_path) {
|
||||
if (wasm !== undefined) return wasm;
|
||||
|
||||
|
||||
if (module_or_path !== undefined) {
|
||||
if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
|
||||
({module_or_path} = module_or_path)
|
||||
} else {
|
||||
console.warn('using deprecated parameters for the initialization function; pass a single object instead')
|
||||
}
|
||||
}
|
||||
|
||||
if (module_or_path === undefined) {
|
||||
module_or_path = new URL('ruvector_cnn_wasm_bg.wasm', import.meta.url);
|
||||
}
|
||||
const imports = __wbg_get_imports();
|
||||
|
||||
if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {
|
||||
module_or_path = fetch(module_or_path);
|
||||
}
|
||||
|
||||
const { instance, module } = await __wbg_load(await module_or_path, imports);
|
||||
|
||||
return __wbg_finalize_init(instance, module);
|
||||
}
|
||||
|
||||
export { initSync, __wbg_init as default };
|
||||
Binary file not shown.
Reference in New Issue
Block a user