[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Commit-gnuradio] [gnuradio] 140/148: Improved the timed samples example
From: |
git |
Subject: |
[Commit-gnuradio] [gnuradio] 140/148: Improved the timed samples example with RTT estimation. |
Date: |
Mon, 15 Aug 2016 00:47:34 +0000 (UTC) |
This is an automated email from the git hooks/post-receive script.
nwest pushed a commit to annotated tag old_usrp_devel_udp
in repository gnuradio.
commit 23e45f33ba50b6658072e9d17c3cd25c0fb1ca7a
Author: Josh Blum <address@hidden>
Date: Wed Jan 20 13:39:29 2010 -0800
Improved the timed samples example with RTT estimation.
---
usrp2/apps/rx_timed_samples.cc | 39 +++++++++++++++++++++++++++++----------
1 file changed, 29 insertions(+), 10 deletions(-)
diff --git a/usrp2/apps/rx_timed_samples.cc b/usrp2/apps/rx_timed_samples.cc
index f1c9f8d..6023483 100644
--- a/usrp2/apps/rx_timed_samples.cc
+++ b/usrp2/apps/rx_timed_samples.cc
@@ -54,7 +54,7 @@ public:
bool //print the timestamps, increment the number of samples
operator()(const uint32_t *items, size_t nitems, const vrt::expanded_header
*vrt_header)
{
- std::cout << boost::format("Got packet: Secs %d, Ticks %d\n")
+ std::cout << boost::format("Got packet: %u secs, %u ticks\n")
% vrt_header->integer_secs % vrt_header->fractional_secs;
d_num_samples += nitems;
return true;
@@ -89,12 +89,18 @@ usage(const char *progname)
std::cerr << boost::format(" -s SECONDS specify number of seconds
in the future to receive [default=3]\n");
}
+static inline double get_time_now(void){
+ timeval tim; gettimeofday(&tim, NULL);
+ return double(tim.tv_sec) + double(tim.tv_usec)/1e6;
+}
+
int
main(int argc, char **argv)
{
// options and their defaults
const char *interface = "eth0";
const char *mac_addr_str = "";
+ const size_t num_rtt_tests = 42;
size_t nsamples = 1000;
size_t nseconds = 3;
@@ -126,7 +132,7 @@ main(int argc, char **argv)
}
}
- std::cout << std::endl << std::endl;
+ std::cout << std::endl;
//create a new handler to print info about packets
rx_handler my_handler(nsamples);
@@ -135,16 +141,29 @@ main(int argc, char **argv)
usrp2::usrp2::sptr u2 = usrp2::usrp2::make(interface, mac_addr_str);
u2->set_rx_decim(16);
- //set the current host time to the usrp2
- struct timeval curr_time;
- gettimeofday(&curr_time, NULL);
- uint32_t curr_secs = curr_time.tv_sec;
+ //get the master clock rate
long clk_rate; u2->fpga_master_clock_freq(&clk_rate);
- uint32_t curr_ticks = (uint64_t)curr_time.tv_usec*clk_rate/1000000ul;
- std::cout << boost::format("Current time: Secs %u, Ticks %u\n") % curr_secs
% curr_ticks;
+ std::cout << boost::format("USRP2 master clock rate: %f MHz\n") %
(clk_rate/1e6);
+
+ //estimate the round trip time
+ double avg_rtt = 0.0;
+ for (size_t i = 0; i < num_rtt_tests; i++){
+ double start_time = get_time_now();
+ u2->set_time(usrp2::time_spec_t());
+ avg_rtt += get_time_now() - start_time;
+ }
+ avg_rtt /= num_rtt_tests;
+ std::cout << boost::format("Average round trip time: %f usecs\n") %
(avg_rtt*1e6);
+
+ //set the system time to the usrp2
+ double curr_time = get_time_now() + avg_rtt/2.0;
+ uint32_t curr_secs = floor(curr_time);
+ uint32_t curr_ticks = (curr_time - curr_secs)*clk_rate;
u2->set_time(usrp2::time_spec_t(curr_secs, curr_ticks));
+ std::cout << boost::format("Current time + RTT/2: %f secs\n") % curr_time;
+ std::cout << boost::format("USRP2 time was set to: %u secs, %u ticks\n") %
curr_secs % curr_ticks;
- //begin streaming n seconds in the future
+ //begin streaming in the future
std::cout << boost::format("Begin streaming %u seconds in the
future...\n\n") % nseconds;
u2->start_rx_streaming(0, usrp2::time_spec_t(curr_secs+nseconds,
curr_ticks));
while(not my_handler.done()){
@@ -154,6 +173,6 @@ main(int argc, char **argv)
//done, stop streaming
u2->stop_rx_streaming();
- std::cout << std::endl << std::endl;
+ std::cout << std::endl;
return 0;
}
- [Commit-gnuradio] [gnuradio] 96/148: Merge branch 'vrt' of address@hidden:jblum into wip/usrp2, (continued)
- [Commit-gnuradio] [gnuradio] 96/148: Merge branch 'vrt' of address@hidden:jblum into wip/usrp2, git, 2016/08/14
- [Commit-gnuradio] [gnuradio] 128/148: yet more debug lines, git, 2016/08/14
- [Commit-gnuradio] [gnuradio] 118/148: more typo fixes., git, 2016/08/14
- [Commit-gnuradio] [gnuradio] 112/148: Merge branch 'wip/usrp2' of http://vps.gnuradio.org/git/jblum into wip/usrp2, git, 2016/08/14
- [Commit-gnuradio] [gnuradio] 115/148: place udp core in the memory space, git, 2016/08/14
- [Commit-gnuradio] [gnuradio] 120/148: make it match the 36 bit wide version, git, 2016/08/14
- [Commit-gnuradio] [gnuradio] 108/148: renamed tics to ticks to be more pc, git, 2016/08/14
- [Commit-gnuradio] [gnuradio] 122/148: debug state, git, 2016/08/14
- [Commit-gnuradio] [gnuradio] 124/148: try proper reset, git, 2016/08/14
- [Commit-gnuradio] [gnuradio] 81/148: Removed stream-at changes to make this mergable into wip/usrp2. Stream-at will be re-implemented with the new vita capabilities., git, 2016/08/14
- [Commit-gnuradio] [gnuradio] 140/148: Improved the timed samples example with RTT estimation.,
git <=
- [Commit-gnuradio] [gnuradio] 123/148: forgot to declare wire, git, 2016/08/14
- [Commit-gnuradio] [gnuradio] 125/148: try a width that works..., git, 2016/08/14
- [Commit-gnuradio] [gnuradio] 80/148: working vrt tx, git, 2016/08/14
- [Commit-gnuradio] [gnuradio] 85/148: also release ethernet frames here, git, 2016/08/14
- [Commit-gnuradio] [gnuradio] 88/148: revered dumb change to vrt expanded header, git, 2016/08/14
- [Commit-gnuradio] [gnuradio] 84/148: Replaced rx metadata with vrt expanded header. Removed timestamp from tx metadata, changes will be made for vrt., git, 2016/08/14
- [Commit-gnuradio] [gnuradio] 93/148: using vrt::expanded_header::unparse in usrp2 impl tx raw, git, 2016/08/14
- [Commit-gnuradio] [gnuradio] 94/148: Replaced the need for code word tables by setting the header/trailer lengths in the switch body jump table, just like in the unparser switch body., git, 2016/08/14
- [Commit-gnuradio] [gnuradio] 72/148: Logic for the start/end of burst bits, git, 2016/08/14
- [Commit-gnuradio] [gnuradio] 82/148: Merge branch 'merge_usrp2' into wip/usrp2, git, 2016/08/14