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>
65 lines
1.8 KiB
Python
65 lines
1.8 KiB
Python
from typing import Dict, List, Optional
|
|
|
|
from fastapi import APIRouter, HTTPException
|
|
from pydantic import BaseModel
|
|
|
|
from internal import decoder_control
|
|
from internal.logger import create_logger
|
|
|
|
LOGGER = create_logger(__name__)
|
|
|
|
|
|
class StartBody(BaseModel):
|
|
mode: str # adsb | ais
|
|
|
|
|
|
class StopBody(BaseModel):
|
|
mode: Optional[str] = None # omit to stop every decoder
|
|
|
|
|
|
class ApplyBody(BaseModel):
|
|
priority: List[str] # ordered, e.g. ["adsb", "ais"]
|
|
pins: Dict[str, str] = {} # mode -> serial of the dongle with its antenna
|
|
reserved: List[str] = [] # serials no decoder may touch (op25's)
|
|
|
|
|
|
def create_secondary_router():
|
|
router = APIRouter()
|
|
|
|
@router.post("/apply")
|
|
async def apply(body: ApplyBody):
|
|
try:
|
|
live = decoder_control.apply(body.priority, body.pins, body.reserved)
|
|
except ValueError as e:
|
|
raise HTTPException(status_code=400, detail=str(e))
|
|
return {"running": live}
|
|
|
|
@router.post("/start")
|
|
async def start(body: StartBody):
|
|
try:
|
|
ok = decoder_control.start(body.mode)
|
|
except ValueError as e:
|
|
raise HTTPException(status_code=400, detail=str(e))
|
|
if not ok:
|
|
raise HTTPException(status_code=409, detail="No free SDR for this decoder")
|
|
return {"status": f"secondary SDR started ({body.mode})"}
|
|
|
|
@router.post("/stop")
|
|
async def stop(body: Optional[StopBody] = None):
|
|
decoder_control.stop(body.mode if body else None)
|
|
return {"status": "secondary SDR stopped"}
|
|
|
|
@router.get("/status")
|
|
async def get_status():
|
|
return decoder_control.status()
|
|
|
|
@router.get("/devices")
|
|
async def get_devices():
|
|
return {"devices": decoder_control.devices()}
|
|
|
|
@router.get("/data")
|
|
async def get_data():
|
|
return decoder_control.data()
|
|
|
|
return router
|