1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-11-23 00:18:37 -05:00

TestSource: refactored Thread to Worker object moved to thread. Equivalent to FileInput changes

This commit is contained in:
f4exb 2020-07-12 02:39:29 +02:00
parent 059d0dc4f2
commit b8681d59a9
5 changed files with 112 additions and 159 deletions

View File

@ -3,7 +3,7 @@ project(testsource)
set(testsource_SOURCES set(testsource_SOURCES
testsourceinput.cpp testsourceinput.cpp
testsourceplugin.cpp testsourceplugin.cpp
testsourcethread.cpp testsourceworker.cpp
testsourcesettings.cpp testsourcesettings.cpp
testsourcewebapiadapter.cpp testsourcewebapiadapter.cpp
) )
@ -11,7 +11,7 @@ set(testsource_SOURCES
set(testsource_HEADERS set(testsource_HEADERS
testsourceinput.h testsourceinput.h
testsourceplugin.h testsourceplugin.h
testsourcethread.h testsourceworker.h
testsourcesettings.h testsourcesettings.h
testsourcewebapiadapter.h testsourcewebapiadapter.h
) )

View File

@ -30,7 +30,7 @@
#include "testsourceinput.h" #include "testsourceinput.h"
#include "device/deviceapi.h" #include "device/deviceapi.h"
#include "testsourcethread.h" #include "testsourceworker.h"
#include "dsp/dspcommands.h" #include "dsp/dspcommands.h"
#include "dsp/dspengine.h" #include "dsp/dspengine.h"
#include "dsp/filerecord.h" #include "dsp/filerecord.h"
@ -43,7 +43,7 @@ MESSAGE_CLASS_DEFINITION(TestSourceInput::MsgStartStop, Message)
TestSourceInput::TestSourceInput(DeviceAPI *deviceAPI) : TestSourceInput::TestSourceInput(DeviceAPI *deviceAPI) :
m_deviceAPI(deviceAPI), m_deviceAPI(deviceAPI),
m_settings(), m_settings(),
m_testSourceThread(0), m_testSourceWorker(nullptr),
m_deviceDescription(), m_deviceDescription(),
m_running(false), m_running(false),
m_masterTimer(deviceAPI->getMasterTimer()) m_masterTimer(deviceAPI->getMasterTimer())
@ -87,11 +87,14 @@ bool TestSourceInput::start()
{ {
QMutexLocker mutexLocker(&m_mutex); QMutexLocker mutexLocker(&m_mutex);
if (m_running) stop(); if (m_running) {
stop();
}
m_testSourceThread = new TestSourceThread(&m_sampleFifo); m_testSourceWorker = new TestSourceWorker(&m_sampleFifo);
m_testSourceThread->setSamplerate(m_settings.m_sampleRate); m_testSourceWorker->moveToThread(&m_testSourceWorkerThread);
m_testSourceThread->startStop(true); m_testSourceWorker->setSamplerate(m_settings.m_sampleRate);
startWorker();
mutexLocker.unlock(); mutexLocker.unlock();
@ -105,16 +108,30 @@ void TestSourceInput::stop()
{ {
QMutexLocker mutexLocker(&m_mutex); QMutexLocker mutexLocker(&m_mutex);
if (m_testSourceThread != 0) if (m_testSourceWorker)
{ {
m_testSourceThread->startStop(false); stopWorker();
m_testSourceThread->deleteLater(); m_testSourceWorker->deleteLater();
m_testSourceThread = 0; m_testSourceWorker = nullptr;
} }
m_running = false; 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 QByteArray TestSourceInput::serialize() const
{ {
return m_settings.serialize(); return m_settings.serialize();
@ -266,9 +283,9 @@ bool TestSourceInput::applySettings(const TestSourceSettings& settings, bool for
{ {
reverseAPIKeys.append("sampleRate"); 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); 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"); 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); 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); DeviceSampleSource::FSHIFT_STD);
} }
if (m_testSourceThread != 0) if (m_testSourceWorker != 0)
{ {
m_testSourceThread->setFcPos((int) settings.m_fcPos); m_testSourceWorker->setFcPos((int) settings.m_fcPos);
m_testSourceThread->setFrequencyShift(frequencyShift); m_testSourceWorker->setFrequencyShift(frequencyShift);
qDebug() << "TestSourceInput::applySettings:" qDebug() << "TestSourceInput::applySettings:"
<< " center freq: " << settings.m_centerFrequency << " Hz" << " center freq: " << settings.m_centerFrequency << " Hz"
<< " device center freq: " << deviceCenterFrequency << " Hz" << " device center freq: " << deviceCenterFrequency << " Hz"
@ -332,8 +349,8 @@ bool TestSourceInput::applySettings(const TestSourceSettings& settings, bool for
{ {
reverseAPIKeys.append("amplitudeBits"); reverseAPIKeys.append("amplitudeBits");
if (m_testSourceThread != 0) { if (m_testSourceWorker != 0) {
m_testSourceThread->setAmplitudeBits(settings.m_amplitudeBits); m_testSourceWorker->setAmplitudeBits(settings.m_amplitudeBits);
} }
} }
@ -341,8 +358,8 @@ bool TestSourceInput::applySettings(const TestSourceSettings& settings, bool for
{ {
reverseAPIKeys.append("dcFactor"); reverseAPIKeys.append("dcFactor");
if (m_testSourceThread != 0) { if (m_testSourceWorker != 0) {
m_testSourceThread->setDCFactor(settings.m_dcFactor); m_testSourceWorker->setDCFactor(settings.m_dcFactor);
} }
} }
@ -350,8 +367,8 @@ bool TestSourceInput::applySettings(const TestSourceSettings& settings, bool for
{ {
reverseAPIKeys.append("iFactor"); reverseAPIKeys.append("iFactor");
if (m_testSourceThread != 0) { if (m_testSourceWorker != 0) {
m_testSourceThread->setIFactor(settings.m_iFactor); m_testSourceWorker->setIFactor(settings.m_iFactor);
} }
} }
@ -359,8 +376,8 @@ bool TestSourceInput::applySettings(const TestSourceSettings& settings, bool for
{ {
reverseAPIKeys.append("qFactor"); reverseAPIKeys.append("qFactor");
if (m_testSourceThread != 0) { if (m_testSourceWorker != 0) {
m_testSourceThread->setQFactor(settings.m_qFactor); m_testSourceWorker->setQFactor(settings.m_qFactor);
} }
} }
@ -368,8 +385,8 @@ bool TestSourceInput::applySettings(const TestSourceSettings& settings, bool for
{ {
reverseAPIKeys.append("phaseImbalance"); reverseAPIKeys.append("phaseImbalance");
if (m_testSourceThread != 0) { if (m_testSourceWorker != 0) {
m_testSourceThread->setPhaseImbalance(settings.m_phaseImbalance); m_testSourceWorker->setPhaseImbalance(settings.m_phaseImbalance);
} }
} }
@ -377,8 +394,8 @@ bool TestSourceInput::applySettings(const TestSourceSettings& settings, bool for
{ {
reverseAPIKeys.append("sampleSizeIndex"); reverseAPIKeys.append("sampleSizeIndex");
if (m_testSourceThread != 0) { if (m_testSourceWorker != 0) {
m_testSourceThread->setBitSize(settings.m_sampleSizeIndex); m_testSourceWorker->setBitSize(settings.m_sampleSizeIndex);
} }
} }
@ -397,8 +414,8 @@ bool TestSourceInput::applySettings(const TestSourceSettings& settings, bool for
{ {
reverseAPIKeys.append("modulationTone"); reverseAPIKeys.append("modulationTone");
if (m_testSourceThread != 0) { if (m_testSourceWorker != 0) {
m_testSourceThread->setToneFrequency(settings.m_modulationTone * 10); m_testSourceWorker->setToneFrequency(settings.m_modulationTone * 10);
} }
} }
@ -406,16 +423,16 @@ bool TestSourceInput::applySettings(const TestSourceSettings& settings, bool for
{ {
reverseAPIKeys.append("modulation"); 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) { if (settings.m_modulation == TestSourceSettings::ModulationPattern0) {
m_testSourceThread->setPattern0(); m_testSourceWorker->setPattern0();
} else if (settings.m_modulation == TestSourceSettings::ModulationPattern1) { } else if (settings.m_modulation == TestSourceSettings::ModulationPattern1) {
m_testSourceThread->setPattern1(); m_testSourceWorker->setPattern1();
} else if (settings.m_modulation == TestSourceSettings::ModulationPattern2) { } 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"); reverseAPIKeys.append("amModulation");
if (m_testSourceThread != 0) { if (m_testSourceWorker != 0) {
m_testSourceThread->setAMModulation(settings.m_amModulation / 100.0f); m_testSourceWorker->setAMModulation(settings.m_amModulation / 100.0f);
} }
} }
@ -433,8 +450,8 @@ bool TestSourceInput::applySettings(const TestSourceSettings& settings, bool for
{ {
reverseAPIKeys.append("fmDeviation"); reverseAPIKeys.append("fmDeviation");
if (m_testSourceThread != 0) { if (m_testSourceWorker != 0) {
m_testSourceThread->setFMDeviation(settings.m_fmDeviation * 100.0f); m_testSourceWorker->setFMDeviation(settings.m_fmDeviation * 100.0f);
} }
} }

View File

@ -22,12 +22,13 @@
#include <QByteArray> #include <QByteArray>
#include <QTimer> #include <QTimer>
#include <QNetworkRequest> #include <QNetworkRequest>
#include <QThread>
#include <dsp/devicesamplesource.h> #include <dsp/devicesamplesource.h>
#include "testsourcesettings.h" #include "testsourcesettings.h"
class DeviceAPI; class DeviceAPI;
class TestSourceThread; class TestSourceWorker;
class FileRecord; class FileRecord;
class QNetworkAccessManager; class QNetworkAccessManager;
class QNetworkReply; class QNetworkReply;
@ -154,13 +155,16 @@ private:
FileRecord *m_fileSink; //!< File sink to record device I/Q output FileRecord *m_fileSink; //!< File sink to record device I/Q output
QMutex m_mutex; QMutex m_mutex;
TestSourceSettings m_settings; TestSourceSettings m_settings;
TestSourceThread* m_testSourceThread; TestSourceWorker* m_testSourceWorker;
QThread m_testSourceWorkerThread;
QString m_deviceDescription; QString m_deviceDescription;
bool m_running; bool m_running;
const QTimer& m_masterTimer; const QTimer& m_masterTimer;
QNetworkAccessManager *m_networkManager; QNetworkAccessManager *m_networkManager;
QNetworkRequest m_networkRequest; QNetworkRequest m_networkRequest;
void startWorker();
void stopWorker();
bool applySettings(const TestSourceSettings& settings, bool force); bool applySettings(const TestSourceSettings& settings, bool force);
void webapiReverseSendSettings(QList<QString>& deviceSettingsKeys, const TestSourceSettings& settings, bool force); void webapiReverseSendSettings(QList<QString>& deviceSettingsKeys, const TestSourceSettings& settings, bool force);
void webapiReverseSendStartStop(bool start); void webapiReverseSendStartStop(bool start);

View File

@ -19,16 +19,14 @@
#include <math.h> #include <math.h>
#include <stdio.h> #include <stdio.h>
#include <errno.h> #include <errno.h>
#include "testsourcethread.h" #include "testsourceworker.h"
#include "dsp/samplesinkfifo.h" #include "dsp/samplesinkfifo.h"
#define TESTSOURCE_BLOCKSIZE 16384 #define TESTSOURCE_BLOCKSIZE 16384
MESSAGE_CLASS_DEFINITION(TestSourceThread::MsgStartStop, Message) TestSourceWorker::TestSourceWorker(SampleSinkFifo* sampleFifo, QObject* parent) :
QObject(parent),
TestSourceThread::TestSourceThread(SampleSinkFifo* sampleFifo, QObject* parent) :
QThread(parent),
m_running(false), m_running(false),
m_buf(0), m_buf(0),
m_bufsize(0), m_bufsize(0),
@ -69,32 +67,28 @@ TestSourceThread::TestSourceThread(SampleSinkFifo* sampleFifo, QObject* parent)
connect(&m_inputMessageQueue, SIGNAL(messageEnqueued()), this, SLOT(handleInputMessages()), Qt::QueuedConnection); connect(&m_inputMessageQueue, SIGNAL(messageEnqueued()), this, SLOT(handleInputMessages()), Qt::QueuedConnection);
} }
TestSourceThread::~TestSourceThread() TestSourceWorker::~TestSourceWorker()
{ {
} }
void TestSourceThread::startWork() void TestSourceWorker::startWork()
{ {
qDebug("TestSourceWorker::startWork");
m_timer.setTimerType(Qt::PreciseTimer); m_timer.setTimerType(Qt::PreciseTimer);
connect(&m_timer, SIGNAL(timeout()), this, SLOT(tick())); connect(&m_timer, SIGNAL(timeout()), this, SLOT(tick()));
m_timer.start(50); m_timer.start(50);
m_startWaitMutex.lock(); m_running = true;
m_elapsedTimer.start();
start();
while(!m_running)
m_startWaiter.wait(&m_startWaitMutex, 100);
m_startWaitMutex.unlock();
} }
void TestSourceThread::stopWork() void TestSourceWorker::stopWork()
{ {
m_running = false; qDebug("TestSourceWorker::stopWork");
wait();
m_timer.stop(); m_timer.stop();
disconnect(&m_timer, SIGNAL(timeout()), this, SLOT(tick())); disconnect(&m_timer, SIGNAL(timeout()), this, SLOT(tick()));
m_running = false;
} }
void TestSourceThread::setSamplerate(int samplerate) void TestSourceWorker::setSamplerate(int samplerate)
{ {
QMutexLocker mutexLocker(&m_mutex); QMutexLocker mutexLocker(&m_mutex);
@ -105,17 +99,17 @@ void TestSourceThread::setSamplerate(int samplerate)
m_toneNco.setFreq(m_toneFrequency, m_samplerate); m_toneNco.setFreq(m_toneFrequency, m_samplerate);
} }
void TestSourceThread::setLog2Decimation(unsigned int log2_decim) void TestSourceWorker::setLog2Decimation(unsigned int log2_decim)
{ {
m_log2Decim = log2_decim; m_log2Decim = log2_decim;
} }
void TestSourceThread::setFcPos(int fcPos) void TestSourceWorker::setFcPos(int fcPos)
{ {
m_fcPos = fcPos; m_fcPos = fcPos;
} }
void TestSourceThread::setBitSize(quint32 bitSizeIndex) void TestSourceWorker::setBitSize(quint32 bitSizeIndex)
{ {
switch (bitSizeIndex) switch (bitSizeIndex)
{ {
@ -135,7 +129,7 @@ void TestSourceThread::setBitSize(quint32 bitSizeIndex)
} }
} }
void TestSourceThread::setAmplitudeBits(int32_t amplitudeBits) void TestSourceWorker::setAmplitudeBits(int32_t amplitudeBits)
{ {
m_amplitudeBits = amplitudeBits; m_amplitudeBits = amplitudeBits;
m_amplitudeBitsDC = m_dcBias * amplitudeBits; m_amplitudeBitsDC = m_dcBias * amplitudeBits;
@ -143,76 +137,57 @@ void TestSourceThread::setAmplitudeBits(int32_t amplitudeBits)
m_amplitudeBitsQ = (1.0f + m_qBias) * amplitudeBits; m_amplitudeBitsQ = (1.0f + m_qBias) * amplitudeBits;
} }
void TestSourceThread::setDCFactor(float dcFactor) void TestSourceWorker::setDCFactor(float dcFactor)
{ {
m_dcBias = dcFactor; m_dcBias = dcFactor;
m_amplitudeBitsDC = m_dcBias * m_amplitudeBits; m_amplitudeBitsDC = m_dcBias * m_amplitudeBits;
} }
void TestSourceThread::setIFactor(float iFactor) void TestSourceWorker::setIFactor(float iFactor)
{ {
m_iBias = iFactor; m_iBias = iFactor;
m_amplitudeBitsI = (1.0f + m_iBias) * m_amplitudeBits; m_amplitudeBitsI = (1.0f + m_iBias) * m_amplitudeBits;
} }
void TestSourceThread::setQFactor(float iFactor) void TestSourceWorker::setQFactor(float iFactor)
{ {
m_qBias = iFactor; m_qBias = iFactor;
m_amplitudeBitsQ = (1.0f + m_qBias) * m_amplitudeBits; m_amplitudeBitsQ = (1.0f + m_qBias) * m_amplitudeBits;
} }
void TestSourceThread::setPhaseImbalance(float phaseImbalance) void TestSourceWorker::setPhaseImbalance(float phaseImbalance)
{ {
m_phaseImbalance = phaseImbalance; m_phaseImbalance = phaseImbalance;
} }
void TestSourceThread::setFrequencyShift(int shift) void TestSourceWorker::setFrequencyShift(int shift)
{ {
m_nco.setFreq(shift, m_samplerate); m_nco.setFreq(shift, m_samplerate);
} }
void TestSourceThread::setToneFrequency(int toneFrequency) void TestSourceWorker::setToneFrequency(int toneFrequency)
{ {
m_toneNco.setFreq(toneFrequency, m_samplerate); m_toneNco.setFreq(toneFrequency, m_samplerate);
} }
void TestSourceThread::setModulation(TestSourceSettings::Modulation modulation) void TestSourceWorker::setModulation(TestSourceSettings::Modulation modulation)
{ {
m_modulation = modulation; m_modulation = modulation;
} }
void TestSourceThread::setAMModulation(float amModulation) void TestSourceWorker::setAMModulation(float amModulation)
{ {
m_amModulation = amModulation < 0.0f ? 0.0f : amModulation > 1.0f ? 1.0f : amModulation; m_amModulation = amModulation < 0.0f ? 0.0f : amModulation > 1.0f ? 1.0f : amModulation;
} }
void TestSourceThread::setFMDeviation(float deviation) void TestSourceWorker::setFMDeviation(float deviation)
{ {
float fmDeviationUnit = deviation / (float) m_samplerate; float fmDeviationUnit = deviation / (float) m_samplerate;
m_fmDeviationUnit = fmDeviationUnit < 0.0f ? 0.0f : fmDeviationUnit > 0.5f ? 0.5f : fmDeviationUnit; m_fmDeviationUnit = fmDeviationUnit < 0.0f ? 0.0f : fmDeviationUnit > 0.5f ? 0.5f : fmDeviationUnit;
qDebug("TestSourceThread::setFMDeviation: m_fmDeviationUnit: %f", m_fmDeviationUnit); qDebug("TestSourceWorker::setFMDeviation: m_fmDeviationUnit: %f", m_fmDeviationUnit);
} }
void TestSourceThread::startStop(bool start) void TestSourceWorker::setBuffers(quint32 chunksize)
{
MsgStartStop *msg = MsgStartStop::create(start);
m_inputMessageQueue.push(msg);
}
void TestSourceThread::run()
{
m_running = true;
m_startWaiter.wakeAll();
while (m_running) // actual work is in the tick() function
{
sleep(1);
}
m_running = false;
}
void TestSourceThread::setBuffers(quint32 chunksize)
{ {
if (chunksize > m_bufsize) if (chunksize > m_bufsize)
{ {
@ -220,14 +195,14 @@ void TestSourceThread::setBuffers(quint32 chunksize)
if (m_buf == 0) if (m_buf == 0)
{ {
qDebug() << "TestSourceThread::setBuffer: Allocate buffer: " qDebug() << "TestSourceWorker::setBuffer: Allocate buffer: "
<< " size: " << m_bufsize << " bytes" << " size: " << m_bufsize << " bytes"
<< " #samples: " << (m_bufsize/4); << " #samples: " << (m_bufsize/4);
m_buf = (qint16*) malloc(m_bufsize); m_buf = (qint16*) malloc(m_bufsize);
} }
else else
{ {
qDebug() << "TestSourceThread::setBuffer: Re-allocate buffer: " qDebug() << "TestSourceWorker::setBuffer: Re-allocate buffer: "
<< " size: " << m_bufsize << " bytes" << " size: " << m_bufsize << " bytes"
<< " #samples: " << (m_bufsize/4); << " #samples: " << (m_bufsize/4);
free(m_buf); free(m_buf);
@ -238,7 +213,7 @@ void TestSourceThread::setBuffers(quint32 chunksize)
} }
} }
void TestSourceThread::generate(quint32 chunksize) void TestSourceWorker::generate(quint32 chunksize)
{ {
int n = chunksize / 2; int n = chunksize / 2;
setBuffers(chunksize); setBuffers(chunksize);
@ -361,13 +336,13 @@ void TestSourceThread::generate(quint32 chunksize)
callback(m_buf, n); callback(m_buf, n);
} }
void TestSourceThread::pullAF(Real& afSample) void TestSourceWorker::pullAF(Real& afSample)
{ {
afSample = m_toneNco.next(); afSample = m_toneNco.next();
} }
// call appropriate conversion (decimation) routine depending on the number of sample bits // call appropriate conversion (decimation) routine depending on the number of sample bits
void TestSourceThread::callback(const qint16* buf, qint32 len) void TestSourceWorker::callback(const qint16* buf, qint32 len)
{ {
SampleVector::iterator it = m_convertBuffer.begin(); SampleVector::iterator it = m_convertBuffer.begin();
@ -388,7 +363,7 @@ void TestSourceThread::callback(const qint16* buf, qint32 len)
m_sampleFifo->write(m_convertBuffer.begin(), it); m_sampleFifo->write(m_convertBuffer.begin(), it);
} }
void TestSourceThread::tick() void TestSourceWorker::tick()
{ {
if (m_running) if (m_running)
{ {
@ -406,9 +381,9 @@ void TestSourceThread::tick()
if (m_histoCounter < 49) { if (m_histoCounter < 49) {
m_histoCounter++; m_histoCounter++;
} else { } else {
// qDebug("TestSourceThread::tick: -----------"); // qDebug("TestSourceWorker::tick: -----------");
// for (std::map<int,int>::iterator it = m_timerHistogram.begin(); it != m_timerHistogram.end(); ++it) { // for (std::map<int,int>::iterator it = m_timerHistogram.begin(); it != m_timerHistogram.end(); ++it) {
// qDebug("TestSourceThread::tick: %d: %d", it->first, it->second); // qDebug("TestSourceWorker::tick: %d: %d", it->first, it->second);
// } // }
m_histoCounter = 0; m_histoCounter = 0;
} }
@ -425,29 +400,11 @@ void TestSourceThread::tick()
} }
} }
void TestSourceThread::handleInputMessages() void TestSourceWorker::handleInputMessages()
{ {
Message* message;
while ((message = m_inputMessageQueue.pop()) != 0)
{
if (MsgStartStop::match(*message))
{
MsgStartStop* notif = (MsgStartStop*) message;
qDebug("TestSourceThread::handleInputMessages: MsgStartStop: %s", notif->getStartStop() ? "start" : "stop");
if (notif->getStartStop()) {
startWork();
} else {
stopWork();
}
delete message;
}
}
} }
void TestSourceThread::setPattern0() void TestSourceWorker::setPattern0()
{ {
m_pulseWidth = 150; m_pulseWidth = 150;
m_pulseSampleCount = 0; m_pulseSampleCount = 0;
@ -456,13 +413,13 @@ void TestSourceThread::setPattern0()
m_pulsePatternPlaces = 3; m_pulsePatternPlaces = 3;
} }
void TestSourceThread::setPattern1() void TestSourceWorker::setPattern1()
{ {
m_pulseWidth = 1000; m_pulseWidth = 1000;
m_pulseSampleCount = 0; m_pulseSampleCount = 0;
} }
void TestSourceThread::setPattern2() void TestSourceWorker::setPattern2()
{ {
m_pulseWidth = 1000; m_pulseWidth = 1000;
m_pulseSampleCount = 0; m_pulseSampleCount = 0;

View File

@ -15,14 +15,12 @@
// along with this program. If not, see <http://www.gnu.org/licenses/>. // // along with this program. If not, see <http://www.gnu.org/licenses/>. //
/////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////
#ifndef _TESTSOURCE_TESTSOURCETHREAD_H_ #ifndef _TESTSOURCE_TESTSOURCEWORKER_H_
#define _TESTSOURCE_TESTSOURCETHREAD_H_ #define _TESTSOURCE_TESTSOURCEWORKER_H_
#include <map> #include <map>
#include <QThread> #include <QObject>
#include <QMutex>
#include <QWaitCondition>
#include <QTimer> #include <QTimer>
#include <QElapsedTimer> #include <QElapsedTimer>
#include <QDebug> #include <QDebug>
@ -37,33 +35,15 @@
#define TESTSOURCE_THROTTLE_MS 50 #define TESTSOURCE_THROTTLE_MS 50
class TestSourceThread : public QThread { class TestSourceWorker : public QObject {
Q_OBJECT Q_OBJECT
public: public:
class MsgStartStop : public Message { TestSourceWorker(SampleSinkFifo* sampleFifo, QObject* parent = 0);
MESSAGE_CLASS_DECLARATION ~TestSourceWorker();
public: void startWork();
bool getStartStop() const { return m_startStop; } void stopWork();
static MsgStartStop* create(bool startStop) {
return new MsgStartStop(startStop);
}
protected:
bool m_startStop;
MsgStartStop(bool startStop) :
Message(),
m_startStop(startStop)
{ }
};
TestSourceThread(SampleSinkFifo* sampleFifo, QObject* parent = 0);
~TestSourceThread();
void startStop(bool start);
void setSamplerate(int samplerate); void setSamplerate(int samplerate);
void setLog2Decimation(unsigned int log2_decim); void setLog2Decimation(unsigned int log2_decim);
void setFcPos(int fcPos); void setFcPos(int fcPos);
@ -83,8 +63,6 @@ public:
void setPattern2(); void setPattern2();
private: private:
QMutex m_startWaitMutex;
QWaitCondition m_startWaiter;
volatile bool m_running; volatile bool m_running;
qint16 *m_buf; qint16 *m_buf;
@ -138,9 +116,6 @@ private:
std::map<int, int> m_timerHistogram; std::map<int, int> m_timerHistogram;
uint32_t m_histoCounter; uint32_t m_histoCounter;
void startWork();
void stopWork();
void run();
void callback(const qint16* buf, qint32 len); void callback(const qint16* buf, qint32 len);
void setBuffers(quint32 chunksize); void setBuffers(quint32 chunksize);
void generate(quint32 chunksize); void generate(quint32 chunksize);
@ -387,4 +362,4 @@ private slots:
void handleInputMessages(); void handleInputMessages();
}; };
#endif // _TESTSOURCE_TESTSOURCETHREAD_H_ #endif // _TESTSOURCE_TESTSOURCEWORKER_H_