aboutsummaryrefslogtreecommitdiffstats
path: root/host/examples
diff options
context:
space:
mode:
authorJosh Blum <josh@joshknows.com>2010-06-24 20:29:11 -0700
committerJosh Blum <josh@joshknows.com>2010-06-24 20:29:11 -0700
commit51cb8da5837adacbc626ee20aa58264e1b4b7a78 (patch)
treef83bd594377bcafd7e42b92be82ccc157f6e888c /host/examples
parentfadd3a44a84e061412accd35c1c97db820190df8 (diff)
downloaduhd-51cb8da5837adacbc626ee20aa58264e1b4b7a78.tar.gz
uhd-51cb8da5837adacbc626ee20aa58264e1b4b7a78.tar.bz2
uhd-51cb8da5837adacbc626ee20aa58264e1b4b7a78.zip
uhd: reworked time_spec_t to be more flexible: arithmetic, comparison operators...
Replaced nsecs with fractional seconds in units of seconds. Replaced nsecs and secs members with public function members. time_spec_t has a more diverse set of constructors and methods. It can handle the cases where frac secs are greater than 1 second.
Diffstat (limited to 'host/examples')
-rw-r--r--host/examples/benchmark_rx_rate.cpp13
-rw-r--r--host/examples/rx_timed_samples.cpp10
-rw-r--r--host/examples/tx_timed_samples.cpp6
3 files changed, 10 insertions, 19 deletions
diff --git a/host/examples/benchmark_rx_rate.cpp b/host/examples/benchmark_rx_rate.cpp
index 2ab98bc22..53f4a3c68 100644
--- a/host/examples/benchmark_rx_rate.cpp
+++ b/host/examples/benchmark_rx_rate.cpp
@@ -26,15 +26,6 @@
namespace po = boost::program_options;
-//TODO add time spec diff to API
-static inline double time_spec_diff(
- uhd::time_spec_t time_spec_begin,
- uhd::time_spec_t time_spec_end
-){
- return (time_spec_end.secs - time_spec_begin.secs) + \
- ((time_spec_end.nsecs - time_spec_begin.nsecs)*1e-9);
-}
-
static inline void test_device(
uhd::usrp::simple_usrp::sptr sdev,
double rx_rate_sps,
@@ -80,10 +71,10 @@ static inline void test_device(
got_first_packet = true;
}
- total_lost_samples += boost::math::iround(rx_rate_sps*time_spec_diff(next_expected_time_spec, md.time_spec));
+ total_lost_samples += boost::math::iround(rx_rate_sps*(md.time_spec - next_expected_time_spec).get_real_secs());
next_expected_time_spec = md.time_spec + uhd::time_spec_t(0, num_rx_samps, rx_rate_sps);
- } while(time_spec_diff(initial_time_spec, next_expected_time_spec) < duration_secs);
+ } while((next_expected_time_spec - initial_time_spec) < uhd::time_spec_t(duration_secs));
sdev->issue_stream_cmd(uhd::stream_cmd_t::STREAM_MODE_STOP_CONTINUOUS);
//flush the buffers
diff --git a/host/examples/rx_timed_samples.cpp b/host/examples/rx_timed_samples.cpp
index adc745024..8db312690 100644
--- a/host/examples/rx_timed_samples.cpp
+++ b/host/examples/rx_timed_samples.cpp
@@ -30,7 +30,7 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){
//variables to be set by po
std::string args;
- int seconds_in_future;
+ time_t seconds_in_future;
size_t total_num_samps;
double rx_rate, freq;
@@ -39,7 +39,7 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){
desc.add_options()
("help", "help message")
("args", po::value<std::string>(&args)->default_value(""), "simple uhd device address args")
- ("secs", po::value<int>(&seconds_in_future)->default_value(3), "number of seconds in the future to receive")
+ ("secs", po::value<time_t>(&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")
("rxrate", po::value<double>(&rx_rate)->default_value(100e6/16), "rate of incoming samples")
("freq", po::value<double>(&freq)->default_value(0), "rf center frequency in Hz")
@@ -67,7 +67,7 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){
std::cout << boost::format("Actual RX Rate: %f Msps...") % (sdev->get_rx_rate()/1e6) << std::endl;
std::cout << boost::format("Setting device timestamp to 0...") << std::endl;
sdev->set_rx_freq(freq);
- sdev->set_time_now(uhd::time_spec_t(0));
+ sdev->set_time_now(uhd::time_spec_t(0.0));
//setup streaming
std::cout << std::endl;
@@ -95,8 +95,8 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){
}
if (num_rx_samps == 0) continue; //wait for packets with contents
- std::cout << boost::format("Got packet: %u samples, %u secs, %u nsecs")
- % num_rx_samps % md.time_spec.secs % md.time_spec.nsecs << std::endl;
+ std::cout << boost::format("Got packet: %u samples, %u full secs, %f frac secs")
+ % num_rx_samps % md.time_spec.get_full_secs() % md.time_spec.get_frac_secs() << std::endl;
num_acc_samps += num_rx_samps;
}
diff --git a/host/examples/tx_timed_samples.cpp b/host/examples/tx_timed_samples.cpp
index 28fd2ee67..333f03fbe 100644
--- a/host/examples/tx_timed_samples.cpp
+++ b/host/examples/tx_timed_samples.cpp
@@ -30,7 +30,7 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){
//variables to be set by po
std::string args;
- int seconds_in_future;
+ time_t seconds_in_future;
size_t total_num_samps;
double tx_rate, freq;
float ampl;
@@ -40,7 +40,7 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){
desc.add_options()
("help", "help message")
("args", po::value<std::string>(&args)->default_value(""), "simple uhd device address args")
- ("secs", po::value<int>(&seconds_in_future)->default_value(3), "number of seconds in the future to transmit")
+ ("secs", po::value<time_t>(&seconds_in_future)->default_value(3), "number of seconds in the future to transmit")
("nsamps", po::value<size_t>(&total_num_samps)->default_value(1000), "total number of samples to transmit")
("txrate", po::value<double>(&tx_rate)->default_value(100e6/16), "rate of outgoing samples")
("freq", po::value<double>(&freq)->default_value(0), "rf center frequency in Hz")
@@ -69,7 +69,7 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){
std::cout << boost::format("Actual TX Rate: %f Msps...") % (sdev->get_tx_rate()/1e6) << std::endl;
std::cout << boost::format("Setting device timestamp to 0...") << std::endl;
sdev->set_tx_freq(freq);
- sdev->set_time_now(uhd::time_spec_t(0));
+ sdev->set_time_now(uhd::time_spec_t(0.0));
//data to send
std::vector<std::complex<float> > buff(total_num_samps, std::complex<float>(ampl, ampl));