Add SDR device registry to prevent decoder conflicts

Implements centralized tracking of SDR device allocation to prevent
multiple decoders from trying to use the same device simultaneously.

- Add sdr_device_registry with claim/release/status functions in app.py
- Update all SDR-based routes to claim devices on start and release on stop
- Return HTTP 409 with DEVICE_BUSY error when device is already in use
- Clear registry on /killall
- Skip device claims for remote connections (rtl_tcp, remote SBS)

Fixes #100
Fixes #101

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Smittix
2026-02-02 21:05:21 +00:00
parent 36f8349bc7
commit a76dfde02d
8 changed files with 275 additions and 51 deletions

View File

@@ -686,6 +686,16 @@ def start_adsb():
app_module.adsb_process = None
logger.info("Killed stale ADS-B process")
# Check if device is available before starting local dump1090
device_int = int(device)
error = app_module.claim_sdr_device(device_int, 'adsb')
if error:
return jsonify({
'status': 'error',
'error_type': 'DEVICE_BUSY',
'message': error
}), 409
# Create device object and build command via abstraction layer
sdr_device = SDRFactory.create_default_device(sdr_type, index=device)
builder = SDRFactory.get_builder(sdr_type)
@@ -714,7 +724,8 @@ def start_adsb():
time.sleep(DUMP1090_START_WAIT)
if app_module.adsb_process.poll() is not None:
# Process exited - try to get error message
# Process exited - release device and get error message
app_module.release_sdr_device(device_int)
stderr_output = ''
if app_module.adsb_process.stderr:
try:
@@ -752,6 +763,8 @@ def start_adsb():
'session': session
})
except Exception as e:
# Release device on failure
app_module.release_sdr_device(device_int)
return jsonify({'status': 'error', 'message': str(e)})
@@ -779,6 +792,11 @@ def stop_adsb():
pass
app_module.adsb_process = None
logger.info("ADS-B process stopped")
# Release device from registry
if adsb_active_device is not None:
app_module.release_sdr_device(adsb_active_device)
adsb_using_service = False
adsb_active_device = None