diff --git a/routes/dmr.py b/routes/dmr.py index e481e38..5ce9fcf 100644 --- a/routes/dmr.py +++ b/routes/dmr.py @@ -334,11 +334,14 @@ def start_dmr() -> Response: if dmr_active_device is not None: app_module.release_sdr_device(dmr_active_device) dmr_active_device = None - # Surface the most relevant error to the user + # Surface a clear error to the user detail = rtl_err.strip() or dsd_err.strip() - msg = 'Failed to start DSD pipeline' - if detail: - msg += f': {detail}' + if 'usb_claim_interface' in rtl_err or 'Failed to open' in rtl_err: + msg = f'SDR device {device} is busy — it may be in use by another mode or process. Try a different device.' + elif detail: + msg = f'Failed to start DSD pipeline: {detail}' + else: + msg = 'Failed to start DSD pipeline' return jsonify({'status': 'error', 'message': msg}), 500 # Drain rtl_fm stderr in background to prevent pipe blocking diff --git a/static/js/modes/dmr.js b/static/js/modes/dmr.js index 511210b..bb02ac8 100644 --- a/static/js/modes/dmr.js +++ b/static/js/modes/dmr.js @@ -59,6 +59,11 @@ function startDmr() { const gain = parseInt(document.getElementById('dmrGain')?.value || 40); const device = typeof getSelectedDevice === 'function' ? getSelectedDevice() : 0; + // Check device availability before starting + if (typeof checkDeviceAvailability === 'function' && !checkDeviceAvailability('dmr')) { + return; + } + fetch('/dmr/start', { method: 'POST', headers: { 'Content-Type': 'application/json' }, @@ -80,6 +85,9 @@ function startDmr() { updateDmrSynthStatus(); const statusEl = document.getElementById('dmrStatus'); if (statusEl) statusEl.textContent = 'DECODING'; + if (typeof reserveDevice === 'function') { + reserveDevice(parseInt(device), 'dmr'); + } if (typeof showNotification === 'function') { showNotification('DMR', `Decoding ${frequency} MHz (${protocol.toUpperCase()})`); } @@ -104,6 +112,9 @@ function stopDmr() { updateDmrSynthStatus(); const statusEl = document.getElementById('dmrStatus'); if (statusEl) statusEl.textContent = 'STOPPED'; + if (typeof releaseDevice === 'function') { + releaseDevice('dmr'); + } }) .catch(err => console.error('[DMR] Stop error:', err)); }