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"
|
2018-05-15 03:17:54 -04:00
|
|
|
#include "audio/audiooutput.h"
|
|
|
|
#include "dsp/downchannelizer.h"
|
2019-11-24 04:12:58 -05:00
|
|
|
#include "dsp/dspcommands.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
|
|
|
|
2018-05-30 09:37:56 -04:00
|
|
|
const QString ChannelAnalyzer::m_channelIdURI = "sdrangel.channel.chanalyzer";
|
|
|
|
const QString 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),
|
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);
|
|
|
|
|
2019-11-24 04:12:58 -05:00
|
|
|
m_thread = new QThread(this);
|
|
|
|
m_basebandSink = new ChannelAnalyzerBaseband();
|
|
|
|
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
|
|
|
{
|
2019-05-08 16:11:53 -04:00
|
|
|
m_deviceAPI->removeChannelSinkAPI(this);
|
2019-11-24 04:12:58 -05:00
|
|
|
m_deviceAPI->removeChannelSink(this);
|
|
|
|
delete m_basebandSink;
|
|
|
|
delete m_thread;
|
2018-05-15 03:17:54 -04:00
|
|
|
}
|
|
|
|
|
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
|
|
|
if (m_basebandSampleRate != 0) {
|
|
|
|
m_basebandSink->setBasebandSampleRate(m_basebandSampleRate);
|
2018-05-19 19:10:08 -04:00
|
|
|
}
|
|
|
|
|
2019-11-24 04:12:58 -05:00
|
|
|
m_basebandSink->reset();
|
|
|
|
m_thread->start();
|
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";
|
|
|
|
m_thread->exit();
|
|
|
|
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();
|
|
|
|
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
|
2018-05-20 12:17:53 -04:00
|
|
|
<< " m_pllPskOrder: " << settings.m_pllPskOrder
|
|
|
|
<< " 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;
|
|
|
|
}
|