Wire ADS-B end to end: secondary-sdr container running dump1090
node-26#9. New secondary-sdr-container claims the node's SECOND physical SDR (RTL-SDR index 1 — op25 always claims index 0; no serial-based binding yet, same gap op25 itself has). Its control API (start/stop/status/data, mirroring op25_controller.py) launches dump1090 in adsb mode and exposes the decoded aircraft.json snapshot; AIS mode 400s until it's wired next. edge-node: on_config_push starts/stops it when secondary_sdr_mode changes, lifespan resumes it after a restart if already configured, and a new telemetry_uplink_loop polls its /secondary/data every 10s and POSTs non-empty snapshots to C2's new /telemetry/adsb (same bearer-key pattern call_recorder.py already uses for audio upload). UNVERIFIED: this container has not been built or run against real hardware in this session (sandboxed authoring machine, no docker) — dump1090's --write-json field names are believed correct from its docs but not confirmed against a real capture. Build + hardware smoke test before this reaches a real node. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 5
parent
8f5fca8757
commit
b2e3804dc3
@@ -136,6 +136,9 @@ class Settings(BaseSettings):
|
||||
op25_api_url: str = "http://localhost:8001"
|
||||
op25_terminal_url: str = "http://localhost:8081"
|
||||
|
||||
# Secondary SDR container (node-26#9) — ADS-B / AIS on a second SDR
|
||||
secondary_sdr_api_url: str = "http://localhost:8002"
|
||||
|
||||
# Paths (volume mounts)
|
||||
config_path: str = "/configs"
|
||||
recordings_path: str = "/recordings"
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
import httpx
|
||||
from typing import Any, Dict, Optional
|
||||
from app.config import settings
|
||||
from app.internal.logger import logger
|
||||
|
||||
|
||||
class SecondarySdrClient:
|
||||
"""Talks to the secondary-sdr-container (node-26#9) over its control API.
|
||||
|
||||
Mirrors op25_client.py's shape on purpose — same failure handling (log
|
||||
and return None/False rather than raise), since this container is
|
||||
optional and its absence must never break the primary op25 radio path.
|
||||
"""
|
||||
|
||||
def __init__(self):
|
||||
self.api_url = settings.secondary_sdr_api_url
|
||||
|
||||
async def start(self, mode: str) -> bool:
|
||||
try:
|
||||
async with httpx.AsyncClient(timeout=10) as client:
|
||||
r = await client.post(f"{self.api_url}/secondary/start", json={"mode": mode})
|
||||
r.raise_for_status()
|
||||
return True
|
||||
except Exception as e:
|
||||
logger.error(f"Secondary SDR start (mode={mode!r}) failed: {e}")
|
||||
return False
|
||||
|
||||
async def stop(self) -> bool:
|
||||
try:
|
||||
async with httpx.AsyncClient(timeout=10) as client:
|
||||
r = await client.post(f"{self.api_url}/secondary/stop")
|
||||
r.raise_for_status()
|
||||
return True
|
||||
except Exception as e:
|
||||
logger.error(f"Secondary SDR stop failed: {e}")
|
||||
return False
|
||||
|
||||
async def status(self) -> Optional[Dict[str, Any]]:
|
||||
try:
|
||||
async with httpx.AsyncClient(timeout=5) as client:
|
||||
r = await client.get(f"{self.api_url}/secondary/status")
|
||||
r.raise_for_status()
|
||||
return r.json()
|
||||
except Exception as e:
|
||||
logger.error(f"Secondary SDR status failed: {e}")
|
||||
return None
|
||||
|
||||
async def data(self) -> Optional[Dict[str, Any]]:
|
||||
try:
|
||||
async with httpx.AsyncClient(timeout=5) as client:
|
||||
r = await client.get(f"{self.api_url}/secondary/data")
|
||||
r.raise_for_status()
|
||||
return r.json()
|
||||
except Exception as e:
|
||||
logger.error(f"Secondary SDR data fetch failed: {e}")
|
||||
return None
|
||||
|
||||
|
||||
secondary_sdr_client = SecondarySdrClient()
|
||||
@@ -0,0 +1,41 @@
|
||||
import asyncio
|
||||
|
||||
import httpx
|
||||
|
||||
from app.config import settings
|
||||
from app.internal import credentials
|
||||
from app.internal.config_manager import load_node_config
|
||||
from app.internal.logger import logger
|
||||
from app.internal.secondary_sdr_client import secondary_sdr_client
|
||||
|
||||
# How often the second-SDR decoder's current snapshot is forwarded to C2
|
||||
# (node-26#9). This is a live-map overlay, not a flight/vessel history, so
|
||||
# there is no backlog/retry on a missed tick — the next one supersedes it.
|
||||
UPLINK_INTERVAL_SECONDS = 10
|
||||
|
||||
|
||||
async def _post_snapshot(path: str, body: dict) -> None:
|
||||
if not settings.c2_url:
|
||||
return
|
||||
api_key = credentials.get_api_key()
|
||||
if not api_key:
|
||||
return
|
||||
headers = {"Authorization": f"Bearer {api_key}"}
|
||||
try:
|
||||
async with httpx.AsyncClient(timeout=10) as client:
|
||||
r = await client.post(f"{settings.c2_url}{path}", json=body, headers=headers)
|
||||
r.raise_for_status()
|
||||
except Exception as e:
|
||||
logger.debug(f"Telemetry uplink to {path} failed: {e}")
|
||||
|
||||
|
||||
async def telemetry_uplink_loop():
|
||||
while True:
|
||||
await asyncio.sleep(UPLINK_INTERVAL_SECONDS)
|
||||
config = load_node_config()
|
||||
if config.secondary_sdr_mode != "adsb":
|
||||
continue
|
||||
snapshot = await secondary_sdr_client.data()
|
||||
if not snapshot or not snapshot.get("aircraft"):
|
||||
continue
|
||||
await _post_snapshot("/telemetry/adsb", {"aircraft": snapshot["aircraft"]})
|
||||
@@ -260,6 +260,13 @@ async def on_config_push(payload: dict):
|
||||
await op25_client.start()
|
||||
logger.info(f"Config push applied: {config.name}")
|
||||
|
||||
if secondary_sdr_mode is not None:
|
||||
from app.internal.secondary_sdr_client import secondary_sdr_client
|
||||
if secondary_sdr_mode in ("adsb", "ais"):
|
||||
await secondary_sdr_client.start(secondary_sdr_mode)
|
||||
else:
|
||||
await secondary_sdr_client.stop()
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# App lifecycle
|
||||
@@ -315,12 +322,20 @@ async def lifespan(app: FastAPI):
|
||||
logger.warning(f"OP25 not ready yet (attempt {attempt + 1}/10), retrying in 3s…")
|
||||
await asyncio.sleep(3)
|
||||
|
||||
if node_cfg.secondary_sdr_mode in ("adsb", "ais"):
|
||||
from app.internal.secondary_sdr_client import secondary_sdr_client
|
||||
logger.info(f"Resuming secondary SDR (mode={node_cfg.secondary_sdr_mode!r}) after restart.")
|
||||
await secondary_sdr_client.start(node_cfg.secondary_sdr_mode)
|
||||
|
||||
heartbeat_task = asyncio.create_task(mqtt_manager.heartbeat_loop())
|
||||
from app.internal.telemetry_uplink import telemetry_uplink_loop
|
||||
telemetry_task = asyncio.create_task(telemetry_uplink_loop())
|
||||
|
||||
yield # --- app running ---
|
||||
|
||||
logger.info("Edge node shutting down.")
|
||||
heartbeat_task.cancel()
|
||||
telemetry_task.cancel()
|
||||
await metadata_watcher.stop()
|
||||
await call_recorder.stop()
|
||||
await radio_bot.stop()
|
||||
|
||||
Reference in New Issue
Block a user