diff --git a/plugins/samplemimo/testmi/testmi.cpp b/plugins/samplemimo/testmi/testmi.cpp index 0bb04e505..e01b8fb58 100644 --- a/plugins/samplemimo/testmi/testmi.cpp +++ b/plugins/samplemimo/testmi/testmi.cpp @@ -22,6 +22,7 @@ #include #include #include +#include #include "SWGDeviceSettings.h" #include "SWGDeviceState.h" diff --git a/plugins/samplemimo/testmi/testmi.h b/plugins/samplemimo/testmi/testmi.h index 569bf641e..db6e60431 100644 --- a/plugins/samplemimo/testmi/testmi.h +++ b/plugins/samplemimo/testmi/testmi.h @@ -22,7 +22,6 @@ #include #include #include -#include #include "dsp/devicesamplemimo.h" #include "testmisettings.h" @@ -31,6 +30,7 @@ class DeviceAPI; class TestMIWorker; class QNetworkAccessManager; class QNetworkReply; +class QThread; class TestMI : public DeviceSampleMIMO { Q_OBJECT diff --git a/plugins/samplemimo/testmosync/testmosync.cpp b/plugins/samplemimo/testmosync/testmosync.cpp index dccbb91df..463eb2730 100644 --- a/plugins/samplemimo/testmosync/testmosync.cpp +++ b/plugins/samplemimo/testmosync/testmosync.cpp @@ -20,6 +20,7 @@ #include #include +#include #include "SWGDeviceSettings.h" #include "SWGDeviceState.h" @@ -42,6 +43,7 @@ TestMOSync::TestMOSync(DeviceAPI *deviceAPI) : m_spectrumVis(SDR_TX_SCALEF), m_settings(), m_sinkWorker(nullptr), + m_sinkWorkerThread(nullptr), m_deviceDescription("TestMOSync"), m_runningTx(false), m_masterTimer(deviceAPI->getMasterTimer()), @@ -68,15 +70,20 @@ void TestMOSync::init() bool TestMOSync::startTx() { - qDebug("TestMOSync::startTx"); QMutexLocker mutexLocker(&m_mutex); if (m_runningTx) { - stopTx(); + return true; } + qDebug("TestMOSync::startTx"); + m_sinkWorkerThread = new QThread(); m_sinkWorker = new TestMOSyncWorker(); - m_sinkWorker->moveToThread(&m_sinkWorkerThread); + m_sinkWorker->moveToThread(m_sinkWorkerThread); + + QObject::connect(m_sinkWorkerThread, &QThread::finished, m_sinkWorker, &QObject::deleteLater); + QObject::connect(m_sinkWorkerThread, &QThread::finished, m_sinkWorkerThread, &QThread::deleteLater); + m_sampleMOFifo.reset(); m_sinkWorker->setFifo(&m_sampleMOFifo); m_sinkWorker->setFcPos(m_settings.m_fcPosTx); @@ -94,31 +101,31 @@ bool TestMOSync::startTx() void TestMOSync::stopTx() { - qDebug("TestMOSync::stopTx"); + QMutexLocker mutexLocker(&m_mutex); - if (!m_sinkWorker) { + if (!m_runningTx) { return; } - QMutexLocker mutexLocker(&m_mutex); + qDebug("TestMOSync::stopTx"); + m_runningTx = false; stopWorker(); - delete m_sinkWorker; m_sinkWorker = nullptr; - m_runningTx = false; + m_sinkWorkerThread = nullptr; } void TestMOSync::startWorker() { m_sinkWorker->startWork(); - m_sinkWorkerThread.start(); + m_sinkWorkerThread->start(); } void TestMOSync::stopWorker() { m_sinkWorker->stopWork(); - m_sinkWorkerThread.quit(); - m_sinkWorkerThread.wait(); + m_sinkWorkerThread->quit(); + m_sinkWorkerThread->wait(); } QByteArray TestMOSync::serialize() const diff --git a/plugins/samplemimo/testmosync/testmosync.h b/plugins/samplemimo/testmosync/testmosync.h index 76caf2587..11c1066f7 100644 --- a/plugins/samplemimo/testmosync/testmosync.h +++ b/plugins/samplemimo/testmosync/testmosync.h @@ -23,7 +23,6 @@ #include #include #include -#include #include "dsp/devicesamplemimo.h" #include "dsp/spectrumvis.h" @@ -32,6 +31,7 @@ class DeviceAPI; class TestMOSyncWorker; class BasebandSampleSink; +class QThread; class TestMOSync : public DeviceSampleMIMO { Q_OBJECT @@ -153,8 +153,8 @@ private: QMutex m_mutex; SpectrumVis m_spectrumVis; TestMOSyncSettings m_settings; - TestMOSyncWorker* m_sinkWorker; - QThread m_sinkWorkerThread; + TestMOSyncWorker *m_sinkWorker; + QThread *m_sinkWorkerThread; QString m_deviceDescription; bool m_runningTx; const QTimer& m_masterTimer;