From bf5aba2dc1b32c8eb0d016e98f942fb7119fdfde Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Sun, 2 Oct 2011 14:45:44 -0700 Subject: uhd: moved wax API into deprecated files --- host/tests/CMakeLists.txt | 1 - host/tests/wax_test.cpp | 104 ---------------------------------------------- 2 files changed, 105 deletions(-) delete mode 100644 host/tests/wax_test.cpp (limited to 'host/tests') diff --git a/host/tests/CMakeLists.txt b/host/tests/CMakeLists.txt index c97116233..28cc1c5da 100644 --- a/host/tests/CMakeLists.txt +++ b/host/tests/CMakeLists.txt @@ -34,7 +34,6 @@ SET(test_sources subdev_spec_test.cpp time_spec_test.cpp vrt_test.cpp - wax_test.cpp ) #turn each test cpp file into an executable with an int main() function diff --git a/host/tests/wax_test.cpp b/host/tests/wax_test.cpp deleted file mode 100644 index 18730e0c2..000000000 --- a/host/tests/wax_test.cpp +++ /dev/null @@ -1,104 +0,0 @@ -// -// Copyright 2010-2011 Ettus Research LLC -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program. If not, see . -// - -#include -#include -#include -#include - -enum opt_a_t{OPTION_A_0, OPTION_A_1}; -enum opt_b_t{OPTION_B_0, OPTION_B_1}; - -BOOST_AUTO_TEST_CASE(test_enums){ - wax::obj opta = OPTION_A_0; - BOOST_CHECK_THROW(opta.as(), std::exception); - BOOST_CHECK_EQUAL(opta.as(), OPTION_A_0); -} - -/*********************************************************************** - * demo class for wax framework - **********************************************************************/ -class wax_demo : public wax::obj{ -public: - typedef boost::shared_ptr sptr; - - wax_demo(size_t sub_demos, size_t len){ - d_nums = std::vector(len); - if (sub_demos != 0){ - for (size_t i = 0; i < len; i++){ - d_subs.push_back(sptr(new wax_demo(sub_demos-1, len))); - } - } - } - ~wax_demo(void){ - /* NOP */ - } -private: - std::vector d_nums; - std::vector d_subs; - - void get(const wax::obj &key, wax::obj &value){ - if (d_subs.size() == 0){ - value = d_nums[key.as()]; - }else{ - value = d_subs[key.as()]->get_link(); - } - } - void set(const wax::obj &key, const wax::obj &value){ - if (d_subs.size() == 0){ - d_nums[key.as()] = value.as(); - }else{ - throw std::runtime_error("cant set to a wax demo with sub demos"); - } - } -}; - -BOOST_AUTO_TEST_CASE(test_chaining){ - wax_demo wd(2, 1); - std::cout << "chain 1" << std::endl; - wd[size_t(0)]; - std::cout << "chain 2" << std::endl; - wd[size_t(0)][size_t(0)]; - std::cout << "chain 3" << std::endl; - wd[size_t(0)][size_t(0)][size_t(0)]; -} - -BOOST_AUTO_TEST_CASE(test_set_get){ - wax_demo wd(2, 10); - std::cout << "set and get all" << std::endl; - for (size_t i = 0; i < 10; i++){ - for (size_t j = 0; j < 10; j++){ - for (size_t k = 0; k < 10; k++){ - float val = float(i * j * k + i + j + k); - //std::cout << i << " " << j << " " << k << std::endl; - wd[i][j][k] = val; - BOOST_CHECK_EQUAL(val, wd[i][j][k].as()); - } - } - } -} - -BOOST_AUTO_TEST_CASE(test_proxy){ - wax_demo wd(2, 1); - std::cout << "store proxy" << std::endl; - wax::obj p = wd[size_t(0)][size_t(0)]; - p[size_t(0)] = float(5); - - std::cout << "assign proxy" << std::endl; - wax::obj a = p[size_t(0)]; - BOOST_CHECK_EQUAL(a.as(), float(5)); -} -- cgit v1.2.3 From 839b9379d436adc1a6b0f876d0d03f11e41dbee6 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Mon, 3 Oct 2011 17:07:45 -0700 Subject: convert: restored unit test functionality --- host/tests/CMakeLists.txt | 4 +- host/tests/convert_test.cpp | 148 +++++++++++++++++++++++--------------------- 2 files changed, 80 insertions(+), 72 deletions(-) (limited to 'host/tests') diff --git a/host/tests/CMakeLists.txt b/host/tests/CMakeLists.txt index 28cc1c5da..25679a33e 100644 --- a/host/tests/CMakeLists.txt +++ b/host/tests/CMakeLists.txt @@ -29,8 +29,8 @@ SET(test_sources msg_test.cpp property_test.cpp ranges_test.cpp - sph_recv_test.cpp - sph_send_test.cpp + #TODO restore sph_recv_test.cpp + #TODO restore sph_send_test.cpp subdev_spec_test.cpp time_spec_test.cpp vrt_test.cpp diff --git a/host/tests/convert_test.cpp b/host/tests/convert_test.cpp index d828ed64a..9dabcf54e 100644 --- a/host/tests/convert_test.cpp +++ b/host/tests/convert_test.cpp @@ -41,8 +41,8 @@ typedef std::complex fc64_t; **********************************************************************/ template static void loopback( size_t nsamps, - const io_type_t &io_type, - const otw_type_t &otw_type, + convert::id_type &in_id, + convert::id_type &out_id, const Range &input, Range &output ){ @@ -53,23 +53,17 @@ template static void loopback( std::vector output0(1, &interm[0]), output1(1, &output[0]); //convert to intermediate type - convert::get_converter_cpu_to_otw( - io_type, otw_type, input0.size(), output0.size() - )(input0, output0, nsamps, 32767.); + convert::get_converter(in_id)(input0, output0, nsamps, 32767.); //convert back to host type - convert::get_converter_otw_to_cpu( - io_type, otw_type, input1.size(), output1.size() - )(input1, output1, nsamps, 1/32767.); + convert::get_converter(out_id)(input1, output1, nsamps, 1/32767.); } /*********************************************************************** * Test short conversion **********************************************************************/ static void test_convert_types_sc16( - size_t nsamps, - const io_type_t &io_type, - const otw_type_t &otw_type + size_t nsamps, convert::id_type &id ){ //fill the input samples std::vector input(nsamps), output(nsamps); @@ -79,31 +73,37 @@ static void test_convert_types_sc16( ); //run the loopback and test - loopback(nsamps, io_type, otw_type, input, output); + convert::id_type in_id = id; + convert::id_type out_id = id; + std::swap(out_id.input_markup, out_id.output_markup); + std::swap(out_id.num_inputs, out_id.num_outputs); + loopback(nsamps, in_id, out_id, input, output); BOOST_CHECK_EQUAL_COLLECTIONS(input.begin(), input.end(), output.begin(), output.end()); } BOOST_AUTO_TEST_CASE(test_convert_types_be_sc16){ - io_type_t io_type(io_type_t::COMPLEX_INT16); - otw_type_t otw_type; - otw_type.byteorder = otw_type_t::BO_BIG_ENDIAN; - otw_type.width = 16; + convert::id_type id; + id.input_markup = "sc16"; + id.num_inputs = 1; + id.output_markup = "sc16_item32_be"; + id.num_outputs = 1; //try various lengths to test edge cases for (size_t nsamps = 1; nsamps < 16; nsamps++){ - test_convert_types_sc16(nsamps, io_type, otw_type); + test_convert_types_sc16(nsamps, id); } } BOOST_AUTO_TEST_CASE(test_convert_types_le_sc16){ - io_type_t io_type(io_type_t::COMPLEX_INT16); - otw_type_t otw_type; - otw_type.byteorder = otw_type_t::BO_LITTLE_ENDIAN; - otw_type.width = 16; + convert::id_type id; + id.input_markup = "sc16"; + id.num_inputs = 1; + id.output_markup = "sc16_item32_le"; + id.num_outputs = 1; //try various lengths to test edge cases for (size_t nsamps = 1; nsamps < 16; nsamps++){ - test_convert_types_sc16(nsamps, io_type, otw_type); + test_convert_types_sc16(nsamps, id); } } @@ -112,9 +112,7 @@ BOOST_AUTO_TEST_CASE(test_convert_types_le_sc16){ **********************************************************************/ template static void test_convert_types_for_floats( - size_t nsamps, - const io_type_t &io_type, - const otw_type_t &otw_type + size_t nsamps, convert::id_type &id ){ typedef typename data_type::value_type value_type; @@ -126,7 +124,11 @@ static void test_convert_types_for_floats( ); //run the loopback and test - loopback(nsamps, io_type, otw_type, input, output); + convert::id_type in_id = id; + convert::id_type out_id = id; + std::swap(out_id.input_markup, out_id.output_markup); + std::swap(out_id.num_inputs, out_id.num_outputs); + loopback(nsamps, in_id, out_id, input, output); for (size_t i = 0; i < nsamps; i++){ MY_CHECK_CLOSE(input[i].real(), output[i].real(), value_type(0.01)); MY_CHECK_CLOSE(input[i].imag(), output[i].imag(), value_type(0.01)); @@ -134,50 +136,54 @@ static void test_convert_types_for_floats( } BOOST_AUTO_TEST_CASE(test_convert_types_be_fc32){ - io_type_t io_type(io_type_t::COMPLEX_FLOAT32); - otw_type_t otw_type; - otw_type.byteorder = otw_type_t::BO_BIG_ENDIAN; - otw_type.width = 16; + convert::id_type id; + id.input_markup = "fc32"; + id.num_inputs = 1; + id.output_markup = "sc16_item32_be"; + id.num_outputs = 1; //try various lengths to test edge cases for (size_t nsamps = 1; nsamps < 16; nsamps++){ - test_convert_types_for_floats(nsamps, io_type, otw_type); + test_convert_types_for_floats(nsamps, id); } } BOOST_AUTO_TEST_CASE(test_convert_types_le_fc32){ - io_type_t io_type(io_type_t::COMPLEX_FLOAT32); - otw_type_t otw_type; - otw_type.byteorder = otw_type_t::BO_LITTLE_ENDIAN; - otw_type.width = 16; + convert::id_type id; + id.input_markup = "fc32"; + id.num_inputs = 1; + id.output_markup = "sc16_item32_le"; + id.num_outputs = 1; //try various lengths to test edge cases for (size_t nsamps = 1; nsamps < 16; nsamps++){ - test_convert_types_for_floats(nsamps, io_type, otw_type); + test_convert_types_for_floats(nsamps, id); } } BOOST_AUTO_TEST_CASE(test_convert_types_be_fc64){ - io_type_t io_type(io_type_t::COMPLEX_FLOAT64); - otw_type_t otw_type; - otw_type.byteorder = otw_type_t::BO_BIG_ENDIAN; - otw_type.width = 16; + convert::id_type id; + id.input_markup = "fc64"; + id.num_inputs = 1; + id.output_markup = "sc16_item32_be"; + id.num_outputs = 1; //try various lengths to test edge cases for (size_t nsamps = 1; nsamps < 16; nsamps++){ - test_convert_types_for_floats(nsamps, io_type, otw_type); + test_convert_types_for_floats(nsamps, id); } } BOOST_AUTO_TEST_CASE(test_convert_types_le_fc64){ - io_type_t io_type(io_type_t::COMPLEX_FLOAT64); - otw_type_t otw_type; - otw_type.byteorder = otw_type_t::BO_LITTLE_ENDIAN; - otw_type.width = 16; + convert::id_type id; + id.input_markup = "fc64"; + id.num_inputs = 1; + id.output_markup = "sc16_item32_le"; + id.num_outputs = 1; //try various lengths to test edge cases for (size_t nsamps = 1; nsamps < 16; nsamps++){ - test_convert_types_for_floats(nsamps, io_type, otw_type); + test_convert_types_for_floats(nsamps, id); } } @@ -185,12 +191,17 @@ BOOST_AUTO_TEST_CASE(test_convert_types_le_fc64){ * Test float to short conversion loopback **********************************************************************/ BOOST_AUTO_TEST_CASE(test_convert_types_fc32_to_sc16){ - io_type_t io_type_in(io_type_t::COMPLEX_FLOAT32); - io_type_t io_type_out(io_type_t::COMPLEX_INT16); - - otw_type_t otw_type; - otw_type.byteorder = otw_type_t::BO_NATIVE; - otw_type.width = 16; + convert::id_type in_id; + in_id.input_markup = "fc32"; + in_id.num_inputs = 1; + in_id.output_markup = "sc16_item32_le"; + in_id.num_outputs = 1; + + convert::id_type out_id; + out_id.input_markup = "sc16_item32_le"; + out_id.num_inputs = 1; + out_id.output_markup = "sc16"; + out_id.num_outputs = 1; const size_t nsamps = 13; std::vector input(nsamps); @@ -205,14 +216,10 @@ BOOST_AUTO_TEST_CASE(test_convert_types_fc32_to_sc16){ std::vector output0(1, &interm[0]), output1(1, &output[0]); //convert float to intermediate - convert::get_converter_cpu_to_otw( - io_type_in, otw_type, input0.size(), output0.size() - )(input0, output0, nsamps, 32767.); + convert::get_converter(in_id)(input0, output0, nsamps, 32767.); //convert intermediate to short - convert::get_converter_otw_to_cpu( - io_type_out, otw_type, input1.size(), output1.size() - )(input1, output1, nsamps, 1/32767.); + convert::get_converter(out_id)(input1, output1, nsamps, 1/32767.); //test that the inputs and outputs match for (size_t i = 0; i < nsamps; i++){ @@ -225,12 +232,17 @@ BOOST_AUTO_TEST_CASE(test_convert_types_fc32_to_sc16){ * Test short to float conversion loopback **********************************************************************/ BOOST_AUTO_TEST_CASE(test_convert_types_sc16_to_fc32){ - io_type_t io_type_in(io_type_t::COMPLEX_INT16); - io_type_t io_type_out(io_type_t::COMPLEX_FLOAT32); - - otw_type_t otw_type; - otw_type.byteorder = otw_type_t::BO_NATIVE; - otw_type.width = 16; + convert::id_type in_id; + in_id.input_markup = "sc16"; + in_id.num_inputs = 1; + in_id.output_markup = "sc16_item32_le"; + in_id.num_outputs = 1; + + convert::id_type out_id; + out_id.input_markup = "sc16_item32_le"; + out_id.num_inputs = 1; + out_id.output_markup = "fc32"; + out_id.num_outputs = 1; const size_t nsamps = 13; std::vector input(nsamps); @@ -245,14 +257,10 @@ BOOST_AUTO_TEST_CASE(test_convert_types_sc16_to_fc32){ std::vector output0(1, &interm[0]), output1(1, &output[0]); //convert short to intermediate - convert::get_converter_cpu_to_otw( - io_type_in, otw_type, input0.size(), output0.size() - )(input0, output0, nsamps, 32767.); + convert::get_converter(in_id)(input0, output0, nsamps, 32767.); //convert intermediate to float - convert::get_converter_otw_to_cpu( - io_type_out, otw_type, input1.size(), output1.size() - )(input1, output1, nsamps, 1/32767.); + convert::get_converter(out_id)(input1, output1, nsamps, 1/32767.); //test that the inputs and outputs match for (size_t i = 0; i < nsamps; i++){ -- cgit v1.2.3 From abed04b3c6d70c260d8725831b8aa6e944f52749 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Tue, 4 Oct 2011 09:56:11 -0700 Subject: uhd: restored super packet handler functionality --- host/include/uhd/device.hpp | 4 +- host/include/uhd/device_deprecated.ipp | 36 ++--- host/include/uhd/streamer.hpp | 16 +-- host/lib/convert/convert_impl.cpp | 10 ++ host/lib/transport/super_recv_packet_handler.hpp | 99 +++++--------- host/lib/transport/super_send_packet_handler.hpp | 121 ++++++----------- host/tests/CMakeLists.txt | 4 +- host/tests/sph_recv_test.cpp | 166 ++++++++++------------- host/tests/sph_send_test.cpp | 44 +++--- 9 files changed, 212 insertions(+), 288 deletions(-) (limited to 'host/tests') diff --git a/host/include/uhd/device.hpp b/host/include/uhd/device.hpp index 47afe7dc6..f76739907 100644 --- a/host/include/uhd/device.hpp +++ b/host/include/uhd/device.hpp @@ -77,10 +77,10 @@ public: static sptr make(const device_addr_t &hint, size_t which = 0); //! Make a new receive streamer given the list of channels - virtual recv_streamer::sptr get_recv_streamer(const std::vector &channels) = 0; + virtual rx_streamer::sptr get_rx_streamer(const std::vector &channels) = 0; //! Make a new transmit streamer given the list of channels - virtual send_streamer::sptr get_send_streamer(const std::vector &channels) = 0; + virtual tx_streamer::sptr get_tx_streamer(const std::vector &channels) = 0; /*! * Receive and asynchronous message from the device. diff --git a/host/include/uhd/device_deprecated.ipp b/host/include/uhd/device_deprecated.ipp index 4b8ec0037..ba0edb1bc 100644 --- a/host/include/uhd/device_deprecated.ipp +++ b/host/include/uhd/device_deprecated.ipp @@ -77,21 +77,21 @@ size_t send( send_mode_t send_mode, double timeout = 0.1 ){ - if (_send_streamer.get() == NULL or _send_streamer->get_num_channels() != buffs.size()){ + if (_tx_streamer.get() == NULL or _tx_streamer->get_num_channels() != buffs.size()){ std::vector chans(buffs.size()); for (size_t ch = 0; ch < chans.size(); ch++) chans[ch] = ch; - _send_streamer.reset(); //cleanup possible old one - _send_streamer = get_send_streamer(chans); + _tx_streamer.reset(); //cleanup possible old one + _tx_streamer = get_tx_streamer(chans); _send_tid = io_type_t::CUSTOM_TYPE; } if (io_type.tid != _send_tid){ _send_tid = io_type.tid; - _send_streamer->set_format((_send_tid == io_type_t::COMPLEX_FLOAT32)? "fc32" : "sc16", "sc16"); + _tx_streamer->set_format((_send_tid == io_type_t::COMPLEX_FLOAT32)? "fc32" : "sc16", "sc16"); } const size_t nsamps = (send_mode == SEND_MODE_ONE_PACKET)? std::min(nsamps_per_buff, get_max_send_samps_per_packet()) : nsamps_per_buff; - return _send_streamer->send(buffs, nsamps, metadata, timeout); + return _tx_streamer->send(buffs, nsamps, metadata, timeout); } /*! @@ -133,21 +133,21 @@ size_t recv( recv_mode_t recv_mode, double timeout = 0.1 ){ - if (_recv_streamer.get() == NULL or _recv_streamer->get_num_channels() != buffs.size()){ + if (_rx_streamer.get() == NULL or _rx_streamer->get_num_channels() != buffs.size()){ std::vector chans(buffs.size()); for (size_t ch = 0; ch < chans.size(); ch++) chans[ch] = ch; - _recv_streamer.reset(); //cleanup possible old one - _recv_streamer = get_recv_streamer(chans); + _rx_streamer.reset(); //cleanup possible old one + _rx_streamer = get_rx_streamer(chans); _recv_tid = io_type_t::CUSTOM_TYPE; } if (io_type.tid != _recv_tid){ _recv_tid = io_type.tid; - _recv_streamer->set_format((_recv_tid == io_type_t::COMPLEX_FLOAT32)? "fc32" : "sc16", "sc16"); + _rx_streamer->set_format((_recv_tid == io_type_t::COMPLEX_FLOAT32)? "fc32" : "sc16", "sc16"); } const size_t nsamps = (recv_mode == RECV_MODE_ONE_PACKET)? std::min(nsamps_per_buff, get_max_recv_samps_per_packet()) : nsamps_per_buff; - return _recv_streamer->recv(buffs, nsamps, metadata, timeout); + return _rx_streamer->recv(buffs, nsamps, metadata, timeout); } /*! @@ -155,11 +155,11 @@ size_t recv( * \return the number of samples */ size_t get_max_send_samps_per_packet(void){ - if (_send_streamer.get() == NULL){ + if (_tx_streamer.get() == NULL){ std::vector chans(1, 0); - _send_streamer = get_send_streamer(chans); + _tx_streamer = get_tx_streamer(chans); } - return _send_streamer->get_items_per_packet(); + return _tx_streamer->get_items_per_packet(); } /*! @@ -167,15 +167,15 @@ size_t get_max_send_samps_per_packet(void){ * \return the number of samples */ size_t get_max_recv_samps_per_packet(void){ - if (_recv_streamer.get() == NULL){ + if (_rx_streamer.get() == NULL){ std::vector chans(1, 0); - _recv_streamer = get_recv_streamer(chans); + _rx_streamer = get_rx_streamer(chans); } - return _recv_streamer->get_items_per_packet(); + return _rx_streamer->get_items_per_packet(); } private: - recv_streamer::sptr _recv_streamer; + rx_streamer::sptr _rx_streamer; io_type_t::tid_t _recv_tid; - send_streamer::sptr _send_streamer; + tx_streamer::sptr _tx_streamer; io_type_t::tid_t _send_tid; diff --git a/host/include/uhd/streamer.hpp b/host/include/uhd/streamer.hpp index dfbe15ec3..d96eeb2b7 100644 --- a/host/include/uhd/streamer.hpp +++ b/host/include/uhd/streamer.hpp @@ -90,12 +90,12 @@ public: }; //! A receive streamer to receive host samples -class UHD_API recv_streamer : public streamer{ +class UHD_API rx_streamer : public streamer{ public: - typedef boost::shared_ptr sptr; + typedef boost::shared_ptr sptr; //! Typedef for a pointer to a single, or a collection of recv buffers - typedef ref_vector recv_buffs_type; + typedef ref_vector buffs_type; /*! * Receive buffers containing samples described by the metadata. @@ -123,7 +123,7 @@ public: * \return the number of samples received or 0 on error */ virtual size_t recv( - const recv_buffs_type &buffs, + const buffs_type &buffs, size_t nsamps_per_buff, rx_metadata_t &metadata, double timeout = 0.1 @@ -131,12 +131,12 @@ public: }; //! A transmit streamer to send host samples -class UHD_API send_streamer : public streamer{ +class UHD_API tx_streamer : public streamer{ public: - typedef boost::shared_ptr sptr; + typedef boost::shared_ptr sptr; //! Typedef for a pointer to a single, or a collection of send buffers - typedef ref_vector send_buffs_type; + typedef ref_vector buffs_type; /*! * Send buffers containing samples described by the metadata. @@ -160,7 +160,7 @@ public: * \return the number of samples sent */ virtual size_t send( - const send_buffs_type &buffs, + const buffs_type &buffs, size_t nsamps_per_buff, const tx_metadata_t &metadata, double timeout = 0.1 diff --git a/host/lib/convert/convert_impl.cpp b/host/lib/convert/convert_impl.cpp index 2ead2f5b4..5c9e77e93 100644 --- a/host/lib/convert/convert_impl.cpp +++ b/host/lib/convert/convert_impl.cpp @@ -114,6 +114,16 @@ void register_bytes_per_item( size_t convert::get_bytes_per_item(const std::string &markup){ if (get_item_size_table().has_key(markup)) return get_item_size_table()[markup]; + + //OK. I am sorry about this. + //We didnt find a match, so lets find a match for the first term. + //This is partially a hack because of the way I append strings. + //But as long as life is kind, we can keep this. + const size_t pos = markup.find("_"); + if (pos != std::string::npos){ + return get_bytes_per_item(markup.substr(0, pos)); + } + throw uhd::key_error("Cannot find an item size " + markup); } diff --git a/host/lib/transport/super_recv_packet_handler.hpp b/host/lib/transport/super_recv_packet_handler.hpp index 541c588e6..4ae51e146 100644 --- a/host/lib/transport/super_recv_packet_handler.hpp +++ b/host/lib/transport/super_recv_packet_handler.hpp @@ -21,11 +21,9 @@ #include #include #include -#include +#include #include #include -#include -#include #include #include #include @@ -124,24 +122,12 @@ public: _props.at(xport_chan).get_buff = get_buff; } - /*! - * Setup the conversion functions (homogeneous across transports). - * Here, we load a table of converters for all possible io types. - * This makes the converter look-up an O(1) operation. - * \param otw_type the channel data type - * \param width the streams per channel (usually 1) - */ - void set_converter(const uhd::otw_type_t &otw_type, const size_t width = 1){ - _io_buffs.resize(width); - _converters.resize(128); - for (size_t io_type = 0; io_type < _converters.size(); io_type++){ - try{ - _converters[io_type] = uhd::convert::get_converter_otw_to_cpu( - io_type_t::tid_t(io_type), otw_type, 1, width - ); - }catch(const uhd::value_error &){} //we expect this, not all io_types valid... - } - _bytes_per_item = otw_type.get_sample_size(); + //! Set the conversion routine for all channels + void set_converter(const uhd::convert::id_type &id){ + _io_buffs.resize(id.num_inputs); + _converter = uhd::convert::get_converter(id); + _bytes_per_otw_item = uhd::convert::get_bytes_per_item(id.input_markup); + _bytes_per_cpu_item = uhd::convert::get_bytes_per_item(id.output_markup); } //! Set the transport channel's overflow handler @@ -165,11 +151,9 @@ public: * Dispatch into combinations of single packet receive calls. ******************************************************************/ UHD_INLINE size_t recv( - const uhd::device::recv_buffs_type &buffs, + const uhd::rx_streamer::buffs_type &buffs, const size_t nsamps_per_buff, uhd::rx_metadata_t &metadata, - const uhd::io_type_t &io_type, - uhd::device::recv_mode_t recv_mode, double timeout ){ boost::mutex::scoped_lock lock(_mutex); @@ -183,43 +167,32 @@ public: if (_queue_metadata.error_code != rx_metadata_t::ERROR_CODE_TIMEOUT) return 0; } - switch(recv_mode){ - - //////////////////////////////////////////////////////////////// - case uhd::device::RECV_MODE_ONE_PACKET:{ - //////////////////////////////////////////////////////////////// - return recv_one_packet(buffs, nsamps_per_buff, metadata, io_type, timeout); - } + size_t accum_num_samps = recv_one_packet( + buffs, nsamps_per_buff, metadata, timeout + ); - //////////////////////////////////////////////////////////////// - case uhd::device::RECV_MODE_FULL_BUFF:{ - //////////////////////////////////////////////////////////////// - size_t accum_num_samps = recv_one_packet( - buffs, nsamps_per_buff, metadata, io_type, timeout - ); + #ifdef SRPH_TEST_MODE_ONE_PACKET + return accum_num_samps; + #endif - //first recv had an error code set, return immediately - if (metadata.error_code != rx_metadata_t::ERROR_CODE_NONE) return accum_num_samps; + //first recv had an error code set, return immediately + if (metadata.error_code != rx_metadata_t::ERROR_CODE_NONE) return accum_num_samps; - //loop until buffer is filled or error code - while(accum_num_samps < nsamps_per_buff){ - size_t num_samps = recv_one_packet( - buffs, nsamps_per_buff - accum_num_samps, _queue_metadata, - io_type, timeout, accum_num_samps*io_type.size - ); + //loop until buffer is filled or error code + while(accum_num_samps < nsamps_per_buff){ + size_t num_samps = recv_one_packet( + buffs, nsamps_per_buff - accum_num_samps, _queue_metadata, + timeout, accum_num_samps*_bytes_per_cpu_item + ); - //metadata had an error code set, store for next call and return - if (_queue_metadata.error_code != rx_metadata_t::ERROR_CODE_NONE){ - _queue_error_for_next_call = true; - break; - } - accum_num_samps += num_samps; + //metadata had an error code set, store for next call and return + if (_queue_metadata.error_code != rx_metadata_t::ERROR_CODE_NONE){ + _queue_error_for_next_call = true; + break; } - return accum_num_samps; + accum_num_samps += num_samps; } - - default: throw uhd::value_error("unknown recv mode"); - }//switch(recv_mode) + return accum_num_samps; } private: @@ -242,8 +215,9 @@ private: }; std::vector _props; std::vector _io_buffs; //used in conversion - size_t _bytes_per_item; //used in conversion - std::vector _converters; //used in conversion + size_t _bytes_per_otw_item; //used in conversion + size_t _bytes_per_cpu_item; //used in conversion + uhd::convert::function_type _converter; //used in conversion double _scale_factor; //! information stored for a received buffer @@ -471,7 +445,7 @@ private: std::swap(curr_info, next_info); //save progress from curr -> next curr_info.metadata.has_time_spec = prev_info.metadata.has_time_spec; curr_info.metadata.time_spec = prev_info.metadata.time_spec + time_spec_t(0, - prev_info[index].ifpi.num_payload_words32*sizeof(boost::uint32_t)/_bytes_per_item, _samp_rate); + prev_info[index].ifpi.num_payload_words32*sizeof(boost::uint32_t)/_bytes_per_otw_item, _samp_rate); curr_info.metadata.more_fragments = false; curr_info.metadata.fragment_offset = 0; curr_info.metadata.start_of_burst = false; @@ -525,10 +499,9 @@ private: * Then copy-convert available data into the user's IO buffers. ******************************************************************/ UHD_INLINE size_t recv_one_packet( - const uhd::device::recv_buffs_type &buffs, + const uhd::rx_streamer::buffs_type &buffs, const size_t nsamps_per_buff, uhd::rx_metadata_t &metadata, - const uhd::io_type_t &io_type, double timeout, const size_t buffer_offset_bytes = 0 ){ @@ -551,9 +524,9 @@ private: metadata.time_spec += time_spec_t(0, info.fragment_offset_in_samps, _samp_rate); //extract the number of samples available to copy - const size_t nsamps_available = info.data_bytes_to_copy/_bytes_per_item; + const size_t nsamps_available = info.data_bytes_to_copy/_bytes_per_otw_item; const size_t nsamps_to_copy = std::min(nsamps_per_buff*_io_buffs.size(), nsamps_available); - const size_t bytes_to_copy = nsamps_to_copy*_bytes_per_item; + const size_t bytes_to_copy = nsamps_to_copy*_bytes_per_otw_item; const size_t nsamps_to_copy_per_io_buff = nsamps_to_copy/_io_buffs.size(); size_t buff_index = 0; @@ -565,7 +538,7 @@ private: } //copy-convert the samples from the recv buffer - _converters[io_type.tid](buff_info.copy_buff, _io_buffs, nsamps_to_copy_per_io_buff, _scale_factor); + _converter(buff_info.copy_buff, _io_buffs, nsamps_to_copy_per_io_buff, _scale_factor); //update the rx copy buffer to reflect the bytes copied buff_info.copy_buff += bytes_to_copy; diff --git a/host/lib/transport/super_send_packet_handler.hpp b/host/lib/transport/super_send_packet_handler.hpp index a99adcb5f..6950abb73 100644 --- a/host/lib/transport/super_send_packet_handler.hpp +++ b/host/lib/transport/super_send_packet_handler.hpp @@ -21,11 +21,9 @@ #include #include #include -#include +#include #include #include -#include -#include #include #include #include @@ -100,24 +98,12 @@ public: _props.at(xport_chan).get_buff = get_buff; } - /*! - * Setup the conversion functions (homogeneous across transports). - * Here, we load a table of converters for all possible io types. - * This makes the converter look-up an O(1) operation. - * \param otw_type the channel data type - * \param width the streams per channel (usually 1) - */ - void set_converter(const uhd::otw_type_t &otw_type, const size_t width = 1){ - _io_buffs.resize(width); - _converters.resize(128); - for (size_t io_type = 0; io_type < _converters.size(); io_type++){ - try{ - _converters[io_type] = uhd::convert::get_converter_cpu_to_otw( - io_type_t::tid_t(io_type), otw_type, 1, width - ); - }catch(const uhd::value_error &){} //we expect this, not all io_types valid... - } - _bytes_per_item = otw_type.get_sample_size(); + //! Set the conversion routine for all channels + void set_converter(const uhd::convert::id_type &id){ + _io_buffs.resize(id.num_outputs); + _converter = uhd::convert::get_converter(id); + _bytes_per_otw_item = uhd::convert::get_bytes_per_item(id.output_markup); + _bytes_per_cpu_item = uhd::convert::get_bytes_per_item(id.input_markup); } /*! @@ -145,11 +131,9 @@ public: * Dispatch into combinations of single packet send calls. ******************************************************************/ UHD_INLINE size_t send( - const uhd::device::send_buffs_type &buffs, + const uhd::tx_streamer::buffs_type &buffs, const size_t nsamps_per_buff, const uhd::tx_metadata_t &metadata, - const uhd::io_type_t &io_type, - uhd::device::send_mode_t send_mode, double timeout ){ boost::mutex::scoped_lock lock(_mutex); @@ -166,69 +150,52 @@ public: if_packet_info.sob = metadata.start_of_burst; if_packet_info.eob = metadata.end_of_burst; - if (nsamps_per_buff <= _max_samples_per_packet) send_mode = uhd::device::SEND_MODE_ONE_PACKET; - switch(send_mode){ - - //////////////////////////////////////////////////////////////// - case uhd::device::SEND_MODE_ONE_PACKET:{ - //////////////////////////////////////////////////////////////// + if (nsamps_per_buff <= _max_samples_per_packet){ //TODO remove this code when sample counts of zero are supported by hardware #ifndef SSPH_DONT_PAD_TO_ONE if (nsamps_per_buff == 0) return send_one_packet( - _zero_buffs, 1, if_packet_info, io_type, timeout + _zero_buffs, 1, if_packet_info, timeout ) & 0x0; #endif - return send_one_packet( - buffs, - std::min(nsamps_per_buff, _max_samples_per_packet), - if_packet_info, io_type, timeout - ); + return send_one_packet(buffs, nsamps_per_buff, if_packet_info, timeout); } + size_t total_num_samps_sent = 0; - //////////////////////////////////////////////////////////////// - case uhd::device::SEND_MODE_FULL_BUFF:{ - //////////////////////////////////////////////////////////////// - size_t total_num_samps_sent = 0; + //false until final fragment + if_packet_info.eob = false; - //false until final fragment - if_packet_info.eob = false; + const size_t num_fragments = (nsamps_per_buff-1)/_max_samples_per_packet; + const size_t final_length = ((nsamps_per_buff-1)%_max_samples_per_packet)+1; - const size_t num_fragments = (nsamps_per_buff-1)/_max_samples_per_packet; - const size_t final_length = ((nsamps_per_buff-1)%_max_samples_per_packet)+1; + //loop through the following fragment indexes + for (size_t i = 0; i < num_fragments; i++){ - //loop through the following fragment indexes - for (size_t i = 0; i < num_fragments; i++){ - - //send a fragment with the helper function - const size_t num_samps_sent = send_one_packet( - buffs, _max_samples_per_packet, - if_packet_info, io_type, timeout, - total_num_samps_sent*io_type.size - ); - total_num_samps_sent += num_samps_sent; - if (num_samps_sent == 0) return total_num_samps_sent; + //send a fragment with the helper function + const size_t num_samps_sent = send_one_packet( + buffs, _max_samples_per_packet, + if_packet_info, timeout, + total_num_samps_sent*_bytes_per_cpu_item + ); + total_num_samps_sent += num_samps_sent; + if (num_samps_sent == 0) return total_num_samps_sent; - //setup metadata for the next fragment - const time_spec_t time_spec = metadata.time_spec + time_spec_t(0, total_num_samps_sent, _samp_rate); - if_packet_info.tsi = boost::uint32_t(time_spec.get_full_secs()); - if_packet_info.tsf = boost::uint64_t(time_spec.get_tick_count(_tick_rate)); - if_packet_info.sob = false; + //setup metadata for the next fragment + const time_spec_t time_spec = metadata.time_spec + time_spec_t(0, total_num_samps_sent, _samp_rate); + if_packet_info.tsi = boost::uint32_t(time_spec.get_full_secs()); + if_packet_info.tsf = boost::uint64_t(time_spec.get_tick_count(_tick_rate)); + if_packet_info.sob = false; - } - - //send the final fragment with the helper function - if_packet_info.eob = metadata.end_of_burst; - return total_num_samps_sent + send_one_packet( - buffs, final_length, - if_packet_info, io_type, timeout, - total_num_samps_sent*io_type.size - ); } - default: throw uhd::value_error("unknown send mode"); - }//switch(send_mode) + //send the final fragment with the helper function + if_packet_info.eob = metadata.end_of_burst; + return total_num_samps_sent + send_one_packet( + buffs, final_length, + if_packet_info, timeout, + total_num_samps_sent*_bytes_per_cpu_item + ); } private: @@ -242,8 +209,9 @@ private: }; std::vector _props; std::vector _io_buffs; //used in conversion - size_t _bytes_per_item; //used in conversion - std::vector _converters; //used in conversion + size_t _bytes_per_otw_item; //used in conversion + size_t _bytes_per_cpu_item; //used in conversion + uhd::convert::function_type _converter; //used in conversion size_t _max_samples_per_packet; std::vector _zero_buffs; size_t _next_packet_seq; @@ -253,15 +221,14 @@ private: * Send a single packet: ******************************************************************/ UHD_INLINE size_t send_one_packet( - const uhd::device::send_buffs_type &buffs, + const uhd::tx_streamer::buffs_type &buffs, const size_t nsamps_per_buff, vrt::if_packet_info_t &if_packet_info, - const uhd::io_type_t &io_type, double timeout, const size_t buffer_offset_bytes = 0 ){ //load the rest of the if_packet_info in here - if_packet_info.num_payload_words32 = (nsamps_per_buff*_io_buffs.size()*_bytes_per_item)/sizeof(boost::uint32_t); + if_packet_info.num_payload_words32 = (nsamps_per_buff*_io_buffs.size()*_bytes_per_otw_item)/sizeof(boost::uint32_t); if_packet_info.packet_count = _next_packet_seq; size_t buff_index = 0; @@ -280,7 +247,7 @@ private: otw_mem += if_packet_info.num_header_words32; //copy-convert the samples into the send buffer - _converters[io_type.tid](_io_buffs, otw_mem, nsamps_per_buff, _scale_factor); + _converter(_io_buffs, otw_mem, nsamps_per_buff, _scale_factor); //commit the samples to the zero-copy interface size_t num_bytes_total = (_header_offset_words32+if_packet_info.num_packet_words32)*sizeof(boost::uint32_t); diff --git a/host/tests/CMakeLists.txt b/host/tests/CMakeLists.txt index 25679a33e..28cc1c5da 100644 --- a/host/tests/CMakeLists.txt +++ b/host/tests/CMakeLists.txt @@ -29,8 +29,8 @@ SET(test_sources msg_test.cpp property_test.cpp ranges_test.cpp - #TODO restore sph_recv_test.cpp - #TODO restore sph_send_test.cpp + sph_recv_test.cpp + sph_send_test.cpp subdev_spec_test.cpp time_spec_test.cpp vrt_test.cpp diff --git a/host/tests/sph_recv_test.cpp b/host/tests/sph_recv_test.cpp index 1387e3b66..3ca123ef2 100644 --- a/host/tests/sph_recv_test.cpp +++ b/host/tests/sph_recv_test.cpp @@ -16,6 +16,7 @@ // #include +#define SRPH_TEST_MODE_ONE_PACKET #include "../lib/transport/super_recv_packet_handler.hpp" #include #include @@ -67,8 +68,8 @@ private: **********************************************************************/ class dummy_recv_xport_class{ public: - dummy_recv_xport_class(const uhd::otw_type_t &otw_type){ - _otw_type = otw_type; + dummy_recv_xport_class(const std::string &end){ + _end = end; } void push_back_packet( @@ -77,10 +78,10 @@ public: ){ const size_t max_pkt_len = (ifpi.num_payload_words32 + uhd::transport::vrt::max_if_hdr_words32 + 1/*tlr*/)*sizeof(boost::uint32_t); _mems.push_back(boost::shared_array(new char[max_pkt_len])); - if (_otw_type.byteorder == uhd::otw_type_t::BO_BIG_ENDIAN){ + if (_end == "big"){ uhd::transport::vrt::if_hdr_pack_be(reinterpret_cast(_mems.back().get()), ifpi); } - if (_otw_type.byteorder == uhd::otw_type_t::BO_LITTLE_ENDIAN){ + if (_end == "little"){ uhd::transport::vrt::if_hdr_pack_le(reinterpret_cast(_mems.back().get()), ifpi); } (reinterpret_cast(_mems.back().get()) + ifpi.num_header_words32)[0] = optional_msg_word | uhd::byteswap(optional_msg_word); @@ -100,18 +101,19 @@ private: std::list > _mems; std::list _lens; std::list _mrbs; //list means no-realloc - uhd::otw_type_t _otw_type; + std::string _end; }; //////////////////////////////////////////////////////////////////////// BOOST_AUTO_TEST_CASE(test_sph_recv_one_channel_normal){ //////////////////////////////////////////////////////////////////////// - uhd::otw_type_t otw_type; - otw_type.width = 16; - otw_type.shift = 0; - otw_type.byteorder = uhd::otw_type_t::BO_BIG_ENDIAN; + uhd::convert::id_type id; + id.input_markup = "sc16_item32_be"; + id.num_inputs = 1; + id.output_markup = "fc32"; + id.num_outputs = 1; - dummy_recv_xport_class dummy_recv_xport(otw_type); + dummy_recv_xport_class dummy_recv_xport("big"); uhd::transport::vrt::if_packet_info_t ifpi; ifpi.packet_type = uhd::transport::vrt::if_packet_info_t::PACKET_TYPE_DATA; ifpi.num_payload_words32 = 0; @@ -144,7 +146,7 @@ BOOST_AUTO_TEST_CASE(test_sph_recv_one_channel_normal){ handler.set_tick_rate(TICK_RATE); handler.set_samp_rate(SAMP_RATE); handler.set_xport_chan_get_buff(0, boost::bind(&dummy_recv_xport_class::get_recv_buff, &dummy_recv_xport, _1)); - handler.set_converter(otw_type); + handler.set_converter(id); //check the received packets size_t num_accum_samps = 0; @@ -153,9 +155,7 @@ BOOST_AUTO_TEST_CASE(test_sph_recv_one_channel_normal){ for (size_t i = 0; i < NUM_PKTS_TO_TEST; i++){ std::cout << "data check " << i << std::endl; size_t num_samps_ret = handler.recv( - &buff.front(), buff.size(), metadata, - uhd::io_type_t::COMPLEX_FLOAT32, - uhd::device::RECV_MODE_ONE_PACKET, 1.0 + &buff.front(), buff.size(), metadata, 1.0 ); BOOST_CHECK_EQUAL(metadata.error_code, uhd::rx_metadata_t::ERROR_CODE_NONE); BOOST_CHECK(not metadata.more_fragments); @@ -169,9 +169,7 @@ BOOST_AUTO_TEST_CASE(test_sph_recv_one_channel_normal){ for (size_t i = 0; i < 3; i++){ std::cout << "timeout check " << i << std::endl; handler.recv( - &buff.front(), buff.size(), metadata, - uhd::io_type_t::COMPLEX_FLOAT32, - uhd::device::RECV_MODE_ONE_PACKET, 1.0 + &buff.front(), buff.size(), metadata, 1.0 ); BOOST_CHECK_EQUAL(metadata.error_code, uhd::rx_metadata_t::ERROR_CODE_TIMEOUT); } @@ -180,12 +178,13 @@ BOOST_AUTO_TEST_CASE(test_sph_recv_one_channel_normal){ //////////////////////////////////////////////////////////////////////// BOOST_AUTO_TEST_CASE(test_sph_recv_one_channel_sequence_error){ //////////////////////////////////////////////////////////////////////// - uhd::otw_type_t otw_type; - otw_type.width = 16; - otw_type.shift = 0; - otw_type.byteorder = uhd::otw_type_t::BO_BIG_ENDIAN; + uhd::convert::id_type id; + id.input_markup = "sc16_item32_be"; + id.num_inputs = 1; + id.output_markup = "fc32"; + id.num_outputs = 1; - dummy_recv_xport_class dummy_recv_xport(otw_type); + dummy_recv_xport_class dummy_recv_xport("big"); uhd::transport::vrt::if_packet_info_t ifpi; ifpi.packet_type = uhd::transport::vrt::if_packet_info_t::PACKET_TYPE_DATA; ifpi.num_payload_words32 = 0; @@ -220,7 +219,7 @@ BOOST_AUTO_TEST_CASE(test_sph_recv_one_channel_sequence_error){ handler.set_tick_rate(TICK_RATE); handler.set_samp_rate(SAMP_RATE); handler.set_xport_chan_get_buff(0, boost::bind(&dummy_recv_xport_class::get_recv_buff, &dummy_recv_xport, _1)); - handler.set_converter(otw_type); + handler.set_converter(id); //check the received packets size_t num_accum_samps = 0; @@ -229,9 +228,7 @@ BOOST_AUTO_TEST_CASE(test_sph_recv_one_channel_sequence_error){ for (size_t i = 0; i < NUM_PKTS_TO_TEST; i++){ std::cout << "data check " << i << std::endl; size_t num_samps_ret = handler.recv( - &buff.front(), buff.size(), metadata, - uhd::io_type_t::COMPLEX_FLOAT32, - uhd::device::RECV_MODE_ONE_PACKET, 1.0 + &buff.front(), buff.size(), metadata, 1.0 ); if (i == NUM_PKTS_TO_TEST/2){ //must get the soft overflow here @@ -253,9 +250,7 @@ BOOST_AUTO_TEST_CASE(test_sph_recv_one_channel_sequence_error){ for (size_t i = 0; i < 3; i++){ std::cout << "timeout check " << i << std::endl; handler.recv( - &buff.front(), buff.size(), metadata, - uhd::io_type_t::COMPLEX_FLOAT32, - uhd::device::RECV_MODE_ONE_PACKET, 1.0 + &buff.front(), buff.size(), metadata, 1.0 ); BOOST_CHECK_EQUAL(metadata.error_code, uhd::rx_metadata_t::ERROR_CODE_TIMEOUT); } @@ -264,12 +259,13 @@ BOOST_AUTO_TEST_CASE(test_sph_recv_one_channel_sequence_error){ //////////////////////////////////////////////////////////////////////// BOOST_AUTO_TEST_CASE(test_sph_recv_one_channel_inline_message){ //////////////////////////////////////////////////////////////////////// - uhd::otw_type_t otw_type; - otw_type.width = 16; - otw_type.shift = 0; - otw_type.byteorder = uhd::otw_type_t::BO_BIG_ENDIAN; + uhd::convert::id_type id; + id.input_markup = "sc16_item32_be"; + id.num_inputs = 1; + id.output_markup = "fc32"; + id.num_outputs = 1; - dummy_recv_xport_class dummy_recv_xport(otw_type); + dummy_recv_xport_class dummy_recv_xport("big"); uhd::transport::vrt::if_packet_info_t ifpi; ifpi.packet_type = uhd::transport::vrt::if_packet_info_t::PACKET_TYPE_DATA; ifpi.num_payload_words32 = 0; @@ -310,7 +306,7 @@ BOOST_AUTO_TEST_CASE(test_sph_recv_one_channel_inline_message){ handler.set_tick_rate(TICK_RATE); handler.set_samp_rate(SAMP_RATE); handler.set_xport_chan_get_buff(0, boost::bind(&dummy_recv_xport_class::get_recv_buff, &dummy_recv_xport, _1)); - handler.set_converter(otw_type); + handler.set_converter(id); //create an overflow handler overflow_handler_type overflow_handler; @@ -323,9 +319,7 @@ BOOST_AUTO_TEST_CASE(test_sph_recv_one_channel_inline_message){ for (size_t i = 0; i < NUM_PKTS_TO_TEST; i++){ std::cout << "data check " << i << std::endl; size_t num_samps_ret = handler.recv( - &buff.front(), buff.size(), metadata, - uhd::io_type_t::COMPLEX_FLOAT32, - uhd::device::RECV_MODE_ONE_PACKET, 1.0 + &buff.front(), buff.size(), metadata, 1.0 ); BOOST_CHECK_EQUAL(metadata.error_code, uhd::rx_metadata_t::ERROR_CODE_NONE); BOOST_CHECK(not metadata.more_fragments); @@ -335,9 +329,7 @@ BOOST_AUTO_TEST_CASE(test_sph_recv_one_channel_inline_message){ num_accum_samps += num_samps_ret; if (i == NUM_PKTS_TO_TEST/2){ handler.recv( - &buff.front(), buff.size(), metadata, - uhd::io_type_t::COMPLEX_FLOAT32, - uhd::device::RECV_MODE_ONE_PACKET, 1.0 + &buff.front(), buff.size(), metadata, 1.0 ); std::cout << "metadata.error_code " << metadata.error_code << std::endl; BOOST_REQUIRE(metadata.error_code == uhd::rx_metadata_t::ERROR_CODE_OVERFLOW); @@ -350,9 +342,7 @@ BOOST_AUTO_TEST_CASE(test_sph_recv_one_channel_inline_message){ for (size_t i = 0; i < 3; i++){ std::cout << "timeout check " << i << std::endl; handler.recv( - &buff.front(), buff.size(), metadata, - uhd::io_type_t::COMPLEX_FLOAT32, - uhd::device::RECV_MODE_ONE_PACKET, 1.0 + &buff.front(), buff.size(), metadata, 1.0 ); BOOST_CHECK_EQUAL(metadata.error_code, uhd::rx_metadata_t::ERROR_CODE_TIMEOUT); } @@ -361,10 +351,11 @@ BOOST_AUTO_TEST_CASE(test_sph_recv_one_channel_inline_message){ //////////////////////////////////////////////////////////////////////// BOOST_AUTO_TEST_CASE(test_sph_recv_multi_channel_normal){ //////////////////////////////////////////////////////////////////////// - uhd::otw_type_t otw_type; - otw_type.width = 16; - otw_type.shift = 0; - otw_type.byteorder = uhd::otw_type_t::BO_BIG_ENDIAN; + uhd::convert::id_type id; + id.input_markup = "sc16_item32_be"; + id.num_inputs = 1; + id.output_markup = "fc32"; + id.num_outputs = 1; uhd::transport::vrt::if_packet_info_t ifpi; ifpi.packet_type = uhd::transport::vrt::if_packet_info_t::PACKET_TYPE_DATA; @@ -386,7 +377,7 @@ BOOST_AUTO_TEST_CASE(test_sph_recv_multi_channel_normal){ static const size_t NUM_SAMPS_PER_BUFF = 20; static const size_t NCHANNELS = 4; - std::vector dummy_recv_xports(NCHANNELS, dummy_recv_xport_class(otw_type)); + std::vector dummy_recv_xports(NCHANNELS, dummy_recv_xport_class("big")); //generate a bunch of packets for (size_t i = 0; i < NUM_PKTS_TO_TEST; i++){ @@ -406,7 +397,7 @@ BOOST_AUTO_TEST_CASE(test_sph_recv_multi_channel_normal){ for (size_t ch = 0; ch < NCHANNELS; ch++){ handler.set_xport_chan_get_buff(ch, boost::bind(&dummy_recv_xport_class::get_recv_buff, &dummy_recv_xports[ch], _1)); } - handler.set_converter(otw_type); + handler.set_converter(id); //check the received packets size_t num_accum_samps = 0; @@ -419,9 +410,7 @@ BOOST_AUTO_TEST_CASE(test_sph_recv_multi_channel_normal){ for (size_t i = 0; i < NUM_PKTS_TO_TEST; i++){ std::cout << "data check " << i << std::endl; size_t num_samps_ret = handler.recv( - buffs, NUM_SAMPS_PER_BUFF, metadata, - uhd::io_type_t::COMPLEX_FLOAT32, - uhd::device::RECV_MODE_ONE_PACKET, 1.0 + buffs, NUM_SAMPS_PER_BUFF, metadata, 1.0 ); BOOST_CHECK_EQUAL(metadata.error_code, uhd::rx_metadata_t::ERROR_CODE_NONE); BOOST_CHECK(not metadata.more_fragments); @@ -435,9 +424,7 @@ BOOST_AUTO_TEST_CASE(test_sph_recv_multi_channel_normal){ for (size_t i = 0; i < 3; i++){ std::cout << "timeout check " << i << std::endl; handler.recv( - buffs, NUM_SAMPS_PER_BUFF, metadata, - uhd::io_type_t::COMPLEX_FLOAT32, - uhd::device::RECV_MODE_ONE_PACKET, 1.0 + buffs, NUM_SAMPS_PER_BUFF, metadata, 1.0 ); BOOST_CHECK_EQUAL(metadata.error_code, uhd::rx_metadata_t::ERROR_CODE_TIMEOUT); } @@ -447,10 +434,11 @@ BOOST_AUTO_TEST_CASE(test_sph_recv_multi_channel_normal){ //////////////////////////////////////////////////////////////////////// BOOST_AUTO_TEST_CASE(test_sph_recv_multi_channel_sequence_error){ //////////////////////////////////////////////////////////////////////// - uhd::otw_type_t otw_type; - otw_type.width = 16; - otw_type.shift = 0; - otw_type.byteorder = uhd::otw_type_t::BO_BIG_ENDIAN; + uhd::convert::id_type id; + id.input_markup = "sc16_item32_be"; + id.num_inputs = 1; + id.output_markup = "fc32"; + id.num_outputs = 1; uhd::transport::vrt::if_packet_info_t ifpi; ifpi.packet_type = uhd::transport::vrt::if_packet_info_t::PACKET_TYPE_DATA; @@ -472,7 +460,7 @@ BOOST_AUTO_TEST_CASE(test_sph_recv_multi_channel_sequence_error){ static const size_t NUM_SAMPS_PER_BUFF = 20; static const size_t NCHANNELS = 4; - std::vector dummy_recv_xports(NCHANNELS, dummy_recv_xport_class(otw_type)); + std::vector dummy_recv_xports(NCHANNELS, dummy_recv_xport_class("big")); //generate a bunch of packets for (size_t i = 0; i < NUM_PKTS_TO_TEST; i++){ @@ -495,7 +483,7 @@ BOOST_AUTO_TEST_CASE(test_sph_recv_multi_channel_sequence_error){ for (size_t ch = 0; ch < NCHANNELS; ch++){ handler.set_xport_chan_get_buff(ch, boost::bind(&dummy_recv_xport_class::get_recv_buff, &dummy_recv_xports[ch], _1)); } - handler.set_converter(otw_type); + handler.set_converter(id); //check the received packets size_t num_accum_samps = 0; @@ -508,9 +496,7 @@ BOOST_AUTO_TEST_CASE(test_sph_recv_multi_channel_sequence_error){ for (size_t i = 0; i < NUM_PKTS_TO_TEST; i++){ std::cout << "data check " << i << std::endl; size_t num_samps_ret = handler.recv( - buffs, NUM_SAMPS_PER_BUFF, metadata, - uhd::io_type_t::COMPLEX_FLOAT32, - uhd::device::RECV_MODE_ONE_PACKET, 1.0 + buffs, NUM_SAMPS_PER_BUFF, metadata, 1.0 ); if (i == NUM_PKTS_TO_TEST/2){ //must get the soft overflow here @@ -532,9 +518,7 @@ BOOST_AUTO_TEST_CASE(test_sph_recv_multi_channel_sequence_error){ for (size_t i = 0; i < 3; i++){ std::cout << "timeout check " << i << std::endl; handler.recv( - buffs, NUM_SAMPS_PER_BUFF, metadata, - uhd::io_type_t::COMPLEX_FLOAT32, - uhd::device::RECV_MODE_ONE_PACKET, 1.0 + buffs, NUM_SAMPS_PER_BUFF, metadata, 1.0 ); BOOST_CHECK_EQUAL(metadata.error_code, uhd::rx_metadata_t::ERROR_CODE_TIMEOUT); } @@ -543,10 +527,11 @@ BOOST_AUTO_TEST_CASE(test_sph_recv_multi_channel_sequence_error){ //////////////////////////////////////////////////////////////////////// BOOST_AUTO_TEST_CASE(test_sph_recv_multi_channel_time_error){ //////////////////////////////////////////////////////////////////////// - uhd::otw_type_t otw_type; - otw_type.width = 16; - otw_type.shift = 0; - otw_type.byteorder = uhd::otw_type_t::BO_BIG_ENDIAN; + uhd::convert::id_type id; + id.input_markup = "sc16_item32_be"; + id.num_inputs = 1; + id.output_markup = "fc32"; + id.num_outputs = 1; uhd::transport::vrt::if_packet_info_t ifpi; ifpi.packet_type = uhd::transport::vrt::if_packet_info_t::PACKET_TYPE_DATA; @@ -568,7 +553,7 @@ BOOST_AUTO_TEST_CASE(test_sph_recv_multi_channel_time_error){ static const size_t NUM_SAMPS_PER_BUFF = 20; static const size_t NCHANNELS = 4; - std::vector dummy_recv_xports(NCHANNELS, dummy_recv_xport_class(otw_type)); + std::vector dummy_recv_xports(NCHANNELS, dummy_recv_xport_class("big")); //generate a bunch of packets for (size_t i = 0; i < NUM_PKTS_TO_TEST; i++){ @@ -591,7 +576,7 @@ BOOST_AUTO_TEST_CASE(test_sph_recv_multi_channel_time_error){ for (size_t ch = 0; ch < NCHANNELS; ch++){ handler.set_xport_chan_get_buff(ch, boost::bind(&dummy_recv_xport_class::get_recv_buff, &dummy_recv_xports[ch], _1)); } - handler.set_converter(otw_type); + handler.set_converter(id); //check the received packets size_t num_accum_samps = 0; @@ -604,9 +589,7 @@ BOOST_AUTO_TEST_CASE(test_sph_recv_multi_channel_time_error){ for (size_t i = 0; i < NUM_PKTS_TO_TEST; i++){ std::cout << "data check " << i << std::endl; size_t num_samps_ret = handler.recv( - buffs, NUM_SAMPS_PER_BUFF, metadata, - uhd::io_type_t::COMPLEX_FLOAT32, - uhd::device::RECV_MODE_ONE_PACKET, 1.0 + buffs, NUM_SAMPS_PER_BUFF, metadata, 1.0 ); BOOST_CHECK_EQUAL(metadata.error_code, uhd::rx_metadata_t::ERROR_CODE_NONE); BOOST_CHECK(not metadata.more_fragments); @@ -623,9 +606,7 @@ BOOST_AUTO_TEST_CASE(test_sph_recv_multi_channel_time_error){ for (size_t i = 0; i < 3; i++){ std::cout << "timeout check " << i << std::endl; handler.recv( - buffs, NUM_SAMPS_PER_BUFF, metadata, - uhd::io_type_t::COMPLEX_FLOAT32, - uhd::device::RECV_MODE_ONE_PACKET, 1.0 + buffs, NUM_SAMPS_PER_BUFF, metadata, 1.0 ); BOOST_CHECK_EQUAL(metadata.error_code, uhd::rx_metadata_t::ERROR_CODE_TIMEOUT); } @@ -634,10 +615,11 @@ BOOST_AUTO_TEST_CASE(test_sph_recv_multi_channel_time_error){ //////////////////////////////////////////////////////////////////////// BOOST_AUTO_TEST_CASE(test_sph_recv_multi_channel_fragment){ //////////////////////////////////////////////////////////////////////// - uhd::otw_type_t otw_type; - otw_type.width = 16; - otw_type.shift = 0; - otw_type.byteorder = uhd::otw_type_t::BO_BIG_ENDIAN; + uhd::convert::id_type id; + id.input_markup = "sc16_item32_be"; + id.num_inputs = 1; + id.output_markup = "fc32"; + id.num_outputs = 1; uhd::transport::vrt::if_packet_info_t ifpi; ifpi.packet_type = uhd::transport::vrt::if_packet_info_t::PACKET_TYPE_DATA; @@ -659,7 +641,7 @@ BOOST_AUTO_TEST_CASE(test_sph_recv_multi_channel_fragment){ static const size_t NUM_SAMPS_PER_BUFF = 10; static const size_t NCHANNELS = 4; - std::vector dummy_recv_xports(NCHANNELS, dummy_recv_xport_class(otw_type)); + std::vector dummy_recv_xports(NCHANNELS, dummy_recv_xport_class("big")); //generate a bunch of packets for (size_t i = 0; i < NUM_PKTS_TO_TEST; i++){ @@ -679,7 +661,7 @@ BOOST_AUTO_TEST_CASE(test_sph_recv_multi_channel_fragment){ for (size_t ch = 0; ch < NCHANNELS; ch++){ handler.set_xport_chan_get_buff(ch, boost::bind(&dummy_recv_xport_class::get_recv_buff, &dummy_recv_xports[ch], _1)); } - handler.set_converter(otw_type); + handler.set_converter(id); //check the received packets size_t num_accum_samps = 0; @@ -692,9 +674,7 @@ BOOST_AUTO_TEST_CASE(test_sph_recv_multi_channel_fragment){ for (size_t i = 0; i < NUM_PKTS_TO_TEST; i++){ std::cout << "data check " << i << std::endl; size_t num_samps_ret = handler.recv( - buffs, NUM_SAMPS_PER_BUFF, metadata, - uhd::io_type_t::COMPLEX_FLOAT32, - uhd::device::RECV_MODE_ONE_PACKET, 1.0 + buffs, NUM_SAMPS_PER_BUFF, metadata, 1.0 ); BOOST_CHECK_EQUAL(metadata.error_code, uhd::rx_metadata_t::ERROR_CODE_NONE); BOOST_CHECK(metadata.has_time_spec); @@ -705,9 +685,7 @@ BOOST_AUTO_TEST_CASE(test_sph_recv_multi_channel_fragment){ if (not metadata.more_fragments) continue; num_samps_ret = handler.recv( - buffs, NUM_SAMPS_PER_BUFF, metadata, - uhd::io_type_t::COMPLEX_FLOAT32, - uhd::device::RECV_MODE_ONE_PACKET, 1.0 + buffs, NUM_SAMPS_PER_BUFF, metadata, 1.0 ); BOOST_CHECK_EQUAL(metadata.error_code, uhd::rx_metadata_t::ERROR_CODE_NONE); BOOST_CHECK(not metadata.more_fragments); @@ -722,9 +700,7 @@ BOOST_AUTO_TEST_CASE(test_sph_recv_multi_channel_fragment){ for (size_t i = 0; i < 3; i++){ std::cout << "timeout check " << i << std::endl; handler.recv( - buffs, NUM_SAMPS_PER_BUFF, metadata, - uhd::io_type_t::COMPLEX_FLOAT32, - uhd::device::RECV_MODE_ONE_PACKET, 1.0 + buffs, NUM_SAMPS_PER_BUFF, metadata, 1.0 ); BOOST_CHECK_EQUAL(metadata.error_code, uhd::rx_metadata_t::ERROR_CODE_TIMEOUT); } diff --git a/host/tests/sph_send_test.cpp b/host/tests/sph_send_test.cpp index ed2f54371..9a91008af 100644 --- a/host/tests/sph_send_test.cpp +++ b/host/tests/sph_send_test.cpp @@ -55,18 +55,18 @@ private: **********************************************************************/ class dummy_send_xport_class{ public: - dummy_send_xport_class(const uhd::otw_type_t &otw_type){ - _otw_type = otw_type; + dummy_send_xport_class(const std::string &end){ + _end = end; } void pop_front_packet( uhd::transport::vrt::if_packet_info_t &ifpi ){ ifpi.num_packet_words32 = _lens.front()/sizeof(boost::uint32_t); - if (_otw_type.byteorder == uhd::otw_type_t::BO_BIG_ENDIAN){ + if (_end == "big"){ uhd::transport::vrt::if_hdr_unpack_be(reinterpret_cast(_mems.front().get()), ifpi); } - if (_otw_type.byteorder == uhd::otw_type_t::BO_LITTLE_ENDIAN){ + if (_end == "little"){ uhd::transport::vrt::if_hdr_unpack_le(reinterpret_cast(_mems.front().get()), ifpi); } _mems.pop_front(); @@ -85,18 +85,19 @@ private: std::list > _mems; std::list _lens; std::list _msbs; //list means no-realloc - uhd::otw_type_t _otw_type; + std::string _end; }; //////////////////////////////////////////////////////////////////////// BOOST_AUTO_TEST_CASE(test_sph_send_one_channel_one_packet_mode){ //////////////////////////////////////////////////////////////////////// - uhd::otw_type_t otw_type; - otw_type.width = 16; - otw_type.shift = 0; - otw_type.byteorder = uhd::otw_type_t::BO_BIG_ENDIAN; + uhd::convert::id_type id; + id.input_markup = "fc32"; + id.num_inputs = 1; + id.output_markup = "sc16_item32_be"; + id.num_outputs = 1; - dummy_send_xport_class dummy_send_xport(otw_type); + dummy_send_xport_class dummy_send_xport("big"); static const double TICK_RATE = 100e6; static const double SAMP_RATE = 10e6; @@ -108,7 +109,7 @@ BOOST_AUTO_TEST_CASE(test_sph_send_one_channel_one_packet_mode){ handler.set_tick_rate(TICK_RATE); handler.set_samp_rate(SAMP_RATE); handler.set_xport_chan_get_buff(0, boost::bind(&dummy_send_xport_class::get_send_buff, &dummy_send_xport, _1)); - handler.set_converter(otw_type); + handler.set_converter(id); handler.set_max_samples_per_packet(20); //allocate metadata and buffer @@ -122,9 +123,7 @@ BOOST_AUTO_TEST_CASE(test_sph_send_one_channel_one_packet_mode){ metadata.start_of_burst = (i == 0); metadata.end_of_burst = (i == NUM_PKTS_TO_TEST-1); const size_t num_sent = handler.send( - &buff.front(), 10 + i%10, metadata, - uhd::io_type_t::COMPLEX_FLOAT32, - uhd::device::SEND_MODE_ONE_PACKET, 1.0 + &buff.front(), 10 + i%10, metadata, 1.0 ); BOOST_CHECK_EQUAL(num_sent, 10 + i%10); metadata.time_spec += uhd::time_spec_t(0, num_sent, SAMP_RATE); @@ -150,12 +149,13 @@ BOOST_AUTO_TEST_CASE(test_sph_send_one_channel_one_packet_mode){ //////////////////////////////////////////////////////////////////////// BOOST_AUTO_TEST_CASE(test_sph_send_one_channel_full_buffer_mode){ //////////////////////////////////////////////////////////////////////// - uhd::otw_type_t otw_type; - otw_type.width = 16; - otw_type.shift = 0; - otw_type.byteorder = uhd::otw_type_t::BO_BIG_ENDIAN; + uhd::convert::id_type id; + id.input_markup = "fc32"; + id.num_inputs = 1; + id.output_markup = "sc16_item32_be"; + id.num_outputs = 1; - dummy_send_xport_class dummy_send_xport(otw_type); + dummy_send_xport_class dummy_send_xport("big"); static const double TICK_RATE = 100e6; static const double SAMP_RATE = 10e6; @@ -167,7 +167,7 @@ BOOST_AUTO_TEST_CASE(test_sph_send_one_channel_full_buffer_mode){ handler.set_tick_rate(TICK_RATE); handler.set_samp_rate(SAMP_RATE); handler.set_xport_chan_get_buff(0, boost::bind(&dummy_send_xport_class::get_send_buff, &dummy_send_xport, _1)); - handler.set_converter(otw_type); + handler.set_converter(id); handler.set_max_samples_per_packet(20); //allocate metadata and buffer @@ -180,9 +180,7 @@ BOOST_AUTO_TEST_CASE(test_sph_send_one_channel_full_buffer_mode){ //generate the test data const size_t num_sent = handler.send( - &buff.front(), buff.size(), metadata, - uhd::io_type_t::COMPLEX_FLOAT32, - uhd::device::SEND_MODE_FULL_BUFF, 1.0 + &buff.front(), buff.size(), metadata, 1.0 ); BOOST_CHECK_EQUAL(num_sent, buff.size()); -- cgit v1.2.3 From fce49fd66f577b92482af6ad516944befa31b861 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Tue, 11 Oct 2011 10:29:33 -0700 Subject: uhd: added one packet mode to rx streamer --- host/include/uhd/stream.hpp | 10 +++++-- host/lib/transport/super_recv_packet_handler.hpp | 14 +++++----- host/lib/transport/super_send_packet_handler.hpp | 6 ++--- host/lib/usrp/usrp1/io_impl.cpp | 18 +++++++++---- host/tests/sph_recv_test.cpp | 33 ++++++++++++------------ 5 files changed, 47 insertions(+), 34 deletions(-) (limited to 'host/tests') diff --git a/host/include/uhd/stream.hpp b/host/include/uhd/stream.hpp index 7a3151276..c86463184 100644 --- a/host/include/uhd/stream.hpp +++ b/host/include/uhd/stream.hpp @@ -123,17 +123,23 @@ public: * Under a timeout condition, the number of samples returned * may be less than the number of samples specified. * + * The one_packet option allows the user to guarantee that + * the call will return after a single packet has been processed. + * This may be useful to maintain packet boundaries in some cases. + * * \param buffs a vector of writable memory to fill with samples * \param nsamps_per_buff the size of each buffer in number of samples * \param metadata data to fill describing the buffer * \param timeout the timeout in seconds to wait for a packet + * \param one_packet return after the first packet is received * \return the number of samples received or 0 on error */ virtual size_t recv( const buffs_type &buffs, const size_t nsamps_per_buff, rx_metadata_t &metadata, - double timeout = 0.1 + const double timeout = 0.1, + const bool one_packet = false ) = 0; }; @@ -180,7 +186,7 @@ public: const buffs_type &buffs, const size_t nsamps_per_buff, const tx_metadata_t &metadata, - double timeout = 0.1 + const double timeout = 0.1 ) = 0; }; diff --git a/host/lib/transport/super_recv_packet_handler.hpp b/host/lib/transport/super_recv_packet_handler.hpp index 83c8988e8..6762a8a00 100644 --- a/host/lib/transport/super_recv_packet_handler.hpp +++ b/host/lib/transport/super_recv_packet_handler.hpp @@ -148,7 +148,8 @@ public: const uhd::rx_streamer::buffs_type &buffs, const size_t nsamps_per_buff, uhd::rx_metadata_t &metadata, - double timeout + const double timeout, + const bool one_packet ){ //handle metadata queued from a previous receive if (_queue_error_for_next_call){ @@ -163,9 +164,7 @@ public: buffs, nsamps_per_buff, metadata, timeout ); - #ifdef SRPH_TEST_MODE_ONE_PACKET - return accum_num_samps; - #endif + if (one_packet) return accum_num_samps; //first recv had an error code set, return immediately if (metadata.error_code != rx_metadata_t::ERROR_CODE_NONE) return accum_num_samps; @@ -493,7 +492,7 @@ private: const uhd::rx_streamer::buffs_type &buffs, const size_t nsamps_per_buff, uhd::rx_metadata_t &metadata, - double timeout, + const double timeout, const size_t buffer_offset_bytes = 0 ){ //get the next buffer if the current one has expired @@ -571,9 +570,10 @@ public: const rx_streamer::buffs_type &buffs, const size_t nsamps_per_buff, uhd::rx_metadata_t &metadata, - double timeout + const double timeout, + const bool one_packet ){ - return recv_packet_handler::recv(buffs, nsamps_per_buff, metadata, timeout); + return recv_packet_handler::recv(buffs, nsamps_per_buff, metadata, timeout, one_packet); } private: diff --git a/host/lib/transport/super_send_packet_handler.hpp b/host/lib/transport/super_send_packet_handler.hpp index 1ac178ad2..5b5ee2981 100644 --- a/host/lib/transport/super_send_packet_handler.hpp +++ b/host/lib/transport/super_send_packet_handler.hpp @@ -128,7 +128,7 @@ public: const uhd::tx_streamer::buffs_type &buffs, const size_t nsamps_per_buff, const uhd::tx_metadata_t &metadata, - double timeout + const double timeout ){ //translate the metadata to vrt if packet info vrt::if_packet_info_t if_packet_info; @@ -215,7 +215,7 @@ private: const uhd::tx_streamer::buffs_type &buffs, const size_t nsamps_per_buff, vrt::if_packet_info_t &if_packet_info, - double timeout, + const double timeout, const size_t buffer_offset_bytes = 0 ){ //load the rest of the if_packet_info in here @@ -269,7 +269,7 @@ public: const tx_streamer::buffs_type &buffs, const size_t nsamps_per_buff, const uhd::tx_metadata_t &metadata, - double timeout + const double timeout ){ return send_packet_handler::send(buffs, nsamps_per_buff, metadata, timeout); } diff --git a/host/lib/usrp/usrp1/io_impl.cpp b/host/lib/usrp/usrp1/io_impl.cpp index c199e4178..a0fdfc6bf 100644 --- a/host/lib/usrp/usrp1/io_impl.cpp +++ b/host/lib/usrp/usrp1/io_impl.cpp @@ -325,13 +325,14 @@ public: const rx_streamer::buffs_type &buffs, const size_t nsamps_per_buff, uhd::rx_metadata_t &metadata, - double timeout + const double timeout, + const bool one_packet ){ //interleave a "soft" inline message into the receive stream: if (_stc->get_inline_queue().pop_with_haste(metadata)) return 0; size_t num_samps_recvd = sph::recv_packet_handler::recv( - buffs, nsamps_per_buff, metadata, timeout + buffs, nsamps_per_buff, metadata, timeout, one_packet ); return _stc->recv_post(metadata, num_samps_recvd); @@ -366,8 +367,9 @@ public: const tx_streamer::buffs_type &buffs, const size_t nsamps_per_buff, const uhd::tx_metadata_t &metadata, - double timeout + const double timeout_ ){ + double timeout = timeout_; //rw copy _stc->send_pre(metadata, timeout); _tx_enb_fcn(true); //always enable (it will do the right thing) @@ -545,7 +547,10 @@ rx_streamer::sptr usrp1_impl::get_rx_stream(const uhd::stream_args_t &args_){ //setup defaults for unspecified values args.otw_format = args.otw_format.empty()? "sc16" : args.otw_format; - args.channels = args.channels.empty()? std::vector(1, 0) : args.channels; + args.channels.clear(); //NOTE: we have no choice about the channel mapping + for (size_t ch = 0; ch < _rx_subdev_spec.size(); ch++){ + args.channels.push_back(ch); + } if (args.otw_format == "sc16"){ _iface->poke32(FR_RX_FORMAT, 0 @@ -610,7 +615,10 @@ tx_streamer::sptr usrp1_impl::get_tx_stream(const uhd::stream_args_t &args_){ //setup defaults for unspecified values args.otw_format = args.otw_format.empty()? "sc16" : args.otw_format; - args.channels = args.channels.empty()? std::vector(1, 0) : args.channels; + args.channels.clear(); //NOTE: we have no choice about the channel mapping + for (size_t ch = 0; ch < _tx_subdev_spec.size(); ch++){ + args.channels.push_back(ch); + } if (args.otw_format != "sc16"){ throw uhd::value_error("USRP1 TX cannot handle requested wire format: " + args.otw_format); diff --git a/host/tests/sph_recv_test.cpp b/host/tests/sph_recv_test.cpp index 3ca123ef2..6fab2ad5f 100644 --- a/host/tests/sph_recv_test.cpp +++ b/host/tests/sph_recv_test.cpp @@ -16,7 +16,6 @@ // #include -#define SRPH_TEST_MODE_ONE_PACKET #include "../lib/transport/super_recv_packet_handler.hpp" #include #include @@ -155,7 +154,7 @@ BOOST_AUTO_TEST_CASE(test_sph_recv_one_channel_normal){ for (size_t i = 0; i < NUM_PKTS_TO_TEST; i++){ std::cout << "data check " << i << std::endl; size_t num_samps_ret = handler.recv( - &buff.front(), buff.size(), metadata, 1.0 + &buff.front(), buff.size(), metadata, 1.0, true ); BOOST_CHECK_EQUAL(metadata.error_code, uhd::rx_metadata_t::ERROR_CODE_NONE); BOOST_CHECK(not metadata.more_fragments); @@ -169,7 +168,7 @@ BOOST_AUTO_TEST_CASE(test_sph_recv_one_channel_normal){ for (size_t i = 0; i < 3; i++){ std::cout << "timeout check " << i << std::endl; handler.recv( - &buff.front(), buff.size(), metadata, 1.0 + &buff.front(), buff.size(), metadata, 1.0, true ); BOOST_CHECK_EQUAL(metadata.error_code, uhd::rx_metadata_t::ERROR_CODE_TIMEOUT); } @@ -228,7 +227,7 @@ BOOST_AUTO_TEST_CASE(test_sph_recv_one_channel_sequence_error){ for (size_t i = 0; i < NUM_PKTS_TO_TEST; i++){ std::cout << "data check " << i << std::endl; size_t num_samps_ret = handler.recv( - &buff.front(), buff.size(), metadata, 1.0 + &buff.front(), buff.size(), metadata, 1.0, true ); if (i == NUM_PKTS_TO_TEST/2){ //must get the soft overflow here @@ -250,7 +249,7 @@ BOOST_AUTO_TEST_CASE(test_sph_recv_one_channel_sequence_error){ for (size_t i = 0; i < 3; i++){ std::cout << "timeout check " << i << std::endl; handler.recv( - &buff.front(), buff.size(), metadata, 1.0 + &buff.front(), buff.size(), metadata, 1.0, true ); BOOST_CHECK_EQUAL(metadata.error_code, uhd::rx_metadata_t::ERROR_CODE_TIMEOUT); } @@ -319,7 +318,7 @@ BOOST_AUTO_TEST_CASE(test_sph_recv_one_channel_inline_message){ for (size_t i = 0; i < NUM_PKTS_TO_TEST; i++){ std::cout << "data check " << i << std::endl; size_t num_samps_ret = handler.recv( - &buff.front(), buff.size(), metadata, 1.0 + &buff.front(), buff.size(), metadata, 1.0, true ); BOOST_CHECK_EQUAL(metadata.error_code, uhd::rx_metadata_t::ERROR_CODE_NONE); BOOST_CHECK(not metadata.more_fragments); @@ -329,7 +328,7 @@ BOOST_AUTO_TEST_CASE(test_sph_recv_one_channel_inline_message){ num_accum_samps += num_samps_ret; if (i == NUM_PKTS_TO_TEST/2){ handler.recv( - &buff.front(), buff.size(), metadata, 1.0 + &buff.front(), buff.size(), metadata, 1.0, true ); std::cout << "metadata.error_code " << metadata.error_code << std::endl; BOOST_REQUIRE(metadata.error_code == uhd::rx_metadata_t::ERROR_CODE_OVERFLOW); @@ -342,7 +341,7 @@ BOOST_AUTO_TEST_CASE(test_sph_recv_one_channel_inline_message){ for (size_t i = 0; i < 3; i++){ std::cout << "timeout check " << i << std::endl; handler.recv( - &buff.front(), buff.size(), metadata, 1.0 + &buff.front(), buff.size(), metadata, 1.0, true ); BOOST_CHECK_EQUAL(metadata.error_code, uhd::rx_metadata_t::ERROR_CODE_TIMEOUT); } @@ -410,7 +409,7 @@ BOOST_AUTO_TEST_CASE(test_sph_recv_multi_channel_normal){ for (size_t i = 0; i < NUM_PKTS_TO_TEST; i++){ std::cout << "data check " << i << std::endl; size_t num_samps_ret = handler.recv( - buffs, NUM_SAMPS_PER_BUFF, metadata, 1.0 + buffs, NUM_SAMPS_PER_BUFF, metadata, 1.0, true ); BOOST_CHECK_EQUAL(metadata.error_code, uhd::rx_metadata_t::ERROR_CODE_NONE); BOOST_CHECK(not metadata.more_fragments); @@ -424,7 +423,7 @@ BOOST_AUTO_TEST_CASE(test_sph_recv_multi_channel_normal){ for (size_t i = 0; i < 3; i++){ std::cout << "timeout check " << i << std::endl; handler.recv( - buffs, NUM_SAMPS_PER_BUFF, metadata, 1.0 + buffs, NUM_SAMPS_PER_BUFF, metadata, 1.0, true ); BOOST_CHECK_EQUAL(metadata.error_code, uhd::rx_metadata_t::ERROR_CODE_TIMEOUT); } @@ -496,7 +495,7 @@ BOOST_AUTO_TEST_CASE(test_sph_recv_multi_channel_sequence_error){ for (size_t i = 0; i < NUM_PKTS_TO_TEST; i++){ std::cout << "data check " << i << std::endl; size_t num_samps_ret = handler.recv( - buffs, NUM_SAMPS_PER_BUFF, metadata, 1.0 + buffs, NUM_SAMPS_PER_BUFF, metadata, 1.0, true ); if (i == NUM_PKTS_TO_TEST/2){ //must get the soft overflow here @@ -518,7 +517,7 @@ BOOST_AUTO_TEST_CASE(test_sph_recv_multi_channel_sequence_error){ for (size_t i = 0; i < 3; i++){ std::cout << "timeout check " << i << std::endl; handler.recv( - buffs, NUM_SAMPS_PER_BUFF, metadata, 1.0 + buffs, NUM_SAMPS_PER_BUFF, metadata, 1.0, true ); BOOST_CHECK_EQUAL(metadata.error_code, uhd::rx_metadata_t::ERROR_CODE_TIMEOUT); } @@ -589,7 +588,7 @@ BOOST_AUTO_TEST_CASE(test_sph_recv_multi_channel_time_error){ for (size_t i = 0; i < NUM_PKTS_TO_TEST; i++){ std::cout << "data check " << i << std::endl; size_t num_samps_ret = handler.recv( - buffs, NUM_SAMPS_PER_BUFF, metadata, 1.0 + buffs, NUM_SAMPS_PER_BUFF, metadata, 1.0, true ); BOOST_CHECK_EQUAL(metadata.error_code, uhd::rx_metadata_t::ERROR_CODE_NONE); BOOST_CHECK(not metadata.more_fragments); @@ -606,7 +605,7 @@ BOOST_AUTO_TEST_CASE(test_sph_recv_multi_channel_time_error){ for (size_t i = 0; i < 3; i++){ std::cout << "timeout check " << i << std::endl; handler.recv( - buffs, NUM_SAMPS_PER_BUFF, metadata, 1.0 + buffs, NUM_SAMPS_PER_BUFF, metadata, 1.0, true ); BOOST_CHECK_EQUAL(metadata.error_code, uhd::rx_metadata_t::ERROR_CODE_TIMEOUT); } @@ -674,7 +673,7 @@ BOOST_AUTO_TEST_CASE(test_sph_recv_multi_channel_fragment){ for (size_t i = 0; i < NUM_PKTS_TO_TEST; i++){ std::cout << "data check " << i << std::endl; size_t num_samps_ret = handler.recv( - buffs, NUM_SAMPS_PER_BUFF, metadata, 1.0 + buffs, NUM_SAMPS_PER_BUFF, metadata, 1.0, true ); BOOST_CHECK_EQUAL(metadata.error_code, uhd::rx_metadata_t::ERROR_CODE_NONE); BOOST_CHECK(metadata.has_time_spec); @@ -685,7 +684,7 @@ BOOST_AUTO_TEST_CASE(test_sph_recv_multi_channel_fragment){ if (not metadata.more_fragments) continue; num_samps_ret = handler.recv( - buffs, NUM_SAMPS_PER_BUFF, metadata, 1.0 + buffs, NUM_SAMPS_PER_BUFF, metadata, 1.0, true ); BOOST_CHECK_EQUAL(metadata.error_code, uhd::rx_metadata_t::ERROR_CODE_NONE); BOOST_CHECK(not metadata.more_fragments); @@ -700,7 +699,7 @@ BOOST_AUTO_TEST_CASE(test_sph_recv_multi_channel_fragment){ for (size_t i = 0; i < 3; i++){ std::cout << "timeout check " << i << std::endl; handler.recv( - buffs, NUM_SAMPS_PER_BUFF, metadata, 1.0 + buffs, NUM_SAMPS_PER_BUFF, metadata, 1.0, true ); BOOST_CHECK_EQUAL(metadata.error_code, uhd::rx_metadata_t::ERROR_CODE_TIMEOUT); } -- cgit v1.2.3 From c885da11389ee275f9c5206b9f8a2155a5393a8a Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Wed, 12 Oct 2011 00:39:04 -0700 Subject: uhd: renamed convert markup to format removed convert args added simd level got orc and neon updated --- host/include/uhd/convert.hpp | 16 ++++----- host/lib/convert/convert_common.hpp | 16 ++++----- host/lib/convert/convert_fc32_with_sse2.cpp | 8 ++--- host/lib/convert/convert_fc64_with_sse2.cpp | 8 ++--- host/lib/convert/convert_impl.cpp | 37 +++++++++----------- host/lib/convert/convert_with_neon.cpp | 8 ++--- host/lib/convert/convert_with_orc.cpp | 12 +++---- host/lib/transport/super_recv_packet_handler.hpp | 4 +-- host/lib/transport/super_send_packet_handler.hpp | 4 +-- host/lib/usrp/b100/io_impl.cpp | 10 +++--- host/lib/usrp/e100/io_impl.cpp | 10 +++--- host/lib/usrp/usrp1/io_impl.cpp | 10 +++--- host/lib/usrp/usrp2/io_impl.cpp | 10 +++--- host/tests/convert_test.cpp | 44 ++++++++++++------------ host/tests/sph_recv_test.cpp | 28 +++++++-------- host/tests/sph_send_test.cpp | 8 ++--- 16 files changed, 110 insertions(+), 123 deletions(-) (limited to 'host/tests') diff --git a/host/include/uhd/convert.hpp b/host/include/uhd/convert.hpp index a0b502ab0..c42edfdec 100644 --- a/host/include/uhd/convert.hpp +++ b/host/include/uhd/convert.hpp @@ -42,17 +42,17 @@ namespace uhd{ namespace convert{ enum priority_type{ PRIORITY_GENERAL = 0, PRIORITY_LIBORC = 1, - PRIORITY_CUSTOM = 2, + PRIORITY_SIMD = 2, + PRIORITY_CUSTOM = 3, PRIORITY_EMPTY = -1, }; //! Identify a conversion routine in the registry struct id_type : boost::equality_comparable{ - std::string input_markup; + std::string input_format; size_t num_inputs; - std::string output_markup; + std::string output_format; size_t num_outputs; - std::string args; std::string to_pp_string(void) const; }; @@ -80,15 +80,15 @@ namespace uhd{ namespace convert{ /*! * Register the size of a particular item. - * \param markup the item markup + * \param format the item format * \param size the size in bytes */ UHD_API void register_bytes_per_item( - const std::string &markup, const size_t size + const std::string &format, const size_t size ); - //! Convert an item markup to a size in bytes - UHD_API size_t get_bytes_per_item(const std::string &markup); + //! Convert an item format to a size in bytes + UHD_API size_t get_bytes_per_item(const std::string &format); }} //namespace diff --git a/host/lib/convert/convert_common.hpp b/host/lib/convert/convert_common.hpp index 56b718292..34fb848c3 100644 --- a/host/lib/convert/convert_common.hpp +++ b/host/lib/convert/convert_common.hpp @@ -23,30 +23,28 @@ #include #include -#define _DECLARE_CONVERTER(fcn, in_mark, num_in, out_mark, num_out, prio) \ +#define _DECLARE_CONVERTER(fcn, in_form, num_in, out_form, num_out, prio) \ static void fcn( \ const uhd::convert::input_type &inputs, \ const uhd::convert::output_type &outputs, \ - const size_t nsamps, \ - const double scale_factor \ + const size_t nsamps, const double scale_factor \ ); \ UHD_STATIC_BLOCK(__register_##fcn##_##prio){ \ uhd::convert::id_type id; \ - id.input_markup = #in_mark; \ + id.input_format = #in_form; \ id.num_inputs = num_in; \ - id.output_markup = #out_mark; \ + id.output_format = #out_form; \ id.num_outputs = num_out; \ uhd::convert::register_converter(id, fcn, prio); \ } \ static void fcn( \ const uhd::convert::input_type &inputs, \ const uhd::convert::output_type &outputs, \ - const size_t nsamps, \ - const double scale_factor \ + const size_t nsamps, const double scale_factor \ ) -#define DECLARE_CONVERTER(in_mark, num_in, out_mark, num_out, prio) \ - _DECLARE_CONVERTER(__convert_##in_mark##_##num_in##_##out_mark##_##num_out, in_mark, num_in, out_mark, num_out, prio) +#define DECLARE_CONVERTER(in_form, num_in, out_form, num_out, prio) \ + _DECLARE_CONVERTER(__convert_##in_form##_##num_in##_##out_form##_##num_out, in_form, num_in, out_form, num_out, prio) /*********************************************************************** * Typedefs diff --git a/host/lib/convert/convert_fc32_with_sse2.cpp b/host/lib/convert/convert_fc32_with_sse2.cpp index b8d1aa8cc..24a939d6c 100644 --- a/host/lib/convert/convert_fc32_with_sse2.cpp +++ b/host/lib/convert/convert_fc32_with_sse2.cpp @@ -21,7 +21,7 @@ using namespace uhd::convert; -DECLARE_CONVERTER(fc32, 1, sc16_item32_le, 1, PRIORITY_CUSTOM){ +DECLARE_CONVERTER(fc32, 1, sc16_item32_le, 1, PRIORITY_SIMD){ const fc32_t *input = reinterpret_cast(inputs[0]); item32_t *output = reinterpret_cast(outputs[0]); @@ -64,7 +64,7 @@ DECLARE_CONVERTER(fc32, 1, sc16_item32_le, 1, PRIORITY_CUSTOM){ } } -DECLARE_CONVERTER(fc32, 1, sc16_item32_be, 1, PRIORITY_CUSTOM){ +DECLARE_CONVERTER(fc32, 1, sc16_item32_be, 1, PRIORITY_SIMD){ const fc32_t *input = reinterpret_cast(inputs[0]); item32_t *output = reinterpret_cast(outputs[0]); @@ -106,7 +106,7 @@ DECLARE_CONVERTER(fc32, 1, sc16_item32_be, 1, PRIORITY_CUSTOM){ } } -DECLARE_CONVERTER(sc16_item32_le, 1, fc32, 1, PRIORITY_CUSTOM){ +DECLARE_CONVERTER(sc16_item32_le, 1, fc32, 1, PRIORITY_SIMD){ const item32_t *input = reinterpret_cast(inputs[0]); fc32_t *output = reinterpret_cast(outputs[0]); @@ -151,7 +151,7 @@ DECLARE_CONVERTER(sc16_item32_le, 1, fc32, 1, PRIORITY_CUSTOM){ } } -DECLARE_CONVERTER(sc16_item32_be, 1, fc32, 1, PRIORITY_CUSTOM){ +DECLARE_CONVERTER(sc16_item32_be, 1, fc32, 1, PRIORITY_SIMD){ const item32_t *input = reinterpret_cast(inputs[0]); fc32_t *output = reinterpret_cast(outputs[0]); diff --git a/host/lib/convert/convert_fc64_with_sse2.cpp b/host/lib/convert/convert_fc64_with_sse2.cpp index a4f2df2e7..837bb584e 100644 --- a/host/lib/convert/convert_fc64_with_sse2.cpp +++ b/host/lib/convert/convert_fc64_with_sse2.cpp @@ -21,7 +21,7 @@ using namespace uhd::convert; -DECLARE_CONVERTER(fc64, 1, sc16_item32_le, 1, PRIORITY_CUSTOM){ +DECLARE_CONVERTER(fc64, 1, sc16_item32_le, 1, PRIORITY_SIMD){ const fc64_t *input = reinterpret_cast(inputs[0]); item32_t *output = reinterpret_cast(outputs[0]); @@ -68,7 +68,7 @@ DECLARE_CONVERTER(fc64, 1, sc16_item32_le, 1, PRIORITY_CUSTOM){ } } -DECLARE_CONVERTER(fc64, 1, sc16_item32_be, 1, PRIORITY_CUSTOM){ +DECLARE_CONVERTER(fc64, 1, sc16_item32_be, 1, PRIORITY_SIMD){ const fc64_t *input = reinterpret_cast(inputs[0]); item32_t *output = reinterpret_cast(outputs[0]); @@ -114,7 +114,7 @@ DECLARE_CONVERTER(fc64, 1, sc16_item32_be, 1, PRIORITY_CUSTOM){ } } -DECLARE_CONVERTER(sc16_item32_le, 1, fc64, 1, PRIORITY_CUSTOM){ +DECLARE_CONVERTER(sc16_item32_le, 1, fc64, 1, PRIORITY_SIMD){ const item32_t *input = reinterpret_cast(inputs[0]); fc64_t *output = reinterpret_cast(outputs[0]); @@ -163,7 +163,7 @@ DECLARE_CONVERTER(sc16_item32_le, 1, fc64, 1, PRIORITY_CUSTOM){ } } -DECLARE_CONVERTER(sc16_item32_be, 1, fc64, 1, PRIORITY_CUSTOM){ +DECLARE_CONVERTER(sc16_item32_be, 1, fc64, 1, PRIORITY_SIMD){ const item32_t *input = reinterpret_cast(inputs[0]); fc64_t *output = reinterpret_cast(outputs[0]); diff --git a/host/lib/convert/convert_impl.cpp b/host/lib/convert/convert_impl.cpp index 280957c2a..df03b44f9 100644 --- a/host/lib/convert/convert_impl.cpp +++ b/host/lib/convert/convert_impl.cpp @@ -27,29 +27,26 @@ using namespace uhd; bool convert::operator==(const convert::id_type &lhs, const convert::id_type &rhs){ - return - (lhs.input_markup == rhs.input_markup) and - (lhs.num_inputs == rhs.num_inputs) and - (lhs.output_markup == rhs.output_markup) and - (lhs.num_outputs == rhs.num_outputs) and - (lhs.args == rhs.args) + return true + and (lhs.input_format == rhs.input_format) + and (lhs.num_inputs == rhs.num_inputs) + and (lhs.output_format == rhs.output_format) + and (lhs.num_outputs == rhs.num_outputs) ; } std::string convert::id_type::to_pp_string(void) const{ return str(boost::format( "conversion ID\n" - " Input markup: %s\n" + " Input format: %s\n" " Num inputs: %d\n" - " Output markup: %s\n" + " Output format: %s\n" " Num outputs: %d\n" - " Optional args: %s\n" ) - % this->input_markup + % this->input_format % this->num_inputs - % this->output_markup + % this->output_format % this->num_outputs - % this->args ); } @@ -101,30 +98,30 @@ convert::function_type convert::get_converter(const id_type &id){ } /*********************************************************************** - * Mappings for item markup to byte size for all items we can + * Mappings for item format to byte size for all items we can **********************************************************************/ typedef uhd::dict item_size_type; UHD_SINGLETON_FCN(item_size_type, get_item_size_table); void register_bytes_per_item( - const std::string &markup, const size_t size + const std::string &format, const size_t size ){ - get_item_size_table()[markup] = size; + get_item_size_table()[format] = size; } -size_t convert::get_bytes_per_item(const std::string &markup){ - if (get_item_size_table().has_key(markup)) return get_item_size_table()[markup]; +size_t convert::get_bytes_per_item(const std::string &format){ + if (get_item_size_table().has_key(format)) return get_item_size_table()[format]; //OK. I am sorry about this. //We didnt find a match, so lets find a match for the first term. //This is partially a hack because of the way I append strings. //But as long as life is kind, we can keep this. - const size_t pos = markup.find("_"); + const size_t pos = format.find("_"); if (pos != std::string::npos){ - return get_bytes_per_item(markup.substr(0, pos)); + return get_bytes_per_item(format.substr(0, pos)); } - throw uhd::key_error("Cannot find an item size:\n" + markup); + throw uhd::key_error("Cannot find an item size:\n" + format); } UHD_STATIC_BLOCK(convert_register_item_sizes){ diff --git a/host/lib/convert/convert_with_neon.cpp b/host/lib/convert/convert_with_neon.cpp index e5f08cad9..c7ad62104 100644 --- a/host/lib/convert/convert_with_neon.cpp +++ b/host/lib/convert/convert_with_neon.cpp @@ -20,7 +20,7 @@ using namespace uhd::convert; -DECLARE_CONVERTER(convert_fc32_1_to_item32_1_nswap, PRIORITY_CUSTOM){ +DECLARE_CONVERTER(fc32, 1, sc16_item32_le, 1, PRIORITY_SIMD){ const fc32_t *input = reinterpret_cast(inputs[0]); item32_t *output = reinterpret_cast(outputs[0]); @@ -37,10 +37,10 @@ DECLARE_CONVERTER(convert_fc32_1_to_item32_1_nswap, PRIORITY_CUSTOM){ } for (; i < nsamps; i++) - output[i] = fc32_to_item32(input[i], float(scale_factor)); + output[i] = fc32_to_item32_sc16(input[i], scale_factor); } -DECLARE_CONVERTER(convert_item32_1_to_fc32_1_nswap, PRIORITY_CUSTOM){ +DECLARE_CONVERTER(sc16_item32_le, 1, fc32, 1, PRIORITY_SIMD){ const item32_t *input = reinterpret_cast(inputs[0]); fc32_t *output = reinterpret_cast(outputs[0]); @@ -57,5 +57,5 @@ DECLARE_CONVERTER(convert_item32_1_to_fc32_1_nswap, PRIORITY_CUSTOM){ } for (; i < nsamps; i++) - output[i] = item32_to_fc32(input[i], float(scale_factor)); + output[i] = item32_sc16_to_fc32(input[i], scale_factor); } diff --git a/host/lib/convert/convert_with_orc.cpp b/host/lib/convert/convert_with_orc.cpp index 844c2595c..0c46bcf1e 100644 --- a/host/lib/convert/convert_with_orc.cpp +++ b/host/lib/convert/convert_with_orc.cpp @@ -29,26 +29,26 @@ extern void _convert_sc16_1_to_item32_1_nswap_orc(void *, const void *, float, i extern void _convert_item32_1_to_sc16_1_nswap_orc(void *, const void *, float, int); } -DECLARE_CONVERTER(convert_fc32_1_to_item32_1_nswap, PRIORITY_LIBORC){ +DECLARE_CONVERTER(fc32, 1, sc16_item32_le, 1, PRIORITY_LIBORC){ _convert_fc32_1_to_item32_1_nswap_orc(outputs[0], inputs[0], scale_factor, nsamps); } -DECLARE_CONVERTER(convert_fc32_1_to_item32_1_bswap, PRIORITY_LIBORC){ +DECLARE_CONVERTER(fc32, 1, sc16_item32_be, 1, PRIORITY_LIBORC){ _convert_fc32_1_to_item32_1_bswap_orc(outputs[0], inputs[0], scale_factor, nsamps); } -DECLARE_CONVERTER(convert_item32_1_to_fc32_1_nswap, PRIORITY_LIBORC){ +DECLARE_CONVERTER(sc16_item32_le, 1, fc32, 1, PRIORITY_LIBORC){ _convert_item32_1_to_fc32_1_nswap_orc(outputs[0], inputs[0], scale_factor, nsamps); } -DECLARE_CONVERTER(convert_item32_1_to_fc32_1_bswap, PRIORITY_LIBORC){ +DECLARE_CONVERTER(sc16_item32_be, 1, fc32, 1, PRIORITY_LIBORC){ _convert_item32_1_to_fc32_1_bswap_orc(outputs[0], inputs[0], scale_factor, nsamps); } -DECLARE_CONVERTER(convert_sc16_1_to_item32_1_nswap, PRIORITY_LIBORC){ +DECLARE_CONVERTER(sc16, 1, sc16_item32_le, 1, PRIORITY_LIBORC){ _convert_sc16_1_to_item32_1_nswap_orc(outputs[0], inputs[0], scale_factor, nsamps); } -DECLARE_CONVERTER(convert_item32_1_to_sc16_1_nswap, PRIORITY_LIBORC){ +DECLARE_CONVERTER(sc16_item32_le, 1, sc16, 1, PRIORITY_LIBORC){ _convert_item32_1_to_sc16_1_nswap_orc(outputs[0], inputs[0], scale_factor, nsamps); } diff --git a/host/lib/transport/super_recv_packet_handler.hpp b/host/lib/transport/super_recv_packet_handler.hpp index 6762a8a00..2310d6aea 100644 --- a/host/lib/transport/super_recv_packet_handler.hpp +++ b/host/lib/transport/super_recv_packet_handler.hpp @@ -125,8 +125,8 @@ public: void set_converter(const uhd::convert::id_type &id){ _io_buffs.resize(id.num_outputs); _converter = uhd::convert::get_converter(id); - _bytes_per_otw_item = uhd::convert::get_bytes_per_item(id.input_markup); - _bytes_per_cpu_item = uhd::convert::get_bytes_per_item(id.output_markup); + _bytes_per_otw_item = uhd::convert::get_bytes_per_item(id.input_format); + _bytes_per_cpu_item = uhd::convert::get_bytes_per_item(id.output_format); } //! Set the transport channel's overflow handler diff --git a/host/lib/transport/super_send_packet_handler.hpp b/host/lib/transport/super_send_packet_handler.hpp index 5b5ee2981..779259d4f 100644 --- a/host/lib/transport/super_send_packet_handler.hpp +++ b/host/lib/transport/super_send_packet_handler.hpp @@ -101,8 +101,8 @@ public: void set_converter(const uhd::convert::id_type &id){ _io_buffs.resize(id.num_inputs); _converter = uhd::convert::get_converter(id); - _bytes_per_otw_item = uhd::convert::get_bytes_per_item(id.output_markup); - _bytes_per_cpu_item = uhd::convert::get_bytes_per_item(id.input_markup); + _bytes_per_otw_item = uhd::convert::get_bytes_per_item(id.output_format); + _bytes_per_cpu_item = uhd::convert::get_bytes_per_item(id.input_format); } /*! diff --git a/host/lib/usrp/b100/io_impl.cpp b/host/lib/usrp/b100/io_impl.cpp index 82298dca6..28b19f14e 100644 --- a/host/lib/usrp/b100/io_impl.cpp +++ b/host/lib/usrp/b100/io_impl.cpp @@ -218,11 +218,10 @@ rx_streamer::sptr b100_impl::get_rx_stream(const uhd::stream_args_t &args_){ //set the converter uhd::convert::id_type id; - id.input_markup = args.otw_format + "_item32_le"; + id.input_format = args.otw_format + "_item32_le"; id.num_inputs = 1; - id.output_markup = args.cpu_format; + id.output_format = args.cpu_format; id.num_outputs = 1; - id.args = args.args; my_streamer->set_converter(id); //bind callbacks for the handler @@ -276,11 +275,10 @@ tx_streamer::sptr b100_impl::get_tx_stream(const uhd::stream_args_t &args_){ //set the converter uhd::convert::id_type id; - id.input_markup = args.cpu_format; + id.input_format = args.cpu_format; id.num_inputs = 1; - id.output_markup = args.otw_format + "_item32_le"; + id.output_format = args.otw_format + "_item32_le"; id.num_outputs = 1; - id.args = args.args; my_streamer->set_converter(id); //bind callbacks for the handler diff --git a/host/lib/usrp/e100/io_impl.cpp b/host/lib/usrp/e100/io_impl.cpp index 5936ee2d7..c47eb8940 100644 --- a/host/lib/usrp/e100/io_impl.cpp +++ b/host/lib/usrp/e100/io_impl.cpp @@ -294,11 +294,10 @@ rx_streamer::sptr e100_impl::get_rx_stream(const uhd::stream_args_t &args_){ //set the converter uhd::convert::id_type id; - id.input_markup = args.otw_format + "_item32_le"; + id.input_format = args.otw_format + "_item32_le"; id.num_inputs = 1; - id.output_markup = args.cpu_format; + id.output_format = args.cpu_format; id.num_outputs = 1; - id.args = args.args; my_streamer->set_converter(id); //bind callbacks for the handler @@ -352,11 +351,10 @@ tx_streamer::sptr e100_impl::get_tx_stream(const uhd::stream_args_t &args_){ //set the converter uhd::convert::id_type id; - id.input_markup = args.cpu_format; + id.input_format = args.cpu_format; id.num_inputs = 1; - id.output_markup = args.otw_format + "_item32_le"; + id.output_format = args.otw_format + "_item32_le"; id.num_outputs = 1; - id.args = args.args; my_streamer->set_converter(id); //bind callbacks for the handler diff --git a/host/lib/usrp/usrp1/io_impl.cpp b/host/lib/usrp/usrp1/io_impl.cpp index f46f4741b..534d33959 100644 --- a/host/lib/usrp/usrp1/io_impl.cpp +++ b/host/lib/usrp/usrp1/io_impl.cpp @@ -600,11 +600,10 @@ rx_streamer::sptr usrp1_impl::get_rx_stream(const uhd::stream_args_t &args_){ //set the converter uhd::convert::id_type id; - id.input_markup = args.otw_format + "_item16_usrp1"; + id.input_format = args.otw_format + "_item16_usrp1"; id.num_inputs = 1; - id.output_markup = args.cpu_format; + id.output_format = args.cpu_format; id.num_outputs = args.channels.size(); - id.args = args.args; my_streamer->set_converter(id); //save as weak ptr for update access @@ -653,11 +652,10 @@ tx_streamer::sptr usrp1_impl::get_tx_stream(const uhd::stream_args_t &args_){ //set the converter uhd::convert::id_type id; - id.input_markup = args.cpu_format; + id.input_format = args.cpu_format; id.num_inputs = args.channels.size(); - id.output_markup = args.otw_format + "_item16_usrp1"; + id.output_format = args.otw_format + "_item16_usrp1"; id.num_outputs = 1; - id.args = args.args; my_streamer->set_converter(id); //save as weak ptr for update access diff --git a/host/lib/usrp/usrp2/io_impl.cpp b/host/lib/usrp/usrp2/io_impl.cpp index f1d0aee2a..660156285 100644 --- a/host/lib/usrp/usrp2/io_impl.cpp +++ b/host/lib/usrp/usrp2/io_impl.cpp @@ -391,11 +391,10 @@ rx_streamer::sptr usrp2_impl::get_rx_stream(const uhd::stream_args_t &args_){ //set the converter uhd::convert::id_type id; - id.input_markup = args.otw_format + "_item32_be"; + id.input_format = args.otw_format + "_item32_be"; id.num_inputs = 1; - id.output_markup = args.cpu_format; + id.output_format = args.cpu_format; id.num_outputs = 1; - id.args = args.args; my_streamer->set_converter(id); //bind callbacks for the handler @@ -459,11 +458,10 @@ tx_streamer::sptr usrp2_impl::get_tx_stream(const uhd::stream_args_t &args_){ //set the converter uhd::convert::id_type id; - id.input_markup = args.cpu_format; + id.input_format = args.cpu_format; id.num_inputs = 1; - id.output_markup = args.otw_format + "_item32_be"; + id.output_format = args.otw_format + "_item32_be"; id.num_outputs = 1; - id.args = args.args; my_streamer->set_converter(id); //bind callbacks for the handler diff --git a/host/tests/convert_test.cpp b/host/tests/convert_test.cpp index 9dabcf54e..b63ff6752 100644 --- a/host/tests/convert_test.cpp +++ b/host/tests/convert_test.cpp @@ -75,7 +75,7 @@ static void test_convert_types_sc16( //run the loopback and test convert::id_type in_id = id; convert::id_type out_id = id; - std::swap(out_id.input_markup, out_id.output_markup); + std::swap(out_id.input_format, out_id.output_format); std::swap(out_id.num_inputs, out_id.num_outputs); loopback(nsamps, in_id, out_id, input, output); BOOST_CHECK_EQUAL_COLLECTIONS(input.begin(), input.end(), output.begin(), output.end()); @@ -83,9 +83,9 @@ static void test_convert_types_sc16( BOOST_AUTO_TEST_CASE(test_convert_types_be_sc16){ convert::id_type id; - id.input_markup = "sc16"; + id.input_format = "sc16"; id.num_inputs = 1; - id.output_markup = "sc16_item32_be"; + id.output_format = "sc16_item32_be"; id.num_outputs = 1; //try various lengths to test edge cases @@ -96,9 +96,9 @@ BOOST_AUTO_TEST_CASE(test_convert_types_be_sc16){ BOOST_AUTO_TEST_CASE(test_convert_types_le_sc16){ convert::id_type id; - id.input_markup = "sc16"; + id.input_format = "sc16"; id.num_inputs = 1; - id.output_markup = "sc16_item32_le"; + id.output_format = "sc16_item32_le"; id.num_outputs = 1; //try various lengths to test edge cases @@ -126,7 +126,7 @@ static void test_convert_types_for_floats( //run the loopback and test convert::id_type in_id = id; convert::id_type out_id = id; - std::swap(out_id.input_markup, out_id.output_markup); + std::swap(out_id.input_format, out_id.output_format); std::swap(out_id.num_inputs, out_id.num_outputs); loopback(nsamps, in_id, out_id, input, output); for (size_t i = 0; i < nsamps; i++){ @@ -137,9 +137,9 @@ static void test_convert_types_for_floats( BOOST_AUTO_TEST_CASE(test_convert_types_be_fc32){ convert::id_type id; - id.input_markup = "fc32"; + id.input_format = "fc32"; id.num_inputs = 1; - id.output_markup = "sc16_item32_be"; + id.output_format = "sc16_item32_be"; id.num_outputs = 1; //try various lengths to test edge cases @@ -150,9 +150,9 @@ BOOST_AUTO_TEST_CASE(test_convert_types_be_fc32){ BOOST_AUTO_TEST_CASE(test_convert_types_le_fc32){ convert::id_type id; - id.input_markup = "fc32"; + id.input_format = "fc32"; id.num_inputs = 1; - id.output_markup = "sc16_item32_le"; + id.output_format = "sc16_item32_le"; id.num_outputs = 1; //try various lengths to test edge cases @@ -163,9 +163,9 @@ BOOST_AUTO_TEST_CASE(test_convert_types_le_fc32){ BOOST_AUTO_TEST_CASE(test_convert_types_be_fc64){ convert::id_type id; - id.input_markup = "fc64"; + id.input_format = "fc64"; id.num_inputs = 1; - id.output_markup = "sc16_item32_be"; + id.output_format = "sc16_item32_be"; id.num_outputs = 1; //try various lengths to test edge cases @@ -176,9 +176,9 @@ BOOST_AUTO_TEST_CASE(test_convert_types_be_fc64){ BOOST_AUTO_TEST_CASE(test_convert_types_le_fc64){ convert::id_type id; - id.input_markup = "fc64"; + id.input_format = "fc64"; id.num_inputs = 1; - id.output_markup = "sc16_item32_le"; + id.output_format = "sc16_item32_le"; id.num_outputs = 1; //try various lengths to test edge cases @@ -192,15 +192,15 @@ BOOST_AUTO_TEST_CASE(test_convert_types_le_fc64){ **********************************************************************/ BOOST_AUTO_TEST_CASE(test_convert_types_fc32_to_sc16){ convert::id_type in_id; - in_id.input_markup = "fc32"; + in_id.input_format = "fc32"; in_id.num_inputs = 1; - in_id.output_markup = "sc16_item32_le"; + in_id.output_format = "sc16_item32_le"; in_id.num_outputs = 1; convert::id_type out_id; - out_id.input_markup = "sc16_item32_le"; + out_id.input_format = "sc16_item32_le"; out_id.num_inputs = 1; - out_id.output_markup = "sc16"; + out_id.output_format = "sc16"; out_id.num_outputs = 1; const size_t nsamps = 13; @@ -233,15 +233,15 @@ BOOST_AUTO_TEST_CASE(test_convert_types_fc32_to_sc16){ **********************************************************************/ BOOST_AUTO_TEST_CASE(test_convert_types_sc16_to_fc32){ convert::id_type in_id; - in_id.input_markup = "sc16"; + in_id.input_format = "sc16"; in_id.num_inputs = 1; - in_id.output_markup = "sc16_item32_le"; + in_id.output_format = "sc16_item32_le"; in_id.num_outputs = 1; convert::id_type out_id; - out_id.input_markup = "sc16_item32_le"; + out_id.input_format = "sc16_item32_le"; out_id.num_inputs = 1; - out_id.output_markup = "fc32"; + out_id.output_format = "fc32"; out_id.num_outputs = 1; const size_t nsamps = 13; diff --git a/host/tests/sph_recv_test.cpp b/host/tests/sph_recv_test.cpp index 6fab2ad5f..85d06aa0d 100644 --- a/host/tests/sph_recv_test.cpp +++ b/host/tests/sph_recv_test.cpp @@ -107,9 +107,9 @@ private: BOOST_AUTO_TEST_CASE(test_sph_recv_one_channel_normal){ //////////////////////////////////////////////////////////////////////// uhd::convert::id_type id; - id.input_markup = "sc16_item32_be"; + id.input_format = "sc16_item32_be"; id.num_inputs = 1; - id.output_markup = "fc32"; + id.output_format = "fc32"; id.num_outputs = 1; dummy_recv_xport_class dummy_recv_xport("big"); @@ -178,9 +178,9 @@ BOOST_AUTO_TEST_CASE(test_sph_recv_one_channel_normal){ BOOST_AUTO_TEST_CASE(test_sph_recv_one_channel_sequence_error){ //////////////////////////////////////////////////////////////////////// uhd::convert::id_type id; - id.input_markup = "sc16_item32_be"; + id.input_format = "sc16_item32_be"; id.num_inputs = 1; - id.output_markup = "fc32"; + id.output_format = "fc32"; id.num_outputs = 1; dummy_recv_xport_class dummy_recv_xport("big"); @@ -259,9 +259,9 @@ BOOST_AUTO_TEST_CASE(test_sph_recv_one_channel_sequence_error){ BOOST_AUTO_TEST_CASE(test_sph_recv_one_channel_inline_message){ //////////////////////////////////////////////////////////////////////// uhd::convert::id_type id; - id.input_markup = "sc16_item32_be"; + id.input_format = "sc16_item32_be"; id.num_inputs = 1; - id.output_markup = "fc32"; + id.output_format = "fc32"; id.num_outputs = 1; dummy_recv_xport_class dummy_recv_xport("big"); @@ -351,9 +351,9 @@ BOOST_AUTO_TEST_CASE(test_sph_recv_one_channel_inline_message){ BOOST_AUTO_TEST_CASE(test_sph_recv_multi_channel_normal){ //////////////////////////////////////////////////////////////////////// uhd::convert::id_type id; - id.input_markup = "sc16_item32_be"; + id.input_format = "sc16_item32_be"; id.num_inputs = 1; - id.output_markup = "fc32"; + id.output_format = "fc32"; id.num_outputs = 1; uhd::transport::vrt::if_packet_info_t ifpi; @@ -434,9 +434,9 @@ BOOST_AUTO_TEST_CASE(test_sph_recv_multi_channel_normal){ BOOST_AUTO_TEST_CASE(test_sph_recv_multi_channel_sequence_error){ //////////////////////////////////////////////////////////////////////// uhd::convert::id_type id; - id.input_markup = "sc16_item32_be"; + id.input_format = "sc16_item32_be"; id.num_inputs = 1; - id.output_markup = "fc32"; + id.output_format = "fc32"; id.num_outputs = 1; uhd::transport::vrt::if_packet_info_t ifpi; @@ -527,9 +527,9 @@ BOOST_AUTO_TEST_CASE(test_sph_recv_multi_channel_sequence_error){ BOOST_AUTO_TEST_CASE(test_sph_recv_multi_channel_time_error){ //////////////////////////////////////////////////////////////////////// uhd::convert::id_type id; - id.input_markup = "sc16_item32_be"; + id.input_format = "sc16_item32_be"; id.num_inputs = 1; - id.output_markup = "fc32"; + id.output_format = "fc32"; id.num_outputs = 1; uhd::transport::vrt::if_packet_info_t ifpi; @@ -615,9 +615,9 @@ BOOST_AUTO_TEST_CASE(test_sph_recv_multi_channel_time_error){ BOOST_AUTO_TEST_CASE(test_sph_recv_multi_channel_fragment){ //////////////////////////////////////////////////////////////////////// uhd::convert::id_type id; - id.input_markup = "sc16_item32_be"; + id.input_format = "sc16_item32_be"; id.num_inputs = 1; - id.output_markup = "fc32"; + id.output_format = "fc32"; id.num_outputs = 1; uhd::transport::vrt::if_packet_info_t ifpi; diff --git a/host/tests/sph_send_test.cpp b/host/tests/sph_send_test.cpp index 9a91008af..25a3f97ee 100644 --- a/host/tests/sph_send_test.cpp +++ b/host/tests/sph_send_test.cpp @@ -92,9 +92,9 @@ private: BOOST_AUTO_TEST_CASE(test_sph_send_one_channel_one_packet_mode){ //////////////////////////////////////////////////////////////////////// uhd::convert::id_type id; - id.input_markup = "fc32"; + id.input_format = "fc32"; id.num_inputs = 1; - id.output_markup = "sc16_item32_be"; + id.output_format = "sc16_item32_be"; id.num_outputs = 1; dummy_send_xport_class dummy_send_xport("big"); @@ -150,9 +150,9 @@ BOOST_AUTO_TEST_CASE(test_sph_send_one_channel_one_packet_mode){ BOOST_AUTO_TEST_CASE(test_sph_send_one_channel_full_buffer_mode){ //////////////////////////////////////////////////////////////////////// uhd::convert::id_type id; - id.input_markup = "fc32"; + id.input_format = "fc32"; id.num_inputs = 1; - id.output_markup = "sc16_item32_be"; + id.output_format = "sc16_item32_be"; id.num_outputs = 1; dummy_send_xport_class dummy_send_xport("big"); -- cgit v1.2.3 From 07fb8d2b82c59ddaf7722b12db8c1387011fb34b Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Thu, 3 Nov 2011 20:34:06 -0700 Subject: usrp: fix rate calculation logic --- host/lib/usrp/cores/rx_dsp_core_200.cpp | 3 +-- host/lib/usrp/cores/tx_dsp_core_200.cpp | 3 +-- host/lib/usrp/usrp1/io_impl.cpp | 6 ++---- host/tests/ranges_test.cpp | 13 +++++++++++++ 4 files changed, 17 insertions(+), 8 deletions(-) (limited to 'host/tests') diff --git a/host/lib/usrp/cores/rx_dsp_core_200.cpp b/host/lib/usrp/cores/rx_dsp_core_200.cpp index 6d306d507..b97f9c58e 100644 --- a/host/lib/usrp/cores/rx_dsp_core_200.cpp +++ b/host/lib/usrp/cores/rx_dsp_core_200.cpp @@ -149,8 +149,7 @@ public: } double set_host_rate(const double rate){ - const size_t decim_rate = this->get_host_rates().clip( - boost::math::iround(_tick_rate/rate), true); + const size_t decim_rate = boost::math::iround(_tick_rate/this->get_host_rates().clip(rate, true)); size_t decim = decim_rate; //determine which half-band filters are activated diff --git a/host/lib/usrp/cores/tx_dsp_core_200.cpp b/host/lib/usrp/cores/tx_dsp_core_200.cpp index 1d571ea7c..9d90d30cc 100644 --- a/host/lib/usrp/cores/tx_dsp_core_200.cpp +++ b/host/lib/usrp/cores/tx_dsp_core_200.cpp @@ -89,8 +89,7 @@ public: } double set_host_rate(const double rate){ - const size_t interp_rate = this->get_host_rates().clip( - boost::math::iround(_tick_rate/rate), true); + const size_t interp_rate = boost::math::iround(_tick_rate/this->get_host_rates().clip(rate, true)); size_t interp = interp_rate; //determine which half-band filters are activated diff --git a/host/lib/usrp/usrp1/io_impl.cpp b/host/lib/usrp/usrp1/io_impl.cpp index 31c834109..937706fdd 100644 --- a/host/lib/usrp/usrp1/io_impl.cpp +++ b/host/lib/usrp/usrp1/io_impl.cpp @@ -470,8 +470,7 @@ uhd::meta_range_t usrp1_impl::get_tx_dsp_host_rates(void){ double usrp1_impl::update_rx_samp_rate(size_t dspno, const double samp_rate){ const size_t div = this->has_rx_halfband()? 2 : 1; - const size_t rate = this->get_rx_dsp_host_rates().clip( - boost::math::iround(_master_clock_rate / samp_rate), true); + const size_t rate = boost::math::iround(_master_clock_rate/this->get_rx_dsp_host_rates().clip(samp_rate, true)); if (rate < 8 and this->has_rx_halfband()) UHD_MSG(warning) << "USRP1 cannot achieve decimations below 8 when the half-band filter is present.\n" @@ -499,8 +498,7 @@ double usrp1_impl::update_rx_samp_rate(size_t dspno, const double samp_rate){ double usrp1_impl::update_tx_samp_rate(size_t dspno, const double samp_rate){ const size_t div = this->has_tx_halfband()? 2 : 1; - const size_t rate = this->get_tx_dsp_host_rates().clip( - boost::math::iround(_master_clock_rate / samp_rate), true); + const size_t rate = boost::math::iround(_master_clock_rate/this->get_tx_dsp_host_rates().clip(samp_rate, true)); if (dspno == 0){ //only care if dsp0 is set since its homogeneous bool s = this->disable_tx(); diff --git a/host/tests/ranges_test.cpp b/host/tests/ranges_test.cpp index 5f6de4645..85bb4c3c4 100644 --- a/host/tests/ranges_test.cpp +++ b/host/tests/ranges_test.cpp @@ -55,3 +55,16 @@ BOOST_AUTO_TEST_CASE(test_ranges_clip){ BOOST_CHECK_CLOSE(mr.clip(50.9, false), 50.9, tolerance); BOOST_CHECK_CLOSE(mr.clip(50.9, true), 51.0, tolerance); } + +BOOST_AUTO_TEST_CASE(test_ranges_clip2){ + meta_range_t mr; + mr.push_back(range_t(1.)); + mr.push_back(range_t(2.)); + mr.push_back(range_t(3.)); + + BOOST_CHECK_CLOSE(mr.clip(2., true), 2., tolerance); + BOOST_CHECK_CLOSE(mr.clip(0., true), 1., tolerance); + BOOST_CHECK_CLOSE(mr.clip(1.2, true), 1., tolerance); + BOOST_CHECK_CLOSE(mr.clip(3.1, true), 3., tolerance); + BOOST_CHECK_CLOSE(mr.clip(4., true), 3., tolerance); +} -- cgit v1.2.3