diff options
author | Josh Blum | 2010-03-01 11:50:09 -0800 |
---|---|---|
committer | Josh Blum | 2010-03-01 11:50:09 -0800 |
commit | 00f9ccaa50ed26d71a66d19f8f1518874004c5de (patch) | |
tree | f3ab00752187a69411e6d18f9f96ac87188b9cd4 /gr-uhd | |
parent | 7c23fd43214e8a729b3022db281dc85040f0e749 (diff) | |
download | gnuradio-00f9ccaa50ed26d71a66d19f8f1518874004c5de.tar.gz gnuradio-00f9ccaa50ed26d71a66d19f8f1518874004c5de.tar.bz2 gnuradio-00f9ccaa50ed26d71a66d19f8f1518874004c5de.zip |
recv noise with uhd
Diffstat (limited to 'gr-uhd')
-rw-r--r-- | gr-uhd/grc/Makefile.am | 5 | ||||
-rw-r--r-- | gr-uhd/lib/Makefile.am | 4 | ||||
-rw-r--r-- | gr-uhd/lib/uhd_simple_source.cc | 56 | ||||
-rw-r--r-- | gr-uhd/lib/uhd_simple_source.h | 5 |
4 files changed, 60 insertions, 10 deletions
diff --git a/gr-uhd/grc/Makefile.am b/gr-uhd/grc/Makefile.am index b78d07ee8..a46146272 100644 --- a/gr-uhd/grc/Makefile.am +++ b/gr-uhd/grc/Makefile.am @@ -20,3 +20,8 @@ # include $(top_srcdir)/Makefile.common + +grcblocksdir = $(grc_blocksdir) + +dist_grcblocks_DATA = \ + uhd_simple_source.xml diff --git a/gr-uhd/lib/Makefile.am b/gr-uhd/lib/Makefile.am index 2f49ed2d6..73424ae8e 100644 --- a/gr-uhd/lib/Makefile.am +++ b/gr-uhd/lib/Makefile.am @@ -29,6 +29,7 @@ AM_CPPFLAGS = \ lib_LTLIBRARIES = libgnuradio-uhd.la libgnuradio_uhd_la_SOURCES = \ + utils.cc \ uhd_simple_source.cc libgnuradio_uhd_la_LIBADD = \ @@ -38,4 +39,5 @@ libgnuradio_uhd_la_LIBADD = \ grinclude_HEADERS = \ uhd_simple_source.h -noinst_HEADERS = +noinst_HEADERS = \ + utils.h diff --git a/gr-uhd/lib/uhd_simple_source.cc b/gr-uhd/lib/uhd_simple_source.cc index 588b27627..4bd3622f3 100644 --- a/gr-uhd/lib/uhd_simple_source.cc +++ b/gr-uhd/lib/uhd_simple_source.cc @@ -22,17 +22,19 @@ #include <uhd_simple_source.h> #include <gr_io_signature.h> +#include <boost/thread.hpp> #include <stdexcept> +#include "utils.h" /*********************************************************************** * Helper Functions **********************************************************************/ -static gr_io_signature_sptr make_io_sig(const std::string &type){ +static size_t get_size(const std::string &type){ if(type == "32fc"){ - return gr_make_io_signature(1, 1, sizeof(std::complex<float>)); + return sizeof(std::complex<float>); } if(type == "16sc"){ - return gr_make_io_signature(1, 1, sizeof(std::complex<short>)); + return sizeof(std::complex<short>); } throw std::runtime_error("unknown type"); } @@ -41,11 +43,11 @@ static gr_io_signature_sptr make_io_sig(const std::string &type){ * Make UHD Source **********************************************************************/ boost::shared_ptr<uhd_simple_source> uhd_make_simple_source( - const uhd::device_addr_t &addr, + const std::string &args, const std::string &type ){ return boost::shared_ptr<uhd_simple_source>( - new uhd_simple_source(addr, type) + new uhd_simple_source(args_to_device_addr(args), type) ); } @@ -58,14 +60,27 @@ uhd_simple_source::uhd_simple_source( ) : gr_sync_block( "uhd source", gr_make_io_signature(0, 0, 0), - make_io_sig(type) + gr_make_io_signature(1, 1, get_size(type)) ){ _type = type; _dev = uhd::device::make(addr); + _sizeof_samp = get_size(type); + + set_streaming(true); } uhd_simple_source::~uhd_simple_source(void){ - /* NOP */ + set_streaming(false); +} + +/*********************************************************************** + * DDC Control + **********************************************************************/ +void uhd_simple_source::set_streaming(bool enb){ + wax::obj ddc = (*_dev) + [uhd::DEVICE_PROP_MBOARD] + [uhd::named_prop_t(uhd::MBOARD_PROP_RX_DSP, "ddc0")]; + ddc[std::string("enabled")] = enb; } /*********************************************************************** @@ -76,6 +91,31 @@ int uhd_simple_source::work( gr_vector_const_void_star &input_items, gr_vector_void_star &output_items ){ + + size_t total_items_read = 0; + size_t count = 0; uhd::metadata_t metadata; - return _dev->recv(boost::asio::buffer(output_items[0], noutput_items), metadata, _type); + while(total_items_read == 0 or total_items_read + 1500/_sizeof_samp < size_t(noutput_items)){ + size_t items_read = _dev->recv( + boost::asio::buffer( + (uint8_t *)output_items[0]+(total_items_read*_sizeof_samp), + (noutput_items-total_items_read)*_sizeof_samp + ), metadata, _type + ); + + //record items read and recv again + if (items_read > 0){ + total_items_read += items_read; + continue; + } + + //if we have read at least once, but not this time, get out + if (total_items_read > 0) break; + + //the timeout part + boost::this_thread::sleep(boost::posix_time::milliseconds(1)); + count++; if (count > 50) break; + } + + return total_items_read; } diff --git a/gr-uhd/lib/uhd_simple_source.h b/gr-uhd/lib/uhd_simple_source.h index 156b9f357..43c4a647a 100644 --- a/gr-uhd/lib/uhd_simple_source.h +++ b/gr-uhd/lib/uhd_simple_source.h @@ -29,7 +29,7 @@ class uhd_simple_source; boost::shared_ptr<uhd_simple_source> -uhd_make_simple_source(const uhd::device_addr_t &addr, const std::string &type); +uhd_make_simple_source(const std::string &args, const std::string &type); class uhd_simple_source : public gr_sync_block{ public: @@ -43,8 +43,11 @@ public: ); protected: + void set_streaming(bool enb); + uhd::device::sptr _dev; std::string _type; + size_t _sizeof_samp; }; #endif /* INCLUDED_UHD_SIMPLE_SOURCE_H */ |