Bug #411
e100: non-monotonic time
| Status: | Closed | Start date: | 03/28/2011 | |
|---|---|---|---|---|
| Priority: | High | Due date: | ||
| Assignee: | Josh Blum | % Done: | 0% | |
| Category: | - | |||
| Target version: | - |
Description
Set at 52MHz and 270.833ksps (1625e3/6), e100 timestamps
will roll backwards at roughly one second intervals using
continuous streaming.
Attached patch modifies rx_timed_samples to use required
values and throws on monotonic time errors.
./rx_timed_samples --nsamps 2783300 --secs .5
Truncated output:
Received packet: 506 samples, 1 full secs, 0.223039 frac secs
Received packet: 506 samples, 1 full secs, 0.224907 frac secs
Received packet: 506 samples, 1 full secs, 0.226776 frac secs
Received packet: 506 samples, 1 full secs, 0.228644 frac secs
Received packet: 506 samples, 1 full secs, 0.230512 frac secs
Received packet: 506 samples, 1 full secs, 0.001611 frac secs
Error: Non-monotonic time detected
---
host/examples/rx_timed_samples.cpp | 22 +++++++++++++++++++---
1 files changed, 19 insertions(+), 3 deletions(-)
diff --git a/host/examples/rx_timed_samples.cpp b/host/examples/rx_timed_samples.cpp
index 28d7ee4..9b6361f 100644
--- a/host/examples/rx_timed_samples.cpp
+++ b/host/examples/rx_timed_samples.cpp
@@ -41,8 +41,8 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){
("args", po::value<std::string>(&args)->default_value(""), "single uhd device address args")
("secs", po::value<double>(&seconds_in_future)->default_value(1.5), "number of seconds in the future to receive")
("nsamps", po::value<size_t>(&total_num_samps)->default_value(10000), "total number of samples to receive")
- ("clock", po::value<double>(&clock), "master clock frequency in Hz")
- ("rate", po::value<double>(&rate)->default_value(100e6/16), "rate of incoming samples")
+ ("clock", po::value<double>(&clock)->default_value(52e6), "master clock frequency in Hz")
+ ("rate", po::value<double>(&rate)->default_value(1625e3/6), "rate of incoming samples")
("dilv", "specify to disable inner-loop verbose")
;
po::variables_map vm;
@@ -82,12 +82,14 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){
std::cout << boost::format(
"Begin streaming %u samples, %f seconds in the future..."
) % total_num_samps % seconds_in_future << std::endl;
- uhd::stream_cmd_t stream_cmd(uhd::stream_cmd_t::STREAM_MODE_NUM_SAMPS_AND_DONE);
+ uhd::stream_cmd_t stream_cmd(uhd::stream_cmd_t::STREAM_MODE_START_CONTINUOUS);
stream_cmd.num_samps = total_num_samps;
stream_cmd.stream_now = false;
stream_cmd.time_spec = uhd::time_spec_t(seconds_in_future);
usrp->issue_stream_cmd(stream_cmd);
+ uhd::stream_cmd_t stop_cmd(uhd::stream_cmd_t::STREAM_MODE_STOP_CONTINUOUS);
+
//meta-data will be filled in by recv()
uhd::rx_metadata_t md;
@@ -97,6 +99,9 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){
//the first call to recv() will block this many seconds before receiving
double timeout = seconds_in_future + 0.1; //timeout (delay before receive + padding)
+ //track previous packet timestamp
+ uhd::time_spec_t prev_ts(0,0);
+
size_t num_acc_samps = 0; //number of accumulated samples
while(num_acc_samps < total_num_samps){
//receive a single packet
@@ -112,6 +117,7 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){
//handle the error code
if (md.error_code == uhd::rx_metadata_t::ERROR_CODE_TIMEOUT) break;
if (md.error_code != uhd::rx_metadata_t::ERROR_CODE_NONE){
+ usrp->issue_stream_cmd(stop_cmd);
throw std::runtime_error(str(boost::format(
"Unexpected error code 0x%x"
) % md.error_code));
@@ -121,9 +127,19 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){
"Received 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;
+ //check for monotonicity
+ if (md.time_spec < prev_ts) {
+ usrp->issue_stream_cmd(stop_cmd);
+ throw std::runtime_error("Non-monotonic time detected");
+ }
+ else {
+ prev_ts = md.time_spec;
+ }
+
num_acc_samps += num_rx_samps;
}
+ usrp->issue_stream_cmd(stop_cmd);
if (num_acc_samps < total_num_samps) std::cerr << "Receive timeout before all samples received..." << std::endl;
//finished
--
1.7.0.2
History
#1 Updated by Josh Blum about 2 years ago
- Status changed from Assigned to Resolved
- Assignee set to Josh Blum
code fix in a2a78451d196a7f52a3e2a3bda94f52d127313d0
phil confirmed the fix at 64 mhz and 52 mhz
#2 Updated by Matt Ettus about 2 years ago
- Status changed from Resolved to Closed
