1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-11-26 09:48:45 -05:00

TestSource: make it more robust

This commit is contained in:
f4exb 2018-09-06 14:29:14 +02:00
parent b839b5d0c3
commit 67f523e629
4 changed files with 67 additions and 17 deletions

View File

@ -74,8 +74,7 @@ bool TestSourceInput::start()
m_testSourceThread = new TestSourceThread(&m_sampleFifo);
m_testSourceThread->setSamplerate(m_settings.m_sampleRate);
m_testSourceThread->connectTimer(m_masterTimer);
m_testSourceThread->startWork();
m_testSourceThread->startStop(true);
mutexLocker.unlock();
@ -91,8 +90,8 @@ void TestSourceInput::stop()
if (m_testSourceThread != 0)
{
m_testSourceThread->stopWork();
delete m_testSourceThread;
m_testSourceThread->startStop(false);
m_testSourceThread->deleteLater();
m_testSourceThread = 0;
}

View File

@ -29,7 +29,7 @@
const PluginDescriptor TestSourcePlugin::m_pluginDescriptor = {
QString("Test Source input"),
QString("4.0.0"),
QString("4.1.0"),
QString("(c) Edouard Griffiths, F4EXB"),
QString("https://github.com/f4exb/sdrangel"),
true,

View File

@ -22,6 +22,8 @@
#define TESTSOURCE_BLOCKSIZE 16384
MESSAGE_CLASS_DEFINITION(TestSourceThread::MsgStartStop, Message)
TestSourceThread::TestSourceThread(SampleSinkFifo* sampleFifo, QObject* parent) :
QThread(parent),
m_running(false),
@ -55,15 +57,17 @@ TestSourceThread::TestSourceThread(SampleSinkFifo* sampleFifo, QObject* parent)
m_throttleToggle(false),
m_mutex(QMutex::Recursive)
{
connect(&m_inputMessageQueue, SIGNAL(messageEnqueued()), this, SLOT(handleInputMessages()), Qt::QueuedConnection);
}
TestSourceThread::~TestSourceThread()
{
stopWork();
}
void TestSourceThread::startWork()
{
connect(&m_timer, SIGNAL(timeout()), this, SLOT(tick()));
m_timer.start(50);
m_startWaitMutex.lock();
m_elapsedTimer.start();
start();
@ -76,6 +80,8 @@ void TestSourceThread::stopWork()
{
m_running = false;
wait();
m_timer.stop();
disconnect(&m_timer, SIGNAL(timeout()), this, SLOT(tick()));
}
void TestSourceThread::setSamplerate(int samplerate)
@ -177,6 +183,12 @@ void TestSourceThread::setFMDeviation(float deviation)
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()
{
m_running = true;
@ -291,19 +303,13 @@ void TestSourceThread::callback(const qint16* buf, qint32 len)
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()
{
if (m_running)
{
qint64 throttlems = m_elapsedTimer.restart();
if (throttlems != m_throttlems)
if ((throttlems > 45) && (throttlems < 55) && (throttlems != m_throttlems))
{
QMutexLocker mutexLocker(&m_mutex);
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;
}
}
}

View File

@ -27,6 +27,8 @@
#include "dsp/samplesinkfifo.h"
#include "dsp/decimators.h"
#include "dsp/ncof.h"
#include "util/message.h"
#include "util/messagequeue.h"
#include "testsourcesettings.h"
@ -36,11 +38,29 @@ class TestSourceThread : public QThread {
Q_OBJECT
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();
void startWork();
void stopWork();
void startStop(bool start);
void setSamplerate(int samplerate);
void setLog2Decimation(unsigned int log2_decim);
void setFcPos(int fcPos);
@ -56,8 +76,6 @@ public:
void setAMModulation(float amModulation);
void setFMDeviation(float deviation);
void connectTimer(const QTimer& timer);
private:
QMutex m_startWaitMutex;
QWaitCondition m_startWaiter;
@ -95,14 +113,19 @@ private:
int m_fcPosShift;
int m_throttlems;
QTimer m_timer;
QElapsedTimer m_elapsedTimer;
bool m_throttleToggle;
QMutex m_mutex;
MessageQueue m_inputMessageQueue;
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, 16> m_decimators_16;
void startWork();
void stopWork();
void run();
void callback(const qint16* buf, qint32 len);
void setBuffers(quint32 chunksize);
@ -347,6 +370,7 @@ private:
private slots:
void tick();
void handleInputMessages();
};
#endif // _TESTSOURCE_TESTSOURCETHREAD_H_