From d4d3daa12ea5491f4b6ba03805d4a2d3f068bc11 Mon Sep 17 00:00:00 2001 From: Tom Tsou Date: Fri, 21 Aug 2015 19:21:28 -0700 Subject: uhd: Use internal UHD tick conversions UHD handles built in tick and floating point timestamp conversion since version 003.005.004. This removes the need for separate UHD timespec to tick conversion. Signed-off-by: Tom Tsou --- Transceiver52M/UHDDevice.cpp | 36 ++++++++++-------------------------- 1 file changed, 10 insertions(+), 26 deletions(-) (limited to 'Transceiver52M') diff --git a/Transceiver52M/UHDDevice.cpp b/Transceiver52M/UHDDevice.cpp index 1f9dd78..99e7967 100644 --- a/Transceiver52M/UHDDevice.cpp +++ b/Transceiver52M/UHDDevice.cpp @@ -212,22 +212,6 @@ static double select_rate(uhd_dev_type type, int sps, bool diversity = false) return -9999.99; } -/** Timestamp conversion - @param timestamp a UHD or OpenBTS timestamp - @param rate sample rate - @return the converted timestamp -*/ -uhd::time_spec_t convert_time(TIMESTAMP ticks, double rate) -{ - double secs = (double) ticks / rate; - return uhd::time_spec_t(secs); -} - -TIMESTAMP convert_time(uhd::time_spec_t ts, double rate) -{ - return (TIMESTAMP)(ts.get_real_secs() * rate + 0.5); -} - /* Sample Buffer - Allows reading and writing of timed samples using OpenBTS or UHD style timestamps. Time conversions are handled @@ -864,7 +848,7 @@ bool uhd_device::flush_recv(size_t num_pkts) } } - ts_initial = convert_time(md.time_spec, rx_rate); + ts_initial = md.time_spec.to_ticks(rx_rate); } LOG(INFO) << "Initial timestamp " << ts_initial << std::endl; @@ -1001,7 +985,7 @@ int uhd_device::readSamples(std::vector &bufs, int len, bool *overrun, // Shift read time with respect to transmit clock timestamp += ts_offset; - ts = convert_time(timestamp, rx_rate); + ts = uhd::time_spec_t::from_ticks(timestamp, rx_rate); LOG(DEBUG) << "Requested timestamp = " << ts.get_real_secs(); // Check that timestamp is valid @@ -1083,7 +1067,7 @@ int uhd_device::writeSamples(std::vector &bufs, int len, bool *underrun metadata.has_time_spec = true; metadata.start_of_burst = false; metadata.end_of_burst = false; - metadata.time_spec = convert_time(timestamp, tx_rate); + metadata.time_spec = uhd::time_spec_t::from_ticks(timestamp, tx_rate); *underrun = false; @@ -1397,7 +1381,7 @@ ssize_t smpl_buf::avail_smpls(TIMESTAMP timestamp) const ssize_t smpl_buf::avail_smpls(uhd::time_spec_t timespec) const { - return avail_smpls(convert_time(timespec, clk_rt)); + return avail_smpls(timespec.to_ticks(clk_rt)); } ssize_t smpl_buf::read(void *buf, size_t len, TIMESTAMP timestamp) @@ -1443,7 +1427,7 @@ ssize_t smpl_buf::read(void *buf, size_t len, TIMESTAMP timestamp) ssize_t smpl_buf::read(void *buf, size_t len, uhd::time_spec_t ts) { - return read(buf, len, convert_time(ts, clk_rt)); + return read(buf, len, ts.to_ticks(clk_rt)); } ssize_t smpl_buf::write(void *buf, size_t len, TIMESTAMP timestamp) @@ -1458,14 +1442,14 @@ ssize_t smpl_buf::write(void *buf, size_t len, TIMESTAMP timestamp) if (timestamp < time_end) { LOG(ERR) << "Overwriting old buffer data: timestamp="<