2018-05-15 03:17:54 -04:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Copyright (C) 2017 Edouard Griffiths, F4EXB //
|
|
|
|
// //
|
|
|
|
// This program is free software; you can redistribute it and/or modify //
|
|
|
|
// it under the terms of the GNU General Public License as published by //
|
|
|
|
// the Free Software Foundation as version 3 of the License, or //
|
2019-04-11 00:39:30 -04:00
|
|
|
// (at your option) any later version. //
|
2018-05-15 03:17:54 -04:00
|
|
|
// //
|
|
|
|
// This program is distributed in the hope that it will be useful, //
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
|
|
|
|
// GNU General Public License V3 for more details. //
|
|
|
|
// //
|
|
|
|
// You should have received a copy of the GNU General Public License //
|
|
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>. //
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#include <QTime>
|
|
|
|
#include <QDebug>
|
2019-11-24 04:12:58 -05:00
|
|
|
#include <QThread>
|
|
|
|
|
2018-05-15 03:17:54 -04:00
|
|
|
#include <stdio.h>
|
|
|
|
|
2019-05-08 16:11:53 -04:00
|
|
|
#include "device/deviceapi.h"
|
2019-11-24 04:12:58 -05:00
|
|
|
#include "dsp/dspcommands.h"
|
2021-07-10 16:41:24 -04:00
|
|
|
#include "dsp/devicesamplesource.h"
|
2018-05-30 09:37:56 -04:00
|
|
|
#include "chanalyzer.h"
|
2018-05-15 03:17:54 -04:00
|
|
|
|
2018-05-30 09:37:56 -04:00
|
|
|
MESSAGE_CLASS_DEFINITION(ChannelAnalyzer::MsgConfigureChannelAnalyzer, Message)
|
2018-05-15 03:17:54 -04:00
|
|
|
|
2020-11-21 14:24:18 -05:00
|
|
|
const char* const ChannelAnalyzer::m_channelIdURI = "sdrangel.channel.chanalyzer";
|
|
|
|
const char* const ChannelAnalyzer::m_channelId = "ChannelAnalyzer";
|
2018-05-15 03:17:54 -04:00
|
|
|
|
2019-05-08 16:11:53 -04:00
|
|
|
ChannelAnalyzer::ChannelAnalyzer(DeviceAPI *deviceAPI) :
|
2019-05-09 11:27:12 -04:00
|
|
|
ChannelAPI(m_channelIdURI, ChannelAPI::StreamSingleSink),
|
2018-05-15 03:17:54 -04:00
|
|
|
m_deviceAPI(deviceAPI),
|
2020-04-30 03:57:05 -04:00
|
|
|
m_spectrumVis(SDR_RX_SCALEF),
|
2019-11-24 04:12:58 -05:00
|
|
|
m_basebandSampleRate(0)
|
2018-05-15 03:17:54 -04:00
|
|
|
{
|
2019-11-24 04:12:58 -05:00
|
|
|
qDebug("ChannelAnalyzer::ChannelAnalyzer");
|
2018-05-15 03:17:54 -04:00
|
|
|
setObjectName(m_channelId);
|
2021-07-10 16:41:24 -04:00
|
|
|
getChannelSampleRate();
|
2019-11-24 04:12:58 -05:00
|
|
|
m_basebandSink = new ChannelAnalyzerBaseband();
|
2020-07-13 04:33:05 -04:00
|
|
|
m_basebandSink->moveToThread(&m_thread);
|
2018-05-15 03:17:54 -04:00
|
|
|
|
2018-05-19 19:10:08 -04:00
|
|
|
applySettings(m_settings, true);
|
2018-05-15 03:17:54 -04:00
|
|
|
|
2019-11-24 04:12:58 -05:00
|
|
|
m_deviceAPI->addChannelSink(this);
|
2019-05-08 16:11:53 -04:00
|
|
|
m_deviceAPI->addChannelSinkAPI(this);
|
2018-05-15 03:17:54 -04:00
|
|
|
}
|
|
|
|
|
2018-05-30 09:37:56 -04:00
|
|
|
ChannelAnalyzer::~ChannelAnalyzer()
|
2018-05-15 03:17:54 -04:00
|
|
|
{
|
2020-10-07 15:28:32 -04:00
|
|
|
qDebug("ChannelAnalyzer::~ChannelAnalyzer");
|
2019-05-08 16:11:53 -04:00
|
|
|
m_deviceAPI->removeChannelSinkAPI(this);
|
2019-11-24 04:12:58 -05:00
|
|
|
m_deviceAPI->removeChannelSink(this);
|
2020-07-13 04:33:05 -04:00
|
|
|
|
|
|
|
if (m_basebandSink->isRunning()) {
|
|
|
|
stop();
|
|
|
|
}
|
|
|
|
|
2019-11-24 04:12:58 -05:00
|
|
|
delete m_basebandSink;
|
2020-10-07 15:28:32 -04:00
|
|
|
qDebug("ChannelAnalyzer::~ChannelAnalyzer: done");
|
2018-05-15 03:17:54 -04:00
|
|
|
}
|
|
|
|
|
2021-07-10 16:41:24 -04:00
|
|
|
int ChannelAnalyzer::getChannelSampleRate()
|
|
|
|
{
|
|
|
|
DeviceSampleSource *source = m_deviceAPI->getSampleSource();
|
|
|
|
|
|
|
|
if (source) {
|
|
|
|
m_basebandSampleRate = source->getSampleRate();
|
|
|
|
}
|
|
|
|
|
|
|
|
qDebug("ChannelAnalyzer::getChannelSampleRate: %d", m_basebandSampleRate);
|
|
|
|
return m_basebandSampleRate;
|
|
|
|
}
|
|
|
|
|
2018-11-12 18:45:03 -05:00
|
|
|
void ChannelAnalyzer::feed(const SampleVector::const_iterator& begin, const SampleVector::const_iterator& end, bool positiveOnly)
|
2018-05-15 03:17:54 -04:00
|
|
|
{
|
2018-11-12 18:45:03 -05:00
|
|
|
(void) positiveOnly;
|
2019-11-24 04:12:58 -05:00
|
|
|
m_basebandSink->feed(begin, end);
|
2018-05-15 03:17:54 -04:00
|
|
|
}
|
|
|
|
|
2019-11-24 04:12:58 -05:00
|
|
|
void ChannelAnalyzer::start()
|
2018-05-19 19:10:08 -04:00
|
|
|
{
|
2019-11-24 04:12:58 -05:00
|
|
|
qDebug() << "ChannelAnalyzer::start";
|
2018-05-19 19:10:08 -04:00
|
|
|
|
2019-11-24 04:12:58 -05:00
|
|
|
m_basebandSink->reset();
|
2020-07-13 04:33:05 -04:00
|
|
|
m_basebandSink->startWork();
|
|
|
|
m_thread.start();
|
|
|
|
|
|
|
|
DSPSignalNotification *dspMsg = new DSPSignalNotification(m_basebandSampleRate, m_centerFrequency);
|
|
|
|
m_basebandSink->getInputMessageQueue()->push(dspMsg);
|
|
|
|
|
|
|
|
ChannelAnalyzerBaseband::MsgConfigureChannelAnalyzerBaseband *msg =
|
|
|
|
ChannelAnalyzerBaseband::MsgConfigureChannelAnalyzerBaseband::create(m_settings, true);
|
|
|
|
m_basebandSink->getInputMessageQueue()->push(msg);
|
2021-07-10 16:41:24 -04:00
|
|
|
|
|
|
|
if (getMessageQueueToGUI())
|
|
|
|
{
|
|
|
|
DSPSignalNotification *notifToGUI = new DSPSignalNotification(m_basebandSampleRate, m_centerFrequency);
|
|
|
|
getMessageQueueToGUI()->push(notifToGUI);
|
|
|
|
}
|
2018-05-15 03:17:54 -04:00
|
|
|
}
|
|
|
|
|
2018-05-30 09:37:56 -04:00
|
|
|
void ChannelAnalyzer::stop()
|
2018-05-15 03:17:54 -04:00
|
|
|
{
|
2019-11-24 04:12:58 -05:00
|
|
|
qDebug() << "ChannelAnalyzer::stop";
|
2020-07-13 04:33:05 -04:00
|
|
|
m_basebandSink->stopWork();
|
|
|
|
m_thread.quit();
|
|
|
|
m_thread.wait();
|
2018-05-15 03:17:54 -04:00
|
|
|
}
|
|
|
|
|
2018-05-30 09:37:56 -04:00
|
|
|
bool ChannelAnalyzer::handleMessage(const Message& cmd)
|
2018-05-15 03:17:54 -04:00
|
|
|
{
|
2019-11-24 04:12:58 -05:00
|
|
|
if (MsgConfigureChannelAnalyzer::match(cmd))
|
2018-05-19 19:10:08 -04:00
|
|
|
{
|
2018-05-30 09:49:28 -04:00
|
|
|
qDebug("ChannelAnalyzer::handleMessage: MsgConfigureChannelAnalyzer");
|
2018-05-19 19:10:08 -04:00
|
|
|
MsgConfigureChannelAnalyzer& cfg = (MsgConfigureChannelAnalyzer&) cmd;
|
|
|
|
|
|
|
|
applySettings(cfg.getSettings(), cfg.getForce());
|
|
|
|
|
2018-05-15 03:17:54 -04:00
|
|
|
return true;
|
|
|
|
}
|
2019-11-24 04:12:58 -05:00
|
|
|
else if (DSPSignalNotification::match(cmd))
|
2018-05-18 23:03:56 -04:00
|
|
|
{
|
2019-11-24 04:12:58 -05:00
|
|
|
DSPSignalNotification& cfg = (DSPSignalNotification&) cmd;
|
|
|
|
m_basebandSampleRate = cfg.getSampleRate();
|
2020-10-07 15:28:32 -04:00
|
|
|
qDebug("ChannelAnalyzer::handleMessage: DSPSignalNotification: %d", m_basebandSampleRate);
|
2020-07-13 04:33:05 -04:00
|
|
|
m_centerFrequency = cfg.getCenterFrequency();
|
2019-11-24 04:12:58 -05:00
|
|
|
DSPSignalNotification *notif = new DSPSignalNotification(cfg);
|
|
|
|
m_basebandSink->getInputMessageQueue()->push(notif);
|
2018-05-18 23:03:56 -04:00
|
|
|
|
2019-11-24 04:12:58 -05:00
|
|
|
if (getMessageQueueToGUI())
|
2018-05-18 23:03:56 -04:00
|
|
|
{
|
2019-11-24 04:12:58 -05:00
|
|
|
DSPSignalNotification *notifToGUI = new DSPSignalNotification(cfg);
|
|
|
|
getMessageQueueToGUI()->push(notifToGUI);
|
2018-05-18 23:03:56 -04:00
|
|
|
}
|
|
|
|
|
2019-11-24 04:12:58 -05:00
|
|
|
return true;
|
2018-05-18 23:03:56 -04:00
|
|
|
}
|
2019-11-24 04:12:58 -05:00
|
|
|
else
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2018-05-18 23:03:56 -04:00
|
|
|
}
|
|
|
|
|
2018-05-30 09:37:56 -04:00
|
|
|
void ChannelAnalyzer::applySettings(const ChannelAnalyzerSettings& settings, bool force)
|
2018-05-18 23:03:56 -04:00
|
|
|
{
|
2018-05-30 09:49:28 -04:00
|
|
|
qDebug() << "ChannelAnalyzer::applySettings:"
|
2019-11-24 04:12:58 -05:00
|
|
|
<< " m_rationalDownSample: " << settings.m_rationalDownSample
|
|
|
|
<< " m_rationalDownSamplerRate: " << settings.m_rationalDownSamplerRate
|
2018-05-21 20:20:36 -04:00
|
|
|
<< " m_rcc: " << settings.m_rrc
|
|
|
|
<< " m_rrcRolloff: " << settings.m_rrcRolloff / 100.0
|
2018-05-19 19:10:08 -04:00
|
|
|
<< " m_bandwidth: " << settings.m_bandwidth
|
|
|
|
<< " m_lowCutoff: " << settings.m_lowCutoff
|
2019-11-24 04:12:58 -05:00
|
|
|
<< " m_log2Decim: " << settings.m_log2Decim
|
2018-05-19 19:10:08 -04:00
|
|
|
<< " m_ssb: " << settings.m_ssb
|
|
|
|
<< " m_pll: " << settings.m_pll
|
|
|
|
<< " m_fll: " << settings.m_fll
|
2021-03-05 08:37:49 -05:00
|
|
|
<< " m_costasLoop: " << settings.m_costasLoop
|
2018-05-20 12:17:53 -04:00
|
|
|
<< " m_pllPskOrder: " << settings.m_pllPskOrder
|
2021-03-05 08:37:49 -05:00
|
|
|
<< " m_pllBandwidth: " << settings.m_pllBandwidth
|
|
|
|
<< " m_pllDampingFactor: " << settings.m_pllDampingFactor
|
|
|
|
<< " m_pllLoopGain: " << settings.m_pllLoopGain
|
2018-05-20 12:17:53 -04:00
|
|
|
<< " m_inputType: " << (int) settings.m_inputType;
|
2018-05-19 19:10:08 -04:00
|
|
|
|
2019-11-24 04:12:58 -05:00
|
|
|
ChannelAnalyzerBaseband::MsgConfigureChannelAnalyzerBaseband *msg
|
|
|
|
= ChannelAnalyzerBaseband::MsgConfigureChannelAnalyzerBaseband::create(settings, force);
|
|
|
|
m_basebandSink->getInputMessageQueue()->push(msg);
|
2018-05-18 23:03:56 -04:00
|
|
|
|
|
|
|
m_settings = settings;
|
|
|
|
}
|