Replaces the single secondary_sdr_mode with secondary_sdr_priority, e.g. ["adsb", "ais"]. OP25 always keeps its own dongle; the secondary-sdr container starts decoders top-down until it runs out of free SDRs, so a 3-SDR node runs ADS-B and AIS at once and a 2-SDR node runs the top pick. - secondary-sdr: one decoder per mode, POST /secondary/apply(priority) (no-op when the right prefix is already running), orphaned decoders from a uvicorn reload are reaped on start, /status reports sdr_count via lsusb (op25's :stable image has none). - edge-node: one apply path (set_secondary_priority) for the local dashboard, a new C2 'set_secondary_priority' MQTT command, and config pushes; it never restarts op25. Legacy mode migrates on load. Checkin reports priority, what's running, and sdr_count. Uplink forwards aircraft and vessels whenever either is present. - Local dashboard: 'Secondary SDRs' card to enable/reorder/save. Verified: edge-node pytest 190 passed, flake8 clean. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
72 lines
2.7 KiB
Python
72 lines
2.7 KiB
Python
import httpx
|
|
from typing import Any, Dict, List, 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 apply(self, priority: List[str]) -> Optional[List[str]]:
|
|
"""Run decoders down the priority list until SDRs run out. Returns the
|
|
modes actually running, or None if the container is unreachable."""
|
|
try:
|
|
async with httpx.AsyncClient(timeout=30) as client:
|
|
r = await client.post(f"{self.api_url}/secondary/apply", json={"priority": priority})
|
|
r.raise_for_status()
|
|
return r.json().get("running", [])
|
|
except Exception as e:
|
|
logger.error(f"Secondary SDR apply (priority={priority!r}) failed: {e}")
|
|
return None
|
|
|
|
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()
|