aboutsummaryrefslogtreecommitdiffstats
path: root/Transceiver52M/radioInterface.cpp
diff options
context:
space:
mode:
authorThomas Tsou <tom@tsou.cc>2013-10-15 15:12:24 -0400
committerThomas Tsou <tom@tsou.cc>2013-10-18 13:10:18 -0400
commit3952d80d057eb3c8c63c4661489581405cf0c87c (patch)
treec934a68951a37ac0cc8b58eb327961205699da51 /Transceiver52M/radioInterface.cpp
parentfe269fe31dc2ae4bc3012d0b83ebc43edfd18cb5 (diff)
Transceiver52M: Reduce and place bounds checking on I/O buffers
Previous send and receive buffers at the radio interface were arbitrarily set to a sufficient size. For normal (non-resampling) devices, use a block (chunk) size of 625 samples. For 64 or 100 MHz resampling devices, use 4 times the reduced resampling numerator or denominator and provide bounds checking where appropriate. Signed-off-by: Thomas Tsou <tom@tsou.cc>
Diffstat (limited to 'Transceiver52M/radioInterface.cpp')
-rw-r--r--Transceiver52M/radioInterface.cpp28
1 files changed, 17 insertions, 11 deletions
diff --git a/Transceiver52M/radioInterface.cpp b/Transceiver52M/radioInterface.cpp
index a633738..a8a54a5 100644
--- a/Transceiver52M/radioInterface.cpp
+++ b/Transceiver52M/radioInterface.cpp
@@ -30,8 +30,8 @@ extern "C" {
#include "convert.h"
}
-#define INCHUNK (625 * SAMPSPERSYM)
-#define OUTCHUNK (625 * SAMPSPERSYM)
+#define CHUNK 625
+#define NUMCHUNKS 4
RadioInterface::RadioInterface(RadioDevice *wRadio,
int wReceiveOffset,
@@ -58,11 +58,11 @@ bool RadioInterface::init(int type)
close();
- sendBuffer = new signalVector(OUTCHUNK * 20);
- recvBuffer = new signalVector(INCHUNK * 20);
+ sendBuffer = new signalVector(CHUNK * mSPSTx);
+ recvBuffer = new signalVector(NUMCHUNKS * CHUNK * mSPSRx);
- convertSendBuffer = new short[OUTCHUNK * 2 * 20];
- convertRecvBuffer = new short[OUTCHUNK * 2 * 2];
+ convertSendBuffer = new short[sendBuffer->size() * 2];
+ convertRecvBuffer = new short[recvBuffer->size() * 2];
sendCursor = 0;
recvCursor = 0;
@@ -276,23 +276,26 @@ double RadioInterface::getRxGain()
void RadioInterface::pullBuffer()
{
bool local_underrun;
- int num_recv, len = OUTCHUNK / mSPSTx;
+ int num_recv;
float *output;
+ if (recvCursor > recvBuffer->size() - CHUNK)
+ return;
+
/* Outer buffer access size is fixed */
num_recv = mRadio->readSamples(convertRecvBuffer,
- len,
+ CHUNK,
&overrun,
readTimestamp,
&local_underrun);
- if (num_recv != len) {
+ if (num_recv != CHUNK) {
LOG(ALERT) << "Receive error " << num_recv;
return;
}
output = (float *) (recvBuffer->begin() + recvCursor);
- convert_short_float(output, convertRecvBuffer, 2 * len);
+ convert_short_float(output, convertRecvBuffer, 2 * num_recv);
underrun |= local_underrun;
@@ -305,9 +308,12 @@ void RadioInterface::pushBuffer()
{
int num_sent;
- if (sendCursor < INCHUNK)
+ if (sendCursor < CHUNK)
return;
+ if (sendCursor > sendBuffer->size())
+ LOG(ALERT) << "Send buffer overflow";
+
convert_float_short(convertSendBuffer,
(float *) sendBuffer->begin(),
powerScaling, 2 * sendCursor);