mirror of
https://github.com/smittix/intercept.git
synced 2026-04-24 06:40:00 -07:00
fix: release SDR device when switching modes across pages
When navigating from another mode (e.g. pager) to the ADS-B dashboard, the old process could still hold the USB device. Two fixes: 1. routes/adsb.py: If dump1090 starts but SBS port never comes up, kill the process and return a DEVICE_BUSY error instead of silently claiming success with no data. 2. templates/adsb_dashboard.html: Pre-flight conflict check in toggleTracking() queries /devices/status and auto-stops any conflicting mode before starting ADS-B, with a 1.5s USB release delay. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -893,6 +893,36 @@ def start_adsb():
|
||||
'message': full_msg
|
||||
})
|
||||
|
||||
# dump1090 is still running but SBS port never came up — device may be
|
||||
# held by a stale process from a previous mode. Kill it so the USB
|
||||
# device is released and report a clear error to the frontend.
|
||||
if not dump1090_ready:
|
||||
logger.warning("dump1090 running but SBS port not available after %.1fs — killing", DUMP1090_START_WAIT)
|
||||
try:
|
||||
pgid = os.getpgid(app_module.adsb_process.pid)
|
||||
os.killpg(pgid, 15)
|
||||
app_module.adsb_process.wait(timeout=ADSB_TERMINATE_TIMEOUT)
|
||||
except (subprocess.TimeoutExpired, ProcessLookupError, OSError):
|
||||
try:
|
||||
pgid = os.getpgid(app_module.adsb_process.pid)
|
||||
os.killpg(pgid, 9)
|
||||
except (ProcessLookupError, OSError):
|
||||
pass
|
||||
app_module.adsb_process = None
|
||||
clear_dump1090_pid()
|
||||
app_module.release_sdr_device(device_int, sdr_type_str)
|
||||
adsb_active_device = None
|
||||
adsb_active_sdr_type = None
|
||||
return jsonify({
|
||||
'status': 'error',
|
||||
'error_type': 'DEVICE_BUSY',
|
||||
'message': (
|
||||
'SDR device did not become ready in time. '
|
||||
'Another mode may still be releasing the device. '
|
||||
'Please wait a moment and try again.'
|
||||
),
|
||||
})
|
||||
|
||||
adsb_using_service = True
|
||||
thread = threading.Thread(target=parse_sbs_stream, args=(f'localhost:{ADSB_SBS_PORT}',), daemon=True)
|
||||
thread.start()
|
||||
|
||||
Reference in New Issue
Block a user