From 96a2061a59c913bc48f50ba89471519809c7629a Mon Sep 17 00:00:00 2001 From: Martin Braun Date: Tue, 21 Nov 2017 15:14:31 -0800 Subject: mg: ad9371: Add shortcut for RPC requests --- .../dboard/magnesium/magnesium_ad9371_iface.cpp | 27 ++++++---------------- .../dboard/magnesium/magnesium_ad9371_iface.hpp | 14 +++++++++-- 2 files changed, 19 insertions(+), 22 deletions(-) diff --git a/host/lib/usrp/dboard/magnesium/magnesium_ad9371_iface.cpp b/host/lib/usrp/dboard/magnesium/magnesium_ad9371_iface.cpp index e6ad6ab57..9a91a316a 100644 --- a/host/lib/usrp/dboard/magnesium/magnesium_ad9371_iface.cpp +++ b/host/lib/usrp/dboard/magnesium/magnesium_ad9371_iface.cpp @@ -51,12 +51,7 @@ double magnesium_ad9371_iface::set_frequency( ) { // Note: This sets the frequency for both channels (1 and 2). auto which = _get_which(dir, chan); - UHD_LOG_TRACE(_L, - "Calling " << _rpc_prefix << "set_freq on " - << which << " with " << freq); - auto actual_freq = - _rpcc->request_with_token(_rpc_prefix + "set_freq", - which, freq, false); + auto actual_freq = request("set_freq", which, freq, false); UHD_LOG_TRACE(_L, _rpc_prefix << "set_freq returned " << actual_freq); return actual_freq; @@ -68,8 +63,7 @@ double magnesium_ad9371_iface::set_gain( const direction_t dir ) { auto which = _get_which(dir, chan); - UHD_LOG_TRACE(_L, "Calling " << _rpc_prefix << "set_gain on " << which << " with " << gain); - auto retval = _rpcc->request_with_token(_rpc_prefix + "set_gain", which, gain); + auto retval = request("set_gain", which, gain); UHD_LOG_TRACE(_L, _rpc_prefix << "set_gain returned " << retval); return retval; @@ -89,8 +83,7 @@ double magnesium_ad9371_iface::get_frequency( const direction_t dir ) { auto which = _get_which(dir, chan); - UHD_LOG_TRACE(_L, "calling " << _rpc_prefix << "get_freq on " << which); - auto retval = _rpcc->request_with_token(_rpc_prefix + "get_freq", which); + auto retval = request("get_freq", which); UHD_LOG_TRACE(_L, _rpc_prefix << "get_freq returned " << retval); return retval; } @@ -98,8 +91,7 @@ double magnesium_ad9371_iface::get_frequency( double magnesium_ad9371_iface::get_gain(const size_t chan, const direction_t dir) { auto which = _get_which(dir, chan); - UHD_LOG_TRACE(_L, "calling " << _rpc_prefix << "get_gain on " << which); - auto retval = _rpcc->request_with_token(_rpc_prefix + "get_gain", which); + auto retval = request("get_gain", which); UHD_LOG_TRACE(_L, _rpc_prefix << "get_gain returned " << retval); return retval; } @@ -117,10 +109,7 @@ std::string magnesium_ad9371_iface::set_lo_source( ) { // There is only one LO for 2 channels. Using channel 0 for 'which' auto which = _get_which(dir, 0); - UHD_LOG_TRACE(_L, "calling " << _rpc_prefix << "set_lo_source " - << which << "with " << source); - auto retval = _rpcc->request_with_token( - _rpc_prefix + "set_lo_source", which, source); + auto retval = request("set_lo_source", which, source); UHD_LOG_TRACE(_L, _rpc_prefix << "set_lo_source returned " << retval); return retval; } @@ -129,10 +118,8 @@ std::string magnesium_ad9371_iface::get_lo_source( const uhd::direction_t dir ) { // There is only one LO for 2 channels. Using channel 0 for 'which' - auto which = _get_which(dir,0); - UHD_LOG_TRACE(_L, "calling " << _rpc_prefix << "get_lo_source " << which); - auto retval = _rpcc->request_with_token( - _rpc_prefix + "get_lo_source", which); + auto which = _get_which(dir, 0); + auto retval = request("get_lo_source", which); UHD_LOG_TRACE(_L, _rpc_prefix << "get_lo_source returned " << retval); return retval; } diff --git a/host/lib/usrp/dboard/magnesium/magnesium_ad9371_iface.hpp b/host/lib/usrp/dboard/magnesium/magnesium_ad9371_iface.hpp index 5598b2540..7d7942a46 100644 --- a/host/lib/usrp/dboard/magnesium/magnesium_ad9371_iface.hpp +++ b/host/lib/usrp/dboard/magnesium/magnesium_ad9371_iface.hpp @@ -65,6 +65,18 @@ public: ); private: + /*! Shorthand to perform an RPC request. Saves some typing. + */ + template + return_type request(std::string const& func_name, Args&&... args) + { + UHD_LOG_TRACE(_L, "[RPC] Calling " << func_name); + return _rpcc->request_with_token( + _rpc_prefix + func_name, + std::forward(args)... + ); + }; + //! Reference to the RPC client uhd::rpc_client::sptr _rpcc; @@ -77,8 +89,6 @@ private: //! Logger prefix const std::string _L; - - }; #endif /* INCLUDED_LIBUHD_RFNOC_MAGNESIUM_AD9371_IFACE_HPP */ -- cgit v1.2.3