diff --git a/plugins/samplesource/kiwisdr/kiwisdrinput.cpp b/plugins/samplesource/kiwisdr/kiwisdrinput.cpp index d64f8df382..23d8edab77 100644 --- a/plugins/samplesource/kiwisdr/kiwisdrinput.cpp +++ b/plugins/samplesource/kiwisdr/kiwisdrinput.cpp @@ -43,6 +43,7 @@ MESSAGE_CLASS_DEFINITION(KiwiSDRInput::MsgSetStatus, Message) KiwiSDRInput::KiwiSDRInput(DeviceAPI *deviceAPI) : m_deviceAPI(deviceAPI), + m_sampleRate(12000), m_settings(), m_kiwiSDRWorker(nullptr), m_kiwiSDRWorkerThread(nullptr), @@ -101,6 +102,7 @@ bool KiwiSDRInput::start() m_kiwiSDRWorkerThread = new QThread(); m_kiwiSDRWorker = new KiwiSDRWorker(&m_sampleFifo); + m_kiwiSDRWorker->setInputMessageQueue(getInputMessageQueue()); m_kiwiSDRWorker->moveToThread(m_kiwiSDRWorkerThread); QObject::connect(m_kiwiSDRWorkerThread, &QThread::finished, m_kiwiSDRWorker, &QObject::deleteLater); @@ -174,7 +176,7 @@ const QString& KiwiSDRInput::getDeviceDescription() const int KiwiSDRInput::getSampleRate() const { - return 12000; + return m_sampleRate; } quint64 KiwiSDRInput::getCenterFrequency() const @@ -219,6 +221,22 @@ bool KiwiSDRInput::handleMessage(const Message& message) return true; } + else if (KiwiSDRWorker::MsgReportSampleRate::match(message)) + { + KiwiSDRWorker::MsgReportSampleRate& report = (KiwiSDRWorker::MsgReportSampleRate&) message; + m_sampleRate = report.getSampleRate(); + qDebug() << "KiwiSDRInput::handleMessage: KiwiSDRWorker::MsgReportSampleRate: m_sampleRate: " << m_sampleRate; + + if (!m_sampleFifo.setSize(m_sampleRate * 2)) { + qCritical("KiwiSDRInput::KiwiSDRInput: Could not allocate SampleFifo"); + } + + DSPSignalNotification *notif = new DSPSignalNotification( + m_sampleRate, m_settings.m_centerFrequency); + m_deviceAPI->getDeviceEngineInputMessageQueue()->push(notif); + + return true; + } else if (MsgStartStop::match(message)) { MsgStartStop& cmd = (MsgStartStop&) message; diff --git a/plugins/samplesource/kiwisdr/kiwisdrinput.h b/plugins/samplesource/kiwisdr/kiwisdrinput.h index 09b9a3af8d..56aa27c029 100644 --- a/plugins/samplesource/kiwisdr/kiwisdrinput.h +++ b/plugins/samplesource/kiwisdr/kiwisdrinput.h @@ -155,6 +155,7 @@ class KiwiSDRInput : public DeviceSampleSource { private: DeviceAPI *m_deviceAPI; QMutex m_mutex; + int m_sampleRate; KiwiSDRSettings m_settings; KiwiSDRWorker* m_kiwiSDRWorker; QThread *m_kiwiSDRWorkerThread; diff --git a/plugins/samplesource/kiwisdr/kiwisdrworker.cpp b/plugins/samplesource/kiwisdr/kiwisdrworker.cpp index a9ae104d7f..3ee68304f9 100644 --- a/plugins/samplesource/kiwisdr/kiwisdrworker.cpp +++ b/plugins/samplesource/kiwisdr/kiwisdrworker.cpp @@ -16,14 +16,19 @@ /////////////////////////////////////////////////////////////////////////////////// #include +#include "util/messagequeue.h" #include "kiwisdrworker.h" +MESSAGE_CLASS_DEFINITION(KiwiSDRWorker::MsgReportSampleRate, Message) + KiwiSDRWorker::KiwiSDRWorker(SampleSinkFifo* sampleFifo) : QObject(), m_timer(this), m_samplesBuf(), m_sampleFifo(sampleFifo), m_centerFrequency(1450000), + m_sampleRate(12000), + m_inputMessageQueue(nullptr), m_gain(20), m_useAGC(true), m_status(0) @@ -66,7 +71,8 @@ void KiwiSDRWorker::sendCenterFrequency() return; QString freq = QString::number(m_centerFrequency / 1000.0, 'f', 3); - QString msg = "SET mod=iq low_cut=-5980 high_cut=5980 freq=" + freq; + int bw = (m_sampleRate/2) - 20; + QString msg = QString("SET mod=iq low_cut=-%1 high_cut=%2 freq=%3").arg(bw).arg(bw).arg(freq); m_webSocket.sendTextMessage(msg); } @@ -87,16 +93,36 @@ void KiwiSDRWorker::onBinaryMessageReceived(const QByteArray &message) if (message[0] == 'M' && message[1] == 'S' && message[2] == 'G') { QStringList al = QString::fromUtf8(message).split(' '); - if (al.size() > 2 && al[2] == "audio_rate=12000") - { - m_webSocket.sendTextMessage("SET AR OK in=12000 out=48000"); - m_webSocket.sendTextMessage("SERVER DE CLIENT KiwiAngel SND"); - sendGain(); - sendCenterFrequency(); - m_timer.start(5000); - m_status = 2; - emit updateStatus(2); - } + + if ((al.size() > 2) && al[2].startsWith("audio_rate=")) + { + QStringList rateKeyVal = al[2].split('='); + + if (rateKeyVal.size() > 1) + { + bool ok; + int sampleRate = rateKeyVal[1].toInt(&ok); + + if (ok) { + m_sampleRate = sampleRate; + } + + qDebug("KiwiSDRWorker::onBinaryMessageReceived: sample rate: %d", m_sampleRate); + + if (m_inputMessageQueue) { + m_inputMessageQueue->push(MsgReportSampleRate::create(m_sampleRate)); + } + + QString msg = QString("SET AR OK in=%1 out=48000").arg(m_sampleRate); + m_webSocket.sendTextMessage(msg); + m_webSocket.sendTextMessage("SERVER DE CLIENT KiwiAngel SND"); + sendGain(); + sendCenterFrequency(); + m_timer.start(5000); + m_status = 2; + emit updateStatus(2); + } + } } else if (message[0] == 'S' && message[1] == 'N' && message[2] == 'D') { diff --git a/plugins/samplesource/kiwisdr/kiwisdrworker.h b/plugins/samplesource/kiwisdr/kiwisdrworker.h index bff2a47370..180744a2ad 100644 --- a/plugins/samplesource/kiwisdr/kiwisdrworker.h +++ b/plugins/samplesource/kiwisdr/kiwisdrworker.h @@ -22,13 +22,36 @@ #include #include "dsp/samplesinkfifo.h" +#include "util/message.h" + +class MessageQueue; class KiwiSDRWorker : public QObject { Q_OBJECT public: + class MsgReportSampleRate : public Message { + MESSAGE_CLASS_DECLARATION + + public: + int getSampleRate() const { return m_sampleRate; } + + static MsgReportSampleRate* create(int sampleRate) { + return new MsgReportSampleRate(sampleRate); + } + + private: + int m_sampleRate; + + MsgReportSampleRate(int sampleRate) : + Message(), + m_sampleRate(sampleRate) + { } + }; + KiwiSDRWorker(SampleSinkFifo* sampleFifo); int getStatus() const { return m_status; } + void setInputMessageQueue(MessageQueue *messageQueue) { m_inputMessageQueue = messageQueue; } private: QTimer m_timer; @@ -39,6 +62,8 @@ class KiwiSDRWorker : public QObject { QString m_serverAddress; uint64_t m_centerFrequency; + int m_sampleRate; + MessageQueue *m_inputMessageQueue; uint32_t m_gain; bool m_useAGC;