Fixes node-26#11. OP25's generated config said "rtl" (= whichever dongle
enumerates first), so on 2-SDR nodes a decoder could take OP25's dongle
and stop recording. Now:
- sdr_pins: {op25|adsb|ais: serial}, absent = automatic. Every OP25
config generation (op25_client.generate_config) rewrites the device to
rtl=<serial>: the pin, else the first dongle's serial, which is what
"rtl" always opened. Left as "rtl" only for unknown/shared serials.
- secondary-sdr: /secondary/devices lists dongles + serials via librtlsdr
(works while claimed). apply(priority, pins, reserved) never touches
OP25's dongle, gives a pinned service only its own dongle, lets a
higher-priority service take a spare from a lower one, and still runs a
pinned lower-priority service when the top pick has no dongle.
- sdr_settings.py replaces secondary_priority.py: one apply path for the
local dashboard, the new set_sdr_config C2 command (set_secondary_priority
kept as an alias) and config pushes. OP25 restarts only when its own
dongle changes. Checkin reports sdr_devices, sdr_pins, op25_sdr_serial.
- Local dashboard: 'SDRs' card with an OP25 SDR dropdown and a per-service
dongle dropdown, duplicate-serial and double-pin warnings.
Verified: edge-node pytest 194 passed; secondary-sdr tests 7 passed;
flake8 clean; page JS passes node --check.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
85 lines
3.4 KiB
Python
85 lines
3.4 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 devices(self) -> Optional[List[Dict[str, Any]]]:
|
|
"""Every RTL-SDR on the node with its serial, or None if unreachable."""
|
|
try:
|
|
async with httpx.AsyncClient(timeout=5) as client:
|
|
r = await client.get(f"{self.api_url}/secondary/devices")
|
|
r.raise_for_status()
|
|
return r.json().get("devices", [])
|
|
except Exception as e:
|
|
logger.error(f"Secondary SDR device list failed: {e}")
|
|
return None
|
|
|
|
async def apply(self, priority: List[str], pins: Dict[str, str], reserved: List[str]) -> Optional[List[str]]:
|
|
"""Run decoders down the priority list until SDRs run out, honouring
|
|
pins and never touching `reserved` (op25's) dongles. Returns the modes
|
|
actually running, or None if the container is unreachable."""
|
|
body = {"priority": priority, "pins": pins, "reserved": reserved}
|
|
try:
|
|
async with httpx.AsyncClient(timeout=30) as client:
|
|
r = await client.post(f"{self.api_url}/secondary/apply", json=body)
|
|
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()
|