diff options
author | Josh Blum <josh@joshknows.com> | 2010-03-23 18:17:47 -0700 |
---|---|---|
committer | Josh Blum <josh@joshknows.com> | 2010-03-23 18:17:47 -0700 |
commit | 1aef83037f6a9988b06a547710afbbe5ce815459 (patch) | |
tree | 7698e49c2f4d891feb49a9b937f9da9fc6f4cbc5 /host | |
parent | 694dc3c7bc6f07b9660aef0c5ace9f6e11f98066 (diff) | |
download | uhd-1aef83037f6a9988b06a547710afbbe5ce815459.tar.gz uhd-1aef83037f6a9988b06a547710afbbe5ce815459.tar.bz2 uhd-1aef83037f6a9988b06a547710afbbe5ce815459.zip |
Added example app to receive timed samples.
Added useful calls to simple device.
Fixed vrt frac time usage (wrong word).
Diffstat (limited to 'host')
-rw-r--r-- | host/apps/CMakeLists.txt | 3 | ||||
-rw-r--r-- | host/apps/uhd_rx_timed_samples.cpp | 91 | ||||
-rw-r--r-- | host/include/uhd/simple_device.hpp | 7 | ||||
-rw-r--r-- | host/lib/simple_device.cpp | 16 | ||||
-rw-r--r-- | host/lib/transport/vrt.cpp | 4 |
5 files changed, 119 insertions, 2 deletions
diff --git a/host/apps/CMakeLists.txt b/host/apps/CMakeLists.txt index 4deb41965..f31206e1a 100644 --- a/host/apps/CMakeLists.txt +++ b/host/apps/CMakeLists.txt @@ -21,3 +21,6 @@ INSTALL(TARGETS discover_usrps RUNTIME DESTINATION ${RUNTIME_DIR}) ADD_EXECUTABLE(usrp2_burner usrp2_burner.cpp) TARGET_LINK_LIBRARIES(usrp2_burner uhd) + +ADD_EXECUTABLE(uhd_rx_timed_samples uhd_rx_timed_samples.cpp) +TARGET_LINK_LIBRARIES(uhd_rx_timed_samples uhd) diff --git a/host/apps/uhd_rx_timed_samples.cpp b/host/apps/uhd_rx_timed_samples.cpp new file mode 100644 index 000000000..97f75647e --- /dev/null +++ b/host/apps/uhd_rx_timed_samples.cpp @@ -0,0 +1,91 @@ +// +// Copyright 2010 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 <http://www.gnu.org/licenses/>. +// + +#include <uhd/simple_device.hpp> +#include <uhd/props.hpp> +#include <boost/program_options.hpp> +#include <boost/format.hpp> +#include <iostream> +#include <complex> + +namespace po = boost::program_options; + +int main(int argc, char *argv[]){ + //variables to be set by po + std::string transport_args; + int seconds_in_future; + size_t total_num_samps; + + //setup the program options + po::options_description desc("Allowed options"); + desc.add_options() + ("help", "help message") + ("args", po::value<std::string>(&transport_args)->default_value(""), "simple uhd transport args") + ("secs", po::value<int>(&seconds_in_future)->default_value(3), "number of seconds in the future to receive") + ("nsamps", po::value<size_t>(&total_num_samps)->default_value(1000), "total number of samples to receive") + ; + po::variables_map vm; + po::store(po::parse_command_line(argc, argv, desc), vm); + po::notify(vm); + + //print the help message + if (vm.count("help")){ + std::cout << boost::format("UHD RX Timed Samples %s") % desc << std::endl; + return ~0; + } + + //create a usrp device + std::cout << std::endl; + std::cout << boost::format("Creating the usrp device with: %s...") + % transport_args << std::endl; + uhd::simple_device::sptr sdev = uhd::simple_device::make(transport_args); + uhd::device::sptr dev = sdev->get_device(); + std::cout << boost::format("Using Device: %s") % sdev->get_name() << std::endl; + + //set properties on the device + double rx_rate = sdev->get_rx_rates()[4]; //pick some rate + std::cout << boost::format("Setting RX Rate: %f Msps...") % (rx_rate/1e6) << std::endl; + sdev->set_rx_rate(rx_rate); + std::cout << boost::format("Setting device timestamp to 0...") << std::endl; + sdev->set_time_now(uhd::time_spec_t(0)); + + //setup streaming + std::cout << std::endl; + std::cout << boost::format("Begin streaming %u seconds in the future...") + % seconds_in_future << std::endl; + sdev->set_streaming_at(uhd::time_spec_t(seconds_in_future)); + + //loop until total number of samples reached + size_t num_acc_samps = 0; //number of accumulated samples + while(num_acc_samps < total_num_samps){ + uhd::rx_metadata_t md; + std::complex<float> buff[1000]; + size_t num_rx_samps = dev->recv(boost::asio::buffer(buff, sizeof(buff)), md, "32fc"); + if (num_rx_samps == 0) continue; //wait for packets with contents + + std::cout << boost::format("Got packet: %u samples, %u secs, %u ticks") + % num_rx_samps % md.time_spec.secs % md.time_spec.ticks << std::endl; + + num_acc_samps += num_rx_samps; + } + + //finished, stop streaming + sdev->set_streaming(false); + std::cout << std::endl << "Done!" << std::endl << std::endl; + + return 0; +} diff --git a/host/include/uhd/simple_device.hpp b/host/include/uhd/simple_device.hpp index ad25eccdc..035757936 100644 --- a/host/include/uhd/simple_device.hpp +++ b/host/include/uhd/simple_device.hpp @@ -43,8 +43,15 @@ public: virtual std::string get_name(void) = 0; /******************************************************************* + * Timing + ******************************************************************/ + virtual void set_time_now(const time_spec_t &time_spec) = 0; + virtual void set_time_next_pps(const time_spec_t &time_spec) = 0; + + /******************************************************************* * Streaming ******************************************************************/ + virtual void set_streaming_at(const time_spec_t &time_spec) = 0; virtual void set_streaming(bool enb) = 0; virtual bool get_streaming(void) = 0; diff --git a/host/lib/simple_device.cpp b/host/lib/simple_device.cpp index ba1966e0d..bb7ddfc68 100644 --- a/host/lib/simple_device.cpp +++ b/host/lib/simple_device.cpp @@ -154,8 +154,24 @@ public: } /******************************************************************* + * Timing + ******************************************************************/ + void set_time_now(const time_spec_t &time_spec){ + _mboard[MBOARD_PROP_TIME_NOW] = time_spec; + } + + void set_time_next_pps(const time_spec_t &time_spec){ + _mboard[MBOARD_PROP_TIME_NEXT_PPS] = time_spec; + } + + /******************************************************************* * Streaming ******************************************************************/ + void set_streaming_at(const time_spec_t &time_spec){ + _rx_ddc[std::string("stream_at")] = time_spec; + _rx_ddc[std::string("enabled")] = true; + } + void set_streaming(bool enb){ _rx_ddc[std::string("enabled")] = enb; } diff --git a/host/lib/transport/vrt.cpp b/host/lib/transport/vrt.cpp index a06b5bf21..cc46b2381 100644 --- a/host/lib/transport/vrt.cpp +++ b/host/lib/transport/vrt.cpp @@ -42,8 +42,8 @@ void vrt::pack( if(metadata.has_time_spec){ vrt_hdr_flags |= (0x3 << 22) | (0x1 << 20); //TSI: Other, TSF: Sample Count Timestamp header_buff[num_header_words32++] = htonl(metadata.time_spec.secs); - header_buff[num_header_words32++] = htonl(metadata.time_spec.ticks); header_buff[num_header_words32++] = 0; //unused part of fractional seconds + header_buff[num_header_words32++] = htonl(metadata.time_spec.ticks); } vrt_hdr_flags |= (metadata.start_of_burst)? (0x1 << 25) : 0; @@ -99,8 +99,8 @@ void vrt::unpack( if (vrt_hdr_word & (0x3 << 20)){ //fractional time metadata.has_time_spec = true; - metadata.time_spec.ticks = ntohl(header_buff[num_header_words32++]); num_header_words32++; //unused part of fractional seconds + metadata.time_spec.ticks = ntohl(header_buff[num_header_words32++]); } size_t num_trailer_words32 = (vrt_hdr_word & (0x1 << 26))? 1 : 0; |