mirror of
https://github.com/ruvnet/RuView
synced 2026-06-20 12:03:19 +00:00
Compare commits
13 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 377413e6a8 | |||
| b9e36a8be0 | |||
| 9e860c3a7a | |||
| ff91d4e8cf | |||
| fc92436f52 | |||
| 285bb0ad37 | |||
| b5ec4ef043 | |||
| 21aba2df8d | |||
| a28a875594 | |||
| e12749bf68 | |||
| 3b37aaf460 | |||
| d3c683cc7e | |||
| 56de77c0ad |
@@ -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.
|
||||
|
||||
|
||||
@@ -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,240 @@
|
||||
# ADR-057: Desktop App Training & RuVector Integration
|
||||
|
||||
| Field | Value |
|
||||
|-------|-------|
|
||||
| Status | Proposed |
|
||||
| Date | 2026-03-10 |
|
||||
| Authors | RuView Team |
|
||||
| Reviewers | - |
|
||||
| Related | ADR-016, ADR-017, ADR-024, ADR-027 |
|
||||
|
||||
## Context
|
||||
|
||||
The RuView desktop application currently provides device discovery, firmware flashing, OTA updates, and real-time sensing visualization. However, users cannot train models or configure RuVector signal processing modules directly from the desktop app.
|
||||
|
||||
The following crates exist in the workspace but are not exposed in the desktop UI:
|
||||
|
||||
### Training Crate (`wifi-densepose-train`)
|
||||
- Dataset management (MM-Fi, Wi-Pose formats)
|
||||
- Model architectures (CSI encoder, pose decoder)
|
||||
- Training loops with metrics tracking
|
||||
- Checkpoint save/load
|
||||
- ruview_metrics integration
|
||||
|
||||
### RuVector Crates (5 modules)
|
||||
1. **ruvector-mincut** - Graph-based person segmentation, DynamicPersonMatcher
|
||||
2. **ruvector-attn-mincut** - Attention-weighted antenna selection
|
||||
3. **ruvector-temporal-tensor** - Temporal CSI compression, breathing detection
|
||||
4. **ruvector-solver** - Sparse interpolation, triangulation
|
||||
5. **ruvector-attention** - Spatial attention, BVP extraction
|
||||
|
||||
## Decision
|
||||
|
||||
Add a new **"Training"** page to the desktop application with tabbed navigation:
|
||||
|
||||
### Tab Structure
|
||||
|
||||
```
|
||||
┌─────────────────────────────────────────────────────────────┐
|
||||
│ Training & Models │
|
||||
├──────────┬──────────┬──────────┬──────────┬────────────────┤
|
||||
│ Datasets │ Models │ Training │ RuVector │ Metrics │
|
||||
└──────────┴──────────┴──────────┴──────────┴────────────────┘
|
||||
```
|
||||
|
||||
### Tab 1: Datasets
|
||||
- **Download** standard datasets (MM-Fi, Wi-Pose)
|
||||
- **Import** custom CSI recordings
|
||||
- **Preview** dataset samples (CSI heatmaps, labels)
|
||||
- **Split** into train/val/test sets
|
||||
- **Statistics** - sample counts, class distribution
|
||||
|
||||
### Tab 2: Models
|
||||
- **Browse** available architectures:
|
||||
- CSI Encoder (CNN, Transformer)
|
||||
- Pose Decoder (LSTM, GRU)
|
||||
- AETHER embedding network (ADR-024)
|
||||
- MERIDIAN domain adaptor (ADR-027)
|
||||
- **Load** checkpoints from disk
|
||||
- **View** model summary (params, layers, memory)
|
||||
- **Export** to ONNX/TorchScript
|
||||
|
||||
### Tab 3: Training
|
||||
- **Configure** training:
|
||||
- Learning rate, batch size, epochs
|
||||
- Optimizer (Adam, SGD, AdamW)
|
||||
- Loss function selection
|
||||
- Data augmentation toggles
|
||||
- **GPU Detection** - CUDA/Metal availability
|
||||
- **Start/Stop** training jobs
|
||||
- **Progress** - live loss curves, ETA
|
||||
- **Checkpointing** - auto-save best model
|
||||
|
||||
### Tab 4: RuVector
|
||||
- **Module Configuration**:
|
||||
- MinCut graph parameters
|
||||
- Attention weights
|
||||
- Temporal compression ratio
|
||||
- Solver interpolation settings
|
||||
- **Live Testing** - apply to real-time CSI stream
|
||||
- **Comparison** - A/B test configurations
|
||||
- **Export** - save optimal config
|
||||
|
||||
### Tab 5: Metrics
|
||||
- **Loss Curves** - training/validation over epochs
|
||||
- **Evaluation** - PCK, mAP, IoU scores
|
||||
- **Confusion Matrix** - per-joint accuracy
|
||||
- **Export** - CSV, JSON, TensorBoard format
|
||||
|
||||
## Architecture
|
||||
|
||||
### Backend (Rust/Tauri)
|
||||
|
||||
```
|
||||
wifi-densepose-desktop/
|
||||
├── src/
|
||||
│ ├── commands/
|
||||
│ │ ├── training.rs # NEW: Training job management
|
||||
│ │ ├── datasets.rs # NEW: Dataset download/import
|
||||
│ │ ├── models.rs # NEW: Model loading/export
|
||||
│ │ ├── ruvector.rs # NEW: RuVector config
|
||||
│ │ └── metrics.rs # NEW: Metrics retrieval
|
||||
│ └── domain/
|
||||
│ ├── training.rs # Training state machine
|
||||
│ └── ruvector.rs # RuVector config types
|
||||
```
|
||||
|
||||
### Frontend (React/TypeScript)
|
||||
|
||||
```
|
||||
ui/src/pages/
|
||||
├── Training/
|
||||
│ ├── index.tsx # Tab container
|
||||
│ ├── DatasetsTab.tsx # Dataset management
|
||||
│ ├── ModelsTab.tsx # Model browser
|
||||
│ ├── TrainingTab.tsx # Training control
|
||||
│ ├── RuVectorTab.tsx # Signal processing config
|
||||
│ └── MetricsTab.tsx # Visualization
|
||||
```
|
||||
|
||||
### Tauri Commands
|
||||
|
||||
| Command | Description |
|
||||
|---------|-------------|
|
||||
| `list_datasets` | Get available datasets |
|
||||
| `download_dataset` | Download standard dataset |
|
||||
| `import_dataset` | Import custom recordings |
|
||||
| `list_models` | Get model architectures |
|
||||
| `load_checkpoint` | Load model weights |
|
||||
| `export_model` | Export to ONNX |
|
||||
| `detect_gpu` | Check CUDA/Metal |
|
||||
| `start_training` | Begin training job |
|
||||
| `stop_training` | Cancel training |
|
||||
| `training_progress` | Get current status |
|
||||
| `get_ruvector_config` | Load RuVector settings |
|
||||
| `set_ruvector_config` | Update settings |
|
||||
| `test_ruvector_live` | Apply to live CSI |
|
||||
| `get_metrics` | Retrieve training metrics |
|
||||
|
||||
### Event System
|
||||
|
||||
Training progress updates via Tauri events:
|
||||
|
||||
```rust
|
||||
#[derive(Serialize, Clone)]
|
||||
pub struct TrainingProgress {
|
||||
pub epoch: u32,
|
||||
pub total_epochs: u32,
|
||||
pub batch: u32,
|
||||
pub total_batches: u32,
|
||||
pub train_loss: f32,
|
||||
pub val_loss: Option<f32>,
|
||||
pub learning_rate: f32,
|
||||
pub eta_secs: u64,
|
||||
pub gpu_memory_mb: Option<u64>,
|
||||
}
|
||||
|
||||
// Emit every batch
|
||||
app.emit("training:progress", progress)?;
|
||||
|
||||
// Emit on completion
|
||||
app.emit("training:complete", result)?;
|
||||
```
|
||||
|
||||
## Implementation Plan
|
||||
|
||||
### Phase 1: Foundation (Week 1-2)
|
||||
1. Create `Training` page skeleton with tabs
|
||||
2. Implement `detect_gpu` command
|
||||
3. Add dataset listing/download commands
|
||||
4. Design TypeScript types for all entities
|
||||
|
||||
### Phase 2: Dataset Management (Week 3)
|
||||
1. MM-Fi dataset downloader
|
||||
2. Wi-Pose dataset downloader
|
||||
3. Custom dataset import (CSV/NPZ)
|
||||
4. Dataset preview component
|
||||
|
||||
### Phase 3: Model Management (Week 4)
|
||||
1. Model architecture browser
|
||||
2. Checkpoint loading
|
||||
3. Model summary display
|
||||
4. ONNX export
|
||||
|
||||
### Phase 4: Training Loop (Week 5-6)
|
||||
1. Training configuration UI
|
||||
2. Background training thread
|
||||
3. Progress event emission
|
||||
4. Checkpoint auto-save
|
||||
5. Training history persistence
|
||||
|
||||
### Phase 5: RuVector Integration (Week 7)
|
||||
1. RuVector config UI
|
||||
2. Live CSI testing
|
||||
3. A/B comparison mode
|
||||
4. Config export/import
|
||||
|
||||
### Phase 6: Metrics & Polish (Week 8)
|
||||
1. Loss curve visualization (Chart.js/Recharts)
|
||||
2. Evaluation metrics display
|
||||
3. Export functionality
|
||||
4. Error handling & edge cases
|
||||
|
||||
## Risks & Mitigations
|
||||
|
||||
| Risk | Probability | Impact | Mitigation |
|
||||
|------|-------------|--------|------------|
|
||||
| No GPU available | Medium | High | CPU fallback with warning |
|
||||
| Large dataset downloads | High | Medium | Resume support, progress UI |
|
||||
| Training crashes | Medium | High | Checkpoint recovery, error reporting |
|
||||
| Memory exhaustion | Low | High | Batch size auto-tuning |
|
||||
| UI blocking | Medium | High | All training in background thread |
|
||||
|
||||
## Success Criteria
|
||||
|
||||
1. User can download MM-Fi dataset from UI
|
||||
2. User can start training with GPU detection
|
||||
3. Live progress updates without UI freeze
|
||||
4. Training can be paused/resumed
|
||||
5. RuVector config changes apply to live CSI
|
||||
6. Metrics display updates in real-time
|
||||
7. Models can be exported to ONNX
|
||||
|
||||
## Alternatives Considered
|
||||
|
||||
### 1. Separate Training App
|
||||
- **Rejected**: Fragments user experience, duplicates code
|
||||
|
||||
### 2. Web-based Training Dashboard
|
||||
- **Rejected**: Requires server, no offline support
|
||||
|
||||
### 3. CLI-only Training
|
||||
- **Rejected**: Poor UX for non-technical users
|
||||
|
||||
## References
|
||||
|
||||
- ADR-016: RuVector Training Pipeline Integration
|
||||
- ADR-017: RuVector Signal + MAT Integration
|
||||
- ADR-024: AETHER Contrastive CSI Embedding
|
||||
- ADR-027: MERIDIAN Domain Generalization
|
||||
- Tauri v2 Events: https://v2.tauri.app/develop/calling-rust/#events
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
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,32 @@
|
||||
# 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
|
||||
|
||||
# Enable NVS encryption for secure credential storage
|
||||
CONFIG_NVS_ENCRYPTION=y
|
||||
|
||||
# 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
+36
-26
@@ -2357,20 +2357,19 @@ dependencies = [
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "hyper-rustls"
|
||||
version = "0.27.7"
|
||||
name = "hyper-tls"
|
||||
version = "0.6.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e3c93eb611681b207e1fe55d5a71ecf91572ec8a6705cdb6857f7d8d5242cf58"
|
||||
checksum = "70206fc6890eaca9fde8a0bf71caa2ddfc9fe045ac9e5c70df101a7dbde866e0"
|
||||
dependencies = [
|
||||
"http",
|
||||
"bytes",
|
||||
"http-body-util",
|
||||
"hyper",
|
||||
"hyper-util",
|
||||
"rustls 0.23.37",
|
||||
"rustls-pki-types",
|
||||
"native-tls",
|
||||
"tokio",
|
||||
"tokio-rustls",
|
||||
"tokio-native-tls",
|
||||
"tower-service",
|
||||
"webpki-roots",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -2871,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"
|
||||
@@ -4758,22 +4777,21 @@ dependencies = [
|
||||
"http-body",
|
||||
"http-body-util",
|
||||
"hyper",
|
||||
"hyper-rustls",
|
||||
"hyper-tls",
|
||||
"hyper-util",
|
||||
"js-sys",
|
||||
"log",
|
||||
"mime_guess",
|
||||
"native-tls",
|
||||
"percent-encoding",
|
||||
"pin-project-lite",
|
||||
"quinn",
|
||||
"rustls 0.23.37",
|
||||
"rustls-pki-types",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"serde_urlencoded",
|
||||
"sync_wrapper",
|
||||
"tokio",
|
||||
"tokio-rustls",
|
||||
"tokio-native-tls",
|
||||
"tower",
|
||||
"tower-http 0.6.8",
|
||||
"tower-service",
|
||||
@@ -4781,7 +4799,6 @@ dependencies = [
|
||||
"wasm-bindgen",
|
||||
"wasm-bindgen-futures",
|
||||
"web-sys",
|
||||
"webpki-roots",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -5617,6 +5634,7 @@ dependencies = [
|
||||
"core-foundation",
|
||||
"core-foundation-sys",
|
||||
"io-kit-sys",
|
||||
"libudev",
|
||||
"mach2",
|
||||
"nix 0.26.4",
|
||||
"scopeguard",
|
||||
@@ -6569,12 +6587,12 @@ dependencies = [
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tokio-rustls"
|
||||
version = "0.26.4"
|
||||
name = "tokio-native-tls"
|
||||
version = "0.3.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1729aa945f29d91ba541258c8df89027d5792d85a8841fb65e8bf0f4ede4ef61"
|
||||
checksum = "bbae76ab933c85776efabc971569dd6119c580d8f5d448769dec1764bf796ef2"
|
||||
dependencies = [
|
||||
"rustls 0.23.37",
|
||||
"native-tls",
|
||||
"tokio",
|
||||
]
|
||||
|
||||
@@ -7523,15 +7541,6 @@ dependencies = [
|
||||
"rustls-pki-types",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "webpki-roots"
|
||||
version = "1.0.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "22cfaf3c063993ff62e73cb4311efde4db1efb31ab78a3e5c457939ad5cc0bed"
|
||||
dependencies = [
|
||||
"rustls-pki-types",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "webview2-com"
|
||||
version = "0.38.2"
|
||||
@@ -7646,6 +7655,7 @@ dependencies = [
|
||||
"reqwest 0.12.28",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"serialport",
|
||||
"sha2",
|
||||
"sysinfo",
|
||||
"tauri",
|
||||
|
||||
+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
+165
-3
@@ -276,11 +276,24 @@ fn parse_beacon_response(data: &[u8], addr: SocketAddr) -> Option<DiscoveredNode
|
||||
/// Filters for known ESP32 USB-to-serial chips (CP2102, CH340, FTDI).
|
||||
#[tauri::command]
|
||||
pub async fn list_serial_ports() -> Result<Vec<SerialPortInfo>, String> {
|
||||
let ports = available_ports().map_err(|e| format!("Failed to enumerate ports: {}", e))?;
|
||||
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 {
|
||||
@@ -294,12 +307,13 @@ pub async fn list_serial_ports() -> Result<Vec<SerialPortInfo>, String> {
|
||||
}
|
||||
_ => {
|
||||
SerialPortInfo {
|
||||
name: port.port_name,
|
||||
name: port.port_name.clone(),
|
||||
vid: None,
|
||||
pid: None,
|
||||
manufacturer: None,
|
||||
serial_number: None,
|
||||
is_esp32_compatible: false,
|
||||
// Mark /dev/cu.usb* ports as potentially compatible
|
||||
is_esp32_compatible: port.port_name.contains("usb"),
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -307,9 +321,72 @@ pub async fn list_serial_ports() -> Result<Vec<SerialPortInfo>, String> {
|
||||
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)
|
||||
}
|
||||
|
||||
@@ -334,6 +411,91 @@ fn is_esp32_compatible(vid: u16, pid: u16) -> bool {
|
||||
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)]
|
||||
pub struct SerialPortInfo {
|
||||
pub name: String,
|
||||
|
||||
@@ -4,4 +4,5 @@ pub mod ota;
|
||||
pub mod provision;
|
||||
pub mod server;
|
||||
pub mod settings;
|
||||
pub mod training;
|
||||
pub mod wasm;
|
||||
|
||||
@@ -2,21 +2,77 @@ use std::process::{Command, Stdio};
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
use sysinfo::{Pid, ProcessesToUpdate, System};
|
||||
use tauri::State;
|
||||
use tauri::{AppHandle, Manager, State};
|
||||
|
||||
use crate::state::AppState;
|
||||
|
||||
/// Default path to the sensing server binary (relative to resources).
|
||||
const DEFAULT_SERVER_BIN: &str = "wifi-densepose-sensing-server";
|
||||
/// Default binary name for the sensing server.
|
||||
const DEFAULT_SERVER_BIN: &str = "sensing-server";
|
||||
|
||||
/// Find the sensing server binary path.
|
||||
///
|
||||
/// Search order:
|
||||
/// 1. Custom path from config.server_path
|
||||
/// 2. Bundled in app resources (macOS: Contents/Resources/bin/)
|
||||
/// 3. Next to the app executable
|
||||
/// 4. System PATH
|
||||
fn find_server_binary(app: &AppHandle, custom_path: Option<&str>) -> Result<String, String> {
|
||||
// 1. Custom path from settings
|
||||
if let Some(path) = custom_path {
|
||||
if std::path::Path::new(path).exists() {
|
||||
return Ok(path.to_string());
|
||||
}
|
||||
}
|
||||
|
||||
// 2. Bundled in resources (Tauri bundles to Contents/Resources/)
|
||||
if let Ok(resource_dir) = app.path().resource_dir() {
|
||||
let bundled = resource_dir.join("bin").join(DEFAULT_SERVER_BIN);
|
||||
if bundled.exists() {
|
||||
return Ok(bundled.to_string_lossy().to_string());
|
||||
}
|
||||
// Also check directly in resources
|
||||
let direct = resource_dir.join(DEFAULT_SERVER_BIN);
|
||||
if direct.exists() {
|
||||
return Ok(direct.to_string_lossy().to_string());
|
||||
}
|
||||
}
|
||||
|
||||
// 3. Next to the executable
|
||||
if let Ok(exe_path) = std::env::current_exe() {
|
||||
if let Some(exe_dir) = exe_path.parent() {
|
||||
let sibling = exe_dir.join(DEFAULT_SERVER_BIN);
|
||||
if sibling.exists() {
|
||||
return Ok(sibling.to_string_lossy().to_string());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 4. Check if it's in PATH
|
||||
if let Ok(output) = Command::new("which").arg(DEFAULT_SERVER_BIN).output() {
|
||||
if output.status.success() {
|
||||
let path = String::from_utf8_lossy(&output.stdout).trim().to_string();
|
||||
if !path.is_empty() {
|
||||
return Ok(path);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Err(format!(
|
||||
"Sensing server binary '{}' not found. Please build it with: cargo build --release -p wifi-densepose-sensing-server",
|
||||
DEFAULT_SERVER_BIN
|
||||
))
|
||||
}
|
||||
|
||||
/// Start the sensing server as a managed child process.
|
||||
///
|
||||
/// The server binary is looked up in the following order:
|
||||
/// 1. Settings `server_path` if set
|
||||
/// 2. Bundled resource path
|
||||
/// 3. System PATH
|
||||
/// 3. Next to executable
|
||||
/// 4. System PATH
|
||||
#[tauri::command]
|
||||
pub async fn start_server(
|
||||
app: AppHandle,
|
||||
config: ServerConfig,
|
||||
state: State<'_, AppState>,
|
||||
) -> Result<ServerStartResult, String> {
|
||||
@@ -28,10 +84,10 @@ pub async fn start_server(
|
||||
}
|
||||
}
|
||||
|
||||
// Determine server binary path
|
||||
let server_path = config.server_path
|
||||
.clone()
|
||||
.unwrap_or_else(|| DEFAULT_SERVER_BIN.to_string());
|
||||
// Find server binary
|
||||
let server_path = find_server_binary(&app, config.server_path.as_deref())?;
|
||||
|
||||
tracing::info!("Starting sensing server from: {}", server_path);
|
||||
|
||||
// Build command with configuration
|
||||
let mut cmd = Command::new(&server_path);
|
||||
@@ -52,6 +108,10 @@ pub async fn start_server(
|
||||
cmd.args(["--log-level", log_level]);
|
||||
}
|
||||
|
||||
// Set data source (default to "simulate" if not specified for demo mode)
|
||||
let source = config.source.as_deref().unwrap_or("simulate");
|
||||
cmd.args(["--source", source]);
|
||||
|
||||
// Redirect stdout/stderr to pipes for monitoring
|
||||
cmd.stdout(Stdio::piped());
|
||||
cmd.stderr(Stdio::piped());
|
||||
@@ -88,14 +148,15 @@ pub async fn start_server(
|
||||
/// First attempts graceful termination (SIGTERM), then SIGKILL after timeout.
|
||||
#[tauri::command]
|
||||
pub async fn stop_server(state: State<'_, AppState>) -> Result<(), String> {
|
||||
// Extract child process ID and take ownership of child for killing
|
||||
// This releases the lock before any await points
|
||||
let child_id = {
|
||||
let srv = state.server.lock().map_err(|e| e.to_string())?;
|
||||
// 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());
|
||||
}
|
||||
srv.pid
|
||||
let pid = srv.pid;
|
||||
let child = srv.child.take(); // Take ownership of child
|
||||
(pid, child)
|
||||
};
|
||||
|
||||
let child_id = match child_id {
|
||||
@@ -103,46 +164,60 @@ pub async fn stop_server(state: State<'_, AppState>) -> Result<(), String> {
|
||||
None => return Err("No server process found".into()),
|
||||
};
|
||||
|
||||
// First try graceful termination
|
||||
tracing::info!("Stopping sensing server with PID {}", child_id);
|
||||
|
||||
// First try graceful termination via SIGTERM
|
||||
#[cfg(unix)]
|
||||
{
|
||||
unsafe {
|
||||
libc::kill(child_id as i32, libc::SIGTERM);
|
||||
// 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 (async operation - no lock held)
|
||||
let wait_result: Result<Result<bool, _>, _> = tokio::time::timeout(
|
||||
std::time::Duration::from_secs(5),
|
||||
tokio::task::spawn_blocking({
|
||||
move || {
|
||||
std::thread::sleep(std::time::Duration::from_millis(100));
|
||||
// Check if process is 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()
|
||||
}
|
||||
})
|
||||
).await;
|
||||
// Wait briefly for graceful shutdown
|
||||
tokio::time::sleep(std::time::Duration::from_millis(500)).await;
|
||||
|
||||
// Force kill if still running - re-acquire lock
|
||||
let still_running = match wait_result {
|
||||
Ok(Ok(running)) => running,
|
||||
_ => true,
|
||||
// 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()
|
||||
};
|
||||
|
||||
{
|
||||
let mut srv = state.server.lock().map_err(|e| e.to_string())?;
|
||||
// Force kill if still running
|
||||
if still_running {
|
||||
tracing::warn!("Server still running after SIGTERM, sending SIGKILL");
|
||||
|
||||
if still_running {
|
||||
if let Some(ref mut child) = srv.child {
|
||||
let _ = child.kill();
|
||||
let _ = child.wait();
|
||||
#[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);
|
||||
}
|
||||
}
|
||||
|
||||
// Clear state
|
||||
// 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;
|
||||
@@ -151,6 +226,19 @@ pub async fn stop_server(state: State<'_, AppState>) -> Result<(), String> {
|
||||
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(())
|
||||
@@ -207,6 +295,7 @@ pub async fn server_status(state: State<'_, AppState>) -> Result<ServerStatusRes
|
||||
/// Restart the sensing server with the same or new configuration.
|
||||
#[tauri::command]
|
||||
pub async fn restart_server(
|
||||
app: AppHandle,
|
||||
config: Option<ServerConfig>,
|
||||
state: State<'_, AppState>,
|
||||
) -> Result<ServerStartResult, String> {
|
||||
@@ -222,6 +311,7 @@ pub async fn restart_server(
|
||||
log_level: None,
|
||||
bind_address: None,
|
||||
server_path: None,
|
||||
source: None, // Use default (simulate)
|
||||
}
|
||||
};
|
||||
|
||||
@@ -232,7 +322,7 @@ pub async fn restart_server(
|
||||
tokio::time::sleep(std::time::Duration::from_millis(500)).await;
|
||||
|
||||
// Start with new config
|
||||
start_server(restart_config, state).await
|
||||
start_server(app, restart_config, state).await
|
||||
}
|
||||
|
||||
/// Get server logs (last N lines from stdout/stderr).
|
||||
@@ -260,6 +350,8 @@ pub struct ServerConfig {
|
||||
pub log_level: Option<String>,
|
||||
pub bind_address: Option<String>,
|
||||
pub server_path: Option<String>,
|
||||
/// Data source: "auto", "wifi", "esp32", "simulate"
|
||||
pub source: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
@@ -302,6 +394,7 @@ mod tests {
|
||||
log_level: None,
|
||||
bind_address: None,
|
||||
server_path: None,
|
||||
source: Some("simulate".to_string()),
|
||||
};
|
||||
|
||||
assert_eq!(config.http_port, Some(8080));
|
||||
|
||||
@@ -0,0 +1,482 @@
|
||||
//! Training commands for the desktop application.
|
||||
//!
|
||||
//! Provides Tauri commands for:
|
||||
//! - GPU detection
|
||||
//! - Dataset management
|
||||
//! - Model/checkpoint operations
|
||||
//! - Training job control
|
||||
//! - RuVector configuration
|
||||
//! - Metrics retrieval
|
||||
|
||||
use crate::domain::training::{
|
||||
CheckpointInfo, DatasetFormat, DatasetInfo, EpochMetrics, EvaluationMetrics,
|
||||
GpuBackend, GpuInfo, JointAccuracy, LiveTestMetrics,
|
||||
ModelInfo, ModelType, RuVectorConfig, TrainingConfig, TrainingJob,
|
||||
TrainingProgress, TrainingStatus,
|
||||
};
|
||||
use crate::state::AppState;
|
||||
use tauri::State;
|
||||
|
||||
// ============================================================================
|
||||
// Standard Datasets (built-in)
|
||||
// ============================================================================
|
||||
|
||||
fn get_standard_datasets() -> Vec<DatasetInfo> {
|
||||
vec![
|
||||
DatasetInfo {
|
||||
id: "mmfi".into(),
|
||||
name: "MM-Fi Dataset".into(),
|
||||
description: "Multi-modal WiFi sensing dataset with 40 subjects, 27 activities".into(),
|
||||
format: DatasetFormat::MmFi,
|
||||
size_mb: 2400.0,
|
||||
samples: 320000,
|
||||
downloaded: false,
|
||||
path: None,
|
||||
url: Some("https://ntu-aiot-lab.github.io/mm-fi".into()),
|
||||
},
|
||||
DatasetInfo {
|
||||
id: "wipose".into(),
|
||||
name: "Wi-Pose Dataset".into(),
|
||||
description: "WiFi-based pose estimation with 3D skeleton annotations".into(),
|
||||
format: DatasetFormat::WiPose,
|
||||
size_mb: 1800.0,
|
||||
samples: 150000,
|
||||
downloaded: false,
|
||||
path: None,
|
||||
url: Some("https://github.com/Wi-Pose".into()),
|
||||
},
|
||||
DatasetInfo {
|
||||
id: "wiar".into(),
|
||||
name: "WiAR Dataset".into(),
|
||||
description: "WiFi activity recognition with CSI data".into(),
|
||||
format: DatasetFormat::Wiar,
|
||||
size_mb: 500.0,
|
||||
samples: 45000,
|
||||
downloaded: false,
|
||||
path: None,
|
||||
url: Some("https://github.com/WiAR".into()),
|
||||
},
|
||||
]
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// Standard Model Architectures
|
||||
// ============================================================================
|
||||
|
||||
fn get_standard_models() -> Vec<ModelInfo> {
|
||||
vec![
|
||||
ModelInfo {
|
||||
id: "csi-encoder-cnn".into(),
|
||||
name: "CSI Encoder (CNN)".into(),
|
||||
model_type: ModelType::Encoder,
|
||||
description: "Convolutional encoder for CSI amplitude/phase features".into(),
|
||||
params_m: 2.3,
|
||||
memory_mb: 128,
|
||||
paper: None,
|
||||
},
|
||||
ModelInfo {
|
||||
id: "csi-encoder-transformer".into(),
|
||||
name: "CSI Encoder (Transformer)".into(),
|
||||
model_type: ModelType::Encoder,
|
||||
description: "Self-attention based CSI feature extraction".into(),
|
||||
params_m: 8.5,
|
||||
memory_mb: 384,
|
||||
paper: Some("WiFi-ViT 2024".into()),
|
||||
},
|
||||
ModelInfo {
|
||||
id: "pose-decoder-lstm".into(),
|
||||
name: "Pose Decoder (LSTM)".into(),
|
||||
model_type: ModelType::Decoder,
|
||||
description: "Recurrent decoder for temporal pose estimation".into(),
|
||||
params_m: 1.8,
|
||||
memory_mb: 96,
|
||||
paper: None,
|
||||
},
|
||||
ModelInfo {
|
||||
id: "pose-decoder-gru".into(),
|
||||
name: "Pose Decoder (GRU)".into(),
|
||||
model_type: ModelType::Decoder,
|
||||
description: "Gated recurrent unit pose decoder (faster)".into(),
|
||||
params_m: 1.2,
|
||||
memory_mb: 64,
|
||||
paper: None,
|
||||
},
|
||||
ModelInfo {
|
||||
id: "aether-embedding".into(),
|
||||
name: "AETHER Embedding".into(),
|
||||
model_type: ModelType::Embedding,
|
||||
description: "Contrastive CSI embedding for person re-identification (ADR-024)".into(),
|
||||
params_m: 4.2,
|
||||
memory_mb: 192,
|
||||
paper: Some("AETHER 2025".into()),
|
||||
},
|
||||
ModelInfo {
|
||||
id: "meridian-adaptor".into(),
|
||||
name: "MERIDIAN Adaptor".into(),
|
||||
model_type: ModelType::Adaptor,
|
||||
description: "Cross-environment domain generalization module (ADR-027)".into(),
|
||||
params_m: 3.1,
|
||||
memory_mb: 144,
|
||||
paper: Some("MERIDIAN 2025".into()),
|
||||
},
|
||||
]
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// GPU Detection Commands
|
||||
// ============================================================================
|
||||
|
||||
/// Detect available GPU(s) and return information.
|
||||
#[tauri::command]
|
||||
pub async fn detect_gpu(state: State<'_, AppState>) -> Result<GpuInfo, String> {
|
||||
// Check for cached GPU info
|
||||
if let Ok(training) = state.training.lock() {
|
||||
if let Some(ref info) = training.gpu_info {
|
||||
return Ok(info.clone());
|
||||
}
|
||||
}
|
||||
|
||||
// Detect GPU
|
||||
let info = detect_gpu_internal();
|
||||
|
||||
// Cache the result
|
||||
if let Ok(mut training) = state.training.lock() {
|
||||
training.gpu_info = Some(info.clone());
|
||||
}
|
||||
|
||||
Ok(info)
|
||||
}
|
||||
|
||||
fn detect_gpu_internal() -> GpuInfo {
|
||||
// Check for Metal on macOS
|
||||
#[cfg(target_os = "macos")]
|
||||
{
|
||||
// Check if system has Apple Silicon or discrete GPU
|
||||
let has_metal = std::process::Command::new("system_profiler")
|
||||
.args(["SPDisplaysDataType", "-json"])
|
||||
.output()
|
||||
.map(|o| {
|
||||
let output = String::from_utf8_lossy(&o.stdout);
|
||||
output.contains("Metal") || output.contains("Apple M")
|
||||
})
|
||||
.unwrap_or(false);
|
||||
|
||||
if has_metal {
|
||||
// Try to get GPU name
|
||||
let name = std::process::Command::new("system_profiler")
|
||||
.args(["SPDisplaysDataType"])
|
||||
.output()
|
||||
.ok()
|
||||
.and_then(|o| {
|
||||
let output = String::from_utf8_lossy(&o.stdout);
|
||||
// Parse chipset name
|
||||
for line in output.lines() {
|
||||
if line.contains("Chipset Model:") {
|
||||
return line.split(':').nth(1).map(|s| s.trim().to_string());
|
||||
}
|
||||
}
|
||||
None
|
||||
});
|
||||
|
||||
return GpuInfo {
|
||||
available: true,
|
||||
backend: GpuBackend::Metal,
|
||||
name,
|
||||
memory_mb: None, // Metal doesn't easily expose this
|
||||
cuda_version: None,
|
||||
metal_supported: true,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
// Check for CUDA on Linux/Windows
|
||||
#[cfg(any(target_os = "linux", target_os = "windows"))]
|
||||
{
|
||||
// Try nvidia-smi for CUDA detection
|
||||
if let Ok(output) = std::process::Command::new("nvidia-smi")
|
||||
.args(["--query-gpu=name,memory.total", "--format=csv,noheader,nounits"])
|
||||
.output()
|
||||
{
|
||||
if output.status.success() {
|
||||
let stdout = String::from_utf8_lossy(&output.stdout);
|
||||
let parts: Vec<&str> = stdout.trim().split(',').collect();
|
||||
|
||||
let name = parts.first().map(|s| s.trim().to_string());
|
||||
let memory_mb = parts.get(1)
|
||||
.and_then(|s| s.trim().parse::<u64>().ok());
|
||||
|
||||
// Get CUDA version
|
||||
let cuda_version = std::process::Command::new("nvidia-smi")
|
||||
.output()
|
||||
.ok()
|
||||
.and_then(|o| {
|
||||
let output = String::from_utf8_lossy(&o.stdout);
|
||||
for line in output.lines() {
|
||||
if line.contains("CUDA Version:") {
|
||||
return line.split("CUDA Version:")
|
||||
.nth(1)
|
||||
.map(|s| s.split_whitespace().next().unwrap_or("").to_string());
|
||||
}
|
||||
}
|
||||
None
|
||||
});
|
||||
|
||||
return GpuInfo {
|
||||
available: true,
|
||||
backend: GpuBackend::Cuda,
|
||||
name,
|
||||
memory_mb,
|
||||
cuda_version,
|
||||
metal_supported: false,
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Fall back to CPU
|
||||
GpuInfo {
|
||||
available: false,
|
||||
backend: GpuBackend::Cpu,
|
||||
name: None,
|
||||
memory_mb: None,
|
||||
cuda_version: None,
|
||||
metal_supported: false,
|
||||
}
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// Dataset Commands
|
||||
// ============================================================================
|
||||
|
||||
/// List available datasets (both standard and downloaded).
|
||||
#[tauri::command]
|
||||
pub async fn list_datasets(state: State<'_, AppState>) -> Result<Vec<String>, String> {
|
||||
let training = state.training.lock().map_err(|e| e.to_string())?;
|
||||
|
||||
// Return IDs of downloaded datasets
|
||||
Ok(training.datasets.iter()
|
||||
.filter(|d| d.downloaded)
|
||||
.map(|d| d.id.clone())
|
||||
.collect())
|
||||
}
|
||||
|
||||
/// Get full dataset information.
|
||||
#[tauri::command]
|
||||
pub async fn get_datasets(state: State<'_, AppState>) -> Result<Vec<DatasetInfo>, String> {
|
||||
let mut training = state.training.lock().map_err(|e| e.to_string())?;
|
||||
|
||||
// Initialize with standard datasets if empty
|
||||
if training.datasets.is_empty() {
|
||||
training.datasets = get_standard_datasets();
|
||||
}
|
||||
|
||||
Ok(training.datasets.clone())
|
||||
}
|
||||
|
||||
/// Download a dataset (placeholder - actual download would need async HTTP).
|
||||
#[tauri::command]
|
||||
pub async fn download_dataset(
|
||||
dataset_id: String,
|
||||
state: State<'_, AppState>,
|
||||
) -> Result<DatasetInfo, String> {
|
||||
let mut training = state.training.lock().map_err(|e| e.to_string())?;
|
||||
|
||||
// Find the dataset
|
||||
let dataset = training.datasets.iter_mut()
|
||||
.find(|d| d.id == dataset_id)
|
||||
.ok_or_else(|| format!("Dataset not found: {}", dataset_id))?;
|
||||
|
||||
// Simulate download completion
|
||||
dataset.downloaded = true;
|
||||
dataset.path = Some(format!("~/.ruview/datasets/{}", dataset_id));
|
||||
|
||||
Ok(dataset.clone())
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// Model/Checkpoint Commands
|
||||
// ============================================================================
|
||||
|
||||
/// List available model architectures.
|
||||
#[tauri::command]
|
||||
pub async fn list_models() -> Result<Vec<ModelInfo>, String> {
|
||||
Ok(get_standard_models())
|
||||
}
|
||||
|
||||
/// List saved checkpoints.
|
||||
#[tauri::command]
|
||||
pub async fn list_checkpoints(state: State<'_, AppState>) -> Result<Vec<CheckpointInfo>, String> {
|
||||
let training = state.training.lock().map_err(|e| e.to_string())?;
|
||||
Ok(training.checkpoints.clone())
|
||||
}
|
||||
|
||||
/// Export a model checkpoint to ONNX or TorchScript.
|
||||
#[tauri::command]
|
||||
pub async fn export_model(
|
||||
checkpoint_id: String,
|
||||
format: String,
|
||||
state: State<'_, AppState>,
|
||||
) -> Result<String, String> {
|
||||
let training = state.training.lock().map_err(|e| e.to_string())?;
|
||||
|
||||
let checkpoint = training.checkpoints.iter()
|
||||
.find(|c| c.id == checkpoint_id)
|
||||
.ok_or_else(|| format!("Checkpoint not found: {}", checkpoint_id))?;
|
||||
|
||||
let output_path = match format.as_str() {
|
||||
"onnx" => format!("{}.onnx", checkpoint.path.trim_end_matches(".pt")),
|
||||
"torchscript" => format!("{}.ts", checkpoint.path.trim_end_matches(".pt")),
|
||||
_ => return Err(format!("Unsupported format: {}", format)),
|
||||
};
|
||||
|
||||
// In a real implementation, this would call the actual export logic
|
||||
Ok(output_path)
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// Training Job Commands
|
||||
// ============================================================================
|
||||
|
||||
/// Start a training job.
|
||||
#[tauri::command]
|
||||
pub async fn start_training(
|
||||
config: TrainingConfig,
|
||||
state: State<'_, AppState>,
|
||||
) -> Result<String, String> {
|
||||
let mut training = state.training.lock().map_err(|e| e.to_string())?;
|
||||
|
||||
// Create a new job
|
||||
let job_id = uuid::Uuid::new_v4().to_string();
|
||||
let job = TrainingJob {
|
||||
id: job_id.clone(),
|
||||
config,
|
||||
status: TrainingStatus::Running,
|
||||
started_at: Some(chrono::Utc::now().to_rfc3339()),
|
||||
progress: TrainingProgress::default(),
|
||||
loss_history: Vec::new(),
|
||||
};
|
||||
|
||||
training.current_job = Some(job);
|
||||
|
||||
// In a real implementation, this would spawn a background training thread
|
||||
// and emit progress events via Tauri's event system
|
||||
|
||||
Ok(job_id)
|
||||
}
|
||||
|
||||
/// Stop the current training job.
|
||||
#[tauri::command]
|
||||
pub async fn stop_training(state: State<'_, AppState>) -> Result<(), String> {
|
||||
let mut training = state.training.lock().map_err(|e| e.to_string())?;
|
||||
|
||||
if let Some(ref mut job) = training.current_job {
|
||||
job.status = TrainingStatus::Paused;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Get current training progress.
|
||||
#[tauri::command]
|
||||
pub async fn training_progress(state: State<'_, AppState>) -> Result<Option<TrainingProgress>, String> {
|
||||
let training = state.training.lock().map_err(|e| e.to_string())?;
|
||||
Ok(training.current_job.as_ref().map(|j| j.progress.clone()))
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// RuVector Configuration Commands
|
||||
// ============================================================================
|
||||
|
||||
/// Get current RuVector configuration.
|
||||
#[tauri::command]
|
||||
pub async fn get_ruvector_config(state: State<'_, AppState>) -> Result<RuVectorConfig, String> {
|
||||
let training = state.training.lock().map_err(|e| e.to_string())?;
|
||||
Ok(training.ruvector_config.clone())
|
||||
}
|
||||
|
||||
/// Set RuVector configuration.
|
||||
#[tauri::command]
|
||||
pub async fn set_ruvector_config(
|
||||
config: RuVectorConfig,
|
||||
state: State<'_, AppState>,
|
||||
) -> Result<(), String> {
|
||||
let mut training = state.training.lock().map_err(|e| e.to_string())?;
|
||||
training.ruvector_config = config;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Test RuVector modules on live CSI data.
|
||||
#[tauri::command]
|
||||
pub async fn test_ruvector_live(
|
||||
_state: State<'_, AppState>,
|
||||
) -> Result<LiveTestMetrics, String> {
|
||||
// In a real implementation, this would process live CSI data
|
||||
// through the RuVector pipeline and return metrics
|
||||
Ok(LiveTestMetrics {
|
||||
fps: 30.0,
|
||||
latency_ms: 15.0,
|
||||
persons_detected: 1,
|
||||
})
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// Metrics Commands
|
||||
// ============================================================================
|
||||
|
||||
/// Get training history (loss/accuracy per epoch).
|
||||
#[tauri::command]
|
||||
pub async fn get_training_history(state: State<'_, AppState>) -> Result<Vec<EpochMetrics>, String> {
|
||||
let training = state.training.lock().map_err(|e| e.to_string())?;
|
||||
Ok(training.training_history.clone())
|
||||
}
|
||||
|
||||
/// Get evaluation metrics.
|
||||
#[tauri::command]
|
||||
pub async fn get_evaluation_metrics(state: State<'_, AppState>) -> Result<Option<EvaluationMetrics>, String> {
|
||||
let training = state.training.lock().map_err(|e| e.to_string())?;
|
||||
Ok(training.evaluation_metrics.clone())
|
||||
}
|
||||
|
||||
/// Get per-joint accuracy metrics.
|
||||
#[tauri::command]
|
||||
pub async fn get_joint_accuracies(state: State<'_, AppState>) -> Result<Vec<JointAccuracy>, String> {
|
||||
let training = state.training.lock().map_err(|e| e.to_string())?;
|
||||
Ok(training.joint_accuracies.clone())
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// Tests
|
||||
// ============================================================================
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn test_standard_datasets() {
|
||||
let datasets = get_standard_datasets();
|
||||
assert_eq!(datasets.len(), 3);
|
||||
assert!(datasets.iter().any(|d| d.id == "mmfi"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_standard_models() {
|
||||
let models = get_standard_models();
|
||||
assert_eq!(models.len(), 6);
|
||||
assert!(models.iter().any(|m| m.id == "csi-encoder-cnn"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_detect_gpu_internal() {
|
||||
let info = detect_gpu_internal();
|
||||
// Just verify it returns valid data
|
||||
assert!(matches!(info.backend, GpuBackend::Cpu | GpuBackend::Cuda | GpuBackend::Metal));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_ruvector_config_default() {
|
||||
let config = RuVectorConfig::default();
|
||||
assert!(config.mincut_enabled);
|
||||
assert_eq!(config.attention_heads, 4);
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
pub mod config;
|
||||
pub mod firmware;
|
||||
pub mod node;
|
||||
pub mod training;
|
||||
|
||||
@@ -0,0 +1,312 @@
|
||||
//! Training domain types for the desktop application.
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
/// GPU backend type.
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Default)]
|
||||
#[serde(rename_all = "lowercase")]
|
||||
pub enum GpuBackend {
|
||||
Cuda,
|
||||
Metal,
|
||||
#[default]
|
||||
Cpu,
|
||||
}
|
||||
|
||||
/// GPU information.
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
|
||||
pub struct GpuInfo {
|
||||
pub available: bool,
|
||||
pub backend: GpuBackend,
|
||||
pub name: Option<String>,
|
||||
pub memory_mb: Option<u64>,
|
||||
pub cuda_version: Option<String>,
|
||||
pub metal_supported: bool,
|
||||
}
|
||||
|
||||
/// Dataset format type.
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Default)]
|
||||
#[serde(rename_all = "lowercase")]
|
||||
pub enum DatasetFormat {
|
||||
#[default]
|
||||
MmFi,
|
||||
WiPose,
|
||||
Wiar,
|
||||
Custom,
|
||||
}
|
||||
|
||||
/// Dataset information.
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct DatasetInfo {
|
||||
pub id: String,
|
||||
pub name: String,
|
||||
pub description: String,
|
||||
pub format: DatasetFormat,
|
||||
pub size_mb: f64,
|
||||
pub samples: u64,
|
||||
pub downloaded: bool,
|
||||
pub path: Option<String>,
|
||||
pub url: Option<String>,
|
||||
}
|
||||
|
||||
/// Model architecture type.
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Default)]
|
||||
#[serde(rename_all = "lowercase")]
|
||||
pub enum ModelType {
|
||||
#[default]
|
||||
Encoder,
|
||||
Decoder,
|
||||
Embedding,
|
||||
Adaptor,
|
||||
}
|
||||
|
||||
/// Model architecture information.
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct ModelInfo {
|
||||
pub id: String,
|
||||
pub name: String,
|
||||
pub model_type: ModelType,
|
||||
pub description: String,
|
||||
pub params_m: f64,
|
||||
pub memory_mb: u64,
|
||||
pub paper: Option<String>,
|
||||
}
|
||||
|
||||
/// Checkpoint information.
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct CheckpointInfo {
|
||||
pub id: String,
|
||||
pub model_id: String,
|
||||
pub name: String,
|
||||
pub epoch: u32,
|
||||
pub val_loss: f64,
|
||||
pub created_at: String,
|
||||
pub path: String,
|
||||
pub size_mb: f64,
|
||||
}
|
||||
|
||||
/// Training configuration.
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct TrainingConfig {
|
||||
pub dataset_id: String,
|
||||
pub model_id: String,
|
||||
pub epochs: u32,
|
||||
pub batch_size: u32,
|
||||
pub learning_rate: f64,
|
||||
pub optimizer: OptimizerType,
|
||||
pub weight_decay: f64,
|
||||
pub use_augmentation: bool,
|
||||
pub checkpoint_every: u32,
|
||||
}
|
||||
|
||||
impl Default for TrainingConfig {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
dataset_id: "mmfi".into(),
|
||||
model_id: "csi-encoder-cnn".into(),
|
||||
epochs: 100,
|
||||
batch_size: 32,
|
||||
learning_rate: 0.001,
|
||||
optimizer: OptimizerType::Adam,
|
||||
weight_decay: 0.0001,
|
||||
use_augmentation: true,
|
||||
checkpoint_every: 10,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Optimizer type.
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Default)]
|
||||
#[serde(rename_all = "lowercase")]
|
||||
pub enum OptimizerType {
|
||||
#[default]
|
||||
Adam,
|
||||
AdamW,
|
||||
Sgd,
|
||||
}
|
||||
|
||||
/// Training job status.
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Default)]
|
||||
#[serde(rename_all = "lowercase")]
|
||||
pub enum TrainingStatus {
|
||||
#[default]
|
||||
Pending,
|
||||
Running,
|
||||
Paused,
|
||||
Completed,
|
||||
Failed,
|
||||
}
|
||||
|
||||
/// Training progress.
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
|
||||
pub struct TrainingProgress {
|
||||
pub epoch: u32,
|
||||
pub total_epochs: u32,
|
||||
pub batch: u32,
|
||||
pub total_batches: u32,
|
||||
pub train_loss: f64,
|
||||
pub val_loss: Option<f64>,
|
||||
pub learning_rate: f64,
|
||||
pub eta_secs: u64,
|
||||
pub gpu_memory_mb: Option<u64>,
|
||||
}
|
||||
|
||||
/// Training job.
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct TrainingJob {
|
||||
pub id: String,
|
||||
pub config: TrainingConfig,
|
||||
pub status: TrainingStatus,
|
||||
pub started_at: Option<String>,
|
||||
pub progress: TrainingProgress,
|
||||
pub loss_history: Vec<EpochMetrics>,
|
||||
}
|
||||
|
||||
/// Metrics for a single epoch.
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct EpochMetrics {
|
||||
pub epoch: u32,
|
||||
pub train_loss: f64,
|
||||
pub val_loss: f64,
|
||||
pub train_acc: f64,
|
||||
pub val_acc: f64,
|
||||
pub learning_rate: f64,
|
||||
pub timestamp: String,
|
||||
}
|
||||
|
||||
/// Evaluation metrics.
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
|
||||
pub struct EvaluationMetrics {
|
||||
pub pck_05: f64,
|
||||
pub pck_10: f64,
|
||||
pub pck_20: f64,
|
||||
pub map_50: f64,
|
||||
pub map_75: f64,
|
||||
pub iou: f64,
|
||||
}
|
||||
|
||||
/// Per-joint accuracy.
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct JointAccuracy {
|
||||
pub joint: String,
|
||||
pub accuracy: f64,
|
||||
}
|
||||
|
||||
/// RuVector interpolation mode.
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Default)]
|
||||
#[serde(rename_all = "lowercase")]
|
||||
pub enum InterpolationMode {
|
||||
Linear,
|
||||
Cubic,
|
||||
#[default]
|
||||
Sparse,
|
||||
}
|
||||
|
||||
/// RuVector module configuration.
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct RuVectorConfig {
|
||||
// MinCut parameters
|
||||
pub mincut_enabled: bool,
|
||||
pub mincut_threshold: f64,
|
||||
pub mincut_max_persons: u32,
|
||||
|
||||
// Attention parameters
|
||||
pub attention_enabled: bool,
|
||||
pub attention_heads: u32,
|
||||
pub attention_dropout: f64,
|
||||
|
||||
// Temporal parameters
|
||||
pub temporal_enabled: bool,
|
||||
pub temporal_window_ms: u32,
|
||||
pub temporal_compression_ratio: u32,
|
||||
|
||||
// Solver parameters
|
||||
pub solver_enabled: bool,
|
||||
pub solver_interpolation: InterpolationMode,
|
||||
pub solver_subcarrier_count: u32,
|
||||
|
||||
// BVP parameters
|
||||
pub bvp_enabled: bool,
|
||||
pub bvp_filter_hz: (f64, f64),
|
||||
}
|
||||
|
||||
impl Default for RuVectorConfig {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
mincut_enabled: true,
|
||||
mincut_threshold: 0.5,
|
||||
mincut_max_persons: 5,
|
||||
attention_enabled: true,
|
||||
attention_heads: 4,
|
||||
attention_dropout: 0.1,
|
||||
temporal_enabled: true,
|
||||
temporal_window_ms: 500,
|
||||
temporal_compression_ratio: 4,
|
||||
solver_enabled: true,
|
||||
solver_interpolation: InterpolationMode::Sparse,
|
||||
solver_subcarrier_count: 56,
|
||||
bvp_enabled: false,
|
||||
bvp_filter_hz: (0.7, 4.0),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Live test metrics from RuVector processing.
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
|
||||
pub struct LiveTestMetrics {
|
||||
pub fps: f64,
|
||||
pub latency_ms: f64,
|
||||
pub persons_detected: u32,
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn test_gpu_info_default() {
|
||||
let info = GpuInfo::default();
|
||||
assert!(!info.available);
|
||||
assert_eq!(info.backend, GpuBackend::Cpu);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_training_config_default() {
|
||||
let config = TrainingConfig::default();
|
||||
assert_eq!(config.epochs, 100);
|
||||
assert_eq!(config.batch_size, 32);
|
||||
assert_eq!(config.optimizer, OptimizerType::Adam);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_ruvector_config_default() {
|
||||
let config = RuVectorConfig::default();
|
||||
assert!(config.mincut_enabled);
|
||||
assert_eq!(config.mincut_threshold, 0.5);
|
||||
assert_eq!(config.attention_heads, 4);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_serialization() {
|
||||
let config = TrainingConfig::default();
|
||||
let json = serde_json::to_string(&config).unwrap();
|
||||
let parsed: TrainingConfig = serde_json::from_str(&json).unwrap();
|
||||
assert_eq!(parsed.epochs, config.epochs);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_dataset_info() {
|
||||
let dataset = DatasetInfo {
|
||||
id: "mmfi".into(),
|
||||
name: "MM-Fi Dataset".into(),
|
||||
description: "Multi-modal WiFi sensing".into(),
|
||||
format: DatasetFormat::MmFi,
|
||||
size_mb: 2400.0,
|
||||
samples: 320000,
|
||||
downloaded: false,
|
||||
path: None,
|
||||
url: Some("https://example.com/mmfi.zip".into()),
|
||||
};
|
||||
assert_eq!(dataset.id, "mmfi");
|
||||
assert!(!dataset.downloaded);
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,7 @@ pub mod commands;
|
||||
pub mod domain;
|
||||
pub mod state;
|
||||
|
||||
use commands::{discovery, flash, ota, provision, server, settings, wasm};
|
||||
use commands::{discovery, flash, ota, provision, server, settings, training, wasm};
|
||||
|
||||
pub fn run() {
|
||||
tauri::Builder::default()
|
||||
@@ -13,6 +13,7 @@ pub fn run() {
|
||||
// Discovery
|
||||
discovery::discover_nodes,
|
||||
discovery::list_serial_ports,
|
||||
discovery::configure_esp32_wifi,
|
||||
// Flash
|
||||
flash::flash_firmware,
|
||||
flash::flash_progress,
|
||||
@@ -45,6 +46,23 @@ pub fn run() {
|
||||
// Settings
|
||||
settings::get_settings,
|
||||
settings::save_settings,
|
||||
// Training
|
||||
training::detect_gpu,
|
||||
training::list_datasets,
|
||||
training::get_datasets,
|
||||
training::download_dataset,
|
||||
training::list_models,
|
||||
training::list_checkpoints,
|
||||
training::export_model,
|
||||
training::start_training,
|
||||
training::stop_training,
|
||||
training::training_progress,
|
||||
training::get_ruvector_config,
|
||||
training::set_ruvector_config,
|
||||
training::test_ruvector_live,
|
||||
training::get_training_history,
|
||||
training::get_evaluation_metrics,
|
||||
training::get_joint_accuracies,
|
||||
])
|
||||
.run(tauri::generate_context!())
|
||||
.expect("error while running tauri application");
|
||||
|
||||
@@ -3,6 +3,10 @@ use std::sync::Mutex;
|
||||
use std::time::Instant;
|
||||
|
||||
use crate::domain::node::DiscoveredNode;
|
||||
use crate::domain::training::{
|
||||
CheckpointInfo, DatasetInfo, EpochMetrics, EvaluationMetrics,
|
||||
GpuInfo, JointAccuracy, RuVectorConfig, TrainingJob,
|
||||
};
|
||||
|
||||
/// Sub-state for discovered nodes.
|
||||
#[derive(Default)]
|
||||
@@ -87,6 +91,33 @@ impl Default for SettingsState {
|
||||
}
|
||||
}
|
||||
|
||||
/// Sub-state for training operations.
|
||||
pub struct TrainingState {
|
||||
pub gpu_info: Option<GpuInfo>,
|
||||
pub datasets: Vec<DatasetInfo>,
|
||||
pub checkpoints: Vec<CheckpointInfo>,
|
||||
pub current_job: Option<TrainingJob>,
|
||||
pub ruvector_config: RuVectorConfig,
|
||||
pub training_history: Vec<EpochMetrics>,
|
||||
pub evaluation_metrics: Option<EvaluationMetrics>,
|
||||
pub joint_accuracies: Vec<JointAccuracy>,
|
||||
}
|
||||
|
||||
impl Default for TrainingState {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
gpu_info: None,
|
||||
datasets: Vec::new(),
|
||||
checkpoints: Vec::new(),
|
||||
current_job: None,
|
||||
ruvector_config: RuVectorConfig::default(),
|
||||
training_history: Vec::new(),
|
||||
evaluation_metrics: None,
|
||||
joint_accuracies: Vec::new(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Top-level application state managed by Tauri.
|
||||
pub struct AppState {
|
||||
pub discovery: Mutex<DiscoveryState>,
|
||||
@@ -94,6 +125,7 @@ pub struct AppState {
|
||||
pub flash: Mutex<FlashState>,
|
||||
pub ota: Mutex<OtaState>,
|
||||
pub settings: Mutex<SettingsState>,
|
||||
pub training: Mutex<TrainingState>,
|
||||
}
|
||||
|
||||
impl Default for AppState {
|
||||
@@ -104,6 +136,7 @@ impl Default for AppState {
|
||||
flash: Mutex::new(FlashState::default()),
|
||||
ota: Mutex::new(OtaState::default()),
|
||||
settings: Mutex::new(SettingsState::default()),
|
||||
training: Mutex::new(TrainingState::default()),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -135,6 +168,9 @@ impl AppState {
|
||||
if let Ok(mut settings) = self.settings.lock() {
|
||||
*settings = SettingsState::default();
|
||||
}
|
||||
if let Ok(mut training) = self.training.lock() {
|
||||
*training = TrainingState::default();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"$schema": "https://raw.githubusercontent.com/tauri-apps/tauri/dev/crates/tauri-config-schema/schema.json",
|
||||
"productName": "RuView Desktop",
|
||||
"version": "0.4.0",
|
||||
"version": "0.5.0",
|
||||
"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.4.0",
|
||||
"version": "0.5.0",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
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";
|
||||
@@ -7,6 +8,7 @@ import { OtaUpdate } from "./pages/OtaUpdate";
|
||||
import { EdgeModules } from "./pages/EdgeModules";
|
||||
import { Sensing } from "./pages/Sensing";
|
||||
import { MeshView } from "./pages/MeshView";
|
||||
import Training from "./pages/Training";
|
||||
import { Settings } from "./pages/Settings";
|
||||
|
||||
type Page =
|
||||
@@ -18,6 +20,7 @@ type Page =
|
||||
| "wasm"
|
||||
| "sensing"
|
||||
| "mesh"
|
||||
| "training"
|
||||
| "settings";
|
||||
|
||||
interface NavItem {
|
||||
@@ -35,6 +38,7 @@ const NAV_ITEMS: NavItem[] = [
|
||||
{ id: "wasm", label: "Edge Modules", icon: "\u2B21" },
|
||||
{ id: "sensing", label: "Sensing", icon: "\u2248" },
|
||||
{ id: "mesh", label: "Mesh View", icon: "\u2B2F" },
|
||||
{ id: "training", label: "Training", icon: "\u2B50" },
|
||||
{ id: "settings", label: "Settings", icon: "\u2699" },
|
||||
];
|
||||
|
||||
@@ -90,14 +94,15 @@ const App: React.FC = () => {
|
||||
|
||||
const renderPage = () => {
|
||||
switch (activePage) {
|
||||
case "dashboard": return <Dashboard />;
|
||||
case "discovery": return <NetworkDiscovery />;
|
||||
case "dashboard": return <Dashboard onNavigate={navigateTo} />;
|
||||
case "discovery": return <NetworkDiscovery onNavigate={navigateTo} />;
|
||||
case "nodes": return <Nodes />;
|
||||
case "flash": return <FlashFirmware />;
|
||||
case "ota": return <OtaUpdate />;
|
||||
case "wasm": return <EdgeModules />;
|
||||
case "sensing": return <Sensing />;
|
||||
case "mesh": return <MeshView />;
|
||||
case "training": return <Training />;
|
||||
case "settings": return <Settings />;
|
||||
}
|
||||
};
|
||||
@@ -167,7 +172,7 @@ const App: React.FC = () => {
|
||||
letterSpacing: "0.02em",
|
||||
}}
|
||||
>
|
||||
v0.4.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",
|
||||
|
||||
+342
-4
@@ -3,6 +3,12 @@ import { invoke } from "@tauri-apps/api/core";
|
||||
import { StatusBadge } from "../components/StatusBadge";
|
||||
import type { HealthStatus, Chip, MeshRole, DiscoveryMethod } from "../types";
|
||||
|
||||
type Page = "dashboard" | "discovery" | "nodes" | "flash" | "ota" | "wasm" | "sensing" | "mesh" | "settings";
|
||||
|
||||
interface NetworkDiscoveryProps {
|
||||
onNavigate?: (page: Page) => void;
|
||||
}
|
||||
|
||||
interface DiscoveredNode {
|
||||
ip: string;
|
||||
mac: string | null;
|
||||
@@ -34,7 +40,7 @@ interface SerialPortInfo {
|
||||
|
||||
type DiscoveryTab = "network" | "serial" | "manual";
|
||||
|
||||
const NetworkDiscovery: React.FC = () => {
|
||||
const NetworkDiscovery: React.FC<NetworkDiscoveryProps> = ({ onNavigate }) => {
|
||||
const [activeTab, setActiveTab] = useState<DiscoveryTab>("network");
|
||||
const [nodes, setNodes] = useState<DiscoveredNode[]>([]);
|
||||
const [serialPorts, setSerialPorts] = useState<SerialPortInfo[]>([]);
|
||||
@@ -43,6 +49,12 @@ const NetworkDiscovery: React.FC = () => {
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [selectedNode, setSelectedNode] = useState<DiscoveredNode | null>(null);
|
||||
const [filterOnline, setFilterOnline] = useState(false);
|
||||
// WiFi config state
|
||||
const [wifiConfigPort, setWifiConfigPort] = useState<string | null>(null);
|
||||
const [wifiSsid, setWifiSsid] = useState("");
|
||||
const [wifiPassword, setWifiPassword] = useState("");
|
||||
const [configuringWifi, setConfiguringWifi] = useState(false);
|
||||
const [wifiResult, setWifiResult] = useState<string | null>(null);
|
||||
const [searchQuery, setSearchQuery] = useState("");
|
||||
// Manual add state
|
||||
const [manualIp, setManualIp] = useState("");
|
||||
@@ -77,6 +89,24 @@ const NetworkDiscovery: React.FC = () => {
|
||||
}
|
||||
}, []);
|
||||
|
||||
const configureWifi = useCallback(async () => {
|
||||
if (!wifiConfigPort || !wifiSsid) return;
|
||||
setConfiguringWifi(true);
|
||||
setWifiResult(null);
|
||||
try {
|
||||
const result = await invoke<string>("configure_esp32_wifi", {
|
||||
port: wifiConfigPort,
|
||||
ssid: wifiSsid,
|
||||
password: wifiPassword,
|
||||
});
|
||||
setWifiResult(result);
|
||||
} catch (err) {
|
||||
setWifiResult(`Error: ${err instanceof Error ? err.message : String(err)}`);
|
||||
} finally {
|
||||
setConfiguringWifi(false);
|
||||
}
|
||||
}, [wifiConfigPort, wifiSsid, wifiPassword]);
|
||||
|
||||
const addManualNode = useCallback(async () => {
|
||||
if (!manualIp.trim()) return;
|
||||
setAddingManual(true);
|
||||
@@ -112,16 +142,22 @@ const NetworkDiscovery: React.FC = () => {
|
||||
}
|
||||
}, [manualIp, manualMac]);
|
||||
|
||||
// Scan both network and serial ports on mount
|
||||
useEffect(() => {
|
||||
scanNetwork();
|
||||
scanSerialPorts();
|
||||
}, []);
|
||||
|
||||
// Also refresh serial ports when switching to that tab
|
||||
useEffect(() => {
|
||||
if (activeTab === "serial") {
|
||||
scanSerialPorts();
|
||||
}
|
||||
}, [activeTab, scanSerialPorts]);
|
||||
|
||||
// Count ESP32-compatible serial ports
|
||||
const esp32SerialCount = serialPorts.filter((p) => p.is_esp32_compatible).length;
|
||||
|
||||
const filteredNodes = nodes.filter((node) => {
|
||||
if (filterOnline && node.health !== "online") return false;
|
||||
if (searchQuery) {
|
||||
@@ -302,21 +338,61 @@ const NetworkDiscovery: React.FC = () => {
|
||||
<div className="card empty-state">
|
||||
<div className="empty-state-icon">{"◉"}</div>
|
||||
<div style={{ fontSize: 14, fontWeight: 600, color: "var(--text-secondary)" }}>
|
||||
{isScanning ? "Scanning for nodes..." : "No nodes discovered"}
|
||||
{isScanning ? "Scanning for nodes..." : "No network nodes found"}
|
||||
</div>
|
||||
<div
|
||||
style={{
|
||||
fontSize: 13,
|
||||
color: "var(--text-muted)",
|
||||
maxWidth: 300,
|
||||
maxWidth: 340,
|
||||
textAlign: "center",
|
||||
lineHeight: 1.5,
|
||||
}}
|
||||
>
|
||||
{isScanning
|
||||
? "Please wait while we search for ESP32 devices on your network."
|
||||
: "Click 'Scan Network' to discover ESP32 devices using mDNS and UDP broadcast."}
|
||||
: "Network discovery uses mDNS/UDP to find ESP32 devices running firmware on WiFi."}
|
||||
</div>
|
||||
|
||||
{/* USB device hint */}
|
||||
{!isScanning && esp32SerialCount > 0 && (
|
||||
<div
|
||||
style={{
|
||||
marginTop: "var(--space-4)",
|
||||
padding: "var(--space-3) var(--space-4)",
|
||||
background: "rgba(56, 139, 253, 0.1)",
|
||||
border: "1px solid rgba(56, 139, 253, 0.3)",
|
||||
borderRadius: 8,
|
||||
maxWidth: 340,
|
||||
}}
|
||||
>
|
||||
<div style={{ display: "flex", alignItems: "center", gap: 8, marginBottom: 6 }}>
|
||||
<span style={{ fontSize: 16 }}>🔌</span>
|
||||
<span style={{ fontSize: 13, fontWeight: 600, color: "var(--accent)" }}>
|
||||
{esp32SerialCount} USB device{esp32SerialCount > 1 ? "s" : ""} detected!
|
||||
</span>
|
||||
</div>
|
||||
<div style={{ fontSize: 12, color: "var(--text-secondary)", lineHeight: 1.5, marginBottom: 10 }}>
|
||||
Your ESP32 is connected via USB. To flash firmware or configure it:
|
||||
</div>
|
||||
<button
|
||||
onClick={() => setActiveTab("serial")}
|
||||
style={{
|
||||
padding: "8px 16px",
|
||||
background: "var(--accent)",
|
||||
border: "none",
|
||||
borderRadius: 6,
|
||||
color: "#fff",
|
||||
fontSize: 12,
|
||||
fontWeight: 600,
|
||||
cursor: "pointer",
|
||||
width: "100%",
|
||||
}}
|
||||
>
|
||||
View Serial Ports →
|
||||
</button>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
) : (
|
||||
<div
|
||||
@@ -384,6 +460,7 @@ const NetworkDiscovery: React.FC = () => {
|
||||
<Th>Manufacturer</Th>
|
||||
<Th>VID:PID</Th>
|
||||
<Th>Compatible</Th>
|
||||
<Th>Actions</Th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@@ -417,6 +494,49 @@ const NetworkDiscovery: React.FC = () => {
|
||||
<span style={{ color: "var(--text-muted)" }}>--</span>
|
||||
)}
|
||||
</Td>
|
||||
<Td>
|
||||
<div style={{ display: "flex", gap: 6 }}>
|
||||
{port.is_esp32_compatible && (
|
||||
<button
|
||||
onClick={() => {
|
||||
setWifiConfigPort(port.name);
|
||||
setWifiSsid("");
|
||||
setWifiPassword("");
|
||||
setWifiResult(null);
|
||||
}}
|
||||
style={{
|
||||
padding: "4px 10px",
|
||||
background: "rgba(56, 139, 253, 0.15)",
|
||||
border: "1px solid rgba(56, 139, 253, 0.3)",
|
||||
borderRadius: 4,
|
||||
color: "var(--accent)",
|
||||
fontSize: 11,
|
||||
fontWeight: 600,
|
||||
cursor: "pointer",
|
||||
}}
|
||||
>
|
||||
WiFi
|
||||
</button>
|
||||
)}
|
||||
{port.is_esp32_compatible && onNavigate && (
|
||||
<button
|
||||
onClick={() => onNavigate("flash")}
|
||||
style={{
|
||||
padding: "4px 10px",
|
||||
background: "var(--accent)",
|
||||
border: "none",
|
||||
borderRadius: 4,
|
||||
color: "#fff",
|
||||
fontSize: 11,
|
||||
fontWeight: 600,
|
||||
cursor: "pointer",
|
||||
}}
|
||||
>
|
||||
Flash
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
</Td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
@@ -507,6 +627,224 @@ const NetworkDiscovery: React.FC = () => {
|
||||
{selectedNode && (
|
||||
<NodeDetailModal node={selectedNode} onClose={() => setSelectedNode(null)} />
|
||||
)}
|
||||
|
||||
{/* WiFi Configuration Modal */}
|
||||
{wifiConfigPort && (
|
||||
<div
|
||||
style={{
|
||||
position: "fixed",
|
||||
inset: 0,
|
||||
background: "rgba(0,0,0,0.6)",
|
||||
display: "flex",
|
||||
alignItems: "center",
|
||||
justifyContent: "center",
|
||||
zIndex: 1000,
|
||||
padding: "var(--space-5)",
|
||||
}}
|
||||
onClick={(e) => {
|
||||
if (e.target === e.currentTarget && !configuringWifi) {
|
||||
setWifiConfigPort(null);
|
||||
}
|
||||
}}
|
||||
>
|
||||
<div
|
||||
style={{
|
||||
background: "var(--bg-surface)",
|
||||
borderRadius: 12,
|
||||
padding: "var(--space-5)",
|
||||
maxWidth: 420,
|
||||
width: "100%",
|
||||
border: "1px solid var(--border)",
|
||||
}}
|
||||
>
|
||||
<div
|
||||
style={{
|
||||
display: "flex",
|
||||
justifyContent: "space-between",
|
||||
alignItems: "start",
|
||||
marginBottom: "var(--space-4)",
|
||||
}}
|
||||
>
|
||||
<div>
|
||||
<h2 className="heading-md" style={{ margin: 0 }}>
|
||||
Configure WiFi
|
||||
</h2>
|
||||
<p className="mono" style={{ color: "var(--text-muted)", marginTop: 4, fontSize: 13 }}>
|
||||
{wifiConfigPort}
|
||||
</p>
|
||||
</div>
|
||||
<button
|
||||
onClick={() => setWifiConfigPort(null)}
|
||||
disabled={configuringWifi}
|
||||
style={{
|
||||
background: "none",
|
||||
border: "none",
|
||||
fontSize: 20,
|
||||
cursor: configuringWifi ? "not-allowed" : "pointer",
|
||||
color: "var(--text-muted)",
|
||||
padding: 4,
|
||||
opacity: configuringWifi ? 0.5 : 1,
|
||||
}}
|
||||
>
|
||||
×
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div style={{ display: "flex", flexDirection: "column", gap: "var(--space-3)" }}>
|
||||
<div>
|
||||
<label
|
||||
style={{
|
||||
display: "block",
|
||||
fontSize: 12,
|
||||
fontWeight: 600,
|
||||
color: "var(--text-secondary)",
|
||||
marginBottom: 4,
|
||||
}}
|
||||
>
|
||||
WiFi SSID *
|
||||
</label>
|
||||
<input
|
||||
type="text"
|
||||
placeholder="Your WiFi network name"
|
||||
value={wifiSsid}
|
||||
onChange={(e) => setWifiSsid(e.target.value)}
|
||||
disabled={configuringWifi}
|
||||
style={{
|
||||
width: "100%",
|
||||
padding: "10px 12px",
|
||||
borderRadius: 6,
|
||||
border: "1px solid var(--border)",
|
||||
background: "var(--bg-base)",
|
||||
color: "var(--text-primary)",
|
||||
fontSize: 13,
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<label
|
||||
style={{
|
||||
display: "block",
|
||||
fontSize: 12,
|
||||
fontWeight: 600,
|
||||
color: "var(--text-secondary)",
|
||||
marginBottom: 4,
|
||||
}}
|
||||
>
|
||||
WiFi Password
|
||||
</label>
|
||||
<input
|
||||
type="password"
|
||||
placeholder="WiFi password"
|
||||
value={wifiPassword}
|
||||
onChange={(e) => setWifiPassword(e.target.value)}
|
||||
disabled={configuringWifi}
|
||||
style={{
|
||||
width: "100%",
|
||||
padding: "10px 12px",
|
||||
borderRadius: 6,
|
||||
border: "1px solid var(--border)",
|
||||
background: "var(--bg-base)",
|
||||
color: "var(--text-primary)",
|
||||
fontSize: 13,
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
|
||||
{wifiResult && (
|
||||
<div
|
||||
style={{
|
||||
padding: "var(--space-3)",
|
||||
borderRadius: 6,
|
||||
fontSize: 12,
|
||||
background: wifiResult.startsWith("Error")
|
||||
? "rgba(248, 81, 73, 0.1)"
|
||||
: wifiResult.includes("configured") || wifiResult.includes("saved")
|
||||
? "rgba(63, 185, 80, 0.1)"
|
||||
: "rgba(56, 139, 253, 0.1)",
|
||||
border: wifiResult.startsWith("Error")
|
||||
? "1px solid rgba(248, 81, 73, 0.3)"
|
||||
: wifiResult.includes("configured") || wifiResult.includes("saved")
|
||||
? "1px solid rgba(63, 185, 80, 0.3)"
|
||||
: "1px solid rgba(56, 139, 253, 0.3)",
|
||||
color: wifiResult.startsWith("Error")
|
||||
? "var(--status-error)"
|
||||
: wifiResult.includes("configured") || wifiResult.includes("saved")
|
||||
? "var(--status-online)"
|
||||
: "var(--accent)",
|
||||
}}
|
||||
>
|
||||
<div style={{ fontWeight: 600, marginBottom: 6 }}>
|
||||
{wifiResult.startsWith("Error") ? "Error" :
|
||||
wifiResult.includes("configured") || wifiResult.includes("saved") ? "Success!" : "Commands Sent"}
|
||||
</div>
|
||||
<div style={{ fontFamily: "var(--font-mono)", whiteSpace: "pre-wrap", maxHeight: 100, overflow: "auto" }}>
|
||||
{wifiResult}
|
||||
</div>
|
||||
{!wifiResult.startsWith("Error") && !wifiResult.includes("configured") && (
|
||||
<div style={{ marginTop: 8, fontSize: 11, color: "var(--text-secondary)" }}>
|
||||
If the ESP32 doesn't connect, try pressing its Reset button or re-flashing with WiFi credentials in the firmware.
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div style={{ display: "flex", gap: "var(--space-3)", marginTop: "var(--space-2)" }}>
|
||||
<button
|
||||
onClick={() => setWifiConfigPort(null)}
|
||||
disabled={configuringWifi}
|
||||
style={{
|
||||
flex: 1,
|
||||
padding: "10px 16px",
|
||||
borderRadius: 6,
|
||||
border: "1px solid var(--border)",
|
||||
background: wifiResult ? "var(--accent)" : "transparent",
|
||||
color: wifiResult ? "#fff" : "var(--text-secondary)",
|
||||
fontSize: 13,
|
||||
fontWeight: 600,
|
||||
cursor: configuringWifi ? "not-allowed" : "pointer",
|
||||
opacity: configuringWifi ? 0.5 : 1,
|
||||
}}
|
||||
>
|
||||
{wifiResult ? "Done" : "Cancel"}
|
||||
</button>
|
||||
{!wifiResult && (
|
||||
<button
|
||||
onClick={configureWifi}
|
||||
disabled={!wifiSsid.trim() || configuringWifi}
|
||||
className="btn-gradient"
|
||||
style={{
|
||||
flex: 1,
|
||||
opacity: !wifiSsid.trim() || configuringWifi ? 0.5 : 1,
|
||||
}}
|
||||
>
|
||||
{configuringWifi ? "Configuring..." : "Configure WiFi"}
|
||||
</button>
|
||||
)}
|
||||
{wifiResult && !wifiResult.startsWith("Error") && (
|
||||
<button
|
||||
onClick={() => {
|
||||
setWifiResult(null);
|
||||
}}
|
||||
style={{
|
||||
flex: 1,
|
||||
padding: "10px 16px",
|
||||
borderRadius: 6,
|
||||
border: "1px solid var(--border)",
|
||||
background: "transparent",
|
||||
color: "var(--text-secondary)",
|
||||
fontSize: 13,
|
||||
fontWeight: 600,
|
||||
cursor: "pointer",
|
||||
}}
|
||||
>
|
||||
Try Again
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
+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 */}
|
||||
|
||||
+369
@@ -0,0 +1,369 @@
|
||||
import React, { useState, useEffect } from "react";
|
||||
import { invoke } from "@tauri-apps/api/core";
|
||||
|
||||
interface Dataset {
|
||||
id: string;
|
||||
name: string;
|
||||
description: string;
|
||||
size_mb: number;
|
||||
samples: number;
|
||||
downloaded: boolean;
|
||||
path: string | null;
|
||||
}
|
||||
|
||||
const STANDARD_DATASETS: Omit<Dataset, "downloaded" | "path">[] = [
|
||||
{
|
||||
id: "mmfi",
|
||||
name: "MM-Fi Dataset",
|
||||
description: "Multi-modal WiFi sensing dataset with 40 subjects, 27 activities",
|
||||
size_mb: 2400,
|
||||
samples: 320000,
|
||||
},
|
||||
{
|
||||
id: "wipose",
|
||||
name: "Wi-Pose Dataset",
|
||||
description: "WiFi-based pose estimation with 3D skeleton annotations",
|
||||
size_mb: 1800,
|
||||
samples: 150000,
|
||||
},
|
||||
{
|
||||
id: "wiar",
|
||||
name: "WiAR Dataset",
|
||||
description: "WiFi activity recognition with CSI data",
|
||||
size_mb: 500,
|
||||
samples: 45000,
|
||||
},
|
||||
];
|
||||
|
||||
const DatasetsTab: React.FC = () => {
|
||||
const [datasets, setDatasets] = useState<Dataset[]>([]);
|
||||
const [downloading, setDownloading] = useState<string | null>(null);
|
||||
const [downloadProgress, setDownloadProgress] = useState<number>(0);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
loadDatasets();
|
||||
}, []);
|
||||
|
||||
const loadDatasets = async () => {
|
||||
try {
|
||||
const downloaded = await invoke<string[]>("list_datasets");
|
||||
const ds = STANDARD_DATASETS.map((d) => ({
|
||||
...d,
|
||||
downloaded: downloaded.includes(d.id),
|
||||
path: downloaded.includes(d.id) ? `~/.ruview/datasets/${d.id}` : null,
|
||||
}));
|
||||
setDatasets(ds);
|
||||
} catch (err) {
|
||||
// If command not implemented yet, show placeholders
|
||||
setDatasets(
|
||||
STANDARD_DATASETS.map((d) => ({
|
||||
...d,
|
||||
downloaded: false,
|
||||
path: null,
|
||||
}))
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
const handleDownload = async (datasetId: string) => {
|
||||
setDownloading(datasetId);
|
||||
setDownloadProgress(0);
|
||||
setError(null);
|
||||
|
||||
try {
|
||||
// Simulate download progress for now
|
||||
for (let i = 0; i <= 100; i += 10) {
|
||||
setDownloadProgress(i);
|
||||
await new Promise((r) => setTimeout(r, 500));
|
||||
}
|
||||
|
||||
// TODO: Call actual download command
|
||||
// await invoke("download_dataset", { datasetId });
|
||||
|
||||
setDatasets((prev) =>
|
||||
prev.map((d) =>
|
||||
d.id === datasetId
|
||||
? { ...d, downloaded: true, path: `~/.ruview/datasets/${d.id}` }
|
||||
: d
|
||||
)
|
||||
);
|
||||
} catch (err) {
|
||||
setError(`Download failed: ${err}`);
|
||||
} finally {
|
||||
setDownloading(null);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<div>
|
||||
{/* Stats Row */}
|
||||
<div
|
||||
style={{
|
||||
display: "grid",
|
||||
gridTemplateColumns: "repeat(3, 1fr)",
|
||||
gap: "var(--space-4)",
|
||||
marginBottom: "var(--space-5)",
|
||||
}}
|
||||
>
|
||||
<StatCard
|
||||
label="Available Datasets"
|
||||
value={datasets.length}
|
||||
/>
|
||||
<StatCard
|
||||
label="Downloaded"
|
||||
value={datasets.filter((d) => d.downloaded).length}
|
||||
color="var(--status-online)"
|
||||
/>
|
||||
<StatCard
|
||||
label="Total Samples"
|
||||
value={`${(datasets.reduce((acc, d) => acc + (d.downloaded ? d.samples : 0), 0) / 1000).toFixed(0)}K`}
|
||||
/>
|
||||
</div>
|
||||
|
||||
{error && (
|
||||
<div
|
||||
style={{
|
||||
background: "rgba(248, 81, 73, 0.1)",
|
||||
border: "1px solid rgba(248, 81, 73, 0.3)",
|
||||
borderRadius: 6,
|
||||
padding: "var(--space-3)",
|
||||
marginBottom: "var(--space-4)",
|
||||
fontSize: 13,
|
||||
color: "var(--status-error)",
|
||||
}}
|
||||
>
|
||||
{error}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Dataset Cards */}
|
||||
<div
|
||||
style={{
|
||||
display: "grid",
|
||||
gridTemplateColumns: "repeat(auto-fill, minmax(340px, 1fr))",
|
||||
gap: "var(--space-4)",
|
||||
}}
|
||||
>
|
||||
{datasets.map((dataset) => (
|
||||
<div
|
||||
key={dataset.id}
|
||||
className="card"
|
||||
style={{
|
||||
padding: "var(--space-4)",
|
||||
opacity: dataset.downloaded ? 1 : 0.85,
|
||||
}}
|
||||
>
|
||||
<div
|
||||
style={{
|
||||
display: "flex",
|
||||
justifyContent: "space-between",
|
||||
alignItems: "start",
|
||||
marginBottom: "var(--space-3)",
|
||||
}}
|
||||
>
|
||||
<div>
|
||||
<h3 style={{ margin: 0, fontSize: 15, fontWeight: 600 }}>
|
||||
{dataset.name}
|
||||
</h3>
|
||||
<p
|
||||
style={{
|
||||
fontSize: 12,
|
||||
color: "var(--text-muted)",
|
||||
marginTop: 4,
|
||||
lineHeight: 1.4,
|
||||
}}
|
||||
>
|
||||
{dataset.description}
|
||||
</p>
|
||||
</div>
|
||||
{dataset.downloaded && (
|
||||
<span
|
||||
style={{
|
||||
background: "rgba(63, 185, 80, 0.15)",
|
||||
color: "var(--status-online)",
|
||||
padding: "2px 8px",
|
||||
borderRadius: 4,
|
||||
fontSize: 10,
|
||||
fontWeight: 600,
|
||||
}}
|
||||
>
|
||||
DOWNLOADED
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div
|
||||
style={{
|
||||
display: "flex",
|
||||
gap: "var(--space-4)",
|
||||
fontSize: 12,
|
||||
color: "var(--text-secondary)",
|
||||
marginBottom: "var(--space-3)",
|
||||
}}
|
||||
>
|
||||
<span>📦 {(dataset.size_mb / 1024).toFixed(1)} GB</span>
|
||||
<span>📊 {(dataset.samples / 1000).toFixed(0)}K samples</span>
|
||||
</div>
|
||||
|
||||
{downloading === dataset.id ? (
|
||||
<div>
|
||||
<div
|
||||
style={{
|
||||
height: 4,
|
||||
background: "var(--border)",
|
||||
borderRadius: 2,
|
||||
overflow: "hidden",
|
||||
}}
|
||||
>
|
||||
<div
|
||||
style={{
|
||||
width: `${downloadProgress}%`,
|
||||
height: "100%",
|
||||
background: "var(--accent)",
|
||||
transition: "width 0.3s",
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
<div
|
||||
style={{
|
||||
fontSize: 11,
|
||||
color: "var(--text-muted)",
|
||||
marginTop: 4,
|
||||
textAlign: "center",
|
||||
}}
|
||||
>
|
||||
Downloading... {downloadProgress}%
|
||||
</div>
|
||||
</div>
|
||||
) : (
|
||||
<div style={{ display: "flex", gap: "var(--space-2)" }}>
|
||||
{dataset.downloaded ? (
|
||||
<>
|
||||
<button
|
||||
style={{
|
||||
flex: 1,
|
||||
padding: "8px 12px",
|
||||
background: "rgba(56, 139, 253, 0.1)",
|
||||
border: "1px solid rgba(56, 139, 253, 0.3)",
|
||||
borderRadius: 6,
|
||||
color: "var(--accent)",
|
||||
fontSize: 12,
|
||||
fontWeight: 600,
|
||||
cursor: "pointer",
|
||||
}}
|
||||
>
|
||||
Preview
|
||||
</button>
|
||||
<button
|
||||
style={{
|
||||
padding: "8px 12px",
|
||||
background: "transparent",
|
||||
border: "1px solid var(--border)",
|
||||
borderRadius: 6,
|
||||
color: "var(--text-secondary)",
|
||||
fontSize: 12,
|
||||
fontWeight: 600,
|
||||
cursor: "pointer",
|
||||
}}
|
||||
>
|
||||
Delete
|
||||
</button>
|
||||
</>
|
||||
) : (
|
||||
<button
|
||||
onClick={() => handleDownload(dataset.id)}
|
||||
className="btn-gradient"
|
||||
style={{ flex: 1, fontSize: 12 }}
|
||||
>
|
||||
Download Dataset
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
|
||||
{/* Import Custom Dataset */}
|
||||
<div
|
||||
className="card"
|
||||
style={{
|
||||
marginTop: "var(--space-5)",
|
||||
padding: "var(--space-4)",
|
||||
border: "2px dashed var(--border)",
|
||||
textAlign: "center",
|
||||
}}
|
||||
>
|
||||
<div style={{ fontSize: 32, marginBottom: "var(--space-2)" }}>📁</div>
|
||||
<h4 style={{ margin: 0, fontSize: 14, fontWeight: 600 }}>
|
||||
Import Custom Dataset
|
||||
</h4>
|
||||
<p
|
||||
style={{
|
||||
fontSize: 12,
|
||||
color: "var(--text-muted)",
|
||||
marginTop: 4,
|
||||
marginBottom: "var(--space-3)",
|
||||
}}
|
||||
>
|
||||
Import CSI recordings in CSV, NPZ, or HDF5 format
|
||||
</p>
|
||||
<button
|
||||
style={{
|
||||
padding: "8px 20px",
|
||||
background: "transparent",
|
||||
border: "1px solid var(--border)",
|
||||
borderRadius: 6,
|
||||
color: "var(--text-secondary)",
|
||||
fontSize: 12,
|
||||
fontWeight: 600,
|
||||
cursor: "pointer",
|
||||
}}
|
||||
>
|
||||
Browse Files
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
function StatCard({
|
||||
label,
|
||||
value,
|
||||
color,
|
||||
}: {
|
||||
label: string;
|
||||
value: number | string;
|
||||
color?: string;
|
||||
}) {
|
||||
return (
|
||||
<div className="card-glow" style={{ padding: "var(--space-4)" }}>
|
||||
<div
|
||||
style={{
|
||||
fontSize: 10,
|
||||
textTransform: "uppercase",
|
||||
letterSpacing: "0.06em",
|
||||
color: "var(--text-muted)",
|
||||
marginBottom: "var(--space-2)",
|
||||
fontWeight: 600,
|
||||
}}
|
||||
>
|
||||
{label}
|
||||
</div>
|
||||
<div
|
||||
style={{
|
||||
fontFamily: "var(--font-mono)",
|
||||
fontSize: 28,
|
||||
fontWeight: 600,
|
||||
color: color || "var(--text-primary)",
|
||||
letterSpacing: "-0.02em",
|
||||
}}
|
||||
>
|
||||
{value}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default DatasetsTab;
|
||||
+609
@@ -0,0 +1,609 @@
|
||||
import React, { useState, useEffect } from "react";
|
||||
import { invoke } from "@tauri-apps/api/core";
|
||||
|
||||
interface TrainingMetrics {
|
||||
epoch: number;
|
||||
train_loss: number;
|
||||
val_loss: number;
|
||||
train_acc: number;
|
||||
val_acc: number;
|
||||
learning_rate: number;
|
||||
timestamp: string;
|
||||
}
|
||||
|
||||
interface EvaluationMetrics {
|
||||
pck_05: number;
|
||||
pck_10: number;
|
||||
pck_20: number;
|
||||
map_50: number;
|
||||
map_75: number;
|
||||
iou: number;
|
||||
}
|
||||
|
||||
interface JointAccuracy {
|
||||
joint: string;
|
||||
accuracy: number;
|
||||
}
|
||||
|
||||
const JOINT_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",
|
||||
];
|
||||
|
||||
const MetricsTab: React.FC = () => {
|
||||
const [trainingHistory, setTrainingHistory] = useState<TrainingMetrics[]>([]);
|
||||
const [evaluation, setEvaluation] = useState<EvaluationMetrics | null>(null);
|
||||
const [jointAccuracies, setJointAccuracies] = useState<JointAccuracy[]>([]);
|
||||
const [selectedMetric, setSelectedMetric] = useState<"loss" | "accuracy">("loss");
|
||||
const [exporting, setExporting] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
loadMetrics();
|
||||
}, []);
|
||||
|
||||
const loadMetrics = async () => {
|
||||
try {
|
||||
const metrics = await invoke<TrainingMetrics[]>("get_training_history");
|
||||
setTrainingHistory(metrics);
|
||||
const evalMetrics = await invoke<EvaluationMetrics>("get_evaluation_metrics");
|
||||
setEvaluation(evalMetrics);
|
||||
const joints = await invoke<JointAccuracy[]>("get_joint_accuracies");
|
||||
setJointAccuracies(joints);
|
||||
} catch (err) {
|
||||
// Generate mock data for demonstration
|
||||
const mockHistory: TrainingMetrics[] = [];
|
||||
for (let i = 1; i <= 50; i++) {
|
||||
mockHistory.push({
|
||||
epoch: i,
|
||||
train_loss: 0.5 * Math.exp(-i / 20) + 0.02 + Math.random() * 0.01,
|
||||
val_loss: 0.55 * Math.exp(-i / 18) + 0.025 + Math.random() * 0.015,
|
||||
train_acc: 1 - 0.5 * Math.exp(-i / 15) - Math.random() * 0.02,
|
||||
val_acc: 1 - 0.55 * Math.exp(-i / 15) - Math.random() * 0.025,
|
||||
learning_rate: 0.001 * Math.pow(0.95, Math.floor(i / 10)),
|
||||
timestamp: new Date(Date.now() - (50 - i) * 60000).toISOString(),
|
||||
});
|
||||
}
|
||||
setTrainingHistory(mockHistory);
|
||||
|
||||
setEvaluation({
|
||||
pck_05: 0.72,
|
||||
pck_10: 0.89,
|
||||
pck_20: 0.96,
|
||||
map_50: 0.84,
|
||||
map_75: 0.71,
|
||||
iou: 0.78,
|
||||
});
|
||||
|
||||
setJointAccuracies(
|
||||
JOINT_NAMES.map((joint) => ({
|
||||
joint,
|
||||
accuracy: 0.7 + Math.random() * 0.25,
|
||||
}))
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
const exportMetrics = async (format: "csv" | "json" | "tensorboard") => {
|
||||
setExporting(true);
|
||||
try {
|
||||
if (format === "json") {
|
||||
const data = {
|
||||
training: trainingHistory,
|
||||
evaluation,
|
||||
joints: jointAccuracies,
|
||||
};
|
||||
const blob = new Blob([JSON.stringify(data, null, 2)], { type: "application/json" });
|
||||
downloadBlob(blob, "metrics.json");
|
||||
} else if (format === "csv") {
|
||||
const headers = "epoch,train_loss,val_loss,train_acc,val_acc,learning_rate\n";
|
||||
const rows = trainingHistory
|
||||
.map(
|
||||
(m) =>
|
||||
`${m.epoch},${m.train_loss.toFixed(6)},${m.val_loss.toFixed(6)},${m.train_acc.toFixed(4)},${m.val_acc.toFixed(4)},${m.learning_rate.toExponential(2)}`
|
||||
)
|
||||
.join("\n");
|
||||
const blob = new Blob([headers + rows], { type: "text/csv" });
|
||||
downloadBlob(blob, "training_history.csv");
|
||||
} else {
|
||||
// TensorBoard format would require server-side handling
|
||||
alert("TensorBoard export requires running the backend server");
|
||||
}
|
||||
} finally {
|
||||
setExporting(false);
|
||||
}
|
||||
};
|
||||
|
||||
const downloadBlob = (blob: Blob, filename: string) => {
|
||||
const url = URL.createObjectURL(blob);
|
||||
const a = document.createElement("a");
|
||||
a.href = url;
|
||||
a.download = filename;
|
||||
a.click();
|
||||
URL.revokeObjectURL(url);
|
||||
};
|
||||
|
||||
const maxLoss = Math.max(
|
||||
...trainingHistory.map((m) => Math.max(m.train_loss, m.val_loss)),
|
||||
0.1
|
||||
);
|
||||
|
||||
return (
|
||||
<div>
|
||||
{/* Summary Stats */}
|
||||
<div
|
||||
style={{
|
||||
display: "grid",
|
||||
gridTemplateColumns: "repeat(4, 1fr)",
|
||||
gap: "var(--space-4)",
|
||||
marginBottom: "var(--space-5)",
|
||||
}}
|
||||
>
|
||||
<StatCard
|
||||
label="Epochs Trained"
|
||||
value={trainingHistory.length}
|
||||
/>
|
||||
<StatCard
|
||||
label="Best Val Loss"
|
||||
value={
|
||||
trainingHistory.length > 0
|
||||
? Math.min(...trainingHistory.map((m) => m.val_loss)).toFixed(4)
|
||||
: "—"
|
||||
}
|
||||
color="var(--status-online)"
|
||||
/>
|
||||
<StatCard
|
||||
label="Best Val Acc"
|
||||
value={
|
||||
trainingHistory.length > 0
|
||||
? `${(Math.max(...trainingHistory.map((m) => m.val_acc)) * 100).toFixed(1)}%`
|
||||
: "—"
|
||||
}
|
||||
color="var(--accent)"
|
||||
/>
|
||||
<StatCard
|
||||
label="PCK@0.1"
|
||||
value={evaluation ? `${(evaluation.pck_10 * 100).toFixed(1)}%` : "—"}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div style={{ display: "grid", gridTemplateColumns: "2fr 1fr", gap: "var(--space-5)" }}>
|
||||
{/* Loss/Accuracy Charts */}
|
||||
<div className="card" style={{ padding: "var(--space-4)" }}>
|
||||
<div
|
||||
style={{
|
||||
display: "flex",
|
||||
justifyContent: "space-between",
|
||||
alignItems: "center",
|
||||
marginBottom: "var(--space-4)",
|
||||
}}
|
||||
>
|
||||
<h3 style={{ margin: 0, fontSize: 14, fontWeight: 600 }}>Training Curves</h3>
|
||||
<div style={{ display: "flex", gap: "var(--space-2)" }}>
|
||||
<button
|
||||
onClick={() => setSelectedMetric("loss")}
|
||||
style={{
|
||||
padding: "6px 12px",
|
||||
background: selectedMetric === "loss" ? "var(--accent)" : "transparent",
|
||||
border: `1px solid ${selectedMetric === "loss" ? "var(--accent)" : "var(--border)"}`,
|
||||
borderRadius: 4,
|
||||
color: selectedMetric === "loss" ? "white" : "var(--text-secondary)",
|
||||
fontSize: 11,
|
||||
fontWeight: 600,
|
||||
cursor: "pointer",
|
||||
}}
|
||||
>
|
||||
Loss
|
||||
</button>
|
||||
<button
|
||||
onClick={() => setSelectedMetric("accuracy")}
|
||||
style={{
|
||||
padding: "6px 12px",
|
||||
background: selectedMetric === "accuracy" ? "var(--accent)" : "transparent",
|
||||
border: `1px solid ${selectedMetric === "accuracy" ? "var(--accent)" : "var(--border)"}`,
|
||||
borderRadius: 4,
|
||||
color: selectedMetric === "accuracy" ? "white" : "var(--text-secondary)",
|
||||
fontSize: 11,
|
||||
fontWeight: 600,
|
||||
cursor: "pointer",
|
||||
}}
|
||||
>
|
||||
Accuracy
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Chart Area */}
|
||||
<div
|
||||
style={{
|
||||
height: 250,
|
||||
position: "relative",
|
||||
background: "var(--bg-secondary)",
|
||||
borderRadius: 8,
|
||||
padding: "var(--space-3)",
|
||||
}}
|
||||
>
|
||||
{trainingHistory.length === 0 ? (
|
||||
<div
|
||||
style={{
|
||||
display: "flex",
|
||||
flexDirection: "column",
|
||||
alignItems: "center",
|
||||
justifyContent: "center",
|
||||
height: "100%",
|
||||
color: "var(--text-muted)",
|
||||
}}
|
||||
>
|
||||
<span style={{ fontSize: 32 }}>📊</span>
|
||||
<p style={{ fontSize: 13, marginTop: "var(--space-2)" }}>
|
||||
No training data yet
|
||||
</p>
|
||||
</div>
|
||||
) : (
|
||||
<svg width="100%" height="100%" viewBox="0 0 500 200" preserveAspectRatio="none">
|
||||
{/* Grid lines */}
|
||||
{[0, 0.25, 0.5, 0.75, 1].map((y) => (
|
||||
<line
|
||||
key={y}
|
||||
x1="0"
|
||||
y1={y * 180}
|
||||
x2="500"
|
||||
y2={y * 180}
|
||||
stroke="var(--border)"
|
||||
strokeWidth="0.5"
|
||||
strokeDasharray="4"
|
||||
/>
|
||||
))}
|
||||
|
||||
{/* Train line */}
|
||||
<polyline
|
||||
fill="none"
|
||||
stroke="var(--accent)"
|
||||
strokeWidth="2"
|
||||
points={trainingHistory
|
||||
.map((m, i) => {
|
||||
const x = (i / (trainingHistory.length - 1)) * 500;
|
||||
const value = selectedMetric === "loss" ? m.train_loss : m.train_acc;
|
||||
const y =
|
||||
selectedMetric === "loss"
|
||||
? (value / maxLoss) * 180
|
||||
: (1 - value) * 180;
|
||||
return `${x},${y}`;
|
||||
})
|
||||
.join(" ")}
|
||||
/>
|
||||
|
||||
{/* Val line */}
|
||||
<polyline
|
||||
fill="none"
|
||||
stroke="var(--status-online)"
|
||||
strokeWidth="2"
|
||||
points={trainingHistory
|
||||
.map((m, i) => {
|
||||
const x = (i / (trainingHistory.length - 1)) * 500;
|
||||
const value = selectedMetric === "loss" ? m.val_loss : m.val_acc;
|
||||
const y =
|
||||
selectedMetric === "loss"
|
||||
? (value / maxLoss) * 180
|
||||
: (1 - value) * 180;
|
||||
return `${x},${y}`;
|
||||
})
|
||||
.join(" ")}
|
||||
/>
|
||||
</svg>
|
||||
)}
|
||||
|
||||
{/* Legend */}
|
||||
<div
|
||||
style={{
|
||||
position: "absolute",
|
||||
top: "var(--space-2)",
|
||||
right: "var(--space-2)",
|
||||
display: "flex",
|
||||
gap: "var(--space-3)",
|
||||
fontSize: 11,
|
||||
}}
|
||||
>
|
||||
<span style={{ display: "flex", alignItems: "center", gap: 4 }}>
|
||||
<span
|
||||
style={{
|
||||
width: 12,
|
||||
height: 3,
|
||||
background: "var(--accent)",
|
||||
borderRadius: 2,
|
||||
}}
|
||||
/>
|
||||
Train
|
||||
</span>
|
||||
<span style={{ display: "flex", alignItems: "center", gap: 4 }}>
|
||||
<span
|
||||
style={{
|
||||
width: 12,
|
||||
height: 3,
|
||||
background: "var(--status-online)",
|
||||
borderRadius: 2,
|
||||
}}
|
||||
/>
|
||||
Validation
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Evaluation Metrics */}
|
||||
<div className="card" style={{ padding: "var(--space-4)" }}>
|
||||
<h3 style={{ margin: 0, fontSize: 14, fontWeight: 600, marginBottom: "var(--space-4)" }}>
|
||||
Evaluation Metrics
|
||||
</h3>
|
||||
|
||||
{!evaluation ? (
|
||||
<div
|
||||
style={{
|
||||
display: "flex",
|
||||
flexDirection: "column",
|
||||
alignItems: "center",
|
||||
justifyContent: "center",
|
||||
height: 200,
|
||||
color: "var(--text-muted)",
|
||||
}}
|
||||
>
|
||||
<span style={{ fontSize: 32 }}>📏</span>
|
||||
<p style={{ fontSize: 13, marginTop: "var(--space-2)" }}>
|
||||
Run evaluation to see metrics
|
||||
</p>
|
||||
</div>
|
||||
) : (
|
||||
<div style={{ display: "flex", flexDirection: "column", gap: "var(--space-3)" }}>
|
||||
<MetricBar label="PCK@0.05" value={evaluation.pck_05} color="#f59e0b" />
|
||||
<MetricBar label="PCK@0.10" value={evaluation.pck_10} color="var(--accent)" />
|
||||
<MetricBar label="PCK@0.20" value={evaluation.pck_20} color="var(--status-online)" />
|
||||
<div style={{ height: 1, background: "var(--border)", margin: "var(--space-2) 0" }} />
|
||||
<MetricBar label="mAP@0.50" value={evaluation.map_50} color="#a855f7" />
|
||||
<MetricBar label="mAP@0.75" value={evaluation.map_75} color="#ec4899" />
|
||||
<MetricBar label="IoU" value={evaluation.iou} color="#06b6d4" />
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Joint-wise Accuracy */}
|
||||
<div className="card" style={{ marginTop: "var(--space-5)", padding: "var(--space-4)" }}>
|
||||
<h3 style={{ margin: 0, fontSize: 14, fontWeight: 600, marginBottom: "var(--space-4)" }}>
|
||||
Per-Joint Accuracy
|
||||
</h3>
|
||||
|
||||
{jointAccuracies.length === 0 ? (
|
||||
<div
|
||||
style={{
|
||||
textAlign: "center",
|
||||
padding: "var(--space-5)",
|
||||
color: "var(--text-muted)",
|
||||
}}
|
||||
>
|
||||
No joint accuracy data available
|
||||
</div>
|
||||
) : (
|
||||
<div
|
||||
style={{
|
||||
display: "grid",
|
||||
gridTemplateColumns: "repeat(auto-fill, minmax(140px, 1fr))",
|
||||
gap: "var(--space-3)",
|
||||
}}
|
||||
>
|
||||
{jointAccuracies.map((ja) => (
|
||||
<div
|
||||
key={ja.joint}
|
||||
style={{
|
||||
padding: "var(--space-3)",
|
||||
background: "var(--bg-secondary)",
|
||||
borderRadius: 6,
|
||||
textAlign: "center",
|
||||
}}
|
||||
>
|
||||
<div
|
||||
style={{
|
||||
fontSize: 11,
|
||||
color: "var(--text-muted)",
|
||||
marginBottom: 4,
|
||||
textTransform: "capitalize",
|
||||
}}
|
||||
>
|
||||
{ja.joint.replace("_", " ")}
|
||||
</div>
|
||||
<div
|
||||
style={{
|
||||
fontFamily: "var(--font-mono)",
|
||||
fontSize: 18,
|
||||
fontWeight: 600,
|
||||
color:
|
||||
ja.accuracy > 0.9
|
||||
? "var(--status-online)"
|
||||
: ja.accuracy > 0.8
|
||||
? "var(--accent)"
|
||||
: ja.accuracy > 0.7
|
||||
? "#f59e0b"
|
||||
: "var(--status-error)",
|
||||
}}
|
||||
>
|
||||
{(ja.accuracy * 100).toFixed(1)}%
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* Export Section */}
|
||||
<div
|
||||
className="card"
|
||||
style={{
|
||||
marginTop: "var(--space-5)",
|
||||
padding: "var(--space-4)",
|
||||
display: "flex",
|
||||
justifyContent: "space-between",
|
||||
alignItems: "center",
|
||||
}}
|
||||
>
|
||||
<div>
|
||||
<h3 style={{ margin: 0, fontSize: 14, fontWeight: 600 }}>Export Metrics</h3>
|
||||
<p style={{ fontSize: 12, color: "var(--text-muted)", marginTop: 4 }}>
|
||||
Download training history and evaluation results
|
||||
</p>
|
||||
</div>
|
||||
<div style={{ display: "flex", gap: "var(--space-2)" }}>
|
||||
<button
|
||||
onClick={() => exportMetrics("csv")}
|
||||
disabled={exporting || trainingHistory.length === 0}
|
||||
style={{
|
||||
padding: "8px 16px",
|
||||
background: "rgba(56, 139, 253, 0.1)",
|
||||
border: "1px solid rgba(56, 139, 253, 0.3)",
|
||||
borderRadius: 6,
|
||||
color: "var(--accent)",
|
||||
fontSize: 12,
|
||||
fontWeight: 600,
|
||||
cursor: trainingHistory.length === 0 ? "not-allowed" : "pointer",
|
||||
opacity: trainingHistory.length === 0 ? 0.5 : 1,
|
||||
}}
|
||||
>
|
||||
CSV
|
||||
</button>
|
||||
<button
|
||||
onClick={() => exportMetrics("json")}
|
||||
disabled={exporting || trainingHistory.length === 0}
|
||||
style={{
|
||||
padding: "8px 16px",
|
||||
background: "rgba(56, 139, 253, 0.1)",
|
||||
border: "1px solid rgba(56, 139, 253, 0.3)",
|
||||
borderRadius: 6,
|
||||
color: "var(--accent)",
|
||||
fontSize: 12,
|
||||
fontWeight: 600,
|
||||
cursor: trainingHistory.length === 0 ? "not-allowed" : "pointer",
|
||||
opacity: trainingHistory.length === 0 ? 0.5 : 1,
|
||||
}}
|
||||
>
|
||||
JSON
|
||||
</button>
|
||||
<button
|
||||
onClick={() => exportMetrics("tensorboard")}
|
||||
disabled={exporting || trainingHistory.length === 0}
|
||||
style={{
|
||||
padding: "8px 16px",
|
||||
background: "transparent",
|
||||
border: "1px solid var(--border)",
|
||||
borderRadius: 6,
|
||||
color: "var(--text-secondary)",
|
||||
fontSize: 12,
|
||||
fontWeight: 600,
|
||||
cursor: trainingHistory.length === 0 ? "not-allowed" : "pointer",
|
||||
opacity: trainingHistory.length === 0 ? 0.5 : 1,
|
||||
}}
|
||||
>
|
||||
TensorBoard
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
function StatCard({
|
||||
label,
|
||||
value,
|
||||
color,
|
||||
}: {
|
||||
label: string;
|
||||
value: number | string;
|
||||
color?: string;
|
||||
}) {
|
||||
return (
|
||||
<div className="card-glow" style={{ padding: "var(--space-4)" }}>
|
||||
<div
|
||||
style={{
|
||||
fontSize: 10,
|
||||
textTransform: "uppercase",
|
||||
letterSpacing: "0.06em",
|
||||
color: "var(--text-muted)",
|
||||
marginBottom: "var(--space-2)",
|
||||
fontWeight: 600,
|
||||
}}
|
||||
>
|
||||
{label}
|
||||
</div>
|
||||
<div
|
||||
style={{
|
||||
fontFamily: "var(--font-mono)",
|
||||
fontSize: 28,
|
||||
fontWeight: 600,
|
||||
color: color || "var(--text-primary)",
|
||||
letterSpacing: "-0.02em",
|
||||
}}
|
||||
>
|
||||
{value}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function MetricBar({
|
||||
label,
|
||||
value,
|
||||
color,
|
||||
}: {
|
||||
label: string;
|
||||
value: number;
|
||||
color: string;
|
||||
}) {
|
||||
return (
|
||||
<div>
|
||||
<div
|
||||
style={{
|
||||
display: "flex",
|
||||
justifyContent: "space-between",
|
||||
fontSize: 12,
|
||||
marginBottom: 4,
|
||||
}}
|
||||
>
|
||||
<span>{label}</span>
|
||||
<span style={{ fontFamily: "var(--font-mono)", fontWeight: 600 }}>
|
||||
{(value * 100).toFixed(1)}%
|
||||
</span>
|
||||
</div>
|
||||
<div
|
||||
style={{
|
||||
height: 6,
|
||||
background: "var(--bg-secondary)",
|
||||
borderRadius: 3,
|
||||
overflow: "hidden",
|
||||
}}
|
||||
>
|
||||
<div
|
||||
style={{
|
||||
width: `${value * 100}%`,
|
||||
height: "100%",
|
||||
background: color,
|
||||
borderRadius: 3,
|
||||
transition: "width 0.5s",
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default MetricsTab;
|
||||
+405
@@ -0,0 +1,405 @@
|
||||
import React, { useState, useEffect } from "react";
|
||||
import { invoke } from "@tauri-apps/api/core";
|
||||
|
||||
interface ModelArchitecture {
|
||||
id: string;
|
||||
name: string;
|
||||
type: "encoder" | "decoder" | "embedding" | "adaptor";
|
||||
description: string;
|
||||
params_m: number;
|
||||
memory_mb: number;
|
||||
paper?: string;
|
||||
}
|
||||
|
||||
interface Checkpoint {
|
||||
id: string;
|
||||
model_id: string;
|
||||
name: string;
|
||||
epoch: number;
|
||||
val_loss: number;
|
||||
created_at: string;
|
||||
path: string;
|
||||
size_mb: number;
|
||||
}
|
||||
|
||||
const MODEL_ARCHITECTURES: ModelArchitecture[] = [
|
||||
{
|
||||
id: "csi-encoder-cnn",
|
||||
name: "CSI Encoder (CNN)",
|
||||
type: "encoder",
|
||||
description: "Convolutional encoder for CSI amplitude/phase features",
|
||||
params_m: 2.3,
|
||||
memory_mb: 128,
|
||||
},
|
||||
{
|
||||
id: "csi-encoder-transformer",
|
||||
name: "CSI Encoder (Transformer)",
|
||||
type: "encoder",
|
||||
description: "Self-attention based CSI feature extraction",
|
||||
params_m: 8.5,
|
||||
memory_mb: 384,
|
||||
paper: "WiFi-ViT 2024",
|
||||
},
|
||||
{
|
||||
id: "pose-decoder-lstm",
|
||||
name: "Pose Decoder (LSTM)",
|
||||
type: "decoder",
|
||||
description: "Recurrent decoder for temporal pose estimation",
|
||||
params_m: 1.8,
|
||||
memory_mb: 96,
|
||||
},
|
||||
{
|
||||
id: "pose-decoder-gru",
|
||||
name: "Pose Decoder (GRU)",
|
||||
type: "decoder",
|
||||
description: "Gated recurrent unit pose decoder (faster)",
|
||||
params_m: 1.2,
|
||||
memory_mb: 64,
|
||||
},
|
||||
{
|
||||
id: "aether-embedding",
|
||||
name: "AETHER Embedding",
|
||||
type: "embedding",
|
||||
description: "Contrastive CSI embedding for person re-identification (ADR-024)",
|
||||
params_m: 4.2,
|
||||
memory_mb: 192,
|
||||
paper: "AETHER 2025",
|
||||
},
|
||||
{
|
||||
id: "meridian-adaptor",
|
||||
name: "MERIDIAN Adaptor",
|
||||
type: "adaptor",
|
||||
description: "Cross-environment domain generalization module (ADR-027)",
|
||||
params_m: 3.1,
|
||||
memory_mb: 144,
|
||||
paper: "MERIDIAN 2025",
|
||||
},
|
||||
];
|
||||
|
||||
const ModelsTab: React.FC = () => {
|
||||
const [checkpoints, setCheckpoints] = useState<Checkpoint[]>([]);
|
||||
const [selectedModel, setSelectedModel] = useState<string | null>(null);
|
||||
const [exporting, setExporting] = useState<string | null>(null);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
loadCheckpoints();
|
||||
}, []);
|
||||
|
||||
const loadCheckpoints = async () => {
|
||||
try {
|
||||
const loaded = await invoke<Checkpoint[]>("list_checkpoints");
|
||||
setCheckpoints(loaded);
|
||||
} catch (err) {
|
||||
// Mock data if command not implemented
|
||||
setCheckpoints([
|
||||
{
|
||||
id: "ckpt-001",
|
||||
model_id: "csi-encoder-cnn",
|
||||
name: "CSI-CNN v1.2",
|
||||
epoch: 50,
|
||||
val_loss: 0.0234,
|
||||
created_at: "2026-03-08T14:30:00Z",
|
||||
path: "~/.ruview/models/csi-cnn-v1.2.pt",
|
||||
size_mb: 12.4,
|
||||
},
|
||||
{
|
||||
id: "ckpt-002",
|
||||
model_id: "pose-decoder-gru",
|
||||
name: "Pose-GRU v2.0",
|
||||
epoch: 100,
|
||||
val_loss: 0.0189,
|
||||
created_at: "2026-03-09T09:15:00Z",
|
||||
path: "~/.ruview/models/pose-gru-v2.pt",
|
||||
size_mb: 8.2,
|
||||
},
|
||||
]);
|
||||
}
|
||||
};
|
||||
|
||||
const handleExport = async (checkpointId: string, format: "onnx" | "torchscript") => {
|
||||
setExporting(checkpointId);
|
||||
setError(null);
|
||||
try {
|
||||
await invoke("export_model", { checkpointId, format });
|
||||
// Success notification would go here
|
||||
} catch (err) {
|
||||
setError(`Export failed: ${err}`);
|
||||
} finally {
|
||||
setExporting(null);
|
||||
}
|
||||
};
|
||||
|
||||
const getTypeColor = (type: ModelArchitecture["type"]) => {
|
||||
switch (type) {
|
||||
case "encoder":
|
||||
return "var(--accent)";
|
||||
case "decoder":
|
||||
return "var(--status-online)";
|
||||
case "embedding":
|
||||
return "#a855f7";
|
||||
case "adaptor":
|
||||
return "#f59e0b";
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<div>
|
||||
{/* Stats Row */}
|
||||
<div
|
||||
style={{
|
||||
display: "grid",
|
||||
gridTemplateColumns: "repeat(4, 1fr)",
|
||||
gap: "var(--space-4)",
|
||||
marginBottom: "var(--space-5)",
|
||||
}}
|
||||
>
|
||||
<StatCard label="Architectures" value={MODEL_ARCHITECTURES.length} />
|
||||
<StatCard
|
||||
label="Checkpoints"
|
||||
value={checkpoints.length}
|
||||
color="var(--status-online)"
|
||||
/>
|
||||
<StatCard
|
||||
label="Total Params"
|
||||
value={`${MODEL_ARCHITECTURES.reduce((acc, m) => acc + m.params_m, 0).toFixed(1)}M`}
|
||||
/>
|
||||
<StatCard
|
||||
label="Storage Used"
|
||||
value={`${checkpoints.reduce((acc, c) => acc + c.size_mb, 0).toFixed(1)} MB`}
|
||||
/>
|
||||
</div>
|
||||
|
||||
{error && (
|
||||
<div
|
||||
style={{
|
||||
background: "rgba(248, 81, 73, 0.1)",
|
||||
border: "1px solid rgba(248, 81, 73, 0.3)",
|
||||
borderRadius: 6,
|
||||
padding: "var(--space-3)",
|
||||
marginBottom: "var(--space-4)",
|
||||
fontSize: 13,
|
||||
color: "var(--status-error)",
|
||||
}}
|
||||
>
|
||||
{error}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Model Architectures */}
|
||||
<h3 style={{ fontSize: 14, fontWeight: 600, marginBottom: "var(--space-3)" }}>
|
||||
Available Architectures
|
||||
</h3>
|
||||
<div
|
||||
style={{
|
||||
display: "grid",
|
||||
gridTemplateColumns: "repeat(auto-fill, minmax(300px, 1fr))",
|
||||
gap: "var(--space-3)",
|
||||
marginBottom: "var(--space-5)",
|
||||
}}
|
||||
>
|
||||
{MODEL_ARCHITECTURES.map((model) => (
|
||||
<div
|
||||
key={model.id}
|
||||
className="card"
|
||||
style={{
|
||||
padding: "var(--space-3)",
|
||||
cursor: "pointer",
|
||||
border:
|
||||
selectedModel === model.id
|
||||
? "1px solid var(--accent)"
|
||||
: "1px solid transparent",
|
||||
}}
|
||||
onClick={() => setSelectedModel(model.id)}
|
||||
>
|
||||
<div
|
||||
style={{
|
||||
display: "flex",
|
||||
justifyContent: "space-between",
|
||||
alignItems: "start",
|
||||
marginBottom: "var(--space-2)",
|
||||
}}
|
||||
>
|
||||
<div>
|
||||
<h4 style={{ margin: 0, fontSize: 14, fontWeight: 600 }}>
|
||||
{model.name}
|
||||
</h4>
|
||||
<span
|
||||
style={{
|
||||
display: "inline-block",
|
||||
marginTop: 4,
|
||||
padding: "1px 6px",
|
||||
borderRadius: 3,
|
||||
fontSize: 10,
|
||||
fontWeight: 600,
|
||||
textTransform: "uppercase",
|
||||
background: `${getTypeColor(model.type)}20`,
|
||||
color: getTypeColor(model.type),
|
||||
}}
|
||||
>
|
||||
{model.type}
|
||||
</span>
|
||||
</div>
|
||||
{model.paper && (
|
||||
<span
|
||||
style={{
|
||||
fontSize: 10,
|
||||
color: "var(--text-muted)",
|
||||
fontStyle: "italic",
|
||||
}}
|
||||
>
|
||||
{model.paper}
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
<p
|
||||
style={{
|
||||
fontSize: 11,
|
||||
color: "var(--text-muted)",
|
||||
margin: "var(--space-2) 0",
|
||||
lineHeight: 1.4,
|
||||
}}
|
||||
>
|
||||
{model.description}
|
||||
</p>
|
||||
<div
|
||||
style={{
|
||||
display: "flex",
|
||||
gap: "var(--space-3)",
|
||||
fontSize: 11,
|
||||
color: "var(--text-secondary)",
|
||||
}}
|
||||
>
|
||||
<span>🧮 {model.params_m}M params</span>
|
||||
<span>💾 {model.memory_mb} MB</span>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
|
||||
{/* Checkpoints */}
|
||||
<h3 style={{ fontSize: 14, fontWeight: 600, marginBottom: "var(--space-3)" }}>
|
||||
Saved Checkpoints
|
||||
</h3>
|
||||
{checkpoints.length === 0 ? (
|
||||
<div
|
||||
className="card"
|
||||
style={{
|
||||
padding: "var(--space-5)",
|
||||
textAlign: "center",
|
||||
color: "var(--text-muted)",
|
||||
}}
|
||||
>
|
||||
<div style={{ fontSize: 32, marginBottom: "var(--space-2)" }}>📦</div>
|
||||
<p style={{ fontSize: 13 }}>No checkpoints saved yet</p>
|
||||
<p style={{ fontSize: 12 }}>Train a model to create checkpoints</p>
|
||||
</div>
|
||||
) : (
|
||||
<div style={{ display: "flex", flexDirection: "column", gap: "var(--space-2)" }}>
|
||||
{checkpoints.map((ckpt) => (
|
||||
<div
|
||||
key={ckpt.id}
|
||||
className="card"
|
||||
style={{
|
||||
padding: "var(--space-3)",
|
||||
display: "flex",
|
||||
justifyContent: "space-between",
|
||||
alignItems: "center",
|
||||
}}
|
||||
>
|
||||
<div>
|
||||
<div style={{ fontWeight: 600, fontSize: 13 }}>{ckpt.name}</div>
|
||||
<div
|
||||
style={{
|
||||
fontSize: 11,
|
||||
color: "var(--text-muted)",
|
||||
marginTop: 2,
|
||||
}}
|
||||
>
|
||||
Epoch {ckpt.epoch} • Val Loss: {ckpt.val_loss.toFixed(4)} •{" "}
|
||||
{ckpt.size_mb.toFixed(1)} MB
|
||||
</div>
|
||||
</div>
|
||||
<div style={{ display: "flex", gap: "var(--space-2)" }}>
|
||||
<button
|
||||
onClick={() => handleExport(ckpt.id, "onnx")}
|
||||
disabled={exporting === ckpt.id}
|
||||
style={{
|
||||
padding: "6px 12px",
|
||||
background: "rgba(56, 139, 253, 0.1)",
|
||||
border: "1px solid rgba(56, 139, 253, 0.3)",
|
||||
borderRadius: 4,
|
||||
color: "var(--accent)",
|
||||
fontSize: 11,
|
||||
fontWeight: 600,
|
||||
cursor: exporting === ckpt.id ? "wait" : "pointer",
|
||||
opacity: exporting === ckpt.id ? 0.6 : 1,
|
||||
}}
|
||||
>
|
||||
{exporting === ckpt.id ? "Exporting..." : "ONNX"}
|
||||
</button>
|
||||
<button
|
||||
onClick={() => handleExport(ckpt.id, "torchscript")}
|
||||
disabled={exporting === ckpt.id}
|
||||
style={{
|
||||
padding: "6px 12px",
|
||||
background: "transparent",
|
||||
border: "1px solid var(--border)",
|
||||
borderRadius: 4,
|
||||
color: "var(--text-secondary)",
|
||||
fontSize: 11,
|
||||
fontWeight: 600,
|
||||
cursor: exporting === ckpt.id ? "wait" : "pointer",
|
||||
opacity: exporting === ckpt.id ? 0.6 : 1,
|
||||
}}
|
||||
>
|
||||
TorchScript
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
function StatCard({
|
||||
label,
|
||||
value,
|
||||
color,
|
||||
}: {
|
||||
label: string;
|
||||
value: number | string;
|
||||
color?: string;
|
||||
}) {
|
||||
return (
|
||||
<div className="card-glow" style={{ padding: "var(--space-4)" }}>
|
||||
<div
|
||||
style={{
|
||||
fontSize: 10,
|
||||
textTransform: "uppercase",
|
||||
letterSpacing: "0.06em",
|
||||
color: "var(--text-muted)",
|
||||
marginBottom: "var(--space-2)",
|
||||
fontWeight: 600,
|
||||
}}
|
||||
>
|
||||
{label}
|
||||
</div>
|
||||
<div
|
||||
style={{
|
||||
fontFamily: "var(--font-mono)",
|
||||
fontSize: 28,
|
||||
fontWeight: 600,
|
||||
color: color || "var(--text-primary)",
|
||||
letterSpacing: "-0.02em",
|
||||
}}
|
||||
>
|
||||
{value}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default ModelsTab;
|
||||
+767
@@ -0,0 +1,767 @@
|
||||
import React, { useState, useEffect } from "react";
|
||||
import { invoke } from "@tauri-apps/api/core";
|
||||
|
||||
interface RuVectorConfig {
|
||||
// MinCut Parameters
|
||||
mincut_enabled: boolean;
|
||||
mincut_threshold: number;
|
||||
mincut_max_persons: number;
|
||||
|
||||
// Attention Parameters
|
||||
attention_enabled: boolean;
|
||||
attention_heads: number;
|
||||
attention_dropout: number;
|
||||
|
||||
// Temporal Parameters
|
||||
temporal_enabled: boolean;
|
||||
temporal_window_ms: number;
|
||||
temporal_compression_ratio: number;
|
||||
|
||||
// Solver Parameters
|
||||
solver_enabled: boolean;
|
||||
solver_interpolation: "linear" | "cubic" | "sparse";
|
||||
solver_subcarrier_count: number;
|
||||
|
||||
// BVP Parameters
|
||||
bvp_enabled: boolean;
|
||||
bvp_filter_hz: [number, number];
|
||||
}
|
||||
|
||||
const DEFAULT_CONFIG: RuVectorConfig = {
|
||||
mincut_enabled: true,
|
||||
mincut_threshold: 0.5,
|
||||
mincut_max_persons: 5,
|
||||
attention_enabled: true,
|
||||
attention_heads: 4,
|
||||
attention_dropout: 0.1,
|
||||
temporal_enabled: true,
|
||||
temporal_window_ms: 500,
|
||||
temporal_compression_ratio: 4,
|
||||
solver_enabled: true,
|
||||
solver_interpolation: "sparse",
|
||||
solver_subcarrier_count: 56,
|
||||
bvp_enabled: false,
|
||||
bvp_filter_hz: [0.7, 4.0],
|
||||
};
|
||||
|
||||
const MODULES = [
|
||||
{
|
||||
id: "mincut",
|
||||
name: "MinCut Segmentation",
|
||||
crate: "ruvector-mincut",
|
||||
description: "Graph-based person segmentation using DynamicPersonMatcher",
|
||||
icon: "✂️",
|
||||
},
|
||||
{
|
||||
id: "attention",
|
||||
name: "Spatial Attention",
|
||||
crate: "ruvector-attention",
|
||||
description: "Attention-weighted antenna selection and BVP extraction",
|
||||
icon: "🎯",
|
||||
},
|
||||
{
|
||||
id: "temporal",
|
||||
name: "Temporal Tensor",
|
||||
crate: "ruvector-temporal-tensor",
|
||||
description: "Temporal CSI compression and breathing detection",
|
||||
icon: "⏱️",
|
||||
},
|
||||
{
|
||||
id: "solver",
|
||||
name: "Sparse Solver",
|
||||
crate: "ruvector-solver",
|
||||
description: "Sparse interpolation (114→56 subcarriers) and triangulation",
|
||||
icon: "🧮",
|
||||
},
|
||||
{
|
||||
id: "attn-mincut",
|
||||
name: "Attention MinCut",
|
||||
crate: "ruvector-attn-mincut",
|
||||
description: "Combined attention-weighted graph segmentation",
|
||||
icon: "🔀",
|
||||
},
|
||||
];
|
||||
|
||||
const RuVectorTab: React.FC = () => {
|
||||
const [config, setConfig] = useState<RuVectorConfig>(DEFAULT_CONFIG);
|
||||
const [testingLive, setTestingLive] = useState(false);
|
||||
const [liveMetrics, setLiveMetrics] = useState<{
|
||||
fps: number;
|
||||
latency_ms: number;
|
||||
persons_detected: number;
|
||||
} | null>(null);
|
||||
const [saved, setSaved] = useState(true);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
loadConfig();
|
||||
}, []);
|
||||
|
||||
const loadConfig = async () => {
|
||||
try {
|
||||
const loaded = await invoke<RuVectorConfig>("get_ruvector_config");
|
||||
setConfig(loaded);
|
||||
} catch (err) {
|
||||
// Use defaults if not implemented
|
||||
}
|
||||
};
|
||||
|
||||
const saveConfig = async () => {
|
||||
setError(null);
|
||||
try {
|
||||
await invoke("set_ruvector_config", { config });
|
||||
setSaved(true);
|
||||
} catch (err) {
|
||||
setError(`Failed to save: ${err}`);
|
||||
}
|
||||
};
|
||||
|
||||
const handleChange = <K extends keyof RuVectorConfig>(
|
||||
key: K,
|
||||
value: RuVectorConfig[K]
|
||||
) => {
|
||||
setConfig((prev) => ({ ...prev, [key]: value }));
|
||||
setSaved(false);
|
||||
};
|
||||
|
||||
const startLiveTest = async () => {
|
||||
setTestingLive(true);
|
||||
setError(null);
|
||||
try {
|
||||
// Simulate live testing metrics
|
||||
const interval = setInterval(() => {
|
||||
setLiveMetrics({
|
||||
fps: 25 + Math.random() * 10,
|
||||
latency_ms: 15 + Math.random() * 10,
|
||||
persons_detected: Math.floor(Math.random() * 3) + 1,
|
||||
});
|
||||
}, 500);
|
||||
|
||||
// Stop after 10 seconds for demo
|
||||
setTimeout(() => {
|
||||
clearInterval(interval);
|
||||
setTestingLive(false);
|
||||
setLiveMetrics(null);
|
||||
}, 10000);
|
||||
} catch (err) {
|
||||
setError(`Live test failed: ${err}`);
|
||||
setTestingLive(false);
|
||||
}
|
||||
};
|
||||
|
||||
const exportConfig = () => {
|
||||
const blob = new Blob([JSON.stringify(config, null, 2)], {
|
||||
type: "application/json",
|
||||
});
|
||||
const url = URL.createObjectURL(blob);
|
||||
const a = document.createElement("a");
|
||||
a.href = url;
|
||||
a.download = "ruvector-config.json";
|
||||
a.click();
|
||||
URL.revokeObjectURL(url);
|
||||
};
|
||||
|
||||
return (
|
||||
<div>
|
||||
{/* Module Cards */}
|
||||
<div
|
||||
style={{
|
||||
display: "grid",
|
||||
gridTemplateColumns: "repeat(auto-fill, minmax(200px, 1fr))",
|
||||
gap: "var(--space-3)",
|
||||
marginBottom: "var(--space-5)",
|
||||
}}
|
||||
>
|
||||
{MODULES.map((mod) => {
|
||||
const isEnabled =
|
||||
config[`${mod.id.replace("-", "_")}_enabled` as keyof RuVectorConfig] ?? true;
|
||||
return (
|
||||
<div
|
||||
key={mod.id}
|
||||
className="card"
|
||||
style={{
|
||||
padding: "var(--space-3)",
|
||||
opacity: isEnabled ? 1 : 0.5,
|
||||
transition: "opacity 0.2s",
|
||||
}}
|
||||
>
|
||||
<div
|
||||
style={{
|
||||
display: "flex",
|
||||
justifyContent: "space-between",
|
||||
alignItems: "start",
|
||||
}}
|
||||
>
|
||||
<span style={{ fontSize: 24 }}>{mod.icon}</span>
|
||||
<span
|
||||
style={{
|
||||
fontSize: 9,
|
||||
padding: "2px 6px",
|
||||
borderRadius: 3,
|
||||
background: isEnabled
|
||||
? "rgba(63, 185, 80, 0.15)"
|
||||
: "rgba(139, 148, 158, 0.15)",
|
||||
color: isEnabled ? "var(--status-online)" : "var(--text-muted)",
|
||||
fontWeight: 600,
|
||||
}}
|
||||
>
|
||||
{isEnabled ? "ON" : "OFF"}
|
||||
</span>
|
||||
</div>
|
||||
<h4 style={{ margin: "var(--space-2) 0 4px", fontSize: 13, fontWeight: 600 }}>
|
||||
{mod.name}
|
||||
</h4>
|
||||
<p
|
||||
style={{
|
||||
fontSize: 11,
|
||||
color: "var(--text-muted)",
|
||||
margin: 0,
|
||||
lineHeight: 1.4,
|
||||
}}
|
||||
>
|
||||
{mod.description}
|
||||
</p>
|
||||
<div
|
||||
style={{
|
||||
marginTop: "var(--space-2)",
|
||||
fontFamily: "var(--font-mono)",
|
||||
fontSize: 10,
|
||||
color: "var(--text-secondary)",
|
||||
}}
|
||||
>
|
||||
{mod.crate}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
|
||||
{error && (
|
||||
<div
|
||||
style={{
|
||||
background: "rgba(248, 81, 73, 0.1)",
|
||||
border: "1px solid rgba(248, 81, 73, 0.3)",
|
||||
borderRadius: 6,
|
||||
padding: "var(--space-3)",
|
||||
marginBottom: "var(--space-4)",
|
||||
fontSize: 13,
|
||||
color: "var(--status-error)",
|
||||
}}
|
||||
>
|
||||
{error}
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div style={{ display: "grid", gridTemplateColumns: "1fr 1fr", gap: "var(--space-5)" }}>
|
||||
{/* Configuration Panel */}
|
||||
<div className="card" style={{ padding: "var(--space-4)" }}>
|
||||
<h3 style={{ margin: 0, fontSize: 14, fontWeight: 600, marginBottom: "var(--space-4)" }}>
|
||||
Module Configuration
|
||||
</h3>
|
||||
|
||||
{/* MinCut Section */}
|
||||
<ConfigSection title="MinCut Segmentation">
|
||||
<ToggleRow
|
||||
label="Enable MinCut"
|
||||
checked={config.mincut_enabled}
|
||||
onChange={(v) => handleChange("mincut_enabled", v)}
|
||||
/>
|
||||
<SliderRow
|
||||
label="Threshold"
|
||||
value={config.mincut_threshold}
|
||||
min={0.1}
|
||||
max={1.0}
|
||||
step={0.05}
|
||||
onChange={(v) => handleChange("mincut_threshold", v)}
|
||||
disabled={!config.mincut_enabled}
|
||||
/>
|
||||
<NumberRow
|
||||
label="Max Persons"
|
||||
value={config.mincut_max_persons}
|
||||
min={1}
|
||||
max={10}
|
||||
onChange={(v) => handleChange("mincut_max_persons", v)}
|
||||
disabled={!config.mincut_enabled}
|
||||
/>
|
||||
</ConfigSection>
|
||||
|
||||
{/* Attention Section */}
|
||||
<ConfigSection title="Spatial Attention">
|
||||
<ToggleRow
|
||||
label="Enable Attention"
|
||||
checked={config.attention_enabled}
|
||||
onChange={(v) => handleChange("attention_enabled", v)}
|
||||
/>
|
||||
<NumberRow
|
||||
label="Attention Heads"
|
||||
value={config.attention_heads}
|
||||
min={1}
|
||||
max={16}
|
||||
onChange={(v) => handleChange("attention_heads", v)}
|
||||
disabled={!config.attention_enabled}
|
||||
/>
|
||||
<SliderRow
|
||||
label="Dropout"
|
||||
value={config.attention_dropout}
|
||||
min={0}
|
||||
max={0.5}
|
||||
step={0.05}
|
||||
onChange={(v) => handleChange("attention_dropout", v)}
|
||||
disabled={!config.attention_enabled}
|
||||
/>
|
||||
</ConfigSection>
|
||||
|
||||
{/* Temporal Section */}
|
||||
<ConfigSection title="Temporal Processing">
|
||||
<ToggleRow
|
||||
label="Enable Temporal"
|
||||
checked={config.temporal_enabled}
|
||||
onChange={(v) => handleChange("temporal_enabled", v)}
|
||||
/>
|
||||
<NumberRow
|
||||
label="Window (ms)"
|
||||
value={config.temporal_window_ms}
|
||||
min={100}
|
||||
max={2000}
|
||||
step={100}
|
||||
onChange={(v) => handleChange("temporal_window_ms", v)}
|
||||
disabled={!config.temporal_enabled}
|
||||
/>
|
||||
<NumberRow
|
||||
label="Compression Ratio"
|
||||
value={config.temporal_compression_ratio}
|
||||
min={1}
|
||||
max={16}
|
||||
onChange={(v) => handleChange("temporal_compression_ratio", v)}
|
||||
disabled={!config.temporal_enabled}
|
||||
/>
|
||||
</ConfigSection>
|
||||
|
||||
{/* Solver Section */}
|
||||
<ConfigSection title="Sparse Solver">
|
||||
<ToggleRow
|
||||
label="Enable Solver"
|
||||
checked={config.solver_enabled}
|
||||
onChange={(v) => handleChange("solver_enabled", v)}
|
||||
/>
|
||||
<div style={{ marginBottom: "var(--space-2)" }}>
|
||||
<label style={labelStyle}>Interpolation</label>
|
||||
<select
|
||||
value={config.solver_interpolation}
|
||||
onChange={(e) =>
|
||||
handleChange(
|
||||
"solver_interpolation",
|
||||
e.target.value as RuVectorConfig["solver_interpolation"]
|
||||
)
|
||||
}
|
||||
disabled={!config.solver_enabled}
|
||||
style={{
|
||||
...inputStyle,
|
||||
opacity: config.solver_enabled ? 1 : 0.5,
|
||||
}}
|
||||
>
|
||||
<option value="linear">Linear</option>
|
||||
<option value="cubic">Cubic</option>
|
||||
<option value="sparse">Sparse (L1)</option>
|
||||
</select>
|
||||
</div>
|
||||
<NumberRow
|
||||
label="Subcarrier Count"
|
||||
value={config.solver_subcarrier_count}
|
||||
min={28}
|
||||
max={114}
|
||||
onChange={(v) => handleChange("solver_subcarrier_count", v)}
|
||||
disabled={!config.solver_enabled}
|
||||
/>
|
||||
</ConfigSection>
|
||||
|
||||
{/* Action Buttons */}
|
||||
<div
|
||||
style={{
|
||||
display: "flex",
|
||||
gap: "var(--space-2)",
|
||||
marginTop: "var(--space-4)",
|
||||
}}
|
||||
>
|
||||
<button
|
||||
onClick={saveConfig}
|
||||
className="btn-gradient"
|
||||
style={{
|
||||
flex: 1,
|
||||
padding: "10px",
|
||||
fontSize: 12,
|
||||
opacity: saved ? 0.6 : 1,
|
||||
}}
|
||||
disabled={saved}
|
||||
>
|
||||
{saved ? "Saved" : "Save Configuration"}
|
||||
</button>
|
||||
<button
|
||||
onClick={exportConfig}
|
||||
style={{
|
||||
padding: "10px 16px",
|
||||
background: "transparent",
|
||||
border: "1px solid var(--border)",
|
||||
borderRadius: 6,
|
||||
color: "var(--text-secondary)",
|
||||
fontSize: 12,
|
||||
fontWeight: 600,
|
||||
cursor: "pointer",
|
||||
}}
|
||||
>
|
||||
Export
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Live Testing Panel */}
|
||||
<div className="card" style={{ padding: "var(--space-4)" }}>
|
||||
<h3 style={{ margin: 0, fontSize: 14, fontWeight: 600, marginBottom: "var(--space-4)" }}>
|
||||
Live Testing
|
||||
</h3>
|
||||
|
||||
<div
|
||||
style={{
|
||||
display: "flex",
|
||||
flexDirection: "column",
|
||||
alignItems: "center",
|
||||
justifyContent: "center",
|
||||
minHeight: 200,
|
||||
background: "var(--bg-secondary)",
|
||||
borderRadius: 8,
|
||||
marginBottom: "var(--space-4)",
|
||||
}}
|
||||
>
|
||||
{testingLive ? (
|
||||
<>
|
||||
<div
|
||||
style={{
|
||||
fontSize: 48,
|
||||
animation: "pulse 1s infinite",
|
||||
}}
|
||||
>
|
||||
📡
|
||||
</div>
|
||||
<p style={{ fontSize: 13, color: "var(--text-secondary)", marginTop: "var(--space-2)" }}>
|
||||
Processing live CSI stream...
|
||||
</p>
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
<div style={{ fontSize: 48, opacity: 0.5 }}>📡</div>
|
||||
<p style={{ fontSize: 13, color: "var(--text-muted)", marginTop: "var(--space-2)" }}>
|
||||
Start live test to apply config to real CSI data
|
||||
</p>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{liveMetrics && (
|
||||
<div
|
||||
style={{
|
||||
display: "grid",
|
||||
gridTemplateColumns: "repeat(3, 1fr)",
|
||||
gap: "var(--space-3)",
|
||||
marginBottom: "var(--space-4)",
|
||||
}}
|
||||
>
|
||||
<MetricCard label="FPS" value={liveMetrics.fps.toFixed(1)} />
|
||||
<MetricCard label="Latency" value={`${liveMetrics.latency_ms.toFixed(0)}ms`} />
|
||||
<MetricCard label="Persons" value={liveMetrics.persons_detected.toString()} />
|
||||
</div>
|
||||
)}
|
||||
|
||||
<button
|
||||
onClick={testingLive ? () => setTestingLive(false) : startLiveTest}
|
||||
style={{
|
||||
width: "100%",
|
||||
padding: "12px",
|
||||
background: testingLive
|
||||
? "rgba(248, 81, 73, 0.1)"
|
||||
: "rgba(56, 139, 253, 0.1)",
|
||||
border: `1px solid ${testingLive ? "rgba(248, 81, 73, 0.3)" : "rgba(56, 139, 253, 0.3)"}`,
|
||||
borderRadius: 6,
|
||||
color: testingLive ? "var(--status-error)" : "var(--accent)",
|
||||
fontSize: 13,
|
||||
fontWeight: 600,
|
||||
cursor: "pointer",
|
||||
}}
|
||||
>
|
||||
{testingLive ? "Stop Test" : "Start Live Test"}
|
||||
</button>
|
||||
|
||||
{/* Presets */}
|
||||
<div style={{ marginTop: "var(--space-5)" }}>
|
||||
<h4 style={{ fontSize: 12, fontWeight: 600, marginBottom: "var(--space-3)" }}>
|
||||
Quick Presets
|
||||
</h4>
|
||||
<div style={{ display: "flex", flexDirection: "column", gap: "var(--space-2)" }}>
|
||||
<PresetButton
|
||||
label="Low Latency"
|
||||
description="Minimal processing for real-time"
|
||||
onClick={() => {
|
||||
setConfig({
|
||||
...DEFAULT_CONFIG,
|
||||
attention_heads: 2,
|
||||
temporal_compression_ratio: 8,
|
||||
solver_subcarrier_count: 28,
|
||||
});
|
||||
setSaved(false);
|
||||
}}
|
||||
/>
|
||||
<PresetButton
|
||||
label="High Accuracy"
|
||||
description="Maximum quality, higher latency"
|
||||
onClick={() => {
|
||||
setConfig({
|
||||
...DEFAULT_CONFIG,
|
||||
attention_heads: 8,
|
||||
temporal_compression_ratio: 2,
|
||||
solver_subcarrier_count: 114,
|
||||
solver_interpolation: "cubic",
|
||||
});
|
||||
setSaved(false);
|
||||
}}
|
||||
/>
|
||||
<PresetButton
|
||||
label="Balanced"
|
||||
description="Default recommended settings"
|
||||
onClick={() => {
|
||||
setConfig(DEFAULT_CONFIG);
|
||||
setSaved(false);
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<style>{`
|
||||
@keyframes pulse {
|
||||
0%, 100% { transform: scale(1); }
|
||||
50% { transform: scale(1.1); }
|
||||
}
|
||||
`}</style>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
// Helper Components
|
||||
function ConfigSection({ title, children }: { title: string; children: React.ReactNode }) {
|
||||
return (
|
||||
<div style={{ marginBottom: "var(--space-4)" }}>
|
||||
<h4
|
||||
style={{
|
||||
fontSize: 11,
|
||||
fontWeight: 600,
|
||||
color: "var(--text-muted)",
|
||||
textTransform: "uppercase",
|
||||
letterSpacing: "0.04em",
|
||||
marginBottom: "var(--space-2)",
|
||||
}}
|
||||
>
|
||||
{title}
|
||||
</h4>
|
||||
{children}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function ToggleRow({
|
||||
label,
|
||||
checked,
|
||||
onChange,
|
||||
}: {
|
||||
label: string;
|
||||
checked: boolean;
|
||||
onChange: (v: boolean) => void;
|
||||
}) {
|
||||
return (
|
||||
<div
|
||||
style={{
|
||||
display: "flex",
|
||||
justifyContent: "space-between",
|
||||
alignItems: "center",
|
||||
marginBottom: "var(--space-2)",
|
||||
}}
|
||||
>
|
||||
<span style={{ fontSize: 12 }}>{label}</span>
|
||||
<button
|
||||
onClick={() => onChange(!checked)}
|
||||
style={{
|
||||
width: 40,
|
||||
height: 22,
|
||||
borderRadius: 11,
|
||||
border: "none",
|
||||
background: checked ? "var(--accent)" : "var(--border)",
|
||||
position: "relative",
|
||||
cursor: "pointer",
|
||||
transition: "background 0.2s",
|
||||
}}
|
||||
>
|
||||
<span
|
||||
style={{
|
||||
position: "absolute",
|
||||
top: 2,
|
||||
left: checked ? 20 : 2,
|
||||
width: 18,
|
||||
height: 18,
|
||||
borderRadius: "50%",
|
||||
background: "white",
|
||||
transition: "left 0.2s",
|
||||
}}
|
||||
/>
|
||||
</button>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function SliderRow({
|
||||
label,
|
||||
value,
|
||||
min,
|
||||
max,
|
||||
step,
|
||||
onChange,
|
||||
disabled,
|
||||
}: {
|
||||
label: string;
|
||||
value: number;
|
||||
min: number;
|
||||
max: number;
|
||||
step: number;
|
||||
onChange: (v: number) => void;
|
||||
disabled?: boolean;
|
||||
}) {
|
||||
return (
|
||||
<div style={{ marginBottom: "var(--space-2)", opacity: disabled ? 0.5 : 1 }}>
|
||||
<div style={{ display: "flex", justifyContent: "space-between", marginBottom: 4 }}>
|
||||
<span style={{ fontSize: 12 }}>{label}</span>
|
||||
<span style={{ fontSize: 11, fontFamily: "var(--font-mono)", color: "var(--text-muted)" }}>
|
||||
{value.toFixed(2)}
|
||||
</span>
|
||||
</div>
|
||||
<input
|
||||
type="range"
|
||||
value={value}
|
||||
min={min}
|
||||
max={max}
|
||||
step={step}
|
||||
onChange={(e) => onChange(parseFloat(e.target.value))}
|
||||
disabled={disabled}
|
||||
style={{ width: "100%", cursor: disabled ? "not-allowed" : "pointer" }}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function NumberRow({
|
||||
label,
|
||||
value,
|
||||
min,
|
||||
max,
|
||||
step = 1,
|
||||
onChange,
|
||||
disabled,
|
||||
}: {
|
||||
label: string;
|
||||
value: number;
|
||||
min: number;
|
||||
max: number;
|
||||
step?: number;
|
||||
onChange: (v: number) => void;
|
||||
disabled?: boolean;
|
||||
}) {
|
||||
return (
|
||||
<div
|
||||
style={{
|
||||
display: "flex",
|
||||
justifyContent: "space-between",
|
||||
alignItems: "center",
|
||||
marginBottom: "var(--space-2)",
|
||||
opacity: disabled ? 0.5 : 1,
|
||||
}}
|
||||
>
|
||||
<span style={{ fontSize: 12 }}>{label}</span>
|
||||
<input
|
||||
type="number"
|
||||
value={value}
|
||||
min={min}
|
||||
max={max}
|
||||
step={step}
|
||||
onChange={(e) => onChange(parseInt(e.target.value) || min)}
|
||||
disabled={disabled}
|
||||
style={{
|
||||
width: 70,
|
||||
padding: "4px 8px",
|
||||
background: "var(--bg-secondary)",
|
||||
border: "1px solid var(--border)",
|
||||
borderRadius: 4,
|
||||
color: "var(--text-primary)",
|
||||
fontSize: 12,
|
||||
textAlign: "right",
|
||||
cursor: disabled ? "not-allowed" : "text",
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function MetricCard({ label, value }: { label: string; value: string }) {
|
||||
return (
|
||||
<div className="card" style={{ padding: "var(--space-3)", textAlign: "center" }}>
|
||||
<div style={{ fontSize: 10, color: "var(--text-muted)", marginBottom: 2 }}>{label}</div>
|
||||
<div style={{ fontFamily: "var(--font-mono)", fontSize: 18, fontWeight: 600 }}>{value}</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function PresetButton({
|
||||
label,
|
||||
description,
|
||||
onClick,
|
||||
}: {
|
||||
label: string;
|
||||
description: string;
|
||||
onClick: () => void;
|
||||
}) {
|
||||
return (
|
||||
<button
|
||||
onClick={onClick}
|
||||
style={{
|
||||
display: "flex",
|
||||
flexDirection: "column",
|
||||
alignItems: "start",
|
||||
padding: "var(--space-3)",
|
||||
background: "var(--bg-secondary)",
|
||||
border: "1px solid var(--border)",
|
||||
borderRadius: 6,
|
||||
cursor: "pointer",
|
||||
textAlign: "left",
|
||||
}}
|
||||
>
|
||||
<span style={{ fontSize: 12, fontWeight: 600, color: "var(--text-primary)" }}>{label}</span>
|
||||
<span style={{ fontSize: 11, color: "var(--text-muted)" }}>{description}</span>
|
||||
</button>
|
||||
);
|
||||
}
|
||||
|
||||
const labelStyle: React.CSSProperties = {
|
||||
display: "block",
|
||||
fontSize: 11,
|
||||
fontWeight: 600,
|
||||
color: "var(--text-muted)",
|
||||
marginBottom: 4,
|
||||
};
|
||||
|
||||
const inputStyle: React.CSSProperties = {
|
||||
width: "100%",
|
||||
padding: "8px 12px",
|
||||
background: "var(--bg-secondary)",
|
||||
border: "1px solid var(--border)",
|
||||
borderRadius: 6,
|
||||
color: "var(--text-primary)",
|
||||
fontSize: 13,
|
||||
};
|
||||
|
||||
export default RuVectorTab;
|
||||
+601
@@ -0,0 +1,601 @@
|
||||
import React, { useState, useEffect } from "react";
|
||||
import { invoke } from "@tauri-apps/api/core";
|
||||
import { listen, UnlistenFn } from "@tauri-apps/api/event";
|
||||
|
||||
interface TrainingConfig {
|
||||
dataset_id: string;
|
||||
model_id: string;
|
||||
epochs: number;
|
||||
batch_size: number;
|
||||
learning_rate: number;
|
||||
optimizer: "adam" | "sgd" | "adamw";
|
||||
weight_decay: number;
|
||||
use_augmentation: boolean;
|
||||
checkpoint_every: number;
|
||||
}
|
||||
|
||||
interface TrainingProgress {
|
||||
epoch: number;
|
||||
total_epochs: number;
|
||||
batch: number;
|
||||
total_batches: number;
|
||||
train_loss: number;
|
||||
val_loss: number | null;
|
||||
learning_rate: number;
|
||||
eta_secs: number;
|
||||
gpu_memory_mb: number | null;
|
||||
}
|
||||
|
||||
interface TrainingJob {
|
||||
id: string;
|
||||
status: "running" | "paused" | "completed" | "failed";
|
||||
started_at: string;
|
||||
progress: TrainingProgress;
|
||||
}
|
||||
|
||||
const DEFAULT_CONFIG: TrainingConfig = {
|
||||
dataset_id: "mmfi",
|
||||
model_id: "csi-encoder-cnn",
|
||||
epochs: 100,
|
||||
batch_size: 32,
|
||||
learning_rate: 0.001,
|
||||
optimizer: "adam",
|
||||
weight_decay: 0.0001,
|
||||
use_augmentation: true,
|
||||
checkpoint_every: 10,
|
||||
};
|
||||
|
||||
interface TrainingTabProps {
|
||||
gpuAvailable: boolean;
|
||||
}
|
||||
|
||||
const TrainingTab: React.FC<TrainingTabProps> = ({ gpuAvailable }) => {
|
||||
const [config, setConfig] = useState<TrainingConfig>(DEFAULT_CONFIG);
|
||||
const [currentJob, setCurrentJob] = useState<TrainingJob | null>(null);
|
||||
const [lossHistory, setLossHistory] = useState<{ epoch: number; train: number; val: number }[]>(
|
||||
[]
|
||||
);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
let unlisten: UnlistenFn | undefined;
|
||||
|
||||
const setupListener = async () => {
|
||||
try {
|
||||
unlisten = await listen<TrainingProgress>("training:progress", (event) => {
|
||||
const progress = event.payload;
|
||||
setCurrentJob((prev) =>
|
||||
prev
|
||||
? { ...prev, progress }
|
||||
: {
|
||||
id: "job-1",
|
||||
status: "running",
|
||||
started_at: new Date().toISOString(),
|
||||
progress,
|
||||
}
|
||||
);
|
||||
|
||||
if (progress.val_loss !== null && progress.batch === progress.total_batches) {
|
||||
setLossHistory((prev) => [
|
||||
...prev,
|
||||
{
|
||||
epoch: progress.epoch,
|
||||
train: progress.train_loss,
|
||||
val: progress.val_loss!,
|
||||
},
|
||||
]);
|
||||
}
|
||||
});
|
||||
} catch (err) {
|
||||
console.error("Failed to setup training listener:", err);
|
||||
}
|
||||
};
|
||||
|
||||
setupListener();
|
||||
|
||||
return () => {
|
||||
if (unlisten) unlisten();
|
||||
};
|
||||
}, []);
|
||||
|
||||
const handleStartTraining = async () => {
|
||||
setError(null);
|
||||
try {
|
||||
await invoke("start_training", { config });
|
||||
setCurrentJob({
|
||||
id: `job-${Date.now()}`,
|
||||
status: "running",
|
||||
started_at: new Date().toISOString(),
|
||||
progress: {
|
||||
epoch: 0,
|
||||
total_epochs: config.epochs,
|
||||
batch: 0,
|
||||
total_batches: 0,
|
||||
train_loss: 0,
|
||||
val_loss: null,
|
||||
learning_rate: config.learning_rate,
|
||||
eta_secs: 0,
|
||||
gpu_memory_mb: null,
|
||||
},
|
||||
});
|
||||
} catch (err) {
|
||||
setError(`Failed to start training: ${err}`);
|
||||
}
|
||||
};
|
||||
|
||||
const handleStopTraining = async () => {
|
||||
try {
|
||||
await invoke("stop_training");
|
||||
setCurrentJob((prev) => (prev ? { ...prev, status: "paused" } : null));
|
||||
} catch (err) {
|
||||
setError(`Failed to stop training: ${err}`);
|
||||
}
|
||||
};
|
||||
|
||||
const formatEta = (seconds: number) => {
|
||||
if (seconds < 60) return `${seconds}s`;
|
||||
if (seconds < 3600) return `${Math.floor(seconds / 60)}m ${seconds % 60}s`;
|
||||
const hours = Math.floor(seconds / 3600);
|
||||
const mins = Math.floor((seconds % 3600) / 60);
|
||||
return `${hours}h ${mins}m`;
|
||||
};
|
||||
|
||||
const progress = currentJob?.progress;
|
||||
const epochProgress = progress ? (progress.epoch / progress.total_epochs) * 100 : 0;
|
||||
const batchProgress = progress && progress.total_batches > 0
|
||||
? (progress.batch / progress.total_batches) * 100
|
||||
: 0;
|
||||
|
||||
return (
|
||||
<div>
|
||||
{/* GPU Warning */}
|
||||
{!gpuAvailable && (
|
||||
<div
|
||||
style={{
|
||||
background: "rgba(245, 158, 11, 0.1)",
|
||||
border: "1px solid rgba(245, 158, 11, 0.3)",
|
||||
borderRadius: 6,
|
||||
padding: "var(--space-3)",
|
||||
marginBottom: "var(--space-4)",
|
||||
display: "flex",
|
||||
alignItems: "center",
|
||||
gap: "var(--space-3)",
|
||||
}}
|
||||
>
|
||||
<span style={{ fontSize: 18 }}>⚠️</span>
|
||||
<div>
|
||||
<div style={{ fontWeight: 600, fontSize: 13, color: "#f59e0b" }}>
|
||||
GPU Not Available
|
||||
</div>
|
||||
<div style={{ fontSize: 12, color: "var(--text-muted)" }}>
|
||||
Training will use CPU, which is significantly slower. Consider using a
|
||||
machine with CUDA or Metal support.
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{error && (
|
||||
<div
|
||||
style={{
|
||||
background: "rgba(248, 81, 73, 0.1)",
|
||||
border: "1px solid rgba(248, 81, 73, 0.3)",
|
||||
borderRadius: 6,
|
||||
padding: "var(--space-3)",
|
||||
marginBottom: "var(--space-4)",
|
||||
fontSize: 13,
|
||||
color: "var(--status-error)",
|
||||
}}
|
||||
>
|
||||
{error}
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div style={{ display: "grid", gridTemplateColumns: "1fr 1fr", gap: "var(--space-5)" }}>
|
||||
{/* Configuration Panel */}
|
||||
<div className="card" style={{ padding: "var(--space-4)" }}>
|
||||
<h3 style={{ margin: 0, fontSize: 14, fontWeight: 600, marginBottom: "var(--space-4)" }}>
|
||||
Training Configuration
|
||||
</h3>
|
||||
|
||||
<div style={{ display: "flex", flexDirection: "column", gap: "var(--space-3)" }}>
|
||||
<div>
|
||||
<label style={labelStyle}>Dataset</label>
|
||||
<select
|
||||
value={config.dataset_id}
|
||||
onChange={(e) => setConfig({ ...config, dataset_id: e.target.value })}
|
||||
style={inputStyle}
|
||||
>
|
||||
<option value="mmfi">MM-Fi Dataset</option>
|
||||
<option value="wipose">Wi-Pose Dataset</option>
|
||||
<option value="wiar">WiAR Dataset</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label style={labelStyle}>Model Architecture</label>
|
||||
<select
|
||||
value={config.model_id}
|
||||
onChange={(e) => setConfig({ ...config, model_id: e.target.value })}
|
||||
style={inputStyle}
|
||||
>
|
||||
<option value="csi-encoder-cnn">CSI Encoder (CNN)</option>
|
||||
<option value="csi-encoder-transformer">CSI Encoder (Transformer)</option>
|
||||
<option value="pose-decoder-lstm">Pose Decoder (LSTM)</option>
|
||||
<option value="pose-decoder-gru">Pose Decoder (GRU)</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div style={{ display: "grid", gridTemplateColumns: "1fr 1fr", gap: "var(--space-3)" }}>
|
||||
<div>
|
||||
<label style={labelStyle}>Epochs</label>
|
||||
<input
|
||||
type="number"
|
||||
value={config.epochs}
|
||||
onChange={(e) => setConfig({ ...config, epochs: parseInt(e.target.value) || 1 })}
|
||||
min={1}
|
||||
max={1000}
|
||||
style={inputStyle}
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<label style={labelStyle}>Batch Size</label>
|
||||
<input
|
||||
type="number"
|
||||
value={config.batch_size}
|
||||
onChange={(e) =>
|
||||
setConfig({ ...config, batch_size: parseInt(e.target.value) || 1 })
|
||||
}
|
||||
min={1}
|
||||
max={512}
|
||||
style={inputStyle}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div style={{ display: "grid", gridTemplateColumns: "1fr 1fr", gap: "var(--space-3)" }}>
|
||||
<div>
|
||||
<label style={labelStyle}>Learning Rate</label>
|
||||
<input
|
||||
type="number"
|
||||
value={config.learning_rate}
|
||||
onChange={(e) =>
|
||||
setConfig({ ...config, learning_rate: parseFloat(e.target.value) || 0.001 })
|
||||
}
|
||||
step={0.0001}
|
||||
min={0.00001}
|
||||
max={1}
|
||||
style={inputStyle}
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<label style={labelStyle}>Optimizer</label>
|
||||
<select
|
||||
value={config.optimizer}
|
||||
onChange={(e) =>
|
||||
setConfig({ ...config, optimizer: e.target.value as TrainingConfig["optimizer"] })
|
||||
}
|
||||
style={inputStyle}
|
||||
>
|
||||
<option value="adam">Adam</option>
|
||||
<option value="adamw">AdamW</option>
|
||||
<option value="sgd">SGD</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div style={{ display: "grid", gridTemplateColumns: "1fr 1fr", gap: "var(--space-3)" }}>
|
||||
<div>
|
||||
<label style={labelStyle}>Weight Decay</label>
|
||||
<input
|
||||
type="number"
|
||||
value={config.weight_decay}
|
||||
onChange={(e) =>
|
||||
setConfig({ ...config, weight_decay: parseFloat(e.target.value) || 0 })
|
||||
}
|
||||
step={0.0001}
|
||||
min={0}
|
||||
max={1}
|
||||
style={inputStyle}
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<label style={labelStyle}>Checkpoint Every</label>
|
||||
<input
|
||||
type="number"
|
||||
value={config.checkpoint_every}
|
||||
onChange={(e) =>
|
||||
setConfig({ ...config, checkpoint_every: parseInt(e.target.value) || 1 })
|
||||
}
|
||||
min={1}
|
||||
max={100}
|
||||
style={inputStyle}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div style={{ display: "flex", alignItems: "center", gap: "var(--space-2)" }}>
|
||||
<input
|
||||
type="checkbox"
|
||||
id="augmentation"
|
||||
checked={config.use_augmentation}
|
||||
onChange={(e) => setConfig({ ...config, use_augmentation: e.target.checked })}
|
||||
style={{ width: 16, height: 16 }}
|
||||
/>
|
||||
<label htmlFor="augmentation" style={{ fontSize: 13, cursor: "pointer" }}>
|
||||
Enable Data Augmentation
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<div style={{ marginTop: "var(--space-3)" }}>
|
||||
{currentJob?.status === "running" ? (
|
||||
<button
|
||||
onClick={handleStopTraining}
|
||||
style={{
|
||||
width: "100%",
|
||||
padding: "12px",
|
||||
background: "rgba(248, 81, 73, 0.1)",
|
||||
border: "1px solid rgba(248, 81, 73, 0.3)",
|
||||
borderRadius: 6,
|
||||
color: "var(--status-error)",
|
||||
fontSize: 13,
|
||||
fontWeight: 600,
|
||||
cursor: "pointer",
|
||||
}}
|
||||
>
|
||||
Stop Training
|
||||
</button>
|
||||
) : (
|
||||
<button
|
||||
onClick={handleStartTraining}
|
||||
className="btn-gradient"
|
||||
style={{ width: "100%", padding: "12px", fontSize: 13 }}
|
||||
>
|
||||
Start Training
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Progress Panel */}
|
||||
<div className="card" style={{ padding: "var(--space-4)" }}>
|
||||
<h3 style={{ margin: 0, fontSize: 14, fontWeight: 600, marginBottom: "var(--space-4)" }}>
|
||||
Training Progress
|
||||
</h3>
|
||||
|
||||
{!currentJob ? (
|
||||
<div
|
||||
style={{
|
||||
display: "flex",
|
||||
flexDirection: "column",
|
||||
alignItems: "center",
|
||||
justifyContent: "center",
|
||||
height: 300,
|
||||
color: "var(--text-muted)",
|
||||
}}
|
||||
>
|
||||
<div style={{ fontSize: 48, marginBottom: "var(--space-3)" }}>🎯</div>
|
||||
<p style={{ fontSize: 13 }}>No training job running</p>
|
||||
<p style={{ fontSize: 12 }}>Configure and start training to begin</p>
|
||||
</div>
|
||||
) : (
|
||||
<div style={{ display: "flex", flexDirection: "column", gap: "var(--space-4)" }}>
|
||||
{/* Status */}
|
||||
<div
|
||||
style={{
|
||||
display: "flex",
|
||||
justifyContent: "space-between",
|
||||
alignItems: "center",
|
||||
}}
|
||||
>
|
||||
<div style={{ display: "flex", alignItems: "center", gap: "var(--space-2)" }}>
|
||||
<span
|
||||
style={{
|
||||
width: 8,
|
||||
height: 8,
|
||||
borderRadius: "50%",
|
||||
background:
|
||||
currentJob.status === "running"
|
||||
? "var(--status-online)"
|
||||
: currentJob.status === "paused"
|
||||
? "#f59e0b"
|
||||
: "var(--status-error)",
|
||||
animation: currentJob.status === "running" ? "pulse 1.5s infinite" : "none",
|
||||
}}
|
||||
/>
|
||||
<span style={{ fontSize: 13, fontWeight: 600, textTransform: "capitalize" }}>
|
||||
{currentJob.status}
|
||||
</span>
|
||||
</div>
|
||||
<span style={{ fontSize: 12, color: "var(--text-muted)" }}>
|
||||
ETA: {formatEta(progress?.eta_secs ?? 0)}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
{/* Epoch Progress */}
|
||||
<div>
|
||||
<div
|
||||
style={{
|
||||
display: "flex",
|
||||
justifyContent: "space-between",
|
||||
fontSize: 12,
|
||||
marginBottom: 4,
|
||||
}}
|
||||
>
|
||||
<span>Epoch</span>
|
||||
<span>
|
||||
{progress?.epoch ?? 0} / {progress?.total_epochs ?? config.epochs}
|
||||
</span>
|
||||
</div>
|
||||
<div
|
||||
style={{
|
||||
height: 6,
|
||||
background: "var(--border)",
|
||||
borderRadius: 3,
|
||||
overflow: "hidden",
|
||||
}}
|
||||
>
|
||||
<div
|
||||
style={{
|
||||
width: `${epochProgress}%`,
|
||||
height: "100%",
|
||||
background: "var(--accent)",
|
||||
transition: "width 0.3s",
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Batch Progress */}
|
||||
<div>
|
||||
<div
|
||||
style={{
|
||||
display: "flex",
|
||||
justifyContent: "space-between",
|
||||
fontSize: 12,
|
||||
marginBottom: 4,
|
||||
}}
|
||||
>
|
||||
<span>Batch</span>
|
||||
<span>
|
||||
{progress?.batch ?? 0} / {progress?.total_batches ?? 0}
|
||||
</span>
|
||||
</div>
|
||||
<div
|
||||
style={{
|
||||
height: 4,
|
||||
background: "var(--border)",
|
||||
borderRadius: 2,
|
||||
overflow: "hidden",
|
||||
}}
|
||||
>
|
||||
<div
|
||||
style={{
|
||||
width: `${batchProgress}%`,
|
||||
height: "100%",
|
||||
background: "rgba(56, 139, 253, 0.5)",
|
||||
transition: "width 0.1s",
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Stats Grid */}
|
||||
<div
|
||||
style={{
|
||||
display: "grid",
|
||||
gridTemplateColumns: "repeat(2, 1fr)",
|
||||
gap: "var(--space-3)",
|
||||
}}
|
||||
>
|
||||
<div className="card" style={{ padding: "var(--space-3)" }}>
|
||||
<div style={{ fontSize: 10, color: "var(--text-muted)", marginBottom: 4 }}>
|
||||
Train Loss
|
||||
</div>
|
||||
<div style={{ fontFamily: "var(--font-mono)", fontSize: 20, fontWeight: 600 }}>
|
||||
{progress?.train_loss.toFixed(4) ?? "—"}
|
||||
</div>
|
||||
</div>
|
||||
<div className="card" style={{ padding: "var(--space-3)" }}>
|
||||
<div style={{ fontSize: 10, color: "var(--text-muted)", marginBottom: 4 }}>
|
||||
Val Loss
|
||||
</div>
|
||||
<div
|
||||
style={{
|
||||
fontFamily: "var(--font-mono)",
|
||||
fontSize: 20,
|
||||
fontWeight: 600,
|
||||
color: "var(--status-online)",
|
||||
}}
|
||||
>
|
||||
{progress?.val_loss?.toFixed(4) ?? "—"}
|
||||
</div>
|
||||
</div>
|
||||
<div className="card" style={{ padding: "var(--space-3)" }}>
|
||||
<div style={{ fontSize: 10, color: "var(--text-muted)", marginBottom: 4 }}>
|
||||
Learning Rate
|
||||
</div>
|
||||
<div style={{ fontFamily: "var(--font-mono)", fontSize: 14, fontWeight: 600 }}>
|
||||
{progress?.learning_rate.toExponential(2) ?? "—"}
|
||||
</div>
|
||||
</div>
|
||||
<div className="card" style={{ padding: "var(--space-3)" }}>
|
||||
<div style={{ fontSize: 10, color: "var(--text-muted)", marginBottom: 4 }}>
|
||||
GPU Memory
|
||||
</div>
|
||||
<div style={{ fontFamily: "var(--font-mono)", fontSize: 14, fontWeight: 600 }}>
|
||||
{progress?.gpu_memory_mb ? `${progress.gpu_memory_mb} MB` : "N/A"}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Mini Loss Chart */}
|
||||
{lossHistory.length > 0 && (
|
||||
<div>
|
||||
<div style={{ fontSize: 12, fontWeight: 600, marginBottom: "var(--space-2)" }}>
|
||||
Loss History
|
||||
</div>
|
||||
<div
|
||||
style={{
|
||||
height: 80,
|
||||
display: "flex",
|
||||
alignItems: "flex-end",
|
||||
gap: 2,
|
||||
padding: "var(--space-2)",
|
||||
background: "var(--bg-secondary)",
|
||||
borderRadius: 4,
|
||||
}}
|
||||
>
|
||||
{lossHistory.slice(-20).map((h, i) => (
|
||||
<div
|
||||
key={i}
|
||||
style={{
|
||||
flex: 1,
|
||||
height: `${Math.max(5, Math.min(100, (1 - h.train) * 100))}%`,
|
||||
background: "var(--accent)",
|
||||
borderRadius: 2,
|
||||
opacity: 0.6 + (i / 20) * 0.4,
|
||||
}}
|
||||
title={`Epoch ${h.epoch}: Train=${h.train.toFixed(4)}, Val=${h.val.toFixed(4)}`}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<style>{`
|
||||
@keyframes pulse {
|
||||
0%, 100% { opacity: 1; }
|
||||
50% { opacity: 0.5; }
|
||||
}
|
||||
`}</style>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
const labelStyle: React.CSSProperties = {
|
||||
display: "block",
|
||||
fontSize: 11,
|
||||
fontWeight: 600,
|
||||
color: "var(--text-muted)",
|
||||
marginBottom: 4,
|
||||
textTransform: "uppercase",
|
||||
letterSpacing: "0.04em",
|
||||
};
|
||||
|
||||
const inputStyle: React.CSSProperties = {
|
||||
width: "100%",
|
||||
padding: "8px 12px",
|
||||
background: "var(--bg-secondary)",
|
||||
border: "1px solid var(--border)",
|
||||
borderRadius: 6,
|
||||
color: "var(--text-primary)",
|
||||
fontSize: 13,
|
||||
};
|
||||
|
||||
export default TrainingTab;
|
||||
+165
@@ -0,0 +1,165 @@
|
||||
import React, { useState, useEffect } from "react";
|
||||
import { invoke } from "@tauri-apps/api/core";
|
||||
import DatasetsTab from "./DatasetsTab";
|
||||
import ModelsTab from "./ModelsTab";
|
||||
import TrainingTab from "./TrainingTab";
|
||||
import RuVectorTab from "./RuVectorTab";
|
||||
import MetricsTab from "./MetricsTab";
|
||||
|
||||
type TrainingTabType = "datasets" | "models" | "training" | "ruvector" | "metrics";
|
||||
|
||||
interface GpuInfo {
|
||||
available: boolean;
|
||||
name: string | null;
|
||||
memory_mb: number | null;
|
||||
cuda_version: string | null;
|
||||
metal_supported: boolean;
|
||||
}
|
||||
|
||||
const Training: React.FC = () => {
|
||||
const [activeTab, setActiveTab] = useState<TrainingTabType>("datasets");
|
||||
const [gpuInfo, setGpuInfo] = useState<GpuInfo | null>(null);
|
||||
const [loading, setLoading] = useState(true);
|
||||
|
||||
useEffect(() => {
|
||||
detectGpu();
|
||||
}, []);
|
||||
|
||||
const detectGpu = async () => {
|
||||
try {
|
||||
const info = await invoke<GpuInfo>("detect_gpu");
|
||||
setGpuInfo(info);
|
||||
} catch (err) {
|
||||
console.error("GPU detection failed:", err);
|
||||
setGpuInfo({
|
||||
available: false,
|
||||
name: null,
|
||||
memory_mb: null,
|
||||
cuda_version: null,
|
||||
metal_supported: false,
|
||||
});
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
const tabs: { id: TrainingTabType; label: string; icon: string }[] = [
|
||||
{ id: "datasets", label: "Datasets", icon: "📊" },
|
||||
{ id: "models", label: "Models", icon: "🧠" },
|
||||
{ id: "training", label: "Training", icon: "⚡" },
|
||||
{ id: "ruvector", label: "RuVector", icon: "📡" },
|
||||
{ id: "metrics", label: "Metrics", icon: "📈" },
|
||||
];
|
||||
|
||||
return (
|
||||
<div style={{ padding: "var(--space-5)", maxWidth: 1400 }}>
|
||||
{/* Header */}
|
||||
<div
|
||||
style={{
|
||||
display: "flex",
|
||||
justifyContent: "space-between",
|
||||
alignItems: "center",
|
||||
marginBottom: "var(--space-5)",
|
||||
}}
|
||||
>
|
||||
<div>
|
||||
<h1 className="heading-lg" style={{ margin: 0 }}>
|
||||
Training & Models
|
||||
</h1>
|
||||
<p
|
||||
style={{
|
||||
fontSize: 13,
|
||||
color: "var(--text-secondary)",
|
||||
marginTop: 4,
|
||||
}}
|
||||
>
|
||||
Train pose estimation models and configure RuVector signal processing
|
||||
</p>
|
||||
</div>
|
||||
|
||||
{/* GPU Status */}
|
||||
<div
|
||||
style={{
|
||||
display: "flex",
|
||||
alignItems: "center",
|
||||
gap: "var(--space-3)",
|
||||
padding: "var(--space-3) var(--space-4)",
|
||||
background: gpuInfo?.available
|
||||
? "rgba(63, 185, 80, 0.1)"
|
||||
: "rgba(139, 148, 158, 0.1)",
|
||||
border: `1px solid ${gpuInfo?.available ? "rgba(63, 185, 80, 0.3)" : "rgba(139, 148, 158, 0.3)"}`,
|
||||
borderRadius: 8,
|
||||
}}
|
||||
>
|
||||
<span style={{ fontSize: 18 }}>{gpuInfo?.available ? "🎮" : "💻"}</span>
|
||||
<div>
|
||||
<div style={{ fontSize: 12, fontWeight: 600, color: "var(--text-primary)" }}>
|
||||
{loading
|
||||
? "Detecting GPU..."
|
||||
: gpuInfo?.available
|
||||
? gpuInfo.name || "GPU Available"
|
||||
: "CPU Mode"}
|
||||
</div>
|
||||
<div style={{ fontSize: 11, color: "var(--text-muted)" }}>
|
||||
{gpuInfo?.cuda_version
|
||||
? `CUDA ${gpuInfo.cuda_version}`
|
||||
: gpuInfo?.metal_supported
|
||||
? "Metal Supported"
|
||||
: "No GPU acceleration"}
|
||||
{gpuInfo?.memory_mb && ` • ${Math.round(gpuInfo.memory_mb / 1024)}GB`}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Tabs */}
|
||||
<div
|
||||
style={{
|
||||
display: "flex",
|
||||
gap: "var(--space-1)",
|
||||
borderBottom: "1px solid var(--border)",
|
||||
marginBottom: "var(--space-5)",
|
||||
}}
|
||||
>
|
||||
{tabs.map((tab) => (
|
||||
<button
|
||||
key={tab.id}
|
||||
onClick={() => setActiveTab(tab.id)}
|
||||
style={{
|
||||
display: "flex",
|
||||
alignItems: "center",
|
||||
gap: 6,
|
||||
padding: "12px 20px",
|
||||
border: "none",
|
||||
background: "transparent",
|
||||
color: activeTab === tab.id ? "var(--accent)" : "var(--text-secondary)",
|
||||
fontSize: 13,
|
||||
fontWeight: 600,
|
||||
cursor: "pointer",
|
||||
borderBottom:
|
||||
activeTab === tab.id
|
||||
? "2px solid var(--accent)"
|
||||
: "2px solid transparent",
|
||||
marginBottom: -1,
|
||||
transition: "color 0.15s, border-color 0.15s",
|
||||
}}
|
||||
>
|
||||
<span>{tab.icon}</span>
|
||||
{tab.label}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
|
||||
{/* Tab Content */}
|
||||
<div>
|
||||
{activeTab === "datasets" && <DatasetsTab />}
|
||||
{activeTab === "models" && <ModelsTab />}
|
||||
{activeTab === "training" && <TrainingTab gpuAvailable={gpuInfo?.available ?? false} />}
|
||||
{activeTab === "ruvector" && <RuVectorTab />}
|
||||
{activeTab === "metrics" && <MetricsTab />}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default Training;
|
||||
@@ -170,6 +170,8 @@ export interface WasmModule {
|
||||
// Sensing Server
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
export type DataSource = "auto" | "wifi" | "esp32" | "simulate";
|
||||
|
||||
export interface ServerConfig {
|
||||
http_port: number;
|
||||
ws_port: number;
|
||||
@@ -177,6 +179,7 @@ export interface ServerConfig {
|
||||
static_dir: string | null;
|
||||
model_dir: string | null;
|
||||
log_level: string;
|
||||
source: DataSource;
|
||||
}
|
||||
|
||||
export interface ServerStatus {
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
// Application version - single source of truth
|
||||
export const APP_VERSION = "0.5.0";
|
||||
+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)
|
||||
|
||||
Reference in New Issue
Block a user