summaryrefslogtreecommitdiff
path: root/gr-uhd/lib
diff options
context:
space:
mode:
authorTom Rondeau <tom@trondeau.com>2015-05-06 17:28:08 -0400
committerTom Rondeau <tom@trondeau.com>2015-05-06 17:28:08 -0400
commitf6e23b145f6a9dd529feb1cac33e6562fd7c0dc7 (patch)
tree33750dd8a1c493d47810fe4781a22a471643aa46 /gr-uhd/lib
parent7ef4258ceaf5fa9fa242138c0abc9572a72c3d6f (diff)
parenta693941515339f77dde55e356381e7039eb7c02c (diff)
Merge branch 'master' into next
Diffstat (limited to 'gr-uhd/lib')
-rw-r--r--gr-uhd/lib/usrp_block_impl.cc302
-rw-r--r--gr-uhd/lib/usrp_block_impl.h45
-rw-r--r--gr-uhd/lib/usrp_sink_impl.cc40
-rw-r--r--gr-uhd/lib/usrp_source_impl.cc20
4 files changed, 323 insertions, 84 deletions
diff --git a/gr-uhd/lib/usrp_block_impl.cc b/gr-uhd/lib/usrp_block_impl.cc
index be24c57c6e..2e73b10538 100644
--- a/gr-uhd/lib/usrp_block_impl.cc
+++ b/gr-uhd/lib/usrp_block_impl.cc
@@ -27,6 +27,20 @@ using namespace gr::uhd;
const double usrp_block_impl::LOCK_TIMEOUT = 1.5;
+const pmt::pmt_t CMD_CHAN_KEY = pmt::mp("chan");
+const pmt::pmt_t CMD_GAIN_KEY = pmt::mp("gain");
+const pmt::pmt_t CMD_FREQ_KEY = pmt::mp("freq");
+const pmt::pmt_t CMD_LO_OFFSET_KEY = pmt::mp("lo_offset");
+const pmt::pmt_t CMD_TUNE_KEY = pmt::mp("tune");
+const pmt::pmt_t CMD_LO_FREQ_KEY = pmt::mp("lo_freq");
+const pmt::pmt_t CMD_DSP_FREQ_KEY = pmt::mp("dsp_freq");
+const pmt::pmt_t CMD_RATE_KEY = pmt::mp("rate");
+const pmt::pmt_t CMD_BANDWIDTH_KEY = pmt::mp("bandwidth");
+const pmt::pmt_t CMD_TIME_KEY = pmt::mp("time");
+const pmt::pmt_t CMD_MBOARD_KEY = pmt::mp("mboard");
+const pmt::pmt_t CMD_ANTENNA_KEY = pmt::mp("antenna");
+
+
/**********************************************************************
* Structors
*********************************************************************/
@@ -47,11 +61,10 @@ usrp_block_impl::usrp_block_impl(
_nchan(stream_args.channels.size()),
_stream_now(_nchan == 1 and ts_tag_name.empty()),
_start_time_set(false),
- _curr_freq(stream_args.channels.size(), 0.0),
- _curr_lo_offset(stream_args.channels.size(), 0.0),
- _curr_gain(stream_args.channels.size(), 0.0),
+ _curr_tune_req(stream_args.channels.size(), ::uhd::tune_request_t()),
_chans_to_tune(stream_args.channels.size())
{
+ // TODO remove this when we update UHD
if(stream_args.cpu_format == "fc32")
_type = boost::make_shared< ::uhd::io_type_t >(::uhd::io_type_t::COMPLEX_FLOAT32);
if(stream_args.cpu_format == "sc16")
@@ -66,6 +79,19 @@ usrp_block_impl::usrp_block_impl(
pmt::mp("command"),
boost::bind(&usrp_block_impl::msg_handler_command, this, _1)
);
+
+// cuz we lazy:
+#define REGISTER_CMD_HANDLER(key, _handler) register_msg_cmd_handler(key, boost::bind(&usrp_block_impl::_handler, this, _1, _2, _3))
+ // Register default command handlers:
+ REGISTER_CMD_HANDLER(CMD_FREQ_KEY, _cmd_handler_freq);
+ REGISTER_CMD_HANDLER(CMD_GAIN_KEY, _cmd_handler_gain);
+ REGISTER_CMD_HANDLER(CMD_LO_OFFSET_KEY, _cmd_handler_looffset);
+ REGISTER_CMD_HANDLER(CMD_TUNE_KEY, _cmd_handler_tune);
+ REGISTER_CMD_HANDLER(CMD_LO_FREQ_KEY, _cmd_handler_lofreq);
+ REGISTER_CMD_HANDLER(CMD_DSP_FREQ_KEY, _cmd_handler_dspfreq);
+ REGISTER_CMD_HANDLER(CMD_RATE_KEY, _cmd_handler_rate);
+ REGISTER_CMD_HANDLER(CMD_BANDWIDTH_KEY, _cmd_handler_bw);
+ REGISTER_CMD_HANDLER(CMD_ANTENNA_KEY, _cmd_handler_antenna);
}
usrp_block_impl::~usrp_block_impl()
@@ -185,10 +211,9 @@ bool usrp_block_impl::_check_mboard_sensors_locked()
void
usrp_block_impl::_set_center_freq_from_internals_allchans()
{
- for (size_t chan = 0; chan < _nchan; chan++) {
- if (_chans_to_tune[chan]) {
- _set_center_freq_from_internals(chan);
- }
+ while (_chans_to_tune.any()) {
+ // This resets() bits, so this loop should not run indefinitely
+ _set_center_freq_from_internals(_chans_to_tune.find_first());
}
}
@@ -389,40 +414,245 @@ usrp_block_impl::setup_rpc()
void usrp_block_impl::msg_handler_command(pmt::pmt_t msg)
{
- std::string command;
- pmt::pmt_t cmd_value;
- int chan = -1;
- if (not _unpack_chan_command(command, cmd_value, chan, msg)) {
- GR_LOG_ALERT(d_logger, boost::format("Error while unpacking command PMT: %s") % msg);
+ // Legacy code back compat: If we receive a tuple, we convert
+ // it to a dict, and call the function again. Yep, this comes
+ // at a slight performance hit. Sometime in the future, we can
+ // hopefully remove this:
+ if (pmt::is_tuple(msg)) {
+ if (pmt::length(msg) != 2 && pmt::length(msg) != 3) {
+ GR_LOG_ALERT(d_logger, boost::format("Error while unpacking command PMT: %s") % msg);
+ return;
+ }
+ pmt::pmt_t new_msg = pmt::make_dict();
+ new_msg = pmt::dict_add(new_msg, pmt::tuple_ref(msg, 0), pmt::tuple_ref(msg, 1));
+ if (pmt::length(msg) == 3) {
+ new_msg = pmt::dict_add(new_msg, pmt::mp("chan"), pmt::tuple_ref(msg, 2));
+ }
+ GR_LOG_WARN(d_debug_logger, boost::format("Using legacy message format (tuples): %s") % msg);
+ return msg_handler_command(new_msg);
+ }
+ // End of legacy backward compat code.
+
+ // Turn pair into dict
+ if (!pmt::is_dict(msg)) {
+ GR_LOG_ERROR(d_logger, boost::format("Command message is neither dict nor pair: %s") % msg);
return;
}
- GR_LOG_DEBUG(d_debug_logger, boost::format("Received command: %s") % command);
+
+ // OK, here comes the horrible part. Pairs pass is_dict(), but they're not dicts. Such dicks.
try {
- if (command == "freq") {
- _chans_to_tune = _update_vector_from_cmd_val<double>(
- _curr_freq, chan, pmt::to_double(cmd_value), true
- );
- _set_center_freq_from_internals_allchans();
- } else if (command == "lo_offset") {
- _chans_to_tune = _update_vector_from_cmd_val<double>(
- _curr_lo_offset, chan, pmt::to_double(cmd_value), true
+ // This will fail if msg is a pair:
+ pmt::pmt_t keys = pmt::dict_keys(msg);
+ } catch (const pmt::wrong_type &e) {
+ // So we fix it:
+ GR_LOG_DEBUG(d_debug_logger, boost::format("Converting pair to dict: %s") % msg);
+ msg = pmt::dict_add(pmt::make_dict(), pmt::car(msg), pmt::cdr(msg));
+ }
+
+ /*** Start the actual message processing *************************/
+ /// 1) Check if there's a time stamp
+ if (pmt::dict_has_key(msg, CMD_TIME_KEY)) {
+ size_t mboard_index = pmt::to_long(
+ pmt::dict_ref(
+ msg, CMD_MBOARD_KEY,
+ pmt::from_long( ::uhd::usrp::multi_usrp::ALL_MBOARDS ) // Default to all mboards
+ )
+ );
+ pmt::pmt_t timespec_p = pmt::dict_ref(msg, CMD_TIME_KEY, pmt::PMT_NIL);
+ if (timespec_p == pmt::PMT_NIL) {
+ clear_command_time(mboard_index);
+ } else {
+ ::uhd::time_spec_t timespec(
+ time_t(pmt::to_uint64(pmt::car(timespec_p))), // Full secs
+ pmt::to_double(pmt::cdr(timespec_p)) // Frac secs
);
- _set_center_freq_from_internals_allchans();
- } else if (command == "gain") {
- boost::dynamic_bitset<> chans_to_change = _update_vector_from_cmd_val<double>(
- _curr_gain, chan, pmt::to_double(cmd_value), true
+ GR_LOG_DEBUG(d_debug_logger, boost::format("Setting command time on mboard %d") % mboard_index);
+ set_command_time(timespec, mboard_index);
+ }
+ }
+
+ /// 2) Read chan value
+ int chan = int(pmt::to_long(
+ pmt::dict_ref(
+ msg, CMD_CHAN_KEY,
+ pmt::from_long(-1) // Default to all chans
+ )
+ ));
+
+ /// 3) Loop through all the values
+ GR_LOG_DEBUG(d_debug_logger, boost::format("Processing command message %s") % msg);
+ pmt::pmt_t msg_items = pmt::dict_items(msg);
+ for (size_t i = 0; i < pmt::length(msg_items); i++) {
+ try {
+ dispatch_msg_cmd_handler(
+ pmt::car(pmt::nth(i, msg_items)),
+ pmt::cdr(pmt::nth(i, msg_items)),
+ chan, msg
);
- if (chans_to_change.any()) {
- for (size_t i = 0; i < chans_to_change.size(); i++) {
- if (chans_to_change[i]) {
- set_gain(_curr_gain[i], i);
- }
- }
- }
- } else {
- GR_LOG_ALERT(d_logger, boost::format("Received unknown command: %s") % command);
+ } catch (pmt::wrong_type &e) {
+ GR_LOG_ALERT(d_logger, boost::format("Invalid command value for key %s: %s") % pmt::car(pmt::nth(i, msg_items)) % pmt::cdr(pmt::nth(i, msg_items)));
+ break;
+ }
+ }
+
+ /// 4) Check if we need to re-tune
+ _set_center_freq_from_internals_allchans();
+}
+
+
+void usrp_block_impl::dispatch_msg_cmd_handler(const pmt::pmt_t &cmd, const pmt::pmt_t &val, int chan, pmt::pmt_t &msg)
+{
+ if (_msg_cmd_handlers.has_key(cmd)) {
+ _msg_cmd_handlers[cmd](val, chan, msg);
+ }
+}
+
+void usrp_block_impl::register_msg_cmd_handler(const pmt::pmt_t &cmd, cmd_handler_t handler)
+{
+ _msg_cmd_handlers[cmd] = handler;
+}
+
+void usrp_block_impl::_update_curr_tune_req(::uhd::tune_request_t &tune_req, int chan)
+{
+ if (chan == -1) {
+ for (size_t i = 0; i < _nchan; i++) {
+ _update_curr_tune_req(tune_req, int(i));
+ return;
}
- } catch (pmt::wrong_type &e) {
- GR_LOG_ALERT(d_logger, boost::format("Received command '%s' with invalid command value: %s") % command % cmd_value);
}
+
+ if (tune_req.target_freq != _curr_tune_req[chan].target_freq ||
+ tune_req.rf_freq_policy != _curr_tune_req[chan].rf_freq_policy ||
+ tune_req.rf_freq != _curr_tune_req[chan].rf_freq ||
+ tune_req.dsp_freq != _curr_tune_req[chan].dsp_freq ||
+ tune_req.dsp_freq_policy != _curr_tune_req[chan].dsp_freq_policy
+ ) {
+ _curr_tune_req[chan] = tune_req;
+ _chans_to_tune.set(chan);
+ }
+}
+
+// Default handlers:
+void usrp_block_impl::_cmd_handler_freq(const pmt::pmt_t &freq_, int chan, const pmt::pmt_t &msg)
+{
+ double freq = pmt::to_double(freq_);
+ ::uhd::tune_request_t new_tune_reqest(freq);
+ if (pmt::dict_has_key(msg, CMD_LO_OFFSET_KEY)) {
+ double lo_offset = pmt::to_double(pmt::dict_ref(msg, CMD_LO_OFFSET_KEY, pmt::PMT_NIL));
+ new_tune_reqest = ::uhd::tune_request_t(freq, lo_offset);
+ }
+
+ _update_curr_tune_req(new_tune_reqest, chan);
+}
+
+void usrp_block_impl::_cmd_handler_looffset(const pmt::pmt_t &lo_offset, int chan, const pmt::pmt_t &msg)
+{
+ if (pmt::dict_has_key(msg, CMD_FREQ_KEY)) {
+ // Then it's already taken care of
+ return;
+ }
+
+ double lo_offs = pmt::to_double(lo_offset);
+ ::uhd::tune_request_t new_tune_request = _curr_tune_req[chan];
+ new_tune_request.rf_freq = new_tune_request.target_freq + lo_offs;
+ new_tune_request.rf_freq_policy = ::uhd::tune_request_t::POLICY_MANUAL;
+ new_tune_request.dsp_freq_policy = ::uhd::tune_request_t::POLICY_AUTO;
+
+ _update_curr_tune_req(new_tune_request, chan);
}
+
+void usrp_block_impl::_cmd_handler_gain(const pmt::pmt_t &gain_, int chan, const pmt::pmt_t &msg)
+{
+ double gain = pmt::to_double(gain_);
+ if (chan == -1) {
+ for (size_t i = 0; i < _nchan; i++) {
+ set_gain(gain, i);
+ }
+ return;
+ }
+
+ set_gain(gain, chan);
+}
+
+void usrp_block_impl::_cmd_handler_antenna(const pmt::pmt_t &ant, int chan, const pmt::pmt_t &msg)
+{
+ const std::string antenna(pmt::symbol_to_string(ant));
+ if (chan == -1) {
+ for (size_t i = 0; i < _nchan; i++) {
+ set_antenna(antenna, i);
+ }
+ return;
+ }
+
+ set_antenna(antenna, chan);
+}
+
+void usrp_block_impl::_cmd_handler_rate(const pmt::pmt_t &rate_, int, const pmt::pmt_t &)
+{
+ const double rate = pmt::to_double(rate_);
+ set_samp_rate(rate);
+}
+
+void usrp_block_impl::_cmd_handler_tune(const pmt::pmt_t &tune, int chan, const pmt::pmt_t &msg)
+{
+ double freq = pmt::to_double(pmt::car(tune));
+ double lo_offset = pmt::to_double(pmt::cdr(tune));
+ ::uhd::tune_request_t new_tune_reqest(freq, lo_offset);
+ _update_curr_tune_req(new_tune_reqest, chan);
+}
+
+void usrp_block_impl::_cmd_handler_bw(const pmt::pmt_t &bw, int chan, const pmt::pmt_t &msg)
+{
+ double bandwidth = pmt::to_double(bw);
+ if (chan == -1) {
+ for (size_t i = 0; i < _nchan; i++) {
+ set_bandwidth(bandwidth, i);
+ }
+ return;
+ }
+
+ set_bandwidth(bandwidth, chan);
+}
+
+void usrp_block_impl::_cmd_handler_lofreq(const pmt::pmt_t &lofreq, int chan, const pmt::pmt_t &msg)
+{
+ if (chan == -1) {
+ for (size_t i = 0; i < _nchan; i++) {
+ _cmd_handler_lofreq(lofreq, int(i), msg);
+ }
+ return;
+ }
+
+ ::uhd::tune_request_t new_tune_request = _curr_tune_req[chan];
+ new_tune_request.rf_freq = pmt::to_double(lofreq);
+ if (pmt::dict_has_key(msg, CMD_DSP_FREQ_KEY)) {
+ new_tune_request.dsp_freq = pmt::to_double(pmt::dict_ref(msg, CMD_DSP_FREQ_KEY, pmt::PMT_NIL));
+ }
+ new_tune_request.rf_freq_policy = ::uhd::tune_request_t::POLICY_MANUAL;
+ new_tune_request.dsp_freq_policy = ::uhd::tune_request_t::POLICY_MANUAL;
+
+ _update_curr_tune_req(new_tune_request, chan);
+}
+
+void usrp_block_impl::_cmd_handler_dspfreq(const pmt::pmt_t &dspfreq, int chan, const pmt::pmt_t &msg)
+{
+ if (pmt::dict_has_key(msg, CMD_LO_FREQ_KEY)) {
+ // Then it's already dealt with
+ return;
+ }
+
+ if (chan == -1) {
+ for (size_t i = 0; i < _nchan; i++) {
+ _cmd_handler_dspfreq(dspfreq, int(i), msg);
+ }
+ return;
+ }
+
+ ::uhd::tune_request_t new_tune_request = _curr_tune_req[chan];
+ new_tune_request.dsp_freq = pmt::to_double(dspfreq);
+ new_tune_request.rf_freq_policy = ::uhd::tune_request_t::POLICY_MANUAL;
+ new_tune_request.dsp_freq_policy = ::uhd::tune_request_t::POLICY_MANUAL;
+
+ _update_curr_tune_req(new_tune_request, chan);
+}
+
diff --git a/gr-uhd/lib/usrp_block_impl.h b/gr-uhd/lib/usrp_block_impl.h
index 1ca613d1dc..5b38b51fa5 100644
--- a/gr-uhd/lib/usrp_block_impl.h
+++ b/gr-uhd/lib/usrp_block_impl.h
@@ -27,6 +27,15 @@
#include <pmt/pmt.h>
#include <uhd/usrp/multi_usrp.hpp>
#include <boost/dynamic_bitset.hpp>
+#include <boost/bind.hpp>
+
+#define SET_CENTER_FREQ_FROM_INTERNALS(usrp_class, tune_method) \
+ ::uhd::tune_result_t \
+ usrp_class::_set_center_freq_from_internals(size_t chan) \
+ { \
+ _chans_to_tune.reset(chan); \
+ return _dev->tune_method(_curr_tune_req[chan], _stream_args.channels[chan]); \
+ }
namespace gr {
namespace uhd {
@@ -35,6 +44,7 @@ namespace gr {
{
public:
typedef boost::function< ::uhd::sensor_value_t (const std::string&)> get_sensor_fn_t;
+ typedef boost::function<void(const pmt::pmt_t &, int, const pmt::pmt_t &)> cmd_handler_t;
static const double LOCK_TIMEOUT;
@@ -91,6 +101,25 @@ namespace gr {
//! Receives commands and handles them
void msg_handler_command(pmt::pmt_t msg);
+ //! For a given argument, call the associated handler, or if none exists,
+ // show a warning through the logging interface.
+ void dispatch_msg_cmd_handler(const pmt::pmt_t &cmd, const pmt::pmt_t &val, int chan, pmt::pmt_t &msg);
+
+ //! Register a new handler for command key \p cmd
+ void register_msg_cmd_handler(const pmt::pmt_t &cmd, cmd_handler_t handler);
+
+
+ // Default handlers
+ void _cmd_handler_freq(const pmt::pmt_t &freq, int chan, const pmt::pmt_t &msg);
+ void _cmd_handler_looffset(const pmt::pmt_t &lo_offset, int chan, const pmt::pmt_t &msg);
+ void _cmd_handler_gain(const pmt::pmt_t &gain, int chan, const pmt::pmt_t &msg);
+ void _cmd_handler_antenna(const pmt::pmt_t &ant, int chan, const pmt::pmt_t &msg);
+ void _cmd_handler_rate(const pmt::pmt_t &rate, int chan, const pmt::pmt_t &msg);
+ void _cmd_handler_tune(const pmt::pmt_t &tune, int chan, const pmt::pmt_t &msg);
+ void _cmd_handler_bw(const pmt::pmt_t &bw, int chan, const pmt::pmt_t &msg);
+ void _cmd_handler_lofreq(const pmt::pmt_t &lofreq, int chan, const pmt::pmt_t &msg);
+ void _cmd_handler_dspfreq(const pmt::pmt_t &dspfreq, int chan, const pmt::pmt_t &msg);
+
/**********************************************************************
* Helpers
**********************************************************************/
@@ -98,6 +127,9 @@ namespace gr {
void _update_stream_args(const ::uhd::stream_args_t &stream_args_);
+ // should be const, doesn't work though 'cause missing operator=() for tune_request_t
+ void _update_curr_tune_req(::uhd::tune_request_t &tune_req, int chan);
+
/*! \brief Wait until a timeout or a sensor returns 'locked'.
*
* If a given sensor is not found, this still returns 'true', so we don't throw
@@ -180,16 +212,13 @@ namespace gr {
/****** Command interface related **********/
//! Stores a list of commands for later execution
std::vector<pmt::pmt_t> _pending_cmds;
- //! Stores the last value we told the USRP to tune to for every channel
+ //! Shadows the last value we told the USRP to tune to for every channel
// (this is not necessarily the true value the USRP is currently tuned to!).
- // We could theoretically ask the device, but during streaming, we want to minimize
- // communication with the USRP.
- std::vector<double> _curr_freq;
- //! Stores the last value we told the USRP to have the LO offset for every channel.
- std::vector<double> _curr_lo_offset;
- //! Stores the last gain value we told the USRP to have for every channel.
- std::vector<double> _curr_gain;
+ std::vector< ::uhd::tune_request_t > _curr_tune_req;
boost::dynamic_bitset<> _chans_to_tune;
+
+ //! Stores the individual command handlers
+ ::uhd::dict<pmt::pmt_t, cmd_handler_t> _msg_cmd_handlers;
};
} /* namespace uhd */
diff --git a/gr-uhd/lib/usrp_sink_impl.cc b/gr-uhd/lib/usrp_sink_impl.cc
index b95b58b81d..0d26f7fcaa 100644
--- a/gr-uhd/lib/usrp_sink_impl.cc
+++ b/gr-uhd/lib/usrp_sink_impl.cc
@@ -71,7 +71,7 @@ namespace gr {
_length_tag_key(length_tag_name.empty() ? pmt::PMT_NIL : pmt::string_to_symbol(length_tag_name)),
_nitems_to_send(0)
{
- // nop
+ _sample_rate = get_samp_rate();
}
usrp_sink_impl::~usrp_sink_impl()
@@ -132,29 +132,12 @@ namespace gr {
usrp_sink_impl::set_center_freq(const ::uhd::tune_request_t tune_request,
size_t chan)
{
- _curr_freq[chan] = tune_request.target_freq;
- if (tune_request.rf_freq_policy == ::uhd::tune_request_t::POLICY_MANUAL) {
- _curr_lo_offset[chan] = tune_request.rf_freq - tune_request.target_freq;
- } else {
- _curr_lo_offset[chan] = 0.0;
- }
+ _curr_tune_req[chan] = tune_request;
chan = _stream_args.channels[chan];
return _dev->set_tx_freq(tune_request, chan);
}
- ::uhd::tune_result_t
- usrp_sink_impl::_set_center_freq_from_internals(size_t chan)
- {
- _chans_to_tune[chan] = false;
- if (_curr_lo_offset[chan] == 0.0) {
- return _dev->set_tx_freq(_curr_freq[chan], _stream_args.channels[chan]);
- } else {
- return _dev->set_tx_freq(
- ::uhd::tune_request_t(_curr_freq[chan], _curr_lo_offset[chan]),
- _stream_args.channels[chan]
- );
- }
- }
+ SET_CENTER_FREQ_FROM_INTERNALS(usrp_sink_impl, set_tx_freq);
double
usrp_sink_impl::get_center_freq(size_t chan)
@@ -173,7 +156,6 @@ namespace gr {
void
usrp_sink_impl::set_gain(double gain, size_t chan)
{
- _curr_gain[chan] = gain;
chan = _stream_args.channels[chan];
return _dev->set_tx_gain(gain, chan);
}
@@ -183,7 +165,6 @@ namespace gr {
const std::string &name,
size_t chan)
{
- _curr_gain[chan] = gain;
chan = _stream_args.channels[chan];
return _dev->set_tx_gain(gain, name, chan);
}
@@ -433,7 +414,7 @@ namespace gr {
// Go through tag list until something indicates the end of a burst.
bool found_time_tag = false;
bool found_eob = false;
- // For commands that are in the middle in the burst:
+ // For commands that are in the middle of the burst:
std::vector<pmt::pmt_t> commands_in_burst; // Store the command
uint64_t in_burst_cmd_offset = 0; // Store its position
BOOST_FOREACH(const tag_t &my_tag, _tags) {
@@ -449,7 +430,7 @@ namespace gr {
*
* This includes:
* - tx_time
- * - tx_command
+ * - tx_command TODO should also work end-of-burst
* - tx_sob
* - length tags
*
@@ -461,6 +442,7 @@ namespace gr {
max_count = my_tag_count;
break;
}
+ // TODO set the command time from the sample time
msg_handler_command(value);
}
@@ -516,12 +498,16 @@ namespace gr {
else if (pmt::equal(key, FREQ_KEY) && my_tag_count == samp0_count) {
// If it's on the first sample, immediately do the tune:
GR_LOG_DEBUG(d_debug_logger, boost::format("Received tx_freq on start of burst."));
- msg_handler_command(pmt::cons(pmt::mp("freq"), value));
+ pmt::pmt_t freq_cmd = pmt::make_dict();
+ freq_cmd = pmt::dict_add(freq_cmd, pmt::mp("freq"), value);
+ msg_handler_command(freq_cmd);
}
else if(pmt::equal(key, FREQ_KEY)) {
// If it's not on the first sample, queue this command and only tx until here:
GR_LOG_DEBUG(d_debug_logger, boost::format("Received tx_freq mid-burst."));
- commands_in_burst.push_back(pmt::cons(pmt::mp("freq"), value));
+ pmt::pmt_t freq_cmd = pmt::make_dict();
+ freq_cmd = pmt::dict_add(freq_cmd, pmt::mp("freq"), value);
+ commands_in_burst.push_back(freq_cmd);
max_count = my_tag_count + 1;
in_burst_cmd_offset = my_tag_count;
}
@@ -552,7 +538,7 @@ namespace gr {
// until before the tag, so it will be on the first sample of the next run.
if (not commands_in_burst.empty()) {
if (not found_eob) {
- // If it's in the middle of a burst, only send() until before the tag
+ // ...then it's in the middle of a burst, only send() until before the tag
max_count = in_burst_cmd_offset;
} else if (in_burst_cmd_offset < max_count) {
BOOST_FOREACH(const pmt::pmt_t &cmd_pmt, commands_in_burst) {
diff --git a/gr-uhd/lib/usrp_source_impl.cc b/gr-uhd/lib/usrp_source_impl.cc
index dfb38f6eb8..de91c3a828 100644
--- a/gr-uhd/lib/usrp_source_impl.cc
+++ b/gr-uhd/lib/usrp_source_impl.cc
@@ -71,6 +71,12 @@ namespace gr {
std::stringstream str;
str << name() << unique_id();
_id = pmt::string_to_symbol(str.str());
+
+ _samp_rate = this->get_samp_rate();
+ _center_freq = this->get_center_freq(0);
+#ifdef GR_UHD_USE_STREAM_API
+ _samps_per_packet = 1;
+#endif
}
usrp_source_impl::~usrp_source_impl()
@@ -139,19 +145,7 @@ namespace gr {
return res;
}
- ::uhd::tune_result_t
- usrp_source_impl::_set_center_freq_from_internals(size_t chan)
- {
- _chans_to_tune[chan] = false;
- if (_curr_lo_offset[chan] == 0.0) {
- return _dev->set_rx_freq(_curr_freq[chan], _stream_args.channels[chan]);
- } else {
- return _dev->set_rx_freq(
- ::uhd::tune_request_t(_curr_freq[chan], _curr_lo_offset[chan]),
- _stream_args.channels[chan]
- );
- }
- }
+ SET_CENTER_FREQ_FROM_INTERNALS(usrp_source_impl, set_rx_freq);
double
usrp_source_impl::get_center_freq(size_t chan)