Secondary SDR priority: every spare SDR runs the next decoder in an ordered list
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>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
1c74edffea
commit
9b6c64fbbf
@@ -210,10 +210,14 @@ class MQTTManager:
|
||||
logger.info("No API key on disk — requesting re-delivery from C2 server.")
|
||||
self._publish(self._t_key_request, {}, qos=1)
|
||||
|
||||
async def publish_checkin(self):
|
||||
await self._publish_checkin()
|
||||
|
||||
async def _publish_checkin(self):
|
||||
from app.internal.discord_radio import radio_bot
|
||||
from app.internal.config_manager import load_node_config
|
||||
from app.internal.op25_client import op25_client
|
||||
from app.internal.secondary_sdr_client import secondary_sdr_client
|
||||
config = load_node_config()
|
||||
devices = await op25_client.devices()
|
||||
payload = {
|
||||
@@ -228,11 +232,18 @@ class MQTTManager:
|
||||
"override_system_id": config.override_system_id,
|
||||
"enforce_override_timeout": config.enforce_override_timeout,
|
||||
"secondary_sdr_mode": config.secondary_sdr_mode,
|
||||
"secondary_sdr_priority": config.secondary_sdr_priority,
|
||||
}
|
||||
# Best-effort — the first node-initiated hardware-report field. Omit
|
||||
# rather than guess if op25's control API is unreachable.
|
||||
if devices is not None:
|
||||
payload["sdr_count"] = devices.get("count")
|
||||
secondary = await secondary_sdr_client.status()
|
||||
if secondary is not None:
|
||||
payload["secondary_sdr_running"] = [r["mode"] for r in secondary.get("running", [])]
|
||||
# Best-effort hardware report — omit rather than guess. op25's :stable
|
||||
# image has no lsusb, so fall back to the secondary-sdr container's count.
|
||||
count = devices.get("count") if devices else None
|
||||
if count is None and secondary is not None:
|
||||
count = secondary.get("sdr_count")
|
||||
if count is not None:
|
||||
payload["sdr_count"] = count
|
||||
self._publish(self._t_checkin, payload, qos=1)
|
||||
|
||||
def _publish(self, topic: str, payload: dict, qos: int = 0, retain: bool = False):
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
import asyncio
|
||||
from typing import Iterable, List, Optional
|
||||
|
||||
from app.internal.config_manager import load_node_config, save_node_config
|
||||
from app.internal.logger import logger
|
||||
from app.internal.secondary_sdr_client import secondary_sdr_client
|
||||
from app.models import normalize_secondary_priority
|
||||
|
||||
|
||||
async def set_secondary_priority(priority: Iterable[str]) -> Optional[List[str]]:
|
||||
"""Persist and apply the node's secondary SDR priority — one path for the
|
||||
local dashboard, a C2 command and a config push alike. Never touches op25:
|
||||
changing what the spare dongles do must not interrupt P25 recording.
|
||||
|
||||
Returns the decoders now running (None if the container is unreachable).
|
||||
"""
|
||||
ordered = normalize_secondary_priority(priority)
|
||||
cfg = load_node_config()
|
||||
cfg.secondary_sdr_priority = ordered
|
||||
cfg.secondary_sdr_mode = ordered[0] if ordered else "none"
|
||||
save_node_config(cfg)
|
||||
|
||||
running = await secondary_sdr_client.apply(ordered)
|
||||
logger.info(f"Secondary SDR priority set to {ordered!r}; running {running!r}")
|
||||
|
||||
# Report straight away so C2's view doesn't wait for the next heartbeat.
|
||||
from app.internal.mqtt_manager import mqtt_manager
|
||||
asyncio.create_task(mqtt_manager.publish_checkin())
|
||||
return running
|
||||
@@ -1,5 +1,5 @@
|
||||
import httpx
|
||||
from typing import Any, Dict, Optional
|
||||
from typing import Any, Dict, List, Optional
|
||||
from app.config import settings
|
||||
from app.internal.logger import logger
|
||||
|
||||
@@ -15,6 +15,18 @@ class SecondarySdrClient:
|
||||
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:
|
||||
|
||||
@@ -32,13 +32,14 @@ async def _post_snapshot(path: str, body: dict) -> None:
|
||||
async def telemetry_uplink_loop():
|
||||
while True:
|
||||
await asyncio.sleep(UPLINK_INTERVAL_SECONDS)
|
||||
config = load_node_config()
|
||||
if config.secondary_sdr_mode not in ("adsb", "ais"):
|
||||
if not load_node_config().secondary_sdr_priority:
|
||||
continue
|
||||
snapshot = await secondary_sdr_client.data()
|
||||
if not snapshot:
|
||||
continue
|
||||
if config.secondary_sdr_mode == "adsb" and snapshot.get("aircraft"):
|
||||
# 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"]})
|
||||
elif config.secondary_sdr_mode == "ais" and snapshot.get("vessels"):
|
||||
if snapshot.get("vessels"):
|
||||
await _post_snapshot("/telemetry/ais", {"vessels": snapshot["vessels"]})
|
||||
|
||||
Reference in New Issue
Block a user