aboutsummaryrefslogtreecommitdiffstats
path: root/host/lib
diff options
context:
space:
mode:
authorMartin Braun <martin.braun@ettus.com>2020-04-10 11:39:42 -0700
committerAaron Rossetto <aaron.rossetto@ni.com>2020-04-13 07:19:42 -0500
commit3b59529e71549976eaa99b75f40df732a8b73d6d (patch)
treeeceb0bc28675b0a0a7ecf2d052c15ac8546d21ef /host/lib
parentb6ff5fd2837bed63b09798e4fa187b169b7dcdc2 (diff)
downloaduhd-3b59529e71549976eaa99b75f40df732a8b73d6d.tar.gz
uhd-3b59529e71549976eaa99b75f40df732a8b73d6d.tar.bz2
uhd-3b59529e71549976eaa99b75f40df732a8b73d6d.zip
multi_usrp: Approximate legacy behaviour for recv_async_msg()
When using multi_usrp with an RFNoC device, the previous behaviour was to throw an exception when calling recv_async_msg() so users would know they're not supposed to call it (calling tx_stream::recv_async_msg is preferred). However, this breaks too many existing applications. Instead, we keep a weak pointer to the streamer, the same way that older devices do, and query the async message from that. This means that calling recv_async_msg() when there are multiple streamers can lead to unexpected behaviour, but that's a general issue with multi_usrp::recv_async_msg() and this way, the RFNoC devices now behave like older devices do.
Diffstat (limited to 'host/lib')
-rw-r--r--host/lib/usrp/multi_usrp_rfnoc.cpp34
1 files changed, 29 insertions, 5 deletions
diff --git a/host/lib/usrp/multi_usrp_rfnoc.cpp b/host/lib/usrp/multi_usrp_rfnoc.cpp
index f81253997..14b5fd50b 100644
--- a/host/lib/usrp/multi_usrp_rfnoc.cpp
+++ b/host/lib/usrp/multi_usrp_rfnoc.cpp
@@ -56,6 +56,7 @@ constexpr char DEFAULT_CPU_FORMAT[] = "fc32";
constexpr char DEFAULT_OTW_FORMAT[] = "sc16";
constexpr double RX_SIGN = +1.0;
constexpr double TX_SIGN = -1.0;
+constexpr char LOG_ID[] = "MULTI_USRP";
//! A faux container for a UHD device
//
@@ -64,7 +65,10 @@ constexpr double TX_SIGN = -1.0;
// similar functionalities; these can be faked with this redirector class.
//
// The only exception is recv_async_msg(), which depends on the streamer. It
-// will throw a uhd::runtime_error now.
+// will print a warning once, and will attempt to access a Tx streamer if it
+// has access to a Tx streamer. If there is only ever one Tx streamer, this will
+// work as expected. For multiple streamers, only the last streamer's async
+// messages will make it through.
class redirector_device : public uhd::device
{
public:
@@ -77,13 +81,22 @@ public:
tx_streamer::sptr get_tx_stream(const stream_args_t& args)
{
- return _musrp->get_tx_stream(args);
+ auto streamer = _musrp->get_tx_stream(args);
+ _last_tx_streamer = streamer;
+ return streamer;
}
- bool recv_async_msg(async_metadata_t&, double)
+ bool recv_async_msg(async_metadata_t& md, double timeout)
{
- throw uhd::runtime_error(
- "uhd::device::recv_async_msg() cannot be called on this device type!");
+ std::call_once(_async_warning_flag, []() {
+ UHD_LOG_WARNING(LOG_ID,
+ "Calling multi_usrp::recv_async_msg() is deprecated and can lead to "
+ "unexpected behaviour. Prefer calling tx_stream::recv_async_msg().");
+ });
+ auto streamer = _last_tx_streamer.lock();
+ if (streamer) {
+ return streamer->recv_async_msg(md, timeout);
+ }
return false;
}
@@ -97,7 +110,14 @@ public:
return USRP;
}
+ void set_tx_stream(tx_streamer::sptr streamer)
+ {
+ _last_tx_streamer = streamer;
+ }
+
private:
+ std::once_flag _async_warning_flag;
+ std::weak_ptr<tx_streamer> _last_tx_streamer;
multi_usrp* _musrp;
};
@@ -380,6 +400,10 @@ public:
}
}
}
+ // For legacy purposes: This enables recv_async_msg(), which is considered
+ // deprecated, but as long as it's there, we need this to approximate
+ // previous behaviour.
+ _device->set_tx_stream(tx_streamer);
return tx_streamer;
}