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>
46 lines
1.7 KiB
Python
46 lines
1.7 KiB
Python
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)
|
|
if not load_node_config().secondary_sdr_priority:
|
|
continue
|
|
snapshot = await secondary_sdr_client.data()
|
|
if not snapshot:
|
|
continue
|
|
# Several decoders can run at once (one per spare SDR), so forward
|
|
# whatever each produced rather than keying off a single mode.
|
|
if snapshot.get("aircraft"):
|
|
await _post_snapshot("/telemetry/adsb", {"aircraft": snapshot["aircraft"]})
|
|
if snapshot.get("vessels"):
|
|
await _post_snapshot("/telemetry/ais", {"vessels": snapshot["vessels"]})
|