diff options
author | Alexander Chemeris <Alexander.Chemeris@gmail.com> | 2015-06-10 21:47:33 -0400 |
---|---|---|
committer | Alexander Chemeris <Alexander.Chemeris@gmail.com> | 2015-06-10 23:13:33 -0400 |
commit | b49874aa646bfae23355a6a4c38d835323f2c8f4 (patch) | |
tree | bba93b527f31e04993a8caf2a23fb3efca54fe23 /Transceiver52M | |
parent | 030951695c3c78557cd27f19533daa412b3937a3 (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.
Diffstat (limited to 'Transceiver52M')
-rw-r--r-- | Transceiver52M/UHDDevice.cpp | 16 |
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; |