Skip to content

Commit

Permalink
All device plugins: make sure start and stop are effective once only.…
Browse files Browse the repository at this point in the history
… PArt of #2159
  • Loading branch information
f4exb committed Aug 27, 2024
1 parent 1b37a4f commit 585d806
Show file tree
Hide file tree
Showing 40 changed files with 453 additions and 242 deletions.
44 changes: 26 additions & 18 deletions plugins/samplemimo/bladerf2mimo/bladerf2mimo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,12 @@ void BladeRF2MIMO::init()

bool BladeRF2MIMO::startRx()
{
QMutexLocker mutexLocker(&m_mutex);

if (m_runningRx) {
return true;
}

qDebug("BladeRF2MIMO::startRx");

if (!m_open)
Expand All @@ -150,12 +156,6 @@ bool BladeRF2MIMO::startRx()
return false;
}

QMutexLocker mutexLocker(&m_mutex);

if (m_runningRx) {
stopRx();
}

m_sourceThread = new BladeRF2MIThread(m_dev->getDev());
m_sampleMIFifo.reset();
m_sourceThread->setFifo(&m_sampleMIFifo);
Expand All @@ -178,6 +178,12 @@ bool BladeRF2MIMO::startRx()

bool BladeRF2MIMO::startTx()
{
QMutexLocker mutexLocker(&m_mutex);

if (m_runningTx) {
return true;
}

qDebug("BladeRF2MIMO::startTx");

if (!m_open)
Expand All @@ -186,12 +192,6 @@ bool BladeRF2MIMO::startTx()
return false;
}

QMutexLocker mutexLocker(&m_mutex);

if (m_runningTx) {
stopTx();
}

m_sinkThread = new BladeRF2MOThread(m_dev->getDev());
m_sampleMOFifo.reset();
m_sinkThread->setFifo(&m_sampleMOFifo);
Expand All @@ -213,18 +213,22 @@ bool BladeRF2MIMO::startTx()

void BladeRF2MIMO::stopRx()
{
qDebug("BladeRF2MIMO::stopRx");
QMutexLocker mutexLocker(&m_mutex);

if (!m_runningRx) {
return;
}

if (!m_sourceThread) {
return;
}

QMutexLocker mutexLocker(&m_mutex);
qDebug("BladeRF2MIMO::stopRx");
m_runningRx = false;

m_sourceThread->stopWork();
delete m_sourceThread;
m_sourceThread = nullptr;
m_runningRx = false;

for (int i = 0; i < 2; i++) {
m_dev->closeRx(i);
Expand All @@ -233,18 +237,22 @@ void BladeRF2MIMO::stopRx()

void BladeRF2MIMO::stopTx()
{
qDebug("BladeRF2MIMO::stopTx");
QMutexLocker mutexLocker(&m_mutex);

if (!m_runningTx) {
return;
}

if (!m_sinkThread) {
return;
}

QMutexLocker mutexLocker(&m_mutex);
qDebug("BladeRF2MIMO::stopTx");
m_runningTx = false;

m_sinkThread->stopWork();
delete m_sinkThread;
m_sinkThread = nullptr;
m_runningTx = false;

for (int i = 0; i < 2; i++) {
m_dev->closeTx(i);
Expand Down
44 changes: 26 additions & 18 deletions plugins/samplemimo/limesdrmimo/limesdrmimo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,12 @@ void LimeSDRMIMO::init()

bool LimeSDRMIMO::startRx()
{
QMutexLocker mutexLocker(&m_mutex);

if (m_runningRx) {
return true;
}

qDebug("LimeSDRMIMO::startRx");
lms_stream_t *streams[2];

Expand All @@ -265,12 +271,6 @@ bool LimeSDRMIMO::startRx()
return false;
}

QMutexLocker mutexLocker(&m_mutex);

if (m_runningRx) {
stopRx();
}

for (unsigned int channel = 0; channel < 2; channel++)
{
if (channel < m_deviceAPI->getNbSourceStreams())
Expand Down Expand Up @@ -307,18 +307,22 @@ bool LimeSDRMIMO::startRx()

void LimeSDRMIMO::stopRx()
{
qDebug("LimeSDRMIMO::stopRx");
QMutexLocker mutexLocker(&m_mutex);

if (!m_runningRx) {
return;
}

if (!m_sourceThread) {
return;
}

QMutexLocker mutexLocker(&m_mutex);
qDebug("LimeSDRMIMO::stopRx");
m_runningRx = false;

m_sourceThread->stopWork();
delete m_sourceThread;
m_sourceThread = nullptr;
m_runningRx = false;

for (unsigned int channel = 0; channel < 2; channel++)
{
Expand All @@ -330,6 +334,12 @@ void LimeSDRMIMO::stopRx()

bool LimeSDRMIMO::startTx()
{
QMutexLocker mutexLocker(&m_mutex);

if (m_runningTx) {
return true;
}

qDebug("LimeSDRMIMO::startTx");
lms_stream_t *streams[2];

Expand All @@ -339,12 +349,6 @@ bool LimeSDRMIMO::startTx()
return false;
}

QMutexLocker mutexLocker(&m_mutex);

if (m_runningTx) {
stopTx();
}

for (unsigned int channel = 0; channel < 2; channel++)
{
if (channel < m_deviceAPI->getNbSinkStreams())
Expand Down Expand Up @@ -380,18 +384,22 @@ bool LimeSDRMIMO::startTx()

void LimeSDRMIMO::stopTx()
{
qDebug("LimeSDRMIMO::stopTx");
QMutexLocker mutexLocker(&m_mutex);

if (!m_runningTx) {
return;
}

if (!m_sinkThread) {
return;
}

QMutexLocker mutexLocker(&m_mutex);
qDebug("LimeSDRMIMO::stopTx");
m_runningTx = false;

m_sinkThread->stopWork();
delete m_sinkThread;
m_sinkThread = nullptr;
m_runningTx = false;

for (unsigned int channel = 0; channel < 2; channel++)
{
Expand Down
44 changes: 26 additions & 18 deletions plugins/samplemimo/plutosdrmimo/plutosdrmimo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,19 +168,19 @@ void PlutoSDRMIMO::init()

bool PlutoSDRMIMO::startRx()
{
qDebug("PlutoSDRMIMO::startRx");
QMutexLocker mutexLocker(&m_mutex);

if (m_runningRx) {
return true;
}

if (!m_open)
{
qCritical("PlutoSDRMIMO::startRx: device was not opened");
return false;
}

QMutexLocker mutexLocker(&m_mutex);

if (m_runningRx) {
stopRx();
}
qDebug("PlutoSDRMIMO::startRx");

m_sourceThread = new PlutoSDRMIThread(m_plutoParams->getBox());
m_sampleMIFifo.reset();
Expand All @@ -206,19 +206,19 @@ bool PlutoSDRMIMO::startRx()

bool PlutoSDRMIMO::startTx()
{
qDebug("PlutoSDRMIMO::startTx");
QMutexLocker mutexLocker(&m_mutex);

if (m_runningTx) {
return true;
}

if (!m_open)
{
qCritical("PlutoSDRMIMO::startTx: device was not opened");
return false;
}

QMutexLocker mutexLocker(&m_mutex);

if (m_runningTx) {
stopTx();
}
qDebug("PlutoSDRMIMO::startTx");

m_sinkThread = new PlutoSDRMOThread(m_plutoParams->getBox());
m_sampleMOFifo.reset();
Expand All @@ -243,18 +243,22 @@ bool PlutoSDRMIMO::startTx()

void PlutoSDRMIMO::stopRx()
{
qDebug("PlutoSDRMIMO::stopRx");
QMutexLocker mutexLocker(&m_mutex);

if (!m_runningRx) {
return;
}

if (!m_sourceThread) {
return;
}

QMutexLocker mutexLocker(&m_mutex);
qDebug("PlutoSDRMIMO::stopRx");
m_runningRx = false;

m_sourceThread->stopWork();
delete m_sourceThread;
m_sourceThread = nullptr;
m_runningRx = false;

if (m_nbRx > 1) {
m_plutoParams->getBox()->closeSecondRx();
Expand All @@ -270,18 +274,22 @@ void PlutoSDRMIMO::stopRx()

void PlutoSDRMIMO::stopTx()
{
qDebug("PlutoSDRMIMO::stopTx");
QMutexLocker mutexLocker(&m_mutex);

if (!m_runningTx) {
return;
}

if (!m_sinkThread) {
return;
}

QMutexLocker mutexLocker(&m_mutex);
qDebug("PlutoSDRMIMO::stopTx");
m_runningTx = false;

m_sinkThread->stopWork();
delete m_sinkThread;
m_sinkThread = nullptr;
m_runningTx = false;

if (m_nbTx > 1) {
m_plutoParams->getBox()->closeSecondTx();
Expand Down
2 changes: 1 addition & 1 deletion plugins/samplemimo/testmi/testmi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ void TestMI::stopRx()
}

qDebug("TestMI::stopRx");
m_running = false;
m_running = false;
stopWorkers();

m_testSourceWorkers.clear();
Expand Down
Loading

0 comments on commit 585d806

Please sign in to comment.