aboutsummaryrefslogtreecommitdiffstats
path: root/Transceiver52M
diff options
context:
space:
mode:
authorAlexander Chemeris <Alexander.Chemeris@gmail.com>2015-06-10 21:47:33 -0400
committerTom Tsou <tom.tsou@ettus.com>2015-07-30 14:22:28 -0700
commitc052aa1d4cbccb1802cdefc02f105c957d037fae (patch)
tree7fdfff6fbd1463519344a93cd334333d50024c14 /Transceiver52M
parent130a8007fa52b96e44e92b12162b8aa253ba183b (diff)
uhd: Fix rounding error in timestamp conversion functions.
Rounding error introduced oscilating timing advance error by regularly overwriting one bit and then skipping one bit. This commit also adds an error message to show up in logs if this ever happens again. Signed-off-by: Tom Tsou <tom.tsou@ettus.com>
Diffstat (limited to 'Transceiver52M')
-rw-r--r--Transceiver52M/UHDDevice.cpp16
1 files changed, 14 insertions, 2 deletions
diff --git a/Transceiver52M/UHDDevice.cpp b/Transceiver52M/UHDDevice.cpp
index 9038bc1..272ce60 100644
--- a/Transceiver52M/UHDDevice.cpp
+++ b/Transceiver52M/UHDDevice.cpp
@@ -210,8 +210,7 @@ uhd::time_spec_t convert_time(TIMESTAMP ticks, double rate)
TIMESTAMP convert_time(uhd::time_spec_t ts, double rate)
{
- TIMESTAMP ticks = ts.get_full_secs() * rate;
- return ts.get_tick_count(rate) + ticks;
+ return (TIMESTAMP)(ts.get_real_secs() * rate + 0.5);
}
/*
@@ -1430,6 +1429,19 @@ ssize_t smpl_buf::write(void *buf, size_t len, TIMESTAMP timestamp)
if ((timestamp + len) <= time_end)
return ERROR_TIMESTAMP;
+ if (timestamp < time_end) {
+ LOG(ERR) << "Overwriting old buffer data: timestamp="<<timestamp<<" time_end="<<time_end;
+ uhd::time_spec_t ts = convert_time(timestamp, clk_rt);
+ LOG(DEBUG) << "Requested timestamp = " << timestamp << " (real_sec=" << std::fixed << ts.get_real_secs() << " = " << convert_time(ts, clk_rt) << ") rate=" << clk_rt;
+ // Do not return error here, because it's a rounding error and is not fatal
+ }
+ if (timestamp > time_end && time_end != 0) {
+ LOG(ERR) << "Skipping buffer data: timestamp="<<timestamp<<" time_end="<<time_end;
+ uhd::time_spec_t ts = convert_time(timestamp, clk_rt);
+ LOG(DEBUG) << "Requested timestamp = " << timestamp << " (real_sec=" << std::fixed << ts.get_real_secs() << " = " << convert_time(ts, clk_rt) << ") rate=" << clk_rt;
+ // Do not return error here, because it's a rounding error and is not fatal
+ }
+
// Starting index
size_t write_start = (data_start + (timestamp - time_start)) % buf_len;