From 68d8db4d8c2b1b7951b76439699fc1e07bb472cb Mon Sep 17 00:00:00 2001 From: Vadim Yanitskiy Date: Mon, 29 Jun 2020 17:39:35 +0700 Subject: UHDDevice: catch LookupError/IndexError in set{Rx,Tx}Antenna() Currently configuring 3 channels in multi-ARFCN mode makes the process crash during the Rx/Tx antenna configuration due to uncaught UHD specific LookupError/IndexError exceptions: terminate called after throwing an instance of 'uhd::index_error' what(): LookupError: IndexError: multi_usrp: TX channel 2 out of range for configured TX frontends Let's catch them and terminate gracefully. Change-Id: If66305f2787c6292375e4bfbd60c1d3d764cffd4 Related: OS#4636 --- Transceiver52M/device/uhd/UHDDevice.cpp | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/Transceiver52M/device/uhd/UHDDevice.cpp b/Transceiver52M/device/uhd/UHDDevice.cpp index 0eb79fc..854ed2e 100644 --- a/Transceiver52M/device/uhd/UHDDevice.cpp +++ b/Transceiver52M/device/uhd/UHDDevice.cpp @@ -1097,7 +1097,14 @@ bool uhd_device::setRxAntenna(const std::string &ant, size_t chan) return false; } - avail = usrp_dev->get_rx_antennas(chan); + /* UHD may throw a LookupError/IndexError here (see OS#4636) */ + try { + avail = usrp_dev->get_rx_antennas(chan); + } catch (const uhd::index_error &e) { + LOGC(DDEV, ALERT) << "UHD Error: " << e.what(); + return false; + } + if (std::find(avail.begin(), avail.end(), ant) == avail.end()) { LOGC(DDEV, ALERT) << "Requested non-existent Rx antenna " << ant << " on channel " << chan; LOGC(DDEV, INFO) << "Available Rx antennas: "; @@ -1133,7 +1140,14 @@ bool uhd_device::setTxAntenna(const std::string &ant, size_t chan) return false; } - avail = usrp_dev->get_tx_antennas(chan); + /* UHD may throw a LookupError/IndexError here (see OS#4636) */ + try { + avail = usrp_dev->get_tx_antennas(chan); + } catch (const uhd::index_error &e) { + LOGC(DDEV, ALERT) << "UHD Error: " << e.what(); + return false; + } + if (std::find(avail.begin(), avail.end(), ant) == avail.end()) { LOGC(DDEV, ALERT) << "Requested non-existent Tx antenna " << ant << " on channel " << chan; LOGC(DDEV, INFO) << "Available Tx antennas: "; -- cgit v1.2.3