aboutsummaryrefslogtreecommitdiffstats
path: root/Transceiver52M
diff options
context:
space:
mode:
authorkurtis.heimerl <kurtis.heimerl@19bc5d8c-e614-43d4-8b26-e1612bc8e597>2011-11-26 03:18:24 +0000
committerkurtis.heimerl <kurtis.heimerl@19bc5d8c-e614-43d4-8b26-e1612bc8e597>2011-11-26 03:18:24 +0000
commit1979c6f15523fd91805c8a976540fc2ce03777d2 (patch)
tree7579ec37d1d66da8362d6d842aafe228aff00744 /Transceiver52M
parentbe1decc0d227d4d986b3170e75359d4fef4ef07f (diff)
transceiver: minor cleanup of sample type sizing in uhd
A small simplification of buffer indexing and sizing. Signed-off-by: Thomas Tsou <ttsou@vt.edu> git-svn-id: http://wush.net/svn/range/software/public/openbts/trunk@2667 19bc5d8c-e614-43d4-8b26-e1612bc8e597
Diffstat (limited to 'Transceiver52M')
-rw-r--r--Transceiver52M/UHDDevice.cpp16
1 files changed, 10 insertions, 6 deletions
diff --git a/Transceiver52M/UHDDevice.cpp b/Transceiver52M/UHDDevice.cpp
index ef5b2fc..740fc5d 100644
--- a/Transceiver52M/UHDDevice.cpp
+++ b/Transceiver52M/UHDDevice.cpp
@@ -766,6 +766,8 @@ ssize_t smpl_buf::avail_smpls(uhd::time_spec_t timespec) const
ssize_t smpl_buf::read(void *buf, size_t len, TIMESTAMP timestamp)
{
+ int type_sz = 2 * sizeof(short);
+
// Check for valid read
if (timestamp < time_start)
return ERROR_TIMESTAMP;
@@ -784,11 +786,11 @@ ssize_t smpl_buf::read(void *buf, size_t len, TIMESTAMP timestamp)
// Read it
if (read_start + num_smpls < buf_len) {
- size_t numBytes = len * 2 * sizeof(short);
+ size_t numBytes = len * type_sz;
memcpy(buf, data + read_start, numBytes);
} else {
- size_t first_cp = (buf_len - read_start) * 2 * sizeof(short);
- size_t second_cp = len * 2 * sizeof(short) - first_cp;
+ size_t first_cp = (buf_len - read_start) * type_sz;
+ size_t second_cp = len * type_sz - first_cp;
memcpy(buf, data + read_start, first_cp);
memcpy((char*) buf + first_cp, data, second_cp);
@@ -810,6 +812,8 @@ ssize_t smpl_buf::read(void *buf, size_t len, uhd::time_spec_t ts)
ssize_t smpl_buf::write(void *buf, size_t len, TIMESTAMP timestamp)
{
+ int type_sz = 2 * sizeof(short);
+
// Check for valid write
if ((len == 0) || (len >= buf_len))
return ERROR_WRITE;
@@ -821,11 +825,11 @@ ssize_t smpl_buf::write(void *buf, size_t len, TIMESTAMP timestamp)
// Write it
if ((write_start + len) < buf_len) {
- size_t numBytes = len * 2 * sizeof(short);
+ size_t numBytes = len * type_sz;
memcpy(data + write_start, buf, numBytes);
} else {
- size_t first_cp = (buf_len - write_start) * 2 * sizeof(short);
- size_t second_cp = len * 2 * sizeof(short) - first_cp;
+ size_t first_cp = (buf_len - write_start) * type_sz;
+ size_t second_cp = len * type_sz - first_cp;
memcpy(data + write_start, buf, first_cp);
memcpy(data, (char*) buf + first_cp, second_cp);