wifi-densepose/scripts/macos-rssi-bridge/Makefile

113 lines
4.7 KiB
Makefile

.PHONY: all build build-server clean start stop test scan run run-verbose listen install-helper dashboard help
HELPER := mac_wifi
BRIDGE := target/release/macos-rssi-bridge
# Sensing-server expectations.
TARGET_HOST ?= 127.0.0.1
TARGET_PORT ?= 5005
INTERVAL ?= 1.5
# Sensing-server (built from the v2 workspace and run from v2/ so it can
# resolve its default --ui-path of ../ui).
SENSING_SERVER_DIR := ../../v2
SENSING_SERVER_BIN := target/release/sensing-server
SENSING_UI_URL := http://localhost:8080
BRIDGE_DASHBOARD := http://localhost:9090/dashboard
all: build
help:
@echo "macos-rssi-bridge — Mac WiFi card → RuView sensing-server bridge"
@echo ""
@echo " make start build + run everything: sensing-server + bridge + open UIs"
@echo " make stop kill any running sensing-server / bridge processes"
@echo " make build compile mac_wifi (Swift) + macos-rssi-bridge (Rust)"
@echo " make build-server compile the v2 sensing-server (release)"
@echo " make scan run a single multi-BSSID scan, print JSON"
@echo " make run start the bridge → udp://$(TARGET_HOST):$(TARGET_PORT) + http://localhost:9090"
@echo " make run-verbose same, with per-frame stats on stderr"
@echo " make dashboard open the multistatic RF tomography UI in your browser"
@echo " make listen debug: print frames arriving on $(TARGET_PORT) (no sensing-server)"
@echo " make test run Rust unit tests"
@echo " make clean delete build artifacts"
@echo ""
@echo "Variables: TARGET_HOST=$(TARGET_HOST) TARGET_PORT=$(TARGET_PORT) INTERVAL=$(INTERVAL)"
build: $(HELPER) $(BRIDGE)
$(HELPER): mac_wifi.swift
swiftc -O mac_wifi.swift -o $(HELPER)
$(BRIDGE): src/main.rs Cargo.toml
cargo build --release
build-server:
cd $(SENSING_SERVER_DIR) && cargo build --release -p wifi-densepose-sensing-server --no-default-features
# One-shot: builds everything, starts sensing-server + bridge under a single
# process group, opens both UIs, waits for Ctrl-C, and kills both children
# cleanly. The sensing-server is run with cwd=v2/ so its default --ui-path of
# ../ui resolves; the bridge stays in this directory so ./mac_wifi works.
#
# --source esp32 is required: the server's "auto" probe only binds UDP if it
# detects frames *before* the bridge starts sending. The bridge IS the ESP32
# source (synthetic, but same wire format), so pin it explicitly. Otherwise
# the server falls back to `simulate`, never binds UDP, and you get
# ECONNREFUSED on the bridge + a UI showing simulated (fake) motion.
start: build build-server
@$(MAKE) -s stop >/dev/null 2>&1 || true
@echo "[start] sensing-server + macos-rssi-bridge → $(SENSING_UI_URL)"
@trap 'echo; echo "[start] stopping…"; kill $$SERVER_PID $$BRIDGE_PID 2>/dev/null; wait 2>/dev/null; exit 0' INT TERM; \
( cd $(SENSING_SERVER_DIR) && ./$(SENSING_SERVER_BIN) \
--source esp32 --udp-port $(TARGET_PORT) ) & \
SERVER_PID=$$!; \
echo "[start] sensing-server pid=$$SERVER_PID (source=esp32) — waiting 3s for UDP bind…"; \
sleep 3; \
./$(BRIDGE) --helper ./$(HELPER) --target-host $(TARGET_HOST) \
--target-port $(TARGET_PORT) --interval $(INTERVAL) & \
BRIDGE_PID=$$!; \
echo "[start] bridge pid=$$BRIDGE_PID — dashboard: $(BRIDGE_DASHBOARD)"; \
( sleep 2; open $(SENSING_UI_URL) 2>/dev/null; open $(BRIDGE_DASHBOARD) 2>/dev/null ) & \
echo "[start] press Ctrl-C to stop both"; \
wait
stop:
-@pkill -f "$(SENSING_SERVER_BIN)" 2>/dev/null && echo "[stop] sensing-server killed" || echo "[stop] no sensing-server"
-@pkill -f "$(BRIDGE)" 2>/dev/null && echo "[stop] bridge killed" || echo "[stop] no bridge"
test:
cargo test --release
scan: $(HELPER)
./$(HELPER) --scan-once
run: build
./$(BRIDGE) --helper ./$(HELPER) --target-host $(TARGET_HOST) \
--target-port $(TARGET_PORT) --interval $(INTERVAL)
run-verbose: build
./$(BRIDGE) --helper ./$(HELPER) --target-host $(TARGET_HOST) \
--target-port $(TARGET_PORT) --interval $(INTERVAL) --verbose
# Open the RF tomography dashboard. Assumes the bridge is already running
# (start it with `make run` or `make run-verbose` in another terminal).
dashboard:
@open http://localhost:9090/dashboard 2>/dev/null || \
echo "Open http://localhost:9090/dashboard in your browser"
# Debug helper — prints magic/seq/rssi for each frame the bridge emits.
# Doesn't require sensing-server.
listen:
@python3 listen.py $(TARGET_PORT)
# Optional: install the Swift helper system-wide so anything on $PATH can find it,
# matching the default lookup of `MacosCoreWlanScanner::new()` in the Rust crate.
install-helper: $(HELPER)
install -m 0755 $(HELPER) /usr/local/bin/mac_wifi
@echo "[install] /usr/local/bin/mac_wifi"
clean:
rm -f $(HELPER)
cargo clean