diff --git a/plugins/samplesink/CMakeLists.txt b/plugins/samplesink/CMakeLists.txt index 0a78c9d47..179ba540e 100644 --- a/plugins/samplesink/CMakeLists.txt +++ b/plugins/samplesink/CMakeLists.txt @@ -17,10 +17,10 @@ if(LIBUSB_FOUND AND LIMESUITE_FOUND) add_subdirectory(limesdroutput) endif(LIBUSB_FOUND AND LIMESUITE_FOUND) -#find_package(LibIIO) -#if(LIBUSB_FOUND AND LIBIIO_FOUND) -# add_subdirectory(plutosdroutput) -#endif(LIBUSB_FOUND AND LIBIIO_FOUND) +find_package(LibIIO) +if(LIBUSB_FOUND AND LIBIIO_FOUND) + add_subdirectory(plutosdroutput) +endif(LIBUSB_FOUND AND LIBIIO_FOUND) find_package(CM256cc) find_package(LibNANOMSG) @@ -35,7 +35,7 @@ if (BUILD_DEBIAN) if (LIBNANOMSG_FOUND) add_subdirectory(sdrdaemonsink) endif (LIBNANOMSG_FOUND) -# add_subdirectory(plutosdroutput) + add_subdirectory(plutosdroutput) endif (BUILD_DEBIAN) add_subdirectory(filesink) diff --git a/plugins/samplesink/plutosdroutput/plutosdroutput.cpp b/plugins/samplesink/plutosdroutput/plutosdroutput.cpp index dc07b8965..afe37339d 100644 --- a/plugins/samplesink/plutosdroutput/plutosdroutput.cpp +++ b/plugins/samplesink/plutosdroutput/plutosdroutput.cpp @@ -25,7 +25,7 @@ #include "plutosdroutput.h" #include "plutosdroutputthread.h" -#define PLUTOSDR_BLOCKSIZE_SAMPLES (32*1024) //complex samples per buffer (must be multiple of 64) +#define PLUTOSDR_BLOCKSIZE_SAMPLES (16*1024) //complex samples per buffer (must be multiple of 64) MESSAGE_CLASS_DEFINITION(PlutoSDROutput::MsgConfigurePlutoSDR, Message) @@ -185,9 +185,11 @@ bool PlutoSDROutput::openDevice() m_deviceAPI->setBuddySharedPtr(&m_deviceShared); // propagate common parameters to API // acquire the channel + suspendBuddies(); DevicePlutoSDRBox *plutoBox = m_deviceShared.m_deviceParams->getBox(); plutoBox->openTx(); m_plutoTxBuffer = plutoBox->createTxBuffer(PLUTOSDR_BLOCKSIZE_SAMPLES, false); // PlutoSDR buffer size is counted in number of (I,Q) samples + resumeBuddies(); return true; } diff --git a/plugins/samplesink/plutosdroutput/plutosdroutputthread.cpp b/plugins/samplesink/plutosdroutput/plutosdroutputthread.cpp index 79a736cda..ea1e553a2 100644 --- a/plugins/samplesink/plutosdroutput/plutosdroutputthread.cpp +++ b/plugins/samplesink/plutosdroutput/plutosdroutputthread.cpp @@ -65,6 +65,13 @@ void PlutoSDROutputThread::setLog2Interpolation(unsigned int log2_interp) void PlutoSDROutputThread::run() { + std::ptrdiff_t p_inc = m_plutoBox->txBufferStep(); + + qDebug("PlutoSDROutputThread::run: txBufferStep: %ld bytes", p_inc); + qDebug("PlutoSDROutputThread::run: Rx sample size is %ld bytes", m_plutoBox->getRxSampleSize()); + qDebug("PlutoSDROutputThread::run: Tx sample size is %ld bytes", m_plutoBox->getTxSampleSize()); + qDebug("PlutoSDROutputThread::run: nominal nbytes_tx is %d bytes", m_blockSizeSamples*4); + m_running = true; m_startWaiter.wakeAll(); @@ -72,13 +79,11 @@ void PlutoSDROutputThread::run() { ssize_t nbytes_tx; char *p_dat, *p_end; - std::ptrdiff_t p_inc; int ihs; // half sample index (I then Q to make a sample) convert(m_buf, 2*m_blockSizeSamples); // size given in number of int16_t (I and Q interleaved) // WRITE: Get pointers to TX buf and write IQ to TX buf port 0 - p_inc = m_plutoBox->txBufferStep(); p_end = m_plutoBox->txBufferEnd(); ihs = 0; @@ -97,7 +102,7 @@ void PlutoSDROutputThread::run() if (nbytes_tx != 4*m_blockSizeSamples) { - qDebug("PlutoSDROutputThread::run: error pushing buf %d != %d\n", (int) nbytes_tx, (int) 4*m_blockSizeSamples); + qDebug("PlutoSDROutputThread::run: error pushing buf %d / %d\n", (int) nbytes_tx, (int) 4*m_blockSizeSamples); usleep(200000); continue; } diff --git a/plugins/samplesource/plutosdrinput/plutosdrinput.cpp b/plugins/samplesource/plutosdrinput/plutosdrinput.cpp index e677dda06..a898a58cb 100644 --- a/plugins/samplesource/plutosdrinput/plutosdrinput.cpp +++ b/plugins/samplesource/plutosdrinput/plutosdrinput.cpp @@ -26,7 +26,7 @@ #include "plutosdrinput.h" #include "plutosdrinputthread.h" -#define PLUTOSDR_BLOCKSIZE_SAMPLES (8*1024) //complex samples per buffer (must be multiple of 64) +#define PLUTOSDR_BLOCKSIZE_SAMPLES (16*1024) //complex samples per buffer (must be multiple of 64) MESSAGE_CLASS_DEFINITION(PlutoSDRInput::MsgConfigurePlutoSDR, Message) MESSAGE_CLASS_DEFINITION(PlutoSDRInput::MsgFileRecord, Message) @@ -214,9 +214,11 @@ bool PlutoSDRInput::openDevice() m_deviceAPI->setBuddySharedPtr(&m_deviceShared); // propagate common parameters to API // acquire the channel + suspendBuddies(); DevicePlutoSDRBox *plutoBox = m_deviceShared.m_deviceParams->getBox(); plutoBox->openRx(); - m_plutoRxBuffer = plutoBox->createRxBuffer(PLUTOSDR_BLOCKSIZE_SAMPLES*2, false); // PlutoSDR buffer size is counted in number of I or Q samples not the combination + m_plutoRxBuffer = plutoBox->createRxBuffer(PLUTOSDR_BLOCKSIZE_SAMPLES, false); + resumeBuddies(); return true; } diff --git a/plugins/samplesource/plutosdrinput/plutosdrinputplugin.cpp b/plugins/samplesource/plutosdrinput/plutosdrinputplugin.cpp index b50916ae0..937f13612 100644 --- a/plugins/samplesource/plutosdrinput/plutosdrinputplugin.cpp +++ b/plugins/samplesource/plutosdrinput/plutosdrinputplugin.cpp @@ -28,7 +28,7 @@ class DeviceSourceAPI; const PluginDescriptor PlutoSDRInputPlugin::m_pluginDescriptor = { QString("PlutoSDR Input"), - QString("3.7.4"), + QString("3.7.8"), QString("(c) Edouard Griffiths, F4EXB"), QString("https://github.com/f4exb/sdrangel"), true, diff --git a/plugins/samplesource/plutosdrinput/plutosdrinputthread.cpp b/plugins/samplesource/plutosdrinput/plutosdrinputthread.cpp index 89b078cc7..2a6ee9f36 100644 --- a/plugins/samplesource/plutosdrinput/plutosdrinputthread.cpp +++ b/plugins/samplesource/plutosdrinput/plutosdrinputthread.cpp @@ -34,8 +34,8 @@ PlutoSDRInputThread::PlutoSDRInputThread(uint32_t blocksizeSamples, DevicePlutoS m_fcPos(PlutoSDRInputSettings::FC_POS_CENTER), m_phasor(0) { - m_buf = new qint16[blocksizeSamples*(sizeof(Sample)/sizeof(qint16))]; - m_bufConv = new qint16[blocksizeSamples*(sizeof(Sample)/sizeof(qint16))]; + m_buf = new qint16[blocksizeSamples*2]; // (I,Q) -> 2 * int16_t + m_bufConv = new qint16[blocksizeSamples*2]; // (I,Q) -> 2 * int16_t } PlutoSDRInputThread::~PlutoSDRInputThread() @@ -75,6 +75,13 @@ void PlutoSDRInputThread::setFcPos(int fcPos) void PlutoSDRInputThread::run() { + std::ptrdiff_t p_inc = m_plutoBox->rxBufferStep(); + + qDebug("PlutoSDRInputThread::run: rxBufferStep: %ld bytes", p_inc); + qDebug("PlutoSDRInputThread::run: Rx sample size is %ld bytes", m_plutoBox->getRxSampleSize()); + qDebug("PlutoSDRInputThread::run: Tx sample size is %ld bytes", m_plutoBox->getTxSampleSize()); + qDebug("PlutoSDRInputThread::run: nominal nbytes_rx is %d bytes with 2 refills", m_blockSizeSamples*2); + m_running = true; m_startWaiter.wakeAll(); @@ -82,21 +89,19 @@ void PlutoSDRInputThread::run() { ssize_t nbytes_rx; char *p_dat, *p_end; - std::ptrdiff_t p_inc; int ihs; // half sample index (I then Q to make a sample) // Refill RX buffer nbytes_rx = m_plutoBox->rxBufferRefill(); - if (nbytes_rx < 0) + if (nbytes_rx != m_blockSizeSamples*2) { - qWarning("PlutoSDRInputThread::run: error refilling buf %d\n",(int) nbytes_rx); + qWarning("PlutoSDRInputThread::run: error refilling buf (1) %d / %d\n",(int) nbytes_rx, (int) m_blockSizeSamples*2); usleep(200000); continue; } // READ: Get pointers to RX buf and read IQ from RX buf port 0 - p_inc = m_plutoBox->rxBufferStep(); p_end = m_plutoBox->rxBufferEnd(); ihs = 0; @@ -111,6 +116,30 @@ void PlutoSDRInputThread::run() ihs++; } + // Refill RX buffer again - we still need twice more samples to complete since they come as I followed by Q + nbytes_rx = m_plutoBox->rxBufferRefill(); + + if (nbytes_rx != m_blockSizeSamples*2) + { + qWarning("PlutoSDRInputThread::run: error refilling buf (2) %d / %d\n",(int) nbytes_rx, (int) m_blockSizeSamples*2); + usleep(200000); + continue; + } + + // READ: Get pointers to RX buf and read IQ from RX buf port 0 + p_end = m_plutoBox->rxBufferEnd(); + + // p_inc is 2 on a char* buffer therefore each iteration processes only the I or Q sample + // I and Q samples are processed one after the other + // conversion is not needed as samples are little endian + + for (p_dat = m_plutoBox->rxBufferFirst(); p_dat < p_end; p_dat += p_inc) + { + m_buf[ihs] = *((int16_t *) p_dat); +// iio_channel_convert(m_plutoBox->getRxChannel0(), (void *) &m_bufConv[ihs], (const void *) &m_buf[ihs]); + ihs++; + } + //m_sampleFifo->write((unsigned char *) m_buf, ihs*sizeof(int16_t)); convert(m_buf, 2*m_blockSizeSamples); // size given in number of int16_t (I and Q interleaved) }