From 5b0ae93c8f319bbc367254172719d40f11a0f55b Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Thu, 6 Oct 2011 09:26:40 -0700 Subject: uhd: backwards compat work which support streamer API --- gr-uhd/lib/gr_uhd_usrp_source.cc | 75 ++++++++++++++++++++++++++++++++++------ 1 file changed, 64 insertions(+), 11 deletions(-) (limited to 'gr-uhd/lib/gr_uhd_usrp_source.cc') diff --git a/gr-uhd/lib/gr_uhd_usrp_source.cc b/gr-uhd/lib/gr_uhd_usrp_source.cc index a3369ade0..12dd1bee7 100644 --- a/gr-uhd/lib/gr_uhd_usrp_source.cc +++ b/gr-uhd/lib/gr_uhd_usrp_source.cc @@ -24,9 +24,23 @@ #include #include #include +#include static const pmt::pmt_t TIME_KEY = pmt::pmt_string_to_symbol("rx_time"); +#include +inline gr_io_signature_sptr args_to_io_sig(const uhd::stream_args_t &args){ + const size_t nchan = std::max(args.channels.size(), 1); + #ifdef GR_UHD_USE_STREAM_API + const size_t size = uhd::convert::get_bytes_per_item(args.cpu_format); + #else + size_t size = 0; + if (args.cpu_format == "fc32") size = 8; + if (args.cpu_format == "sc16") size = 4; + #endif + return gr_make_io_signature(nchan, nchan, size); +} + /*********************************************************************** * UHD Multi USRP Source Impl **********************************************************************/ @@ -34,19 +48,20 @@ class uhd_usrp_source_impl : public uhd_usrp_source{ public: uhd_usrp_source_impl( const uhd::device_addr_t &device_addr, - const uhd::io_type_t &io_type, - size_t num_channels + const uhd::stream_args_t &stream_args ): gr_sync_block( "gr uhd usrp source", gr_make_io_signature(0, 0, 0), - gr_make_io_signature(num_channels, num_channels, io_type.size) + args_to_io_sig(stream_args) ), - _type(io_type), - _nchan(num_channels), + _stream_args(stream_args), + _nchan(stream_args.channels.size()), _stream_now(_nchan == 1), _tag_now(false) { + if (stream_args.cpu_format == "fc32") _type = boost::make_shared(uhd::io_type_t::COMPLEX_FLOAT32); + if (stream_args.cpu_format == "sc16") _type = boost::make_shared(uhd::io_type_t::COMPLEX_INT16); std::stringstream str; str << name() << unique_id(); _id = pmt::pmt_string_to_symbol(str.str()); @@ -187,22 +202,33 @@ public: gr_vector_const_void_star &input_items, gr_vector_void_star &output_items ){ + #ifdef GR_UHD_USE_STREAM_API //In order to allow for low-latency: //We receive all available packets without timeout. //This call can timeout under regular operation... - size_t num_samps = _dev->get_device()->recv( - output_items, noutput_items, _metadata, - _type, uhd::device::RECV_MODE_FULL_BUFF, 0.0 + size_t num_samps = _rx_stream->recv( + output_items, noutput_items, _metadata, 0.0 ); //If receive resulted in a timeout condition: //We now receive a single packet with a large timeout. + if (_metadata.error_code == uhd::rx_metadata_t::ERROR_CODE_TIMEOUT){ + num_samps = _rx_stream->recv( + output_items, noutput_items, _metadata, 1.0 + ); + } + #else + size_t num_samps = _dev->get_device()->recv( + output_items, noutput_items, _metadata, + *_type, uhd::device::RECV_MODE_FULL_BUFF, 0.0 + ); if (_metadata.error_code == uhd::rx_metadata_t::ERROR_CODE_TIMEOUT){ num_samps = _dev->get_device()->recv( output_items, noutput_items, _metadata, - _type, uhd::device::RECV_MODE_ONE_PACKET, 1.0 + *_type, uhd::device::RECV_MODE_ONE_PACKET, 1.0 ); } + #endif //handle possible errors conditions switch(_metadata.error_code){ @@ -242,6 +268,10 @@ public: } bool start(void){ + #ifdef GR_UHD_USE_STREAM_API + _rx_stream = _dev->get_rx_stream(_stream_args); + _samps_per_packet = _rx_stream->get_max_num_samps(); + #endif //setup a stream command that starts streaming slightly in the future static const double reasonable_delay = 0.1; //order of magnitude over RTT uhd::stream_cmd_t stream_cmd(uhd::stream_cmd_t::STREAM_MODE_START_CONTINUOUS); @@ -278,7 +308,12 @@ public: private: uhd::usrp::multi_usrp::sptr _dev; - const uhd::io_type_t _type; + const uhd::stream_args_t _stream_args; + boost::shared_ptr _type; + #ifdef GR_UHD_USE_STREAM_API + uhd::rx_streamer::sptr _rx_stream; + size_t _samps_per_packet; + #endif size_t _nchan; bool _stream_now, _tag_now; uhd::rx_metadata_t _metadata; @@ -293,8 +328,26 @@ boost::shared_ptr uhd_make_usrp_source( const uhd::device_addr_t &device_addr, const uhd::io_type_t &io_type, size_t num_channels +){ + //fill in the streamer args + uhd::stream_args_t stream_args; + switch(io_type.tid){ + case uhd::io_type_t::COMPLEX_FLOAT32: stream_args.cpu_format = "fc32"; break; + case uhd::io_type_t::COMPLEX_INT16: stream_args.cpu_format = "sc16"; break; + default: throw std::runtime_error("only complex float and shorts known to work"); + } + stream_args.otw_format = "sc16"; //only sc16 known to work + for (size_t chan = 0; chan < num_channels; chan++) + stream_args.channels.push_back(chan); //linear mapping + + return uhd_make_usrp_source(device_addr, stream_args); +} + +boost::shared_ptr uhd_make_usrp_source( + const uhd::device_addr_t &device_addr, + const uhd::stream_args_t &stream_args ){ return boost::shared_ptr( - new uhd_usrp_source_impl(device_addr, io_type, num_channels) + new uhd_usrp_source_impl(device_addr, stream_args) ); } -- cgit From 017fb41de0843703810799c8a5d99d6b640437f9 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Tue, 11 Oct 2011 10:26:55 -0700 Subject: uhd: restored source block recv single packet functionality --- gr-uhd/lib/gr_uhd_usrp_source.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'gr-uhd/lib/gr_uhd_usrp_source.cc') diff --git a/gr-uhd/lib/gr_uhd_usrp_source.cc b/gr-uhd/lib/gr_uhd_usrp_source.cc index 12dd1bee7..adb234f25 100644 --- a/gr-uhd/lib/gr_uhd_usrp_source.cc +++ b/gr-uhd/lib/gr_uhd_usrp_source.cc @@ -214,7 +214,7 @@ public: //We now receive a single packet with a large timeout. if (_metadata.error_code == uhd::rx_metadata_t::ERROR_CODE_TIMEOUT){ num_samps = _rx_stream->recv( - output_items, noutput_items, _metadata, 1.0 + output_items, noutput_items, _metadata, 1.0, true/*one pkt*/ ); } #else -- cgit From f3d2a28dc8d1abfe42435a4b5040eb20dd295479 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Sun, 16 Oct 2011 11:49:11 -0700 Subject: uhd: added get_samp_rates calls --- gr-uhd/lib/gr_uhd_usrp_source.cc | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'gr-uhd/lib/gr_uhd_usrp_source.cc') diff --git a/gr-uhd/lib/gr_uhd_usrp_source.cc b/gr-uhd/lib/gr_uhd_usrp_source.cc index adb234f25..207e049d8 100644 --- a/gr-uhd/lib/gr_uhd_usrp_source.cc +++ b/gr-uhd/lib/gr_uhd_usrp_source.cc @@ -80,6 +80,14 @@ public: return _dev->get_rx_rate(); } + uhd::meta_range_t get_samp_rates(void){ + #ifdef UHD_USRP_MULTI_USRP_GET_RATES_API + return _dev->get_rx_rates(); + #else + throw std::runtime_error("not implemented in this version"); + #endif + } + uhd::tune_result_t set_center_freq( const uhd::tune_request_t tune_request, size_t chan ){ -- cgit From 8e60469acd6be356c64bfb27f58b393f3dd361cf Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Sun, 16 Oct 2011 12:11:40 -0700 Subject: uhd: added set/get time/clock source calls --- gr-uhd/lib/gr_uhd_usrp_source.cc | 48 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) (limited to 'gr-uhd/lib/gr_uhd_usrp_source.cc') diff --git a/gr-uhd/lib/gr_uhd_usrp_source.cc b/gr-uhd/lib/gr_uhd_usrp_source.cc index 207e049d8..4f46fce79 100644 --- a/gr-uhd/lib/gr_uhd_usrp_source.cc +++ b/gr-uhd/lib/gr_uhd_usrp_source.cc @@ -166,6 +166,54 @@ public: return _dev->set_clock_config(clock_config, mboard); } + void set_time_source(const std::string &source, const size_t mboard){ + #ifdef UHD_USRP_MULTI_USRP_REF_SOURCES_API + return _dev->set_time_source(source, mboard); + #else + throw std::runtime_error("not implemented in this version"); + #endif + } + + std::string get_time_source(const size_t mboard){ + #ifdef UHD_USRP_MULTI_USRP_REF_SOURCES_API + return _dev->get_time_source(mboard); + #else + throw std::runtime_error("not implemented in this version"); + #endif + } + + std::vector get_time_sources(const size_t mboard){ + #ifdef UHD_USRP_MULTI_USRP_REF_SOURCES_API + return _dev->get_time_sources(mboard); + #else + throw std::runtime_error("not implemented in this version"); + #endif + } + + void set_clock_source(const std::string &source, const size_t mboard){ + #ifdef UHD_USRP_MULTI_USRP_REF_SOURCES_API + return _dev->set_clock_source(source, mboard); + #else + throw std::runtime_error("not implemented in this version"); + #endif + } + + std::string get_clock_source(const size_t mboard){ + #ifdef UHD_USRP_MULTI_USRP_REF_SOURCES_API + return _dev->get_clock_source(mboard); + #else + throw std::runtime_error("not implemented in this version"); + #endif + } + + std::vector get_clock_sources(const size_t mboard){ + #ifdef UHD_USRP_MULTI_USRP_REF_SOURCES_API + return _dev->get_clock_sources(mboard); + #else + throw std::runtime_error("not implemented in this version"); + #endif + } + double get_clock_rate(size_t mboard){ return _dev->get_master_clock_rate(mboard); } -- cgit From 9058109de812a5a8c45a180131531b5ad10a9d7a Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Mon, 24 Oct 2011 11:31:59 -0700 Subject: uhd: added set for RX/TX iq balance and dc offset --- gr-uhd/lib/gr_uhd_usrp_source.cc | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) (limited to 'gr-uhd/lib/gr_uhd_usrp_source.cc') diff --git a/gr-uhd/lib/gr_uhd_usrp_source.cc b/gr-uhd/lib/gr_uhd_usrp_source.cc index 4f46fce79..421adafe1 100644 --- a/gr-uhd/lib/gr_uhd_usrp_source.cc +++ b/gr-uhd/lib/gr_uhd_usrp_source.cc @@ -146,11 +146,35 @@ public: return _dev->set_rx_bandwidth(bandwidth, chan); } - uhd::sensor_value_t get_dboard_sensor(const std::string &name, size_t chan){ + void set_dc_offset(const bool enable, size_t chan){ + #ifdef UHD_USRP_MULTI_USRP_FRONTEND_CAL_API + return _dev->set_rx_dc_offset(enable, chan); + #else + throw std::runtime_error("not implemented in this version"); + #endif + } + + void set_dc_offset(const std::complex &offset, size_t chan){ + #ifdef UHD_USRP_MULTI_USRP_FRONTEND_CAL_API + return _dev->set_rx_dc_offset(offset, chan); + #else + throw std::runtime_error("not implemented in this version"); + #endif + } + + void set_iq_balance(const std::complex &correction, size_t chan){ + #ifdef UHD_USRP_MULTI_USRP_FRONTEND_CAL_API + return _dev->set_rx_iq_balance(correction, chan); + #else + throw std::runtime_error("not implemented in this version"); + #endif + } + + uhd::sensor_value_t get_sensor(const std::string &name, size_t chan){ return _dev->get_rx_sensor(name, chan); } - std::vector get_dboard_sensor_names(size_t chan){ + std::vector get_sensor_names(size_t chan){ return _dev->get_rx_sensor_names(chan); } -- cgit From bf8984bac6551dc2a98d615431fb6c9b4bfb9f4e Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Thu, 3 Nov 2011 20:03:44 -0700 Subject: uhd: rebase tweaks + update on command feature --- gr-uhd/lib/gr_uhd_usrp_source.cc | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) (limited to 'gr-uhd/lib/gr_uhd_usrp_source.cc') diff --git a/gr-uhd/lib/gr_uhd_usrp_source.cc b/gr-uhd/lib/gr_uhd_usrp_source.cc index 421adafe1..953ef6995 100644 --- a/gr-uhd/lib/gr_uhd_usrp_source.cc +++ b/gr-uhd/lib/gr_uhd_usrp_source.cc @@ -56,7 +56,7 @@ public: args_to_io_sig(stream_args) ), _stream_args(stream_args), - _nchan(stream_args.channels.size()), + _nchan(std::max(1, stream_args.channels.size())), _stream_now(_nchan == 1), _tag_now(false) { @@ -266,6 +266,22 @@ public: return _dev->set_time_unknown_pps(time_spec); } + void set_command_time(const uhd::time_spec_t &time_spec, size_t mboard){ + #ifdef UHD_USRP_MULTI_USRP_COMMAND_TIME_API + return _dev->set_command_time(time_spec, mboard); + #else + throw std::runtime_error("not implemented in this version"); + #endif + } + + void clear_command_time(size_t mboard){ + #ifdef UHD_USRP_MULTI_USRP_COMMAND_TIME_API + return _dev->clear_command_time(mboard); + #else + throw std::runtime_error("not implemented in this version"); + #endif + } + uhd::usrp::dboard_iface::sptr get_dboard_iface(size_t chan){ return _dev->get_rx_dboard_iface(chan); } @@ -370,10 +386,17 @@ public: outputs.push_back(&buffs[i].front()); } while (true){ + #ifdef GR_UHD_USE_STREAM_API + const size_t bpi = uhd::convert::get_bytes_per_item(_stream_args.cpu_format); + const size_t num_samps = _rx_stream->recv( + outputs, nbytes/bpi, _metadata, 0.0 + ); + #else const size_t num_samps = _dev->get_device()->recv( - outputs, nbytes/_type.size, _metadata, - _type, uhd::device::RECV_MODE_FULL_BUFF, 0.0 + outputs, nbytes/_type->size, _metadata, + *_type, uhd::device::RECV_MODE_FULL_BUFF, 0.0 ); + #endif if (_metadata.error_code == uhd::rx_metadata_t::ERROR_CODE_TIMEOUT) break; } } -- cgit