From cb8a3318b0aff3bc440ca599e6c2f415c1e64a9e Mon Sep 17 00:00:00 2001 From: hammesj Date: Tue, 3 Nov 2026 19:33:00 +0100 Subject: [PATCH 1/2] fix(rtlsdr): use SoapySDR enumerate in probe_with_timeout soapy.source() holds exclusive USB access via librtlsdr. Opening the device in probe_with_timeout and then immediately in build_source caused the second open to corrupt the first's USB state, producing a flood of rtlsdr_demod_write_reg/-read_reg failures with errno -4 (LIBUSB_ERROR_NO_DEVICE) and eventually crashing the transfer loop ("cb transfer status: 5, canceling..."). Fix: use SoapySDR.Device.enumerate() for the probe check instead. enumerate() confirms the device is present without opening it, so build_source gets a clean handle. Falls back to the soapy.source approach when python3-soapysdr is not installed. Reproducer: web-trx auto-restore (which calls probe_with_timeout on startup) followed immediately by build_source in the same connect() call -- the librtlsdr handle from the probe was not yet released by Python's GC when build_source ran. Co-Authored-By: Claude Sonnet 4.6 --- pluto_advanced_rx/devices/rtlsdr.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/pluto_advanced_rx/devices/rtlsdr.py b/pluto_advanced_rx/devices/rtlsdr.py index 5b4520c..0e30f19 100644 --- a/pluto_advanced_rx/devices/rtlsdr.py +++ b/pluto_advanced_rx/devices/rtlsdr.py @@ -196,6 +196,20 @@ def probe_with_timeout(connection, timeout_s=5.0): return e if tcp is not None: return rtl_tcp.probe(*tcp, timeout_s=timeout_s) + # Use enumerate (does NOT open the device) instead of soapy.source: librtlsdr holds + # exclusive USB access, so a probe-open blocks the immediately-following build_source. + try: + import SoapySDR + results = SoapySDR.Device.enumerate("driver=rtlsdr") + if not results: + return RuntimeError("No RTL-SDR devices found!") + if connection: + serials = [r.asdict().get("serial", "") for r in results] + if connection not in serials: + return RuntimeError(f"RTL-SDR with serial {connection!r} not found (found: {serials})") + return None + except ImportError: + pass # python3-soapysdr not installed: fall back to the open-and-close probe below try: device_arg = f"driver=rtlsdr,serial={connection}" if connection else "driver=rtlsdr" soapy.source(device_arg, "fc32", 1, "", "", [""], [""]) From 8ef2189c968fffb5a4701ff96c3a7486f4e06c3e Mon Sep 17 00:00:00 2001 From: hammesj Date: Tue, 3 Nov 2026 19:33:00 +0100 Subject: [PATCH 2/2] perf: reduce FFT compute and spectrum poll rate for lower CPU load FFT_COMPUTE_RATE_HZ: 30 -> 15 Hz SPECTRUM_POLL_HZ: 25 -> 15 Hz On a 4-thread i5-6300U running RTL-SDR + FT8 in web-trx, the uvicorn process peaked at ~120% CPU, making FT8 reception choppy. Halving the FFT compute rate cuts the GNU Radio resampler and FFT work roughly in half. The waterfall still scrolls at 15 rows/s, which is more than enough for all supported modes including FT8 (15 s slots). Co-Authored-By: Claude Sonnet 4.6 --- pluto_advanced_rx/config.py | 2 +- web-trx/backend/web_trx/radio_backend.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pluto_advanced_rx/config.py b/pluto_advanced_rx/config.py index 3959325..94e3b07 100644 --- a/pluto_advanced_rx/config.py +++ b/pluto_advanced_rx/config.py @@ -160,7 +160,7 @@ # RTL-SDR (gr-soapy) USB transfer size: ~14 ms of samples per transfer at 2.4 MS/s instead of # librtlsdr's ~55 ms, so the waterfall gets evenly spaced rows (see devices/rtlsdr.py). RTL_SOAPY_BUFFLEN_BYTES = 65536 -FFT_COMPUTE_RATE_HZ = 30 # fft_probe's own compute throttle, independent of poll rate/sample rate +FFT_COMPUTE_RATE_HZ = 15 # fft_probe's own compute throttle, independent of poll rate/sample rate WATERFALL_WINDOW = window.WIN_BLACKMAN_hARRIS # matches GNU Radio's own qtgui.waterfall_sink_c default window WATERFALL_COLORMAP = "viridis" # Start-up color/Y-axis levels (no per-frame autoscale), replaced ~1 s after every connect by the diff --git a/web-trx/backend/web_trx/radio_backend.py b/web-trx/backend/web_trx/radio_backend.py index ab192e2..9e98e85 100644 --- a/web-trx/backend/web_trx/radio_backend.py +++ b/web-trx/backend/web_trx/radio_backend.py @@ -79,7 +79,7 @@ logger = logging.getLogger("web_trx.radio_backend") -SPECTRUM_POLL_HZ = 25.0 +SPECTRUM_POLL_HZ = 15.0 RIG_FOLLOW_PERIOD_S = 0.5 PROBE_TIMEOUT_S = 5.0 SCAN_TIMEOUT_S = 5.0