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>
This commit is contained in:
Thomas Tsou
2013-10-15 15:12:24 -04:00
parent fe269fe31d
commit 3952d80d05
2 changed files with 49 additions and 31 deletions

View File

@@ -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);