From 4ca6e8dba9fb625220e18776f58186084c348f56 Mon Sep 17 00:00:00 2001 From: Jake Drahos Date: Sun, 13 Jan 2019 21:53:37 -0600 Subject: [PATCH] Safer calls to setGainMode Will call hasGainMode first - this will prevent crashes when the underlying device situationally doesn't support setGainMode calls. --- src/sdr/SoapySDRThread.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/sdr/SoapySDRThread.cpp b/src/sdr/SoapySDRThread.cpp index 4013c69..d760c2e 100644 --- a/src/sdr/SoapySDRThread.cpp +++ b/src/sdr/SoapySDRThread.cpp @@ -130,8 +130,10 @@ bool SDRThread::init() { } else { hasHardwareDC.store(false); } - - device->setGainMode(SOAPY_SDR_RX,0,agc_mode.load()); + + if (device->hasGainMode(SOAPY_SDR_RX, 0)) { + device->setGainMode(SOAPY_SDR_RX, 0, agc_mode.load()); + } numChannels.store(getOptimalChannelCount(sampleRate.load())); numElems.store(getOptimalElementCount(sampleRate.load(), TARGET_DISPLAY_FPS)); @@ -484,7 +486,9 @@ void SDRThread::updateSettings() { // } if (agc_mode_changed.load()) { - device->setGainMode(SOAPY_SDR_RX, 0, agc_mode.load()); + if (device->hasGainMode(SOAPY_SDR_RX, 0)) { + device->setGainMode(SOAPY_SDR_RX, 0, agc_mode.load()); + } agc_mode_changed.store(false); if (!agc_mode.load()) { updateGains();