From 956d1e6c078e505aa06387089f4392ea98a80895 Mon Sep 17 00:00:00 2001 From: f4exb Date: Sat, 27 Apr 2024 22:12:03 +0200 Subject: [PATCH] AudioCATSISO: fixed CAT worker handling --- .../samplemimo/audiocatsiso/audiocatsiso.cpp | 10 ++++++- .../audiocatsiso/audiocatsisocatworker.cpp | 30 +++++++++++++++---- .../audiocatsiso/audiocatsisocatworker.h | 19 ++++++++++-- 3 files changed, 51 insertions(+), 8 deletions(-) diff --git a/plugins/samplemimo/audiocatsiso/audiocatsiso.cpp b/plugins/samplemimo/audiocatsiso/audiocatsiso.cpp index 0bae8601d..708eea91c 100644 --- a/plugins/samplemimo/audiocatsiso/audiocatsiso.cpp +++ b/plugins/samplemimo/audiocatsiso/audiocatsiso.cpp @@ -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) || diff --git a/plugins/samplemimo/audiocatsiso/audiocatsisocatworker.cpp b/plugins/samplemimo/audiocatsiso/audiocatsisocatworker.cpp index 042df919a..3df6814b0 100644 --- a/plugins/samplemimo/audiocatsiso/audiocatsisocatworker.cpp +++ b/plugins/samplemimo/audiocatsiso/audiocatsisocatworker.cpp @@ -16,6 +16,7 @@ /////////////////////////////////////////////////////////////////////////////////// #include +#include #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 */ diff --git a/plugins/samplemimo/audiocatsiso/audiocatsisocatworker.h b/plugins/samplemimo/audiocatsiso/audiocatsisocatworker.h index 4ab750c2f..178f56726 100644 --- a/plugins/samplemimo/audiocatsiso/audiocatsisocatworker.h +++ b/plugins/samplemimo/audiocatsiso/audiocatsisocatworker.h @@ -21,12 +21,13 @@ #include #include -#include #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;