diff --git a/plugins/samplesource/sdrdaemon/sdrdaemonbuffer.cpp b/plugins/samplesource/sdrdaemon/sdrdaemonbuffer.cpp index 0126a1b2b..e1a85a73b 100644 --- a/plugins/samplesource/sdrdaemon/sdrdaemonbuffer.cpp +++ b/plugins/samplesource/sdrdaemon/sdrdaemonbuffer.cpp @@ -55,7 +55,8 @@ SDRdaemonBuffer::SDRdaemonBuffer(uint32_t rateDivider) : m_readCycles(0), m_lastWriteIndex(0), m_skewRateSum(0.0), - m_skewRate(0.0) + m_skewRate(0.0), + m_autoFollowRate(false) { m_currentMeta.init(); } @@ -113,18 +114,25 @@ bool SDRdaemonBuffer::readMeta(char *array, uint32_t length) uint32_t frameSize = m_iqSampleSize * metaData->m_nbSamples * metaData->m_nbBlocks; int sampleRate = metaData->m_sampleRate; - if (sampleRate != m_sampleRateStream) + if (m_autoFollowRate) { - m_sampleRateStream = sampleRate; + if (sampleRate != m_sampleRateStream) + { + m_sampleRateStream = sampleRate; + } + else + { + sampleRate = m_sampleRate; + } + + sampleRate += sampleRate * m_skewRate; + sampleRate = (sampleRate / m_rateDivider) * m_rateDivider; } else { - sampleRate = m_sampleRate; + m_sampleRateStream = sampleRate; } - sampleRate += sampleRate * m_skewRate; - sampleRate = (sampleRate / m_rateDivider) * m_rateDivider; - if (metaData->m_sampleBytes & 0x10) { m_lz4 = true; @@ -268,7 +276,11 @@ uint8_t *SDRdaemonBuffer::readDataChunk() //qDebug("SDRdaemonBuffer::readDataChunk: %d / %d (%lf)", m_writeIndex, m_rawSize, oneCycleSkew); - if (m_readCycles && ((m_writeIndex < m_rawSize / 10) || (m_rawSize - m_writeIndex < m_rawSize / 10))) + if (!m_autoFollowRate) + { + m_skewRate = 0.0; + } + else if (m_readCycles && ((m_writeIndex < m_rawSize / 10) || (m_rawSize - m_writeIndex < m_rawSize / 10))) { m_skewRate = m_skewRateSum / m_readCycles; if (m_skewRate > 0.2) { diff --git a/plugins/samplesource/sdrdaemon/sdrdaemonbuffer.h b/plugins/samplesource/sdrdaemon/sdrdaemonbuffer.h index d4e27cd17..09bdbd26d 100644 --- a/plugins/samplesource/sdrdaemon/sdrdaemonbuffer.h +++ b/plugins/samplesource/sdrdaemon/sdrdaemonbuffer.h @@ -77,6 +77,7 @@ public: float getCompressionRatio() const { return (m_frameSize > 0 ? (float) m_lz4InSize / (float) m_frameSize : 1.0); } uint32_t getLz4DataCRCOK() const { return m_nbLastLz4CRCOK; } uint32_t getLz4SuccessfulDecodes() const { return m_nbLastLz4SuccessfulDecodes; } + void setAutoFollowRate(bool autoFollowRate) { m_autoFollowRate = autoFollowRate; } static const int m_udpPayloadSize; static const int m_sampleSize; @@ -127,6 +128,7 @@ private: uint32_t m_lastWriteIndex; //!< Write index at last skew estimation double m_skewRateSum; double m_skewRate; + bool m_autoFollowRate; //!< Aito follow stream sample rate else stick with meta data sample rate }; diff --git a/plugins/samplesource/sdrdaemon/sdrdaemongui.cpp b/plugins/samplesource/sdrdaemon/sdrdaemongui.cpp index bae5edb37..114132c2d 100644 --- a/plugins/samplesource/sdrdaemon/sdrdaemongui.cpp +++ b/plugins/samplesource/sdrdaemon/sdrdaemongui.cpp @@ -50,7 +50,8 @@ SDRdaemonGui::SDRdaemonGui(PluginAPI* pluginAPI, QWidget* parent) : m_address("127.0.0.1"), m_port(9090), m_dcBlock(false), - m_iqCorrection(false) + m_iqCorrection(false), + m_autoFollowRate(false) { m_startingTimeStamp.tv_sec = 0; m_startingTimeStamp.tv_usec = 0; @@ -94,6 +95,7 @@ void SDRdaemonGui::resetToDefaults() m_port = 9090; m_dcBlock = false; m_iqCorrection = false; + m_autoFollowRate = false; displaySettings(); } @@ -112,6 +114,7 @@ QByteArray SDRdaemonGui::serialize() const s.writeU32(2, uintval); s.writeBool(3, m_dcBlock); s.writeBool(4, m_iqCorrection); + s.writeBool(5, m_autoFollowRate); return s.final(); } @@ -124,6 +127,7 @@ bool SDRdaemonGui::deserialize(const QByteArray& data) quint16 port; bool dcBlock; bool iqCorrection; + bool autoFollowRate; if (!d.isValid()) { @@ -146,6 +150,7 @@ bool SDRdaemonGui::deserialize(const QByteArray& data) d.readBool(3, &dcBlock, false); d.readBool(4, &iqCorrection, false); + d.readBool(5, &autoFollowRate, false); if ((address != m_address) || (port != m_port)) { @@ -161,6 +166,11 @@ bool SDRdaemonGui::deserialize(const QByteArray& data) configureAutoCorrections(); } + if (m_autoFollowRate != autoFollowRate) { + m_autoFollowRate = autoFollowRate; + configureAutoFollowRate(); + } + displaySettings(); return true; } @@ -248,6 +258,7 @@ void SDRdaemonGui::displaySettings() ui->port->setText(QString::number(m_port)); ui->dcOffset->setChecked(m_dcBlock); ui->iqImbalance->setChecked(m_iqCorrection); + ui->autoFollowRate->setChecked(m_autoFollowRate); } void SDRdaemonGui::on_applyButton_clicked(bool checked) @@ -297,6 +308,14 @@ void SDRdaemonGui::on_iqImbalance_toggled(bool checked) } } +void SDRdaemonGui::on_autoFollowRate_toggled(bool checked) +{ + if (m_autoFollowRate != checked) { + m_autoFollowRate = checked; + configureAutoFollowRate(); + } +} + void SDRdaemonGui::configureUDPLink() { qDebug() << "SDRdaemonGui::configureUDPLink: " << m_address.toStdString().c_str() @@ -312,6 +331,12 @@ void SDRdaemonGui::configureAutoCorrections() m_sampleSource->getInputMessageQueue()->push(message); } +void SDRdaemonGui::configureAutoFollowRate() +{ + SDRdaemonInput::MsgConfigureSDRdaemonAutoFollowRate* message = SDRdaemonInput::MsgConfigureSDRdaemonAutoFollowRate::create(m_autoFollowRate); + m_sampleSource->getInputMessageQueue()->push(message); +} + void SDRdaemonGui::updateWithAcquisition() { } diff --git a/plugins/samplesource/sdrdaemon/sdrdaemongui.h b/plugins/samplesource/sdrdaemon/sdrdaemongui.h index 9e3a2ac7d..2957d5fa9 100644 --- a/plugins/samplesource/sdrdaemon/sdrdaemongui.h +++ b/plugins/samplesource/sdrdaemon/sdrdaemongui.h @@ -73,11 +73,13 @@ private: quint16 m_port; bool m_dcBlock; bool m_iqCorrection; + bool m_autoFollowRate; void displaySettings(); void displayTime(); void configureUDPLink(); void configureAutoCorrections(); + void configureAutoFollowRate(); void updateWithAcquisition(); void updateWithStreamData(); void updateWithStreamTime(); @@ -87,6 +89,7 @@ private slots: void on_applyButton_clicked(bool checked); void on_dcOffset_toggled(bool checked); void on_iqImbalance_toggled(bool checked); + void on_autoFollowRate_toggled(bool checked); void on_address_textEdited(const QString& arg1); void on_port_textEdited(const QString& arg1); void tick(); diff --git a/plugins/samplesource/sdrdaemon/sdrdaemongui.ui b/plugins/samplesource/sdrdaemon/sdrdaemongui.ui index b0b368e61..7c1eacd41 100644 --- a/plugins/samplesource/sdrdaemon/sdrdaemongui.ui +++ b/plugins/samplesource/sdrdaemon/sdrdaemongui.ui @@ -2,6 +2,14 @@ SDRdaemonGui + + + 0 + 0 + 398 + 156 + + 340 @@ -168,23 +176,6 @@ - - - - false - - - Stream locked status i.e. synced with meta data - - - ... - - - - :/locked.png:/locked.png - - - @@ -302,6 +293,16 @@ + + + + Follow stream sample rate automatically + + + Auto + + + @@ -330,6 +331,23 @@ + + + + false + + + Stream locked status i.e. synced with meta data + + + ... + + + + :/locked.png:/locked.png + + + diff --git a/plugins/samplesource/sdrdaemon/sdrdaemoninput.cpp b/plugins/samplesource/sdrdaemon/sdrdaemoninput.cpp index 8e29a77ce..043b93c81 100644 --- a/plugins/samplesource/sdrdaemon/sdrdaemoninput.cpp +++ b/plugins/samplesource/sdrdaemon/sdrdaemoninput.cpp @@ -30,6 +30,7 @@ MESSAGE_CLASS_DEFINITION(SDRdaemonInput::MsgConfigureSDRdaemonUDPLink, Message) MESSAGE_CLASS_DEFINITION(SDRdaemonInput::MsgConfigureSDRdaemonAutoCorr, Message) MESSAGE_CLASS_DEFINITION(SDRdaemonInput::MsgConfigureSDRdaemonWork, Message) +MESSAGE_CLASS_DEFINITION(SDRdaemonInput::MsgConfigureSDRdaemonAutoFollowRate, Message) MESSAGE_CLASS_DEFINITION(SDRdaemonInput::MsgConfigureSDRdaemonStreamTiming, Message) MESSAGE_CLASS_DEFINITION(SDRdaemonInput::MsgReportSDRdaemonAcquisition, Message) MESSAGE_CLASS_DEFINITION(SDRdaemonInput::MsgReportSDRdaemonStreamData, Message) @@ -113,6 +114,13 @@ bool SDRdaemonInput::handleMessage(const Message& message) DSPEngine::instance()->configureCorrections(dcBlock, iqImbalance); return true; } + else if (MsgConfigureSDRdaemonAutoFollowRate::match(message)) + { + MsgConfigureSDRdaemonAutoFollowRate& conf = (MsgConfigureSDRdaemonAutoFollowRate&) message; + bool autoFollowRate = conf.autoFollowRate(); + m_SDRdaemonUDPHandler->setAutoFollowRate(autoFollowRate); + return true; + } else if (MsgConfigureSDRdaemonWork::match(message)) { MsgConfigureSDRdaemonWork& conf = (MsgConfigureSDRdaemonWork&) message; diff --git a/plugins/samplesource/sdrdaemon/sdrdaemoninput.h b/plugins/samplesource/sdrdaemon/sdrdaemoninput.h index 6befbc5d4..a8125f859 100644 --- a/plugins/samplesource/sdrdaemon/sdrdaemoninput.h +++ b/plugins/samplesource/sdrdaemon/sdrdaemoninput.h @@ -93,6 +93,26 @@ public: { } }; + class MsgConfigureSDRdaemonAutoFollowRate : public Message { + MESSAGE_CLASS_DECLARATION + + public: + bool autoFollowRate() const { return m_autoFollowRate; } + + static MsgConfigureSDRdaemonAutoFollowRate* create(bool autoFollowRate) + { + return new MsgConfigureSDRdaemonAutoFollowRate(autoFollowRate); + } + + private: + bool m_autoFollowRate; + + MsgConfigureSDRdaemonAutoFollowRate(bool autoFollowRate) : + Message(), + m_autoFollowRate(autoFollowRate) + { } + }; + class MsgConfigureSDRdaemonStreamTiming : public Message { MESSAGE_CLASS_DECLARATION diff --git a/plugins/samplesource/sdrdaemon/sdrdaemonudphandler.h b/plugins/samplesource/sdrdaemon/sdrdaemonudphandler.h index 50ed52f2c..9e9647b26 100644 --- a/plugins/samplesource/sdrdaemon/sdrdaemonudphandler.h +++ b/plugins/samplesource/sdrdaemon/sdrdaemonudphandler.h @@ -39,7 +39,7 @@ public: void start(); void stop(); void configureUDPLink(const QString& address, quint16 port); - + void setAutoFollowRate(bool autoFollowRate) { m_sdrDaemonBuffer.setAutoFollowRate(autoFollowRate); } public slots: void dataReadyRead();