From 7e06806ff0d2b4e0c8eceb75ec92ff41926a4e29 Mon Sep 17 00:00:00 2001 From: Thomas Tsou Date: Mon, 8 Apr 2013 19:39:37 -0400 Subject: Transceiver52M: Use exception blocks for rate changes UHD will throw if something goes awry in these sensitive sections, so we should catch and shutdown gracefully. There is no recovery if we can't set rates. Signed-off-by: Thomas Tsou --- Transceiver52M/UHDDevice.cpp | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) (limited to 'Transceiver52M/UHDDevice.cpp') diff --git a/Transceiver52M/UHDDevice.cpp b/Transceiver52M/UHDDevice.cpp index 575cb01..a627a64 100644 --- a/Transceiver52M/UHDDevice.cpp +++ b/Transceiver52M/UHDDevice.cpp @@ -383,12 +383,18 @@ int uhd_device::set_master_clk(double clk_rate) { double actual_clk_rt; - // Set master clock rate - usrp_dev->set_master_clock_rate(clk_rate); - actual_clk_rt = usrp_dev->get_master_clock_rate(); + try { + usrp_dev->set_master_clock_rate(clk_rate); + actual_clk_rt = usrp_dev->get_master_clock_rate(); + } catch (const std::exception &ex) { + LOG(ALERT) << "UHD clock rate setting failed: " << clk_rate; + LOG(ALERT) << ex.what(); + return -1; + } if (actual_clk_rt != clk_rate) { LOG(ALERT) << "Failed to set master clock rate"; + LOG(ALERT) << "Requested clock rate " << clk_rate; LOG(ALERT) << "Actual clock rate " << actual_clk_rt; return -1; } @@ -408,8 +414,14 @@ int uhd_device::set_rates(double rate) } // Set sample rates - usrp_dev->set_tx_rate(rate); - usrp_dev->set_rx_rate(rate); + try { + usrp_dev->set_tx_rate(rate); + usrp_dev->set_rx_rate(rate); + } catch (const std::exception &ex) { + LOG(ALERT) << "UHD rate setting failed: " << rate; + LOG(ALERT) << ex.what(); + return -1; + } actual_smpl_rt = usrp_dev->get_tx_rate(); tx_offset = actual_smpl_rt - rate; -- cgit v1.2.3