mirror of
https://github.com/f4exb/sdrangel.git
synced 2025-07-03 09:25:23 -04:00
TestSource: make it more robust
This commit is contained in:
parent
b839b5d0c3
commit
67f523e629
@ -74,8 +74,7 @@ bool TestSourceInput::start()
|
|||||||
|
|
||||||
m_testSourceThread = new TestSourceThread(&m_sampleFifo);
|
m_testSourceThread = new TestSourceThread(&m_sampleFifo);
|
||||||
m_testSourceThread->setSamplerate(m_settings.m_sampleRate);
|
m_testSourceThread->setSamplerate(m_settings.m_sampleRate);
|
||||||
m_testSourceThread->connectTimer(m_masterTimer);
|
m_testSourceThread->startStop(true);
|
||||||
m_testSourceThread->startWork();
|
|
||||||
|
|
||||||
mutexLocker.unlock();
|
mutexLocker.unlock();
|
||||||
|
|
||||||
@ -91,8 +90,8 @@ void TestSourceInput::stop()
|
|||||||
|
|
||||||
if (m_testSourceThread != 0)
|
if (m_testSourceThread != 0)
|
||||||
{
|
{
|
||||||
m_testSourceThread->stopWork();
|
m_testSourceThread->startStop(false);
|
||||||
delete m_testSourceThread;
|
m_testSourceThread->deleteLater();
|
||||||
m_testSourceThread = 0;
|
m_testSourceThread = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -29,7 +29,7 @@
|
|||||||
|
|
||||||
const PluginDescriptor TestSourcePlugin::m_pluginDescriptor = {
|
const PluginDescriptor TestSourcePlugin::m_pluginDescriptor = {
|
||||||
QString("Test Source input"),
|
QString("Test Source input"),
|
||||||
QString("4.0.0"),
|
QString("4.1.0"),
|
||||||
QString("(c) Edouard Griffiths, F4EXB"),
|
QString("(c) Edouard Griffiths, F4EXB"),
|
||||||
QString("https://github.com/f4exb/sdrangel"),
|
QString("https://github.com/f4exb/sdrangel"),
|
||||||
true,
|
true,
|
||||||
|
@ -22,6 +22,8 @@
|
|||||||
|
|
||||||
#define TESTSOURCE_BLOCKSIZE 16384
|
#define TESTSOURCE_BLOCKSIZE 16384
|
||||||
|
|
||||||
|
MESSAGE_CLASS_DEFINITION(TestSourceThread::MsgStartStop, Message)
|
||||||
|
|
||||||
TestSourceThread::TestSourceThread(SampleSinkFifo* sampleFifo, QObject* parent) :
|
TestSourceThread::TestSourceThread(SampleSinkFifo* sampleFifo, QObject* parent) :
|
||||||
QThread(parent),
|
QThread(parent),
|
||||||
m_running(false),
|
m_running(false),
|
||||||
@ -55,15 +57,17 @@ TestSourceThread::TestSourceThread(SampleSinkFifo* sampleFifo, QObject* parent)
|
|||||||
m_throttleToggle(false),
|
m_throttleToggle(false),
|
||||||
m_mutex(QMutex::Recursive)
|
m_mutex(QMutex::Recursive)
|
||||||
{
|
{
|
||||||
|
connect(&m_inputMessageQueue, SIGNAL(messageEnqueued()), this, SLOT(handleInputMessages()), Qt::QueuedConnection);
|
||||||
}
|
}
|
||||||
|
|
||||||
TestSourceThread::~TestSourceThread()
|
TestSourceThread::~TestSourceThread()
|
||||||
{
|
{
|
||||||
stopWork();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void TestSourceThread::startWork()
|
void TestSourceThread::startWork()
|
||||||
{
|
{
|
||||||
|
connect(&m_timer, SIGNAL(timeout()), this, SLOT(tick()));
|
||||||
|
m_timer.start(50);
|
||||||
m_startWaitMutex.lock();
|
m_startWaitMutex.lock();
|
||||||
m_elapsedTimer.start();
|
m_elapsedTimer.start();
|
||||||
start();
|
start();
|
||||||
@ -76,6 +80,8 @@ void TestSourceThread::stopWork()
|
|||||||
{
|
{
|
||||||
m_running = false;
|
m_running = false;
|
||||||
wait();
|
wait();
|
||||||
|
m_timer.stop();
|
||||||
|
disconnect(&m_timer, SIGNAL(timeout()), this, SLOT(tick()));
|
||||||
}
|
}
|
||||||
|
|
||||||
void TestSourceThread::setSamplerate(int samplerate)
|
void TestSourceThread::setSamplerate(int samplerate)
|
||||||
@ -177,6 +183,12 @@ void TestSourceThread::setFMDeviation(float deviation)
|
|||||||
qDebug("TestSourceThread::setFMDeviation: m_fmDeviationUnit: %f", m_fmDeviationUnit);
|
qDebug("TestSourceThread::setFMDeviation: m_fmDeviationUnit: %f", m_fmDeviationUnit);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TestSourceThread::startStop(bool start)
|
||||||
|
{
|
||||||
|
MsgStartStop *msg = MsgStartStop::create(start);
|
||||||
|
m_inputMessageQueue.push(msg);
|
||||||
|
}
|
||||||
|
|
||||||
void TestSourceThread::run()
|
void TestSourceThread::run()
|
||||||
{
|
{
|
||||||
m_running = true;
|
m_running = true;
|
||||||
@ -291,19 +303,13 @@ void TestSourceThread::callback(const qint16* buf, qint32 len)
|
|||||||
m_sampleFifo->write(m_convertBuffer.begin(), it);
|
m_sampleFifo->write(m_convertBuffer.begin(), it);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TestSourceThread::connectTimer(const QTimer& timer)
|
|
||||||
{
|
|
||||||
qDebug() << "TestSourceThread::connectTimer";
|
|
||||||
connect(&timer, SIGNAL(timeout()), this, SLOT(tick()));
|
|
||||||
}
|
|
||||||
|
|
||||||
void TestSourceThread::tick()
|
void TestSourceThread::tick()
|
||||||
{
|
{
|
||||||
if (m_running)
|
if (m_running)
|
||||||
{
|
{
|
||||||
qint64 throttlems = m_elapsedTimer.restart();
|
qint64 throttlems = m_elapsedTimer.restart();
|
||||||
|
|
||||||
if (throttlems != m_throttlems)
|
if ((throttlems > 45) && (throttlems < 55) && (throttlems != m_throttlems))
|
||||||
{
|
{
|
||||||
QMutexLocker mutexLocker(&m_mutex);
|
QMutexLocker mutexLocker(&m_mutex);
|
||||||
m_throttlems = throttlems;
|
m_throttlems = throttlems;
|
||||||
@ -315,3 +321,24 @@ void TestSourceThread::tick()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TestSourceThread::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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -27,6 +27,8 @@
|
|||||||
#include "dsp/samplesinkfifo.h"
|
#include "dsp/samplesinkfifo.h"
|
||||||
#include "dsp/decimators.h"
|
#include "dsp/decimators.h"
|
||||||
#include "dsp/ncof.h"
|
#include "dsp/ncof.h"
|
||||||
|
#include "util/message.h"
|
||||||
|
#include "util/messagequeue.h"
|
||||||
|
|
||||||
#include "testsourcesettings.h"
|
#include "testsourcesettings.h"
|
||||||
|
|
||||||
@ -36,11 +38,29 @@ class TestSourceThread : public QThread {
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
class MsgStartStop : public Message {
|
||||||
|
MESSAGE_CLASS_DECLARATION
|
||||||
|
|
||||||
|
public:
|
||||||
|
bool getStartStop() const { return m_startStop; }
|
||||||
|
|
||||||
|
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(SampleSinkFifo* sampleFifo, QObject* parent = 0);
|
||||||
~TestSourceThread();
|
~TestSourceThread();
|
||||||
|
|
||||||
void startWork();
|
void startStop(bool start);
|
||||||
void stopWork();
|
|
||||||
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);
|
||||||
@ -56,8 +76,6 @@ public:
|
|||||||
void setAMModulation(float amModulation);
|
void setAMModulation(float amModulation);
|
||||||
void setFMDeviation(float deviation);
|
void setFMDeviation(float deviation);
|
||||||
|
|
||||||
void connectTimer(const QTimer& timer);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QMutex m_startWaitMutex;
|
QMutex m_startWaitMutex;
|
||||||
QWaitCondition m_startWaiter;
|
QWaitCondition m_startWaiter;
|
||||||
@ -95,14 +113,19 @@ private:
|
|||||||
int m_fcPosShift;
|
int m_fcPosShift;
|
||||||
|
|
||||||
int m_throttlems;
|
int m_throttlems;
|
||||||
|
QTimer m_timer;
|
||||||
QElapsedTimer m_elapsedTimer;
|
QElapsedTimer m_elapsedTimer;
|
||||||
bool m_throttleToggle;
|
bool m_throttleToggle;
|
||||||
QMutex m_mutex;
|
QMutex m_mutex;
|
||||||
|
|
||||||
|
MessageQueue m_inputMessageQueue;
|
||||||
|
|
||||||
Decimators<qint32, qint16, SDR_RX_SAMP_SZ, 8> m_decimators_8;
|
Decimators<qint32, qint16, SDR_RX_SAMP_SZ, 8> m_decimators_8;
|
||||||
Decimators<qint32, qint16, SDR_RX_SAMP_SZ, 12> m_decimators_12;
|
Decimators<qint32, qint16, SDR_RX_SAMP_SZ, 12> m_decimators_12;
|
||||||
Decimators<qint32, qint16, SDR_RX_SAMP_SZ, 16> m_decimators_16;
|
Decimators<qint32, qint16, SDR_RX_SAMP_SZ, 16> m_decimators_16;
|
||||||
|
|
||||||
|
void startWork();
|
||||||
|
void stopWork();
|
||||||
void run();
|
void run();
|
||||||
void callback(const qint16* buf, qint32 len);
|
void callback(const qint16* buf, qint32 len);
|
||||||
void setBuffers(quint32 chunksize);
|
void setBuffers(quint32 chunksize);
|
||||||
@ -347,6 +370,7 @@ private:
|
|||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void tick();
|
void tick();
|
||||||
|
void handleInputMessages();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // _TESTSOURCE_TESTSOURCETHREAD_H_
|
#endif // _TESTSOURCE_TESTSOURCETHREAD_H_
|
||||||
|
Loading…
x
Reference in New Issue
Block a user