mirror of
https://github.com/smittix/intercept.git
synced 2026-04-24 06:40:00 -07:00
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:
@@ -370,6 +370,16 @@ def start_ais():
|
||||
app_module.ais_process = None
|
||||
logger.info("Killed existing AIS process")
|
||||
|
||||
# Check if device is available
|
||||
device_int = int(device)
|
||||
error = app_module.claim_sdr_device(device_int, 'ais')
|
||||
if error:
|
||||
return jsonify({
|
||||
'status': 'error',
|
||||
'error_type': 'DEVICE_BUSY',
|
||||
'message': error
|
||||
}), 409
|
||||
|
||||
# Build command using SDR abstraction
|
||||
sdr_device = SDRFactory.create_default_device(sdr_type, index=device)
|
||||
builder = SDRFactory.get_builder(sdr_type)
|
||||
@@ -400,6 +410,8 @@ def start_ais():
|
||||
time.sleep(2.0)
|
||||
|
||||
if app_module.ais_process.poll() is not None:
|
||||
# Release device on failure
|
||||
app_module.release_sdr_device(device_int)
|
||||
stderr_output = ''
|
||||
if app_module.ais_process.stderr:
|
||||
try:
|
||||
@@ -425,6 +437,8 @@ def start_ais():
|
||||
'port': tcp_port
|
||||
})
|
||||
except Exception as e:
|
||||
# Release device on failure
|
||||
app_module.release_sdr_device(device_int)
|
||||
logger.error(f"Failed to start AIS-catcher: {e}")
|
||||
return jsonify({'status': 'error', 'message': str(e)}), 500
|
||||
|
||||
@@ -448,6 +462,11 @@ def stop_ais():
|
||||
pass
|
||||
app_module.ais_process = None
|
||||
logger.info("AIS process stopped")
|
||||
|
||||
# Release device from registry
|
||||
if ais_active_device is not None:
|
||||
app_module.release_sdr_device(ais_active_device)
|
||||
|
||||
ais_running = False
|
||||
ais_active_device = None
|
||||
|
||||
|
||||
Reference in New Issue
Block a user