2017-02-23 02:18:56 -05:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////
|
2023-11-18 06:02:48 -05:00
|
|
|
// Copyright (C) 2017-2020, 2022 Edouard Griffiths, F4EXB <f4exb06@gmail.com> //
|
|
|
|
// Copyright (C) 2020 Kacper Michajłow <kasper93@gmail.com> //
|
2017-02-23 02:18:56 -05:00
|
|
|
// for F4EXB / SDRAngel //
|
|
|
|
// //
|
|
|
|
// 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. //
|
2017-02-23 02:18:56 -05: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-12-01 09:13:35 -05:00
|
|
|
|
2017-02-23 02:18:56 -05:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <complex.h>
|
2017-11-06 17:57:59 -05:00
|
|
|
|
2019-05-08 16:11:53 -04:00
|
|
|
#include "device/deviceapi.h"
|
2017-11-06 17:57:59 -05:00
|
|
|
|
|
|
|
#include "atvdemod.h"
|
2024-04-20 05:51:29 -04:00
|
|
|
#include "dsp/dspcommands.h"
|
2017-02-23 02:18:56 -05:00
|
|
|
|
|
|
|
MESSAGE_CLASS_DEFINITION(ATVDemod::MsgConfigureATVDemod, Message)
|
|
|
|
|
2020-11-21 14:24:18 -05:00
|
|
|
const char* const ATVDemod::m_channelIdURI = "sdrangel.channel.demodatv";
|
|
|
|
const char* const ATVDemod::m_channelId = "ATVDemod";
|
2017-03-16 18:13:51 -04:00
|
|
|
|
2019-05-08 16:11:53 -04:00
|
|
|
ATVDemod::ATVDemod(DeviceAPI *deviceAPI) :
|
2019-12-01 09:13:35 -05:00
|
|
|
ChannelAPI(m_channelIdURI, ChannelAPI::StreamSingleSink),
|
|
|
|
m_deviceAPI(deviceAPI),
|
2020-07-11 15:01:32 -04:00
|
|
|
m_centerFrequency(0),
|
2019-12-01 09:13:35 -05:00
|
|
|
m_basebandSampleRate(0)
|
2017-02-23 02:18:56 -05:00
|
|
|
{
|
2019-12-01 09:13:35 -05:00
|
|
|
qDebug("ATVDemod::ATVDemod");
|
2017-11-22 19:19:32 -05:00
|
|
|
setObjectName(m_channelId);
|
2017-02-23 02:18:56 -05:00
|
|
|
|
2019-12-01 09:13:35 -05:00
|
|
|
m_basebandSink = new ATVDemodBaseband();
|
2022-03-17 16:10:30 -04:00
|
|
|
m_basebandSink->setFifoLabel(QString("%1 [%2:%3]")
|
|
|
|
.arg(m_channelId)
|
|
|
|
.arg(m_deviceAPI->getDeviceSetIndex())
|
|
|
|
.arg(getIndexInDeviceSet())
|
|
|
|
);
|
2020-08-19 07:12:23 -04:00
|
|
|
m_basebandSink->moveToThread(&m_thread);
|
2017-03-26 20:29:02 -04:00
|
|
|
|
2019-12-01 09:13:35 -05:00
|
|
|
applySettings(m_settings, true);
|
2018-03-16 05:24:19 -04:00
|
|
|
|
2019-12-01 09:13:35 -05:00
|
|
|
m_deviceAPI->addChannelSink(this);
|
2019-05-08 16:11:53 -04:00
|
|
|
m_deviceAPI->addChannelSinkAPI(this);
|
2022-03-18 12:08:04 -04:00
|
|
|
|
|
|
|
QObject::connect(
|
|
|
|
this,
|
|
|
|
&ChannelAPI::indexInDeviceSetChanged,
|
|
|
|
this,
|
|
|
|
&ATVDemod::handleIndexInDeviceSetChanged
|
|
|
|
);
|
2017-02-23 02:18:56 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
ATVDemod::~ATVDemod()
|
2017-02-25 01:12:41 -05:00
|
|
|
{
|
2019-12-01 09:13:35 -05:00
|
|
|
qDebug("ATVDemod::~ATVDemod");
|
2019-05-08 16:11:53 -04:00
|
|
|
m_deviceAPI->removeChannelSinkAPI(this);
|
2019-12-01 09:13:35 -05:00
|
|
|
m_deviceAPI->removeChannelSink(this);
|
2020-08-19 07:12:23 -04:00
|
|
|
|
|
|
|
if (m_basebandSink->isRunning()) {
|
|
|
|
stop();
|
|
|
|
}
|
|
|
|
|
2019-12-01 09:13:35 -05:00
|
|
|
delete m_basebandSink;
|
2017-03-18 00:37:52 -04:00
|
|
|
}
|
2017-02-23 02:18:56 -05:00
|
|
|
|
2022-04-16 10:45:53 -04:00
|
|
|
void ATVDemod::setDeviceAPI(DeviceAPI *deviceAPI)
|
|
|
|
{
|
|
|
|
if (deviceAPI != m_deviceAPI)
|
|
|
|
{
|
|
|
|
m_deviceAPI->removeChannelSinkAPI(this);
|
|
|
|
m_deviceAPI->removeChannelSink(this);
|
|
|
|
m_deviceAPI = deviceAPI;
|
|
|
|
m_deviceAPI->addChannelSink(this);
|
|
|
|
m_deviceAPI->addChannelSinkAPI(this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-17 19:42:03 -04:00
|
|
|
uint32_t ATVDemod::getNumberOfDeviceStreams() const
|
|
|
|
{
|
|
|
|
return m_deviceAPI->getNbSourceStreams();
|
|
|
|
}
|
|
|
|
|
2019-12-01 09:13:35 -05:00
|
|
|
void ATVDemod::start()
|
2017-03-18 00:37:52 -04:00
|
|
|
{
|
2019-12-01 09:13:35 -05:00
|
|
|
qDebug("ATVDemod::start");
|
2017-02-23 02:18:56 -05:00
|
|
|
|
2019-12-01 09:13:35 -05:00
|
|
|
m_basebandSink->reset();
|
2020-08-19 07:12:23 -04:00
|
|
|
m_basebandSink->startWork();
|
|
|
|
m_thread.start();
|
2020-07-11 15:01:32 -04:00
|
|
|
|
|
|
|
// re-apply essential messages
|
|
|
|
|
|
|
|
DSPSignalNotification* notifToSink = new DSPSignalNotification(m_basebandSampleRate, m_centerFrequency);
|
|
|
|
m_basebandSink->getInputMessageQueue()->push(notifToSink);
|
|
|
|
|
|
|
|
ATVDemodBaseband::MsgConfigureATVDemodBaseband *msg = ATVDemodBaseband::MsgConfigureATVDemodBaseband::create(m_settings, true);
|
|
|
|
m_basebandSink->getInputMessageQueue()->push(msg);
|
2017-02-23 02:18:56 -05:00
|
|
|
}
|
|
|
|
|
2019-12-01 09:13:35 -05:00
|
|
|
void ATVDemod::stop()
|
2017-02-23 02:18:56 -05:00
|
|
|
{
|
2019-12-01 09:13:35 -05:00
|
|
|
qDebug("ATVDemod::stop");
|
2020-08-19 07:12:23 -04:00
|
|
|
m_basebandSink->stopWork();
|
|
|
|
m_thread.exit();
|
|
|
|
m_thread.wait();
|
2017-02-23 02:18:56 -05:00
|
|
|
}
|
|
|
|
|
2019-12-01 09:13:35 -05:00
|
|
|
void ATVDemod::feed(const SampleVector::const_iterator& begin, const SampleVector::const_iterator& end, bool firstOfBurst)
|
2017-02-23 02:18:56 -05:00
|
|
|
{
|
2019-12-01 09:13:35 -05:00
|
|
|
(void) firstOfBurst;
|
|
|
|
m_basebandSink->feed(begin, end);
|
2017-02-23 02:18:56 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
bool ATVDemod::handleMessage(const Message& cmd)
|
2017-02-25 01:12:41 -05:00
|
|
|
{
|
2019-12-01 09:13:35 -05:00
|
|
|
if (MsgConfigureATVDemod::match(cmd))
|
2017-03-17 05:04:00 -04:00
|
|
|
{
|
2019-12-01 09:13:35 -05:00
|
|
|
MsgConfigureATVDemod& cfg = (MsgConfigureATVDemod&) cmd;
|
|
|
|
applySettings(cfg.getSettings(), cfg.getForce());
|
2017-03-17 05:04:00 -04:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2019-12-01 09:13:35 -05:00
|
|
|
else if (DSPSignalNotification::match(cmd))
|
2017-03-16 20:42:15 -04:00
|
|
|
{
|
2019-12-01 09:13:35 -05:00
|
|
|
DSPSignalNotification& notif = (DSPSignalNotification&) cmd;
|
2020-07-11 15:01:32 -04:00
|
|
|
m_centerFrequency = notif.getCenterFrequency();
|
2019-12-01 09:13:35 -05:00
|
|
|
m_basebandSampleRate = notif.getSampleRate(); // store for init at start
|
|
|
|
qDebug() << "ATVDemod::handleMessage: DSPSignalNotification" << m_basebandSampleRate;
|
2017-04-02 17:20:25 -04:00
|
|
|
|
2019-12-01 09:13:35 -05:00
|
|
|
// Forward to the sink
|
|
|
|
DSPSignalNotification* notifToSink = new DSPSignalNotification(notif); // make a copy
|
|
|
|
m_basebandSink->getInputMessageQueue()->push(notifToSink);
|
2017-03-30 16:11:35 -04:00
|
|
|
|
2019-12-01 09:13:35 -05:00
|
|
|
// Forward to GUI
|
2022-04-13 05:08:21 -04:00
|
|
|
if (getMessageQueueToGUI()) {
|
|
|
|
getMessageQueueToGUI()->push(new DSPSignalNotification(notif));
|
2017-11-06 17:57:59 -05:00
|
|
|
}
|
2017-03-26 20:29:02 -04:00
|
|
|
|
2019-12-01 09:13:35 -05:00
|
|
|
return true;
|
2017-03-19 05:28:54 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2017-03-20 00:06:33 -04:00
|
|
|
|
2022-01-06 16:47:41 -05:00
|
|
|
void ATVDemod::setCenterFrequency(qint64 frequency)
|
|
|
|
{
|
|
|
|
ATVDemodSettings settings = m_settings;
|
|
|
|
settings.m_inputFrequencyOffset = frequency;
|
|
|
|
applySettings(settings, false);
|
|
|
|
|
|
|
|
if (getMessageQueueToGUI())
|
|
|
|
{
|
|
|
|
MsgConfigureATVDemod *msg = MsgConfigureATVDemod::create(settings, false);
|
|
|
|
getMessageQueueToGUI()->push(msg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-01 09:13:35 -05:00
|
|
|
void ATVDemod::applySettings(const ATVDemodSettings& settings, bool force)
|
|
|
|
{
|
|
|
|
qDebug() << "ATVDemod::applySettings:"
|
|
|
|
<< "m_inputFrequencyOffset:" << settings.m_inputFrequencyOffset
|
|
|
|
<< "m_bfoFrequency:" << settings.m_bfoFrequency
|
|
|
|
<< "m_atvModulation:" << settings.m_atvModulation
|
|
|
|
<< "m_fmDeviation:" << settings.m_fmDeviation
|
|
|
|
<< "m_fftFiltering:" << settings.m_fftFiltering
|
|
|
|
<< "m_fftOppBandwidth:" << settings.m_fftOppBandwidth
|
|
|
|
<< "m_fftBandwidth:" << settings.m_fftBandwidth
|
|
|
|
<< "m_nbLines:" << settings.m_nbLines
|
|
|
|
<< "m_fps:" << settings.m_fps
|
|
|
|
<< "m_atvStd:" << settings.m_atvStd
|
|
|
|
<< "m_hSync:" << settings.m_hSync
|
|
|
|
<< "m_vSync:" << settings.m_vSync
|
|
|
|
<< "m_invertVideo:" << settings.m_invertVideo
|
|
|
|
<< "m_halfFrames:" << settings.m_halfFrames
|
|
|
|
<< "m_levelSynchroTop:" << settings.m_levelSynchroTop
|
|
|
|
<< "m_levelBlack:" << settings.m_levelBlack
|
|
|
|
<< "m_rgbColor:" << settings.m_rgbColor
|
|
|
|
<< "m_title:" << settings.m_title
|
|
|
|
<< "m_udpAddress:" << settings.m_udpAddress
|
|
|
|
<< "m_udpPort:" << settings.m_udpPort
|
|
|
|
<< "force:" << force;
|
|
|
|
|
2023-12-14 15:57:10 -05:00
|
|
|
if (m_settings.m_streamIndex != settings.m_streamIndex)
|
|
|
|
{
|
|
|
|
if (m_deviceAPI->getSampleMIMO()) // change of stream is possible for MIMO devices only
|
|
|
|
{
|
|
|
|
m_deviceAPI->removeChannelSinkAPI(this);
|
|
|
|
m_deviceAPI->removeChannelSink(this, m_settings.m_streamIndex);
|
|
|
|
m_deviceAPI->addChannelSink(this, settings.m_streamIndex);
|
|
|
|
m_deviceAPI->addChannelSinkAPI(this);
|
|
|
|
m_settings.m_streamIndex = settings.m_streamIndex; // make sure ChannelAPI::getStreamIndex() is consistent
|
|
|
|
emit streamIndexChanged(settings.m_streamIndex);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-01 09:13:35 -05:00
|
|
|
ATVDemodBaseband::MsgConfigureATVDemodBaseband *msg = ATVDemodBaseband::MsgConfigureATVDemodBaseband::create(settings, force);
|
|
|
|
m_basebandSink->getInputMessageQueue()->push(msg);
|
|
|
|
|
|
|
|
m_settings = settings;
|
2017-11-06 17:57:59 -05:00
|
|
|
}
|
2022-03-18 12:08:04 -04:00
|
|
|
|
|
|
|
void ATVDemod::handleIndexInDeviceSetChanged(int index)
|
|
|
|
{
|
|
|
|
if (index < 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString fifoLabel = QString("%1 [%2:%3]")
|
|
|
|
.arg(m_channelId)
|
|
|
|
.arg(m_deviceAPI->getDeviceSetIndex())
|
|
|
|
.arg(index);
|
|
|
|
m_basebandSink->setFifoLabel(fifoLabel);
|
|
|
|
}
|