1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-12-22 17:45:48 -05:00

AudioCATSISO: fixed CAT worker handling

This commit is contained in:
f4exb 2024-04-27 22:12:03 +02:00
parent c33c8464cd
commit 956d1e6c07
3 changed files with 51 additions and 8 deletions

View File

@ -151,7 +151,7 @@ bool AudioCATSISO::startRx()
m_catWorkerThread = new QThread();
m_catWorker = new AudioCATSISOCATWorker();
m_inputWorker->moveToThread(m_catWorkerThread);
m_catWorker->moveToThread(m_catWorkerThread);
QObject::connect(m_catWorkerThread, &QThread::started, m_catWorker, &AudioCATSISOCATWorker::startWork);
QObject::connect(m_catWorkerThread, &QThread::finished, m_catWorker, &QObject::deleteLater);
@ -159,6 +159,7 @@ bool AudioCATSISO::startRx()
m_catWorker->setMessageQueueToGUI(getMessageQueueToGUI());
m_catWorker->setMessageQueueToSISO(getInputMessageQueue());
m_catWorker->startWork();
m_catWorkerThread->start();
AudioCATSISOCATWorker::MsgConfigureAudioCATSISOCATWorker *msgToCAT = AudioCATSISOCATWorker::MsgConfigureAudioCATSISOCATWorker::create(
@ -166,6 +167,9 @@ bool AudioCATSISO::startRx()
);
m_catWorker->getInputMessageQueue()->push(msgToCAT);
AudioCATSISOCATWorker::MsgPollTimerConnect *startTimerMsg = AudioCATSISOCATWorker::MsgPollTimerConnect::create();
m_catWorker->getInputMessageQueue()->push(startTimerMsg);
qDebug() << "AudioCATSISO::startRx: CAT started";
m_catRunning = true;
@ -557,6 +561,10 @@ void AudioCATSISO::applySettings(const AudioCATSISOSettings& settings, const QLi
forwardTxChange = true;
}
if (settingsKeys.contains("catPollingMs") || force) {
forwardToCAT = true;
}
if (settings.m_useReverseAPI)
{
bool fullUpdate = (settingsKeys.contains("useReverseAPI") && settings.m_useReverseAPI) ||

View File

@ -16,6 +16,7 @@
///////////////////////////////////////////////////////////////////////////////////
#include <QDebug>
#include <QTimer>
#include "audiocatsisocatworker.h"
@ -25,6 +26,7 @@
#endif
MESSAGE_CLASS_DEFINITION(AudioCATSISOCATWorker::MsgConfigureAudioCATSISOCATWorker, Message)
MESSAGE_CLASS_DEFINITION(AudioCATSISOCATWorker::MsgPollTimerConnect, Message)
MESSAGE_CLASS_DEFINITION(AudioCATSISOCATWorker::MsgReportFrequency, Message)
AudioCATSISOCATWorker::AudioCATSISOCATWorker(QObject* parent) :
@ -33,6 +35,7 @@ AudioCATSISOCATWorker::AudioCATSISOCATWorker(QObject* parent) :
m_inputMessageQueueToSISO(nullptr),
m_running(false),
m_connected(false),
m_pollTimer(nullptr),
m_ptt(false),
m_frequency(0)
{
@ -42,6 +45,10 @@ AudioCATSISOCATWorker::AudioCATSISOCATWorker(QObject* parent) :
AudioCATSISOCATWorker::~AudioCATSISOCATWorker()
{
stopWork();
if (m_pollTimer) {
delete m_pollTimer;
}
}
void AudioCATSISOCATWorker::startWork()
@ -86,7 +93,9 @@ void AudioCATSISOCATWorker::applySettings(const AudioCATSISOSettings& settings,
if (settingsKeys.contains("catPollingMs") || force)
{
m_pollTimer.setInterval(settings.m_catPollingMs);
if (m_pollTimer) {
m_pollTimer->setInterval(settings.m_catPollingMs);
}
}
if (force) {
@ -125,6 +134,15 @@ bool AudioCATSISOCATWorker::handleMessage(const Message& message)
return true;
}
else if (MsgPollTimerConnect::match(message))
{
qDebug("AudioCATSISOCATWorker::handleMessage: MsgPollTimerConnect");
m_pollTimer = new QTimer();
connect(m_pollTimer, SIGNAL(timeout()), this, SLOT(pollingTick()));
m_pollTimer->start(m_settings.m_catPollingMs);
return true;
}
return false;
}
@ -177,8 +195,6 @@ void AudioCATSISOCATWorker::catConnect()
if (retcode == RIG_OK)
{
m_connected = true;
connect(&m_pollTimer, SIGNAL(timeout()), this, SLOT(pollingTick()));
m_pollTimer.start(m_settings.m_catPollingMs);
msg = AudioCATSISOSettings::MsgCATReportStatus::create(AudioCATSISOSettings::MsgCATReportStatus::StatusConnected);
}
else
@ -196,8 +212,12 @@ void AudioCATSISOCATWorker::catConnect()
void AudioCATSISOCATWorker::catDisconnect()
{
disconnect(&m_pollTimer, SIGNAL(timeout()), this, SLOT(pollingTick()));
m_pollTimer.stop();
if (m_pollTimer)
{
disconnect(m_pollTimer, SIGNAL(timeout()), this, SLOT(pollingTick()));
m_pollTimer->stop();
}
m_connected = false;
rig_close(m_rig); /* close port */
rig_cleanup(m_rig); /* if you care about memory */

View File

@ -21,12 +21,13 @@
#include <hamlib/rig.h>
#include <QObject>
#include <QTimer>
#include "util/message.h"
#include "util/messagequeue.h"
#include "audiocatsisosettings.h"
class QTimer;
class AudioCATSISOCATWorker : public QObject {
Q_OBJECT
@ -56,6 +57,20 @@ public:
{ }
};
class MsgPollTimerConnect : public Message {
MESSAGE_CLASS_DECLARATION
public:
static MsgPollTimerConnect* create() {
return new MsgPollTimerConnect();
}
protected:
MsgPollTimerConnect() :
Message()
{ }
};
class MsgReportFrequency : public Message {
MESSAGE_CLASS_DECLARATION
@ -99,7 +114,7 @@ private:
bool m_connected;
AudioCATSISOSettings m_settings;
RIG *m_rig;
QTimer m_pollTimer;
QTimer *m_pollTimer;
bool m_ptt;
uint64_t m_frequency;