mirror of
				https://github.com/f4exb/sdrangel.git
				synced 2025-11-03 13:11:20 -05:00 
			
		
		
		
	TestMOSync: updated threading model. Part of #1346
This commit is contained in:
		
							parent
							
								
									0e236f8acc
								
							
						
					
					
						commit
						9e4fe95bba
					
				@ -22,6 +22,7 @@
 | 
				
			|||||||
#include <QNetworkReply>
 | 
					#include <QNetworkReply>
 | 
				
			||||||
#include <QNetworkAccessManager>
 | 
					#include <QNetworkAccessManager>
 | 
				
			||||||
#include <QBuffer>
 | 
					#include <QBuffer>
 | 
				
			||||||
 | 
					#include <QThread>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include "SWGDeviceSettings.h"
 | 
					#include "SWGDeviceSettings.h"
 | 
				
			||||||
#include "SWGDeviceState.h"
 | 
					#include "SWGDeviceState.h"
 | 
				
			||||||
 | 
				
			|||||||
@ -22,7 +22,6 @@
 | 
				
			|||||||
#include <QByteArray>
 | 
					#include <QByteArray>
 | 
				
			||||||
#include <QTimer>
 | 
					#include <QTimer>
 | 
				
			||||||
#include <QNetworkRequest>
 | 
					#include <QNetworkRequest>
 | 
				
			||||||
#include <QThread>
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include "dsp/devicesamplemimo.h"
 | 
					#include "dsp/devicesamplemimo.h"
 | 
				
			||||||
#include "testmisettings.h"
 | 
					#include "testmisettings.h"
 | 
				
			||||||
@ -31,6 +30,7 @@ class DeviceAPI;
 | 
				
			|||||||
class TestMIWorker;
 | 
					class TestMIWorker;
 | 
				
			||||||
class QNetworkAccessManager;
 | 
					class QNetworkAccessManager;
 | 
				
			||||||
class QNetworkReply;
 | 
					class QNetworkReply;
 | 
				
			||||||
 | 
					class QThread;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class TestMI : public DeviceSampleMIMO {
 | 
					class TestMI : public DeviceSampleMIMO {
 | 
				
			||||||
    Q_OBJECT
 | 
					    Q_OBJECT
 | 
				
			||||||
 | 
				
			|||||||
@ -20,6 +20,7 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
#include <QDebug>
 | 
					#include <QDebug>
 | 
				
			||||||
#include <QBuffer>
 | 
					#include <QBuffer>
 | 
				
			||||||
 | 
					#include <QThread>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include "SWGDeviceSettings.h"
 | 
					#include "SWGDeviceSettings.h"
 | 
				
			||||||
#include "SWGDeviceState.h"
 | 
					#include "SWGDeviceState.h"
 | 
				
			||||||
@ -42,6 +43,7 @@ TestMOSync::TestMOSync(DeviceAPI *deviceAPI) :
 | 
				
			|||||||
    m_spectrumVis(SDR_TX_SCALEF),
 | 
					    m_spectrumVis(SDR_TX_SCALEF),
 | 
				
			||||||
	m_settings(),
 | 
						m_settings(),
 | 
				
			||||||
    m_sinkWorker(nullptr),
 | 
					    m_sinkWorker(nullptr),
 | 
				
			||||||
 | 
					    m_sinkWorkerThread(nullptr),
 | 
				
			||||||
	m_deviceDescription("TestMOSync"),
 | 
						m_deviceDescription("TestMOSync"),
 | 
				
			||||||
    m_runningTx(false),
 | 
					    m_runningTx(false),
 | 
				
			||||||
    m_masterTimer(deviceAPI->getMasterTimer()),
 | 
					    m_masterTimer(deviceAPI->getMasterTimer()),
 | 
				
			||||||
@ -68,15 +70,20 @@ void TestMOSync::init()
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
bool TestMOSync::startTx()
 | 
					bool TestMOSync::startTx()
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    qDebug("TestMOSync::startTx");
 | 
					 | 
				
			||||||
	QMutexLocker mutexLocker(&m_mutex);
 | 
						QMutexLocker mutexLocker(&m_mutex);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (m_runningTx) {
 | 
					    if (m_runningTx) {
 | 
				
			||||||
        stopTx();
 | 
					        return true;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    qDebug("TestMOSync::startTx");
 | 
				
			||||||
 | 
					    m_sinkWorkerThread = new QThread();
 | 
				
			||||||
    m_sinkWorker = new TestMOSyncWorker();
 | 
					    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_sampleMOFifo.reset();
 | 
				
			||||||
    m_sinkWorker->setFifo(&m_sampleMOFifo);
 | 
					    m_sinkWorker->setFifo(&m_sampleMOFifo);
 | 
				
			||||||
    m_sinkWorker->setFcPos(m_settings.m_fcPosTx);
 | 
					    m_sinkWorker->setFcPos(m_settings.m_fcPosTx);
 | 
				
			||||||
@ -94,31 +101,31 @@ bool TestMOSync::startTx()
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
void TestMOSync::stopTx()
 | 
					void TestMOSync::stopTx()
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    qDebug("TestMOSync::stopTx");
 | 
						QMutexLocker mutexLocker(&m_mutex);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (!m_sinkWorker) {
 | 
					    if (!m_runningTx) {
 | 
				
			||||||
        return;
 | 
					        return;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	QMutexLocker mutexLocker(&m_mutex);
 | 
					    qDebug("TestMOSync::stopTx");
 | 
				
			||||||
 | 
					    m_runningTx = false;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    stopWorker();
 | 
					    stopWorker();
 | 
				
			||||||
    delete m_sinkWorker;
 | 
					 | 
				
			||||||
    m_sinkWorker = nullptr;
 | 
					    m_sinkWorker = nullptr;
 | 
				
			||||||
    m_runningTx = false;
 | 
					    m_sinkWorkerThread = nullptr;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void TestMOSync::startWorker()
 | 
					void TestMOSync::startWorker()
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    m_sinkWorker->startWork();
 | 
					    m_sinkWorker->startWork();
 | 
				
			||||||
    m_sinkWorkerThread.start();
 | 
					    m_sinkWorkerThread->start();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void TestMOSync::stopWorker()
 | 
					void TestMOSync::stopWorker()
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    m_sinkWorker->stopWork();
 | 
					    m_sinkWorker->stopWork();
 | 
				
			||||||
    m_sinkWorkerThread.quit();
 | 
					    m_sinkWorkerThread->quit();
 | 
				
			||||||
    m_sinkWorkerThread.wait();
 | 
					    m_sinkWorkerThread->wait();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
QByteArray TestMOSync::serialize() const
 | 
					QByteArray TestMOSync::serialize() const
 | 
				
			||||||
 | 
				
			|||||||
@ -23,7 +23,6 @@
 | 
				
			|||||||
#include <QString>
 | 
					#include <QString>
 | 
				
			||||||
#include <QByteArray>
 | 
					#include <QByteArray>
 | 
				
			||||||
#include <QTimer>
 | 
					#include <QTimer>
 | 
				
			||||||
#include <QThread>
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include "dsp/devicesamplemimo.h"
 | 
					#include "dsp/devicesamplemimo.h"
 | 
				
			||||||
#include "dsp/spectrumvis.h"
 | 
					#include "dsp/spectrumvis.h"
 | 
				
			||||||
@ -32,6 +31,7 @@
 | 
				
			|||||||
class DeviceAPI;
 | 
					class DeviceAPI;
 | 
				
			||||||
class TestMOSyncWorker;
 | 
					class TestMOSyncWorker;
 | 
				
			||||||
class BasebandSampleSink;
 | 
					class BasebandSampleSink;
 | 
				
			||||||
 | 
					class QThread;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class TestMOSync : public DeviceSampleMIMO {
 | 
					class TestMOSync : public DeviceSampleMIMO {
 | 
				
			||||||
    Q_OBJECT
 | 
					    Q_OBJECT
 | 
				
			||||||
@ -153,8 +153,8 @@ private:
 | 
				
			|||||||
	QMutex m_mutex;
 | 
						QMutex m_mutex;
 | 
				
			||||||
    SpectrumVis m_spectrumVis;
 | 
					    SpectrumVis m_spectrumVis;
 | 
				
			||||||
	TestMOSyncSettings m_settings;
 | 
						TestMOSyncSettings m_settings;
 | 
				
			||||||
    TestMOSyncWorker* m_sinkWorker;
 | 
					    TestMOSyncWorker *m_sinkWorker;
 | 
				
			||||||
    QThread m_sinkWorkerThread;
 | 
					    QThread *m_sinkWorkerThread;
 | 
				
			||||||
	QString m_deviceDescription;
 | 
						QString m_deviceDescription;
 | 
				
			||||||
	bool m_runningTx;
 | 
						bool m_runningTx;
 | 
				
			||||||
    const QTimer& m_masterTimer;
 | 
					    const QTimer& m_masterTimer;
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user