mirror of
https://github.com/f4exb/sdrangel.git
synced 2026-06-01 21:54:55 -04:00
TestSource: refactored Thread to Worker object moved to thread. Equivalent to FileInput changes
This commit is contained in:
@@ -30,7 +30,7 @@
|
||||
|
||||
#include "testsourceinput.h"
|
||||
#include "device/deviceapi.h"
|
||||
#include "testsourcethread.h"
|
||||
#include "testsourceworker.h"
|
||||
#include "dsp/dspcommands.h"
|
||||
#include "dsp/dspengine.h"
|
||||
#include "dsp/filerecord.h"
|
||||
@@ -43,7 +43,7 @@ MESSAGE_CLASS_DEFINITION(TestSourceInput::MsgStartStop, Message)
|
||||
TestSourceInput::TestSourceInput(DeviceAPI *deviceAPI) :
|
||||
m_deviceAPI(deviceAPI),
|
||||
m_settings(),
|
||||
m_testSourceThread(0),
|
||||
m_testSourceWorker(nullptr),
|
||||
m_deviceDescription(),
|
||||
m_running(false),
|
||||
m_masterTimer(deviceAPI->getMasterTimer())
|
||||
@@ -87,11 +87,14 @@ bool TestSourceInput::start()
|
||||
{
|
||||
QMutexLocker mutexLocker(&m_mutex);
|
||||
|
||||
if (m_running) stop();
|
||||
if (m_running) {
|
||||
stop();
|
||||
}
|
||||
|
||||
m_testSourceThread = new TestSourceThread(&m_sampleFifo);
|
||||
m_testSourceThread->setSamplerate(m_settings.m_sampleRate);
|
||||
m_testSourceThread->startStop(true);
|
||||
m_testSourceWorker = new TestSourceWorker(&m_sampleFifo);
|
||||
m_testSourceWorker->moveToThread(&m_testSourceWorkerThread);
|
||||
m_testSourceWorker->setSamplerate(m_settings.m_sampleRate);
|
||||
startWorker();
|
||||
|
||||
mutexLocker.unlock();
|
||||
|
||||
@@ -105,16 +108,30 @@ void TestSourceInput::stop()
|
||||
{
|
||||
QMutexLocker mutexLocker(&m_mutex);
|
||||
|
||||
if (m_testSourceThread != 0)
|
||||
if (m_testSourceWorker)
|
||||
{
|
||||
m_testSourceThread->startStop(false);
|
||||
m_testSourceThread->deleteLater();
|
||||
m_testSourceThread = 0;
|
||||
stopWorker();
|
||||
m_testSourceWorker->deleteLater();
|
||||
m_testSourceWorker = nullptr;
|
||||
}
|
||||
|
||||
m_running = false;
|
||||
}
|
||||
|
||||
void TestSourceInput::startWorker()
|
||||
{
|
||||
m_testSourceWorker->startWork();
|
||||
m_testSourceWorkerThread.start();
|
||||
}
|
||||
|
||||
void TestSourceInput::stopWorker()
|
||||
{
|
||||
m_testSourceWorker->stopWork();
|
||||
m_testSourceWorkerThread.quit();
|
||||
m_testSourceWorkerThread.wait();
|
||||
}
|
||||
|
||||
|
||||
QByteArray TestSourceInput::serialize() const
|
||||
{
|
||||
return m_settings.serialize();
|
||||
@@ -266,9 +283,9 @@ bool TestSourceInput::applySettings(const TestSourceSettings& settings, bool for
|
||||
{
|
||||
reverseAPIKeys.append("sampleRate");
|
||||
|
||||
if (m_testSourceThread != 0)
|
||||
if (m_testSourceWorker != 0)
|
||||
{
|
||||
m_testSourceThread->setSamplerate(settings.m_sampleRate);
|
||||
m_testSourceWorker->setSamplerate(settings.m_sampleRate);
|
||||
qDebug("TestSourceInput::applySettings: sample rate set to %d", settings.m_sampleRate);
|
||||
}
|
||||
}
|
||||
@@ -277,9 +294,9 @@ bool TestSourceInput::applySettings(const TestSourceSettings& settings, bool for
|
||||
{
|
||||
reverseAPIKeys.append("log2Decim");
|
||||
|
||||
if (m_testSourceThread != 0)
|
||||
if (m_testSourceWorker != 0)
|
||||
{
|
||||
m_testSourceThread->setLog2Decimation(settings.m_log2Decim);
|
||||
m_testSourceWorker->setLog2Decimation(settings.m_log2Decim);
|
||||
qDebug() << "TestSourceInput::applySettings: set decimation to " << (1<<settings.m_log2Decim);
|
||||
}
|
||||
}
|
||||
@@ -315,10 +332,10 @@ bool TestSourceInput::applySettings(const TestSourceSettings& settings, bool for
|
||||
DeviceSampleSource::FSHIFT_STD);
|
||||
}
|
||||
|
||||
if (m_testSourceThread != 0)
|
||||
if (m_testSourceWorker != 0)
|
||||
{
|
||||
m_testSourceThread->setFcPos((int) settings.m_fcPos);
|
||||
m_testSourceThread->setFrequencyShift(frequencyShift);
|
||||
m_testSourceWorker->setFcPos((int) settings.m_fcPos);
|
||||
m_testSourceWorker->setFrequencyShift(frequencyShift);
|
||||
qDebug() << "TestSourceInput::applySettings:"
|
||||
<< " center freq: " << settings.m_centerFrequency << " Hz"
|
||||
<< " device center freq: " << deviceCenterFrequency << " Hz"
|
||||
@@ -332,8 +349,8 @@ bool TestSourceInput::applySettings(const TestSourceSettings& settings, bool for
|
||||
{
|
||||
reverseAPIKeys.append("amplitudeBits");
|
||||
|
||||
if (m_testSourceThread != 0) {
|
||||
m_testSourceThread->setAmplitudeBits(settings.m_amplitudeBits);
|
||||
if (m_testSourceWorker != 0) {
|
||||
m_testSourceWorker->setAmplitudeBits(settings.m_amplitudeBits);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -341,8 +358,8 @@ bool TestSourceInput::applySettings(const TestSourceSettings& settings, bool for
|
||||
{
|
||||
reverseAPIKeys.append("dcFactor");
|
||||
|
||||
if (m_testSourceThread != 0) {
|
||||
m_testSourceThread->setDCFactor(settings.m_dcFactor);
|
||||
if (m_testSourceWorker != 0) {
|
||||
m_testSourceWorker->setDCFactor(settings.m_dcFactor);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -350,8 +367,8 @@ bool TestSourceInput::applySettings(const TestSourceSettings& settings, bool for
|
||||
{
|
||||
reverseAPIKeys.append("iFactor");
|
||||
|
||||
if (m_testSourceThread != 0) {
|
||||
m_testSourceThread->setIFactor(settings.m_iFactor);
|
||||
if (m_testSourceWorker != 0) {
|
||||
m_testSourceWorker->setIFactor(settings.m_iFactor);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -359,8 +376,8 @@ bool TestSourceInput::applySettings(const TestSourceSettings& settings, bool for
|
||||
{
|
||||
reverseAPIKeys.append("qFactor");
|
||||
|
||||
if (m_testSourceThread != 0) {
|
||||
m_testSourceThread->setQFactor(settings.m_qFactor);
|
||||
if (m_testSourceWorker != 0) {
|
||||
m_testSourceWorker->setQFactor(settings.m_qFactor);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -368,8 +385,8 @@ bool TestSourceInput::applySettings(const TestSourceSettings& settings, bool for
|
||||
{
|
||||
reverseAPIKeys.append("phaseImbalance");
|
||||
|
||||
if (m_testSourceThread != 0) {
|
||||
m_testSourceThread->setPhaseImbalance(settings.m_phaseImbalance);
|
||||
if (m_testSourceWorker != 0) {
|
||||
m_testSourceWorker->setPhaseImbalance(settings.m_phaseImbalance);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -377,8 +394,8 @@ bool TestSourceInput::applySettings(const TestSourceSettings& settings, bool for
|
||||
{
|
||||
reverseAPIKeys.append("sampleSizeIndex");
|
||||
|
||||
if (m_testSourceThread != 0) {
|
||||
m_testSourceThread->setBitSize(settings.m_sampleSizeIndex);
|
||||
if (m_testSourceWorker != 0) {
|
||||
m_testSourceWorker->setBitSize(settings.m_sampleSizeIndex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -397,8 +414,8 @@ bool TestSourceInput::applySettings(const TestSourceSettings& settings, bool for
|
||||
{
|
||||
reverseAPIKeys.append("modulationTone");
|
||||
|
||||
if (m_testSourceThread != 0) {
|
||||
m_testSourceThread->setToneFrequency(settings.m_modulationTone * 10);
|
||||
if (m_testSourceWorker != 0) {
|
||||
m_testSourceWorker->setToneFrequency(settings.m_modulationTone * 10);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -406,16 +423,16 @@ bool TestSourceInput::applySettings(const TestSourceSettings& settings, bool for
|
||||
{
|
||||
reverseAPIKeys.append("modulation");
|
||||
|
||||
if (m_testSourceThread != 0)
|
||||
if (m_testSourceWorker != 0)
|
||||
{
|
||||
m_testSourceThread->setModulation(settings.m_modulation);
|
||||
m_testSourceWorker->setModulation(settings.m_modulation);
|
||||
|
||||
if (settings.m_modulation == TestSourceSettings::ModulationPattern0) {
|
||||
m_testSourceThread->setPattern0();
|
||||
m_testSourceWorker->setPattern0();
|
||||
} else if (settings.m_modulation == TestSourceSettings::ModulationPattern1) {
|
||||
m_testSourceThread->setPattern1();
|
||||
m_testSourceWorker->setPattern1();
|
||||
} else if (settings.m_modulation == TestSourceSettings::ModulationPattern2) {
|
||||
m_testSourceThread->setPattern2();
|
||||
m_testSourceWorker->setPattern2();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -424,8 +441,8 @@ bool TestSourceInput::applySettings(const TestSourceSettings& settings, bool for
|
||||
{
|
||||
reverseAPIKeys.append("amModulation");
|
||||
|
||||
if (m_testSourceThread != 0) {
|
||||
m_testSourceThread->setAMModulation(settings.m_amModulation / 100.0f);
|
||||
if (m_testSourceWorker != 0) {
|
||||
m_testSourceWorker->setAMModulation(settings.m_amModulation / 100.0f);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -433,8 +450,8 @@ bool TestSourceInput::applySettings(const TestSourceSettings& settings, bool for
|
||||
{
|
||||
reverseAPIKeys.append("fmDeviation");
|
||||
|
||||
if (m_testSourceThread != 0) {
|
||||
m_testSourceThread->setFMDeviation(settings.m_fmDeviation * 100.0f);
|
||||
if (m_testSourceWorker != 0) {
|
||||
m_testSourceWorker->setFMDeviation(settings.m_fmDeviation * 100.0f);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user