2016-10-20 16:04:15 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Copyright (C) 2016 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 04:39:30 +00:00
|
|
|
// (at your option) any later version. //
|
2016-10-20 16:04:15 +00: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/>. //
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2018-12-19 23:09:53 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <complex.h>
|
2016-10-20 16:04:15 +00:00
|
|
|
|
|
|
|
#include <QTime>
|
|
|
|
#include <QDebug>
|
2016-10-20 17:34:30 +00:00
|
|
|
#include <QMutexLocker>
|
2018-12-19 23:09:53 +00:00
|
|
|
#include <QNetworkAccessManager>
|
|
|
|
#include <QNetworkReply>
|
|
|
|
#include <QBuffer>
|
2018-02-14 19:11:36 +00:00
|
|
|
|
2018-04-05 22:54:18 +00:00
|
|
|
#include "SWGChannelSettings.h"
|
|
|
|
#include "SWGChannelReport.h"
|
|
|
|
#include "SWGAMModReport.h"
|
|
|
|
|
2018-12-19 23:09:53 +00:00
|
|
|
#include "ammod.h"
|
|
|
|
|
2018-02-14 19:11:36 +00:00
|
|
|
#include "dsp/upchannelizer.h"
|
2016-10-20 16:04:15 +00:00
|
|
|
#include "dsp/dspengine.h"
|
2017-10-10 20:37:33 +00:00
|
|
|
#include "dsp/threadedbasebandsamplesource.h"
|
2018-02-14 19:11:36 +00:00
|
|
|
#include "dsp/dspcommands.h"
|
2019-05-08 20:11:53 +00:00
|
|
|
#include "device/deviceapi.h"
|
2018-04-05 22:54:18 +00:00
|
|
|
#include "util/db.h"
|
2016-10-20 16:04:15 +00:00
|
|
|
|
|
|
|
MESSAGE_CLASS_DEFINITION(AMMod::MsgConfigureAMMod, Message)
|
2017-10-10 07:10:03 +00:00
|
|
|
MESSAGE_CLASS_DEFINITION(AMMod::MsgConfigureChannelizer, Message)
|
2016-11-28 01:17:08 +00:00
|
|
|
MESSAGE_CLASS_DEFINITION(AMMod::MsgConfigureFileSourceName, Message)
|
|
|
|
MESSAGE_CLASS_DEFINITION(AMMod::MsgConfigureFileSourceSeek, Message)
|
|
|
|
MESSAGE_CLASS_DEFINITION(AMMod::MsgConfigureFileSourceStreamTiming, Message)
|
|
|
|
MESSAGE_CLASS_DEFINITION(AMMod::MsgReportFileSourceStreamData, Message)
|
|
|
|
MESSAGE_CLASS_DEFINITION(AMMod::MsgReportFileSourceStreamTiming, Message)
|
|
|
|
|
2017-11-23 00:19:32 +00:00
|
|
|
const QString AMMod::m_channelIdURI = "sdrangel.channeltx.modam";
|
|
|
|
const QString AMMod::m_channelId ="AMMod";
|
2016-12-02 16:56:19 +00:00
|
|
|
const int AMMod::m_levelNbSamples = 480; // every 10ms
|
2016-10-20 16:04:15 +00:00
|
|
|
|
2019-05-08 20:11:53 +00:00
|
|
|
AMMod::AMMod(DeviceAPI *deviceAPI) :
|
2019-05-09 15:27:12 +00:00
|
|
|
ChannelAPI(m_channelIdURI, ChannelAPI::StreamSingleSource),
|
2017-10-10 20:37:33 +00:00
|
|
|
m_deviceAPI(deviceAPI),
|
2017-12-29 10:42:33 +00:00
|
|
|
m_basebandSampleRate(48000),
|
|
|
|
m_outputSampleRate(48000),
|
|
|
|
m_inputFrequencyOffset(0),
|
2017-08-24 22:02:49 +00:00
|
|
|
m_audioFifo(4800),
|
2019-07-30 16:31:24 +00:00
|
|
|
m_feedbackAudioFifo(4800),
|
2016-11-28 17:19:23 +00:00
|
|
|
m_settingsMutex(QMutex::Recursive),
|
|
|
|
m_fileSize(0),
|
|
|
|
m_recordLength(0),
|
|
|
|
m_sampleRate(48000),
|
2016-12-02 16:56:19 +00:00
|
|
|
m_levelCalcCount(0),
|
|
|
|
m_peakLevel(0.0f),
|
2017-05-25 18:13:34 +00:00
|
|
|
m_levelSum(0.0f)
|
2016-10-20 16:04:15 +00:00
|
|
|
{
|
2017-11-23 00:19:32 +00:00
|
|
|
setObjectName(m_channelId);
|
2016-10-20 16:04:15 +00:00
|
|
|
|
2016-12-26 00:39:34 +00:00
|
|
|
m_audioBuffer.resize(1<<14);
|
|
|
|
m_audioBufferFill = 0;
|
2016-10-20 16:04:15 +00:00
|
|
|
|
2019-07-30 16:31:24 +00:00
|
|
|
m_feedbackAudioBuffer.resize(1<<14);
|
|
|
|
m_feedbackAudioBufferFill = 0;
|
|
|
|
|
2016-10-20 16:04:15 +00:00
|
|
|
m_magsq = 0.0;
|
2016-10-20 17:34:30 +00:00
|
|
|
|
2018-03-25 09:50:34 +00:00
|
|
|
DSPEngine::instance()->getAudioDeviceManager()->addAudioSource(&m_audioFifo, getInputMessageQueue());
|
2018-03-29 13:20:38 +00:00
|
|
|
m_audioSampleRate = DSPEngine::instance()->getAudioDeviceManager()->getInputSampleRate();
|
2019-07-30 16:31:24 +00:00
|
|
|
|
|
|
|
DSPEngine::instance()->getAudioDeviceManager()->addAudioSink(&m_feedbackAudioFifo, getInputMessageQueue());
|
|
|
|
m_feedbackAudioSampleRate = DSPEngine::instance()->getAudioDeviceManager()->getOutputSampleRate();
|
|
|
|
|
2018-03-29 13:20:38 +00:00
|
|
|
m_toneNco.setFreq(1000.0, m_audioSampleRate);
|
2019-07-29 23:31:46 +00:00
|
|
|
m_cwKeyer.setSampleRate(m_audioSampleRate);
|
|
|
|
m_cwKeyer.reset();
|
2017-10-10 19:43:58 +00:00
|
|
|
|
2018-03-16 09:26:49 +00:00
|
|
|
applyChannelSettings(m_basebandSampleRate, m_outputSampleRate, m_inputFrequencyOffset, true);
|
|
|
|
applySettings(m_settings, true);
|
|
|
|
|
2017-10-10 20:37:33 +00:00
|
|
|
m_channelizer = new UpChannelizer(this);
|
|
|
|
m_threadedChannelizer = new ThreadedBasebandSampleSource(m_channelizer, this);
|
2019-05-08 20:11:53 +00:00
|
|
|
m_deviceAPI->addChannelSource(m_threadedChannelizer);
|
|
|
|
m_deviceAPI->addChannelSourceAPI(this);
|
2018-12-19 23:09:53 +00:00
|
|
|
|
|
|
|
m_networkManager = new QNetworkAccessManager();
|
|
|
|
connect(m_networkManager, SIGNAL(finished(QNetworkReply*)), this, SLOT(networkManagerFinished(QNetworkReply*)));
|
2016-10-20 16:04:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
AMMod::~AMMod()
|
|
|
|
{
|
2018-12-19 23:09:53 +00:00
|
|
|
disconnect(m_networkManager, SIGNAL(finished(QNetworkReply*)), this, SLOT(networkManagerFinished(QNetworkReply*)));
|
|
|
|
delete m_networkManager;
|
2019-05-08 20:11:53 +00:00
|
|
|
m_deviceAPI->removeChannelSourceAPI(this);
|
|
|
|
m_deviceAPI->removeChannelSource(m_threadedChannelizer);
|
2017-10-10 20:37:33 +00:00
|
|
|
delete m_threadedChannelizer;
|
|
|
|
delete m_channelizer;
|
2019-07-30 16:31:24 +00:00
|
|
|
DSPEngine::instance()->getAudioDeviceManager()->removeAudioSink(&m_feedbackAudioFifo);
|
2018-03-24 02:36:49 +00:00
|
|
|
DSPEngine::instance()->getAudioDeviceManager()->removeAudioSource(&m_audioFifo);
|
2016-10-20 16:04:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void AMMod::pull(Sample& sample)
|
|
|
|
{
|
2017-10-10 07:10:03 +00:00
|
|
|
if (m_settings.m_channelMute)
|
2016-12-19 17:09:07 +00:00
|
|
|
{
|
|
|
|
sample.m_real = 0.0f;
|
|
|
|
sample.m_imag = 0.0f;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-10-20 17:34:30 +00:00
|
|
|
Complex ci;
|
|
|
|
|
2016-10-30 19:57:27 +00:00
|
|
|
m_settingsMutex.lock();
|
2016-10-28 02:34:06 +00:00
|
|
|
|
|
|
|
if (m_interpolatorDistance > 1.0f) // decimate
|
|
|
|
{
|
2016-11-30 16:58:35 +00:00
|
|
|
modulateSample();
|
2016-10-28 02:34:06 +00:00
|
|
|
|
|
|
|
while (!m_interpolator.decimate(&m_interpolatorDistanceRemain, m_modSample, &ci))
|
|
|
|
{
|
2016-11-30 16:58:35 +00:00
|
|
|
modulateSample();
|
2016-10-28 02:34:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (m_interpolator.interpolate(&m_interpolatorDistanceRemain, m_modSample, &ci))
|
|
|
|
{
|
2016-11-30 16:58:35 +00:00
|
|
|
modulateSample();
|
2016-10-28 02:34:06 +00:00
|
|
|
}
|
|
|
|
}
|
2016-10-20 17:34:30 +00:00
|
|
|
|
2016-10-28 01:18:24 +00:00
|
|
|
m_interpolatorDistanceRemain += m_interpolatorDistance;
|
|
|
|
|
2016-10-24 00:24:36 +00:00
|
|
|
ci *= m_carrierNco.nextIQ(); // shift to carrier frequency
|
2016-10-20 17:34:30 +00:00
|
|
|
|
2016-10-30 19:57:27 +00:00
|
|
|
m_settingsMutex.unlock();
|
|
|
|
|
2018-01-21 09:57:04 +00:00
|
|
|
double magsq = ci.real() * ci.real() + ci.imag() * ci.imag();
|
2018-01-22 07:46:05 +00:00
|
|
|
magsq /= (SDR_TX_SCALED*SDR_TX_SCALED);
|
2018-02-03 09:33:02 +00:00
|
|
|
m_movingAverage(magsq);
|
|
|
|
m_magsq = m_movingAverage.asDouble();
|
2016-10-20 17:34:30 +00:00
|
|
|
|
|
|
|
sample.m_real = (FixReal) ci.real();
|
|
|
|
sample.m_imag = (FixReal) ci.imag();
|
2016-10-20 16:04:15 +00:00
|
|
|
}
|
|
|
|
|
2016-12-26 00:39:34 +00:00
|
|
|
void AMMod::pullAudio(int nbSamples)
|
|
|
|
{
|
|
|
|
// qDebug("AMMod::pullAudio: %d", nbSamples);
|
2018-03-29 13:20:38 +00:00
|
|
|
unsigned int nbAudioSamples = nbSamples * ((Real) m_audioSampleRate / (Real) m_basebandSampleRate);
|
2016-12-26 00:39:34 +00:00
|
|
|
|
2016-12-26 01:15:24 +00:00
|
|
|
if (nbAudioSamples > m_audioBuffer.size())
|
2016-12-26 00:39:34 +00:00
|
|
|
{
|
2016-12-26 01:15:24 +00:00
|
|
|
m_audioBuffer.resize(nbAudioSamples);
|
2016-12-26 00:39:34 +00:00
|
|
|
}
|
|
|
|
|
2018-09-12 13:30:53 +00:00
|
|
|
m_audioFifo.read(reinterpret_cast<quint8*>(&m_audioBuffer[0]), nbAudioSamples);
|
2016-12-26 00:39:34 +00:00
|
|
|
m_audioBufferFill = 0;
|
|
|
|
}
|
|
|
|
|
2016-11-30 16:58:35 +00:00
|
|
|
void AMMod::modulateSample()
|
|
|
|
{
|
|
|
|
Real t;
|
|
|
|
|
|
|
|
pullAF(t);
|
2016-12-02 16:56:19 +00:00
|
|
|
calculateLevel(t);
|
2016-12-26 01:15:24 +00:00
|
|
|
m_audioBufferFill++;
|
2016-11-30 16:58:35 +00:00
|
|
|
|
2017-10-10 07:10:03 +00:00
|
|
|
m_modSample.real((t*m_settings.m_modFactor + 1.0f) * 16384.0f); // modulate and scale zero frequency carrier
|
2016-11-30 16:58:35 +00:00
|
|
|
m_modSample.imag(0.0f);
|
|
|
|
}
|
|
|
|
|
2016-11-28 01:17:08 +00:00
|
|
|
void AMMod::pullAF(Real& sample)
|
|
|
|
{
|
2018-04-05 19:58:45 +00:00
|
|
|
switch (m_settings.m_modAFInput)
|
2016-11-28 01:17:08 +00:00
|
|
|
{
|
2018-04-05 19:58:45 +00:00
|
|
|
case AMModSettings::AMModInputTone:
|
2016-11-28 01:17:08 +00:00
|
|
|
sample = m_toneNco.next();
|
|
|
|
break;
|
2018-04-05 19:58:45 +00:00
|
|
|
case AMModSettings::AMModInputFile:
|
2016-11-28 01:17:08 +00:00
|
|
|
// sox f4exb_call.wav --encoding float --endian little f4exb_call.raw
|
|
|
|
// ffplay -f f32le -ar 48k -ac 1 f4exb_call.raw
|
|
|
|
if (m_ifstream.is_open())
|
|
|
|
{
|
2016-11-28 17:19:23 +00:00
|
|
|
if (m_ifstream.eof())
|
2016-11-28 01:17:08 +00:00
|
|
|
{
|
2017-10-10 07:10:03 +00:00
|
|
|
if (m_settings.m_playLoop)
|
2016-11-28 17:19:23 +00:00
|
|
|
{
|
|
|
|
m_ifstream.clear();
|
|
|
|
m_ifstream.seekg(0, std::ios::beg);
|
|
|
|
}
|
2016-11-28 01:17:08 +00:00
|
|
|
}
|
|
|
|
|
2016-11-28 17:19:23 +00:00
|
|
|
if (m_ifstream.eof())
|
|
|
|
{
|
|
|
|
sample = 0.0f;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_ifstream.read(reinterpret_cast<char*>(&sample), sizeof(Real));
|
2017-10-10 07:10:03 +00:00
|
|
|
sample *= m_settings.m_volumeFactor;
|
2016-11-28 17:19:23 +00:00
|
|
|
}
|
2016-11-28 01:17:08 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
sample = 0.0f;
|
|
|
|
}
|
|
|
|
break;
|
2018-04-05 19:58:45 +00:00
|
|
|
case AMModSettings::AMModInputAudio:
|
2017-10-10 07:10:03 +00:00
|
|
|
sample = ((m_audioBuffer[m_audioBufferFill].l + m_audioBuffer[m_audioBufferFill].r) / 65536.0f) * m_settings.m_volumeFactor;
|
2016-11-28 01:17:08 +00:00
|
|
|
break;
|
2018-04-05 19:58:45 +00:00
|
|
|
case AMModSettings::AMModInputCWTone:
|
2016-12-14 22:45:16 +00:00
|
|
|
Real fadeFactor;
|
|
|
|
|
2016-12-10 07:12:16 +00:00
|
|
|
if (m_cwKeyer.getSample())
|
|
|
|
{
|
2017-10-21 03:27:05 +00:00
|
|
|
m_cwKeyer.getCWSmoother().getFadeSample(true, fadeFactor);
|
2016-12-14 22:45:16 +00:00
|
|
|
sample = m_toneNco.next() * fadeFactor;
|
2016-12-10 07:12:16 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-10-21 03:27:05 +00:00
|
|
|
if (m_cwKeyer.getCWSmoother().getFadeSample(false, fadeFactor))
|
2016-12-14 22:45:16 +00:00
|
|
|
{
|
|
|
|
sample = m_toneNco.next() * fadeFactor;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
sample = 0.0f;
|
|
|
|
m_toneNco.setPhase(0);
|
|
|
|
}
|
2016-12-10 07:12:16 +00:00
|
|
|
}
|
|
|
|
break;
|
2018-04-05 19:58:45 +00:00
|
|
|
case AMModSettings::AMModInputNone:
|
2016-11-28 01:17:08 +00:00
|
|
|
default:
|
|
|
|
sample = 0.0f;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-02 16:56:19 +00:00
|
|
|
void AMMod::calculateLevel(Real& sample)
|
|
|
|
{
|
|
|
|
if (m_levelCalcCount < m_levelNbSamples)
|
|
|
|
{
|
|
|
|
m_peakLevel = std::max(std::fabs(m_peakLevel), sample);
|
|
|
|
m_levelSum += sample * sample;
|
|
|
|
m_levelCalcCount++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
qreal rmsLevel = sqrt(m_levelSum / m_levelNbSamples);
|
|
|
|
//qDebug("NFMMod::calculateLevel: %f %f", rmsLevel, m_peakLevel);
|
|
|
|
emit levelChanged(rmsLevel, m_peakLevel, m_levelNbSamples);
|
|
|
|
m_peakLevel = 0.0f;
|
|
|
|
m_levelSum = 0.0f;
|
|
|
|
m_levelCalcCount = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-20 16:04:15 +00:00
|
|
|
void AMMod::start()
|
|
|
|
{
|
2017-12-29 10:42:33 +00:00
|
|
|
qDebug() << "AMMod::start: m_outputSampleRate: " << m_outputSampleRate
|
2017-10-10 19:47:15 +00:00
|
|
|
<< " m_inputFrequencyOffset: " << m_settings.m_inputFrequencyOffset;
|
2016-10-20 16:04:15 +00:00
|
|
|
|
|
|
|
m_audioFifo.clear();
|
2018-01-09 00:10:49 +00:00
|
|
|
applyChannelSettings(m_basebandSampleRate, m_outputSampleRate, m_inputFrequencyOffset, true);
|
2016-10-20 16:04:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void AMMod::stop()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
bool AMMod::handleMessage(const Message& cmd)
|
|
|
|
{
|
|
|
|
if (UpChannelizer::MsgChannelizerNotification::match(cmd))
|
|
|
|
{
|
|
|
|
UpChannelizer::MsgChannelizerNotification& notif = (UpChannelizer::MsgChannelizerNotification&) cmd;
|
|
|
|
qDebug() << "AMMod::handleMessage: MsgChannelizerNotification:"
|
2017-12-29 10:42:33 +00:00
|
|
|
<< " basebandSampleRate: " << notif.getBasebandSampleRate()
|
|
|
|
<< " outputSampleRate: " << notif.getSampleRate()
|
|
|
|
<< " inputFrequencyOffset: " << notif.getFrequencyOffset();
|
|
|
|
|
|
|
|
applyChannelSettings(notif.getBasebandSampleRate(), notif.getSampleRate(), notif.getFrequencyOffset());
|
2016-10-20 16:04:15 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2017-10-10 22:47:51 +00:00
|
|
|
else if (MsgConfigureChannelizer::match(cmd))
|
|
|
|
{
|
|
|
|
MsgConfigureChannelizer& cfg = (MsgConfigureChannelizer&) cmd;
|
2017-12-29 10:42:33 +00:00
|
|
|
qDebug() << "AMMod::handleMessage: MsgConfigureChannelizer:"
|
|
|
|
<< " getSampleRate: " << cfg.getSampleRate()
|
|
|
|
<< " getCenterFrequency: " << cfg.getCenterFrequency();
|
2017-10-10 22:47:51 +00:00
|
|
|
|
|
|
|
m_channelizer->configure(m_channelizer->getInputMessageQueue(),
|
|
|
|
cfg.getSampleRate(),
|
|
|
|
cfg.getCenterFrequency());
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2017-10-10 07:10:03 +00:00
|
|
|
else if (MsgConfigureAMMod::match(cmd))
|
|
|
|
{
|
|
|
|
MsgConfigureAMMod& cfg = (MsgConfigureAMMod&) cmd;
|
2017-12-29 10:42:33 +00:00
|
|
|
qDebug() << "AMMod::handleMessage: MsgConfigureAMMod";
|
2017-10-10 07:10:03 +00:00
|
|
|
|
2017-12-29 10:42:33 +00:00
|
|
|
applySettings(cfg.getSettings(), cfg.getForce());
|
2017-10-10 07:10:03 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2016-11-28 01:17:08 +00:00
|
|
|
else if (MsgConfigureFileSourceName::match(cmd))
|
|
|
|
{
|
|
|
|
MsgConfigureFileSourceName& conf = (MsgConfigureFileSourceName&) cmd;
|
|
|
|
m_fileName = conf.getFileName();
|
|
|
|
openFileStream();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else if (MsgConfigureFileSourceSeek::match(cmd))
|
|
|
|
{
|
|
|
|
MsgConfigureFileSourceSeek& conf = (MsgConfigureFileSourceSeek&) cmd;
|
|
|
|
int seekPercentage = conf.getPercentage();
|
|
|
|
seekFileStream(seekPercentage);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else if (MsgConfigureFileSourceStreamTiming::match(cmd))
|
|
|
|
{
|
2016-11-28 17:19:23 +00:00
|
|
|
std::size_t samplesCount;
|
|
|
|
|
|
|
|
if (m_ifstream.eof()) {
|
|
|
|
samplesCount = m_fileSize / sizeof(Real);
|
|
|
|
} else {
|
|
|
|
samplesCount = m_ifstream.tellg() / sizeof(Real);
|
|
|
|
}
|
|
|
|
|
|
|
|
MsgReportFileSourceStreamTiming *report;
|
2016-11-28 01:17:08 +00:00
|
|
|
report = MsgReportFileSourceStreamTiming::create(samplesCount);
|
2017-09-28 06:33:05 +00:00
|
|
|
getMessageQueueToGUI()->push(report);
|
2016-11-28 01:17:08 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2018-12-19 23:09:53 +00:00
|
|
|
else if (CWKeyer::MsgConfigureCWKeyer::match(cmd))
|
|
|
|
{
|
|
|
|
const CWKeyer::MsgConfigureCWKeyer& cfg = (CWKeyer::MsgConfigureCWKeyer&) cmd;
|
|
|
|
|
|
|
|
if (m_settings.m_useReverseAPI) {
|
|
|
|
webapiReverseSendCWSettings(cfg.getSettings());
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2018-03-29 13:20:38 +00:00
|
|
|
else if (DSPConfigureAudio::match(cmd))
|
|
|
|
{
|
|
|
|
DSPConfigureAudio& cfg = (DSPConfigureAudio&) cmd;
|
|
|
|
uint32_t sampleRate = cfg.getSampleRate();
|
|
|
|
|
|
|
|
qDebug() << "AMMod::handleMessage: DSPConfigureAudio:"
|
|
|
|
<< " sampleRate: " << sampleRate;
|
|
|
|
|
|
|
|
if (sampleRate != m_audioSampleRate) {
|
|
|
|
applyAudioSampleRate(sampleRate);
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2018-02-14 19:11:36 +00:00
|
|
|
else if (DSPSignalNotification::match(cmd))
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
2016-10-20 16:04:15 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-28 01:17:08 +00:00
|
|
|
void AMMod::openFileStream()
|
|
|
|
{
|
|
|
|
if (m_ifstream.is_open()) {
|
|
|
|
m_ifstream.close();
|
|
|
|
}
|
|
|
|
|
|
|
|
m_ifstream.open(m_fileName.toStdString().c_str(), std::ios::binary | std::ios::ate);
|
2016-11-28 17:19:23 +00:00
|
|
|
m_fileSize = m_ifstream.tellg();
|
2016-11-28 01:17:08 +00:00
|
|
|
m_ifstream.seekg(0,std::ios_base::beg);
|
|
|
|
|
|
|
|
m_sampleRate = 48000; // fixed rate
|
2016-11-28 17:19:23 +00:00
|
|
|
m_recordLength = m_fileSize / (sizeof(Real) * m_sampleRate);
|
2016-11-28 01:17:08 +00:00
|
|
|
|
|
|
|
qDebug() << "AMMod::openFileStream: " << m_fileName.toStdString().c_str()
|
2016-11-28 17:19:23 +00:00
|
|
|
<< " fileSize: " << m_fileSize << "bytes"
|
2016-11-28 01:17:08 +00:00
|
|
|
<< " length: " << m_recordLength << " seconds";
|
|
|
|
|
|
|
|
MsgReportFileSourceStreamData *report;
|
|
|
|
report = MsgReportFileSourceStreamData::create(m_sampleRate, m_recordLength);
|
2017-09-28 06:33:05 +00:00
|
|
|
getMessageQueueToGUI()->push(report);
|
2016-11-28 01:17:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void AMMod::seekFileStream(int seekPercentage)
|
|
|
|
{
|
|
|
|
QMutexLocker mutexLocker(&m_settingsMutex);
|
|
|
|
|
|
|
|
if (m_ifstream.is_open())
|
|
|
|
{
|
|
|
|
int seekPoint = ((m_recordLength * seekPercentage) / 100) * m_sampleRate;
|
|
|
|
seekPoint *= sizeof(Real);
|
|
|
|
m_ifstream.clear();
|
|
|
|
m_ifstream.seekg(seekPoint, std::ios::beg);
|
|
|
|
}
|
|
|
|
}
|
2017-10-10 07:10:03 +00:00
|
|
|
|
2018-03-29 13:20:38 +00:00
|
|
|
void AMMod::applyAudioSampleRate(int sampleRate)
|
|
|
|
{
|
|
|
|
qDebug("AMMod::applyAudioSampleRate: %d", sampleRate);
|
|
|
|
|
|
|
|
MsgConfigureChannelizer* channelConfigMsg = MsgConfigureChannelizer::create(
|
|
|
|
sampleRate, m_settings.m_inputFrequencyOffset);
|
|
|
|
m_inputMessageQueue.push(channelConfigMsg);
|
|
|
|
|
|
|
|
m_settingsMutex.lock();
|
|
|
|
|
|
|
|
m_interpolatorDistanceRemain = 0;
|
|
|
|
m_interpolatorConsumed = false;
|
|
|
|
m_interpolatorDistance = (Real) sampleRate / (Real) m_outputSampleRate;
|
|
|
|
m_interpolator.create(48, sampleRate, m_settings.m_rfBandwidth / 2.2, 3.0);
|
|
|
|
m_toneNco.setFreq(m_settings.m_toneFrequency, sampleRate);
|
|
|
|
m_cwKeyer.setSampleRate(sampleRate);
|
|
|
|
|
|
|
|
m_settingsMutex.unlock();
|
|
|
|
|
|
|
|
m_audioSampleRate = sampleRate;
|
|
|
|
}
|
|
|
|
|
2018-01-09 00:10:49 +00:00
|
|
|
void AMMod::applyChannelSettings(int basebandSampleRate, int outputSampleRate, int inputFrequencyOffset, bool force)
|
2017-10-10 07:10:03 +00:00
|
|
|
{
|
2017-12-29 10:42:33 +00:00
|
|
|
qDebug() << "AMMod::applyChannelSettings:"
|
|
|
|
<< " basebandSampleRate: " << basebandSampleRate
|
|
|
|
<< " outputSampleRate: " << outputSampleRate
|
|
|
|
<< " inputFrequencyOffset: " << inputFrequencyOffset;
|
|
|
|
|
|
|
|
if ((inputFrequencyOffset != m_inputFrequencyOffset) ||
|
2018-01-09 00:10:49 +00:00
|
|
|
(outputSampleRate != m_outputSampleRate) || force)
|
2017-12-29 10:42:33 +00:00
|
|
|
{
|
|
|
|
m_settingsMutex.lock();
|
|
|
|
m_carrierNco.setFreq(inputFrequencyOffset, outputSampleRate);
|
|
|
|
m_settingsMutex.unlock();
|
|
|
|
}
|
|
|
|
|
2018-01-09 00:10:49 +00:00
|
|
|
if ((outputSampleRate != m_outputSampleRate) || force)
|
2017-10-10 07:10:03 +00:00
|
|
|
{
|
|
|
|
m_settingsMutex.lock();
|
2017-12-29 10:42:33 +00:00
|
|
|
m_interpolatorDistanceRemain = 0;
|
|
|
|
m_interpolatorConsumed = false;
|
2018-03-29 13:20:38 +00:00
|
|
|
m_interpolatorDistance = (Real) m_audioSampleRate / (Real) outputSampleRate;
|
|
|
|
m_interpolator.create(48, m_audioSampleRate, m_settings.m_rfBandwidth / 2.2, 3.0);
|
2017-10-10 07:10:03 +00:00
|
|
|
m_settingsMutex.unlock();
|
|
|
|
}
|
|
|
|
|
2017-12-29 10:42:33 +00:00
|
|
|
m_basebandSampleRate = basebandSampleRate;
|
|
|
|
m_outputSampleRate = outputSampleRate;
|
|
|
|
m_inputFrequencyOffset = inputFrequencyOffset;
|
|
|
|
}
|
|
|
|
|
|
|
|
void AMMod::applySettings(const AMModSettings& settings, bool force)
|
|
|
|
{
|
|
|
|
qDebug() << "AMMod::applySettings:"
|
|
|
|
<< " m_inputFrequencyOffset: " << settings.m_inputFrequencyOffset
|
|
|
|
<< " m_rfBandwidth: " << settings.m_rfBandwidth
|
|
|
|
<< " m_modFactor: " << settings.m_modFactor
|
|
|
|
<< " m_toneFrequency: " << settings.m_toneFrequency
|
|
|
|
<< " m_volumeFactor: " << settings.m_volumeFactor
|
2018-12-19 23:09:53 +00:00
|
|
|
<< " m_channelMute: " << settings.m_channelMute
|
2018-03-29 13:20:38 +00:00
|
|
|
<< " m_playLoop: " << settings.m_playLoop
|
2018-04-05 19:58:45 +00:00
|
|
|
<< " m_modAFInput " << settings.m_modAFInput
|
2018-03-29 13:20:38 +00:00
|
|
|
<< " m_audioDeviceName: " << settings.m_audioDeviceName
|
2018-12-19 23:09:53 +00:00
|
|
|
<< " m_useReverseAPI: " << settings.m_useReverseAPI
|
|
|
|
<< " m_reverseAPIAddress: " << settings.m_reverseAPIAddress
|
|
|
|
<< " m_reverseAPIAddress: " << settings.m_reverseAPIPort
|
|
|
|
<< " m_reverseAPIDeviceIndex: " << settings.m_reverseAPIDeviceIndex
|
|
|
|
<< " m_reverseAPIChannelIndex: " << settings.m_reverseAPIChannelIndex
|
2018-03-29 13:20:38 +00:00
|
|
|
<< " force: " << force;
|
2017-12-29 10:42:33 +00:00
|
|
|
|
2018-12-19 23:09:53 +00:00
|
|
|
QList<QString> reverseAPIKeys;
|
|
|
|
|
|
|
|
if ((settings.m_inputFrequencyOffset != m_settings.m_inputFrequencyOffset) || force) {
|
|
|
|
reverseAPIKeys.append("inputFrequencyOffset");
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((settings.m_modFactor != m_settings.m_modFactor) || force) {
|
|
|
|
reverseAPIKeys.append("modFactor");
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((settings.m_volumeFactor != m_settings.m_volumeFactor) || force) {
|
|
|
|
reverseAPIKeys.append("volumeFactor");
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((settings.m_channelMute != m_settings.m_channelMute) || force) {
|
|
|
|
reverseAPIKeys.append("channelMute");
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((settings.m_playLoop != m_settings.m_playLoop) || force) {
|
|
|
|
reverseAPIKeys.append("playLoop");
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((settings.m_modAFInput != m_settings.m_modAFInput) || force) {
|
|
|
|
reverseAPIKeys.append("modAFInput");
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((settings.m_rfBandwidth != m_settings.m_rfBandwidth) || force)
|
2017-10-10 07:10:03 +00:00
|
|
|
{
|
2018-12-19 23:09:53 +00:00
|
|
|
reverseAPIKeys.append("rfBandwidth");
|
2017-10-10 07:10:03 +00:00
|
|
|
m_settingsMutex.lock();
|
|
|
|
m_interpolatorDistanceRemain = 0;
|
|
|
|
m_interpolatorConsumed = false;
|
2018-03-29 13:20:38 +00:00
|
|
|
m_interpolatorDistance = (Real) m_audioSampleRate / (Real) m_outputSampleRate;
|
|
|
|
m_interpolator.create(48, m_audioSampleRate, settings.m_rfBandwidth / 2.2, 3.0);
|
2017-10-10 07:10:03 +00:00
|
|
|
m_settingsMutex.unlock();
|
|
|
|
}
|
|
|
|
|
2018-03-29 13:20:38 +00:00
|
|
|
if ((settings.m_toneFrequency != m_settings.m_toneFrequency) || force)
|
2017-10-10 07:10:03 +00:00
|
|
|
{
|
2018-12-19 23:09:53 +00:00
|
|
|
reverseAPIKeys.append("toneFrequency");
|
2017-10-10 07:10:03 +00:00
|
|
|
m_settingsMutex.lock();
|
2018-03-29 13:20:38 +00:00
|
|
|
m_toneNco.setFreq(settings.m_toneFrequency, m_audioSampleRate);
|
2017-10-10 07:10:03 +00:00
|
|
|
m_settingsMutex.unlock();
|
|
|
|
}
|
|
|
|
|
2018-03-29 13:20:38 +00:00
|
|
|
if ((settings.m_audioDeviceName != m_settings.m_audioDeviceName) || force)
|
2017-10-10 07:10:03 +00:00
|
|
|
{
|
2018-12-19 23:09:53 +00:00
|
|
|
reverseAPIKeys.append("audioDeviceName");
|
2018-03-29 13:20:38 +00:00
|
|
|
AudioDeviceManager *audioDeviceManager = DSPEngine::instance()->getAudioDeviceManager();
|
|
|
|
int audioDeviceIndex = audioDeviceManager->getInputDeviceIndex(settings.m_audioDeviceName);
|
|
|
|
audioDeviceManager->addAudioSource(&m_audioFifo, getInputMessageQueue(), audioDeviceIndex);
|
|
|
|
uint32_t audioSampleRate = audioDeviceManager->getInputSampleRate(audioDeviceIndex);
|
|
|
|
|
|
|
|
if (m_audioSampleRate != audioSampleRate) {
|
2018-12-19 23:09:53 +00:00
|
|
|
reverseAPIKeys.append("audioSampleRate");
|
2018-03-29 13:20:38 +00:00
|
|
|
applyAudioSampleRate(audioSampleRate);
|
|
|
|
}
|
2017-10-10 07:10:03 +00:00
|
|
|
}
|
2017-10-10 22:47:51 +00:00
|
|
|
|
2018-12-19 23:09:53 +00:00
|
|
|
if (settings.m_useReverseAPI)
|
|
|
|
{
|
|
|
|
bool fullUpdate = ((m_settings.m_useReverseAPI != settings.m_useReverseAPI) && settings.m_useReverseAPI) ||
|
|
|
|
(m_settings.m_reverseAPIAddress != settings.m_reverseAPIAddress) ||
|
|
|
|
(m_settings.m_reverseAPIPort != settings.m_reverseAPIPort) ||
|
|
|
|
(m_settings.m_reverseAPIDeviceIndex != settings.m_reverseAPIDeviceIndex) ||
|
|
|
|
(m_settings.m_reverseAPIChannelIndex != settings.m_reverseAPIChannelIndex);
|
|
|
|
webapiReverseSendSettings(reverseAPIKeys, settings, fullUpdate || force);
|
|
|
|
}
|
|
|
|
|
2017-10-10 22:47:51 +00:00
|
|
|
m_settings = settings;
|
2017-10-10 07:10:03 +00:00
|
|
|
}
|
2017-12-17 22:15:42 +00:00
|
|
|
|
|
|
|
QByteArray AMMod::serialize() const
|
|
|
|
{
|
|
|
|
return m_settings.serialize();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool AMMod::deserialize(const QByteArray& data)
|
|
|
|
{
|
|
|
|
if (m_settings.deserialize(data))
|
|
|
|
{
|
|
|
|
MsgConfigureAMMod *msg = MsgConfigureAMMod::create(m_settings, true);
|
|
|
|
m_inputMessageQueue.push(msg);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_settings.resetToDefaults();
|
|
|
|
MsgConfigureAMMod *msg = MsgConfigureAMMod::create(m_settings, true);
|
|
|
|
m_inputMessageQueue.push(msg);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2018-04-05 22:54:18 +00:00
|
|
|
|
|
|
|
int AMMod::webapiSettingsGet(
|
|
|
|
SWGSDRangel::SWGChannelSettings& response,
|
2018-11-12 23:45:03 +00:00
|
|
|
QString& errorMessage)
|
2018-04-05 22:54:18 +00:00
|
|
|
{
|
2018-11-12 23:45:03 +00:00
|
|
|
(void) errorMessage;
|
2018-04-05 22:54:18 +00:00
|
|
|
response.setAmModSettings(new SWGSDRangel::SWGAMModSettings());
|
|
|
|
response.getAmModSettings()->init();
|
|
|
|
webapiFormatChannelSettings(response, m_settings);
|
|
|
|
return 200;
|
|
|
|
}
|
|
|
|
|
|
|
|
int AMMod::webapiSettingsPutPatch(
|
|
|
|
bool force,
|
|
|
|
const QStringList& channelSettingsKeys,
|
|
|
|
SWGSDRangel::SWGChannelSettings& response,
|
2018-11-12 23:45:03 +00:00
|
|
|
QString& errorMessage)
|
2018-04-05 22:54:18 +00:00
|
|
|
{
|
2018-11-12 23:45:03 +00:00
|
|
|
(void) errorMessage;
|
2018-08-08 07:17:25 +00:00
|
|
|
AMModSettings settings = m_settings;
|
2018-04-05 22:54:18 +00:00
|
|
|
bool frequencyOffsetChanged = false;
|
|
|
|
|
|
|
|
if (channelSettingsKeys.contains("channelMute")) {
|
|
|
|
settings.m_channelMute = response.getAmModSettings()->getChannelMute() != 0;
|
|
|
|
}
|
|
|
|
if (channelSettingsKeys.contains("inputFrequencyOffset"))
|
|
|
|
{
|
|
|
|
settings.m_inputFrequencyOffset = response.getAmModSettings()->getInputFrequencyOffset();
|
|
|
|
frequencyOffsetChanged = true;
|
|
|
|
}
|
|
|
|
if (channelSettingsKeys.contains("modAFInput")) {
|
|
|
|
settings.m_modAFInput = (AMModSettings::AMModInputAF) response.getAmModSettings()->getModAfInput();
|
|
|
|
}
|
2018-04-14 19:46:53 +00:00
|
|
|
if (channelSettingsKeys.contains("audioDeviceName")) {
|
|
|
|
settings.m_audioDeviceName = *response.getAmModSettings()->getAudioDeviceName();
|
|
|
|
}
|
2018-04-05 22:54:18 +00:00
|
|
|
if (channelSettingsKeys.contains("playLoop")) {
|
|
|
|
settings.m_playLoop = response.getAmModSettings()->getPlayLoop() != 0;
|
|
|
|
}
|
|
|
|
if (channelSettingsKeys.contains("rfBandwidth")) {
|
|
|
|
settings.m_rfBandwidth = response.getAmModSettings()->getRfBandwidth();
|
|
|
|
}
|
|
|
|
if (channelSettingsKeys.contains("rgbColor")) {
|
|
|
|
settings.m_rgbColor = response.getAmModSettings()->getRgbColor();
|
|
|
|
}
|
|
|
|
if (channelSettingsKeys.contains("title")) {
|
|
|
|
settings.m_title = *response.getAmModSettings()->getTitle();
|
|
|
|
}
|
|
|
|
if (channelSettingsKeys.contains("toneFrequency")) {
|
|
|
|
settings.m_toneFrequency = response.getAmModSettings()->getToneFrequency();
|
|
|
|
}
|
|
|
|
if (channelSettingsKeys.contains("volumeFactor")) {
|
|
|
|
settings.m_volumeFactor = response.getAmModSettings()->getVolumeFactor();
|
|
|
|
}
|
|
|
|
if (channelSettingsKeys.contains("modFactor")) {
|
|
|
|
settings.m_modFactor = response.getAmModSettings()->getModFactor();
|
|
|
|
}
|
2018-12-20 07:29:48 +00:00
|
|
|
if (channelSettingsKeys.contains("useReverseAPI")) {
|
|
|
|
settings.m_useReverseAPI = response.getAmModSettings()->getUseReverseApi() != 0;
|
|
|
|
}
|
|
|
|
if (channelSettingsKeys.contains("reverseAPIAddress")) {
|
2019-04-20 17:53:16 +00:00
|
|
|
settings.m_reverseAPIAddress = *response.getAmModSettings()->getReverseApiAddress();
|
2018-12-20 07:29:48 +00:00
|
|
|
}
|
|
|
|
if (channelSettingsKeys.contains("reverseAPIPort")) {
|
|
|
|
settings.m_reverseAPIPort = response.getAmModSettings()->getReverseApiPort();
|
|
|
|
}
|
|
|
|
if (channelSettingsKeys.contains("reverseAPIDeviceIndex")) {
|
|
|
|
settings.m_reverseAPIDeviceIndex = response.getAmModSettings()->getReverseApiDeviceIndex();
|
|
|
|
}
|
|
|
|
if (channelSettingsKeys.contains("reverseAPIChannelIndex")) {
|
|
|
|
settings.m_reverseAPIChannelIndex = response.getAmModSettings()->getReverseApiChannelIndex();
|
|
|
|
}
|
2018-04-05 22:54:18 +00:00
|
|
|
|
|
|
|
if (channelSettingsKeys.contains("cwKeyer"))
|
|
|
|
{
|
|
|
|
SWGSDRangel::SWGCWKeyerSettings *apiCwKeyerSettings = response.getAmModSettings()->getCwKeyer();
|
|
|
|
CWKeyerSettings cwKeyerSettings = m_cwKeyer.getSettings();
|
2019-07-30 11:12:15 +00:00
|
|
|
m_cwKeyer.webapiSettingsPutPatch(channelSettingsKeys, cwKeyerSettings, apiCwKeyerSettings);
|
2018-04-05 22:54:18 +00:00
|
|
|
|
2019-07-29 23:31:46 +00:00
|
|
|
CWKeyer::MsgConfigureCWKeyer *msgCwKeyer = CWKeyer::MsgConfigureCWKeyer::create(cwKeyerSettings, force);
|
|
|
|
m_cwKeyer.getInputMessageQueue()->push(msgCwKeyer);
|
2018-04-05 22:54:18 +00:00
|
|
|
|
|
|
|
if (m_guiMessageQueue) // forward to GUI if any
|
|
|
|
{
|
2019-07-29 23:31:46 +00:00
|
|
|
CWKeyer::MsgConfigureCWKeyer *msgCwKeyerToGUI = CWKeyer::MsgConfigureCWKeyer::create(cwKeyerSettings, force);
|
|
|
|
m_guiMessageQueue->push(msgCwKeyerToGUI);
|
2018-04-05 22:54:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (frequencyOffsetChanged)
|
|
|
|
{
|
|
|
|
AMMod::MsgConfigureChannelizer *msgChan = AMMod::MsgConfigureChannelizer::create(
|
|
|
|
m_audioSampleRate, settings.m_inputFrequencyOffset);
|
|
|
|
m_inputMessageQueue.push(msgChan);
|
|
|
|
}
|
|
|
|
|
|
|
|
MsgConfigureAMMod *msg = MsgConfigureAMMod::create(settings, force);
|
|
|
|
m_inputMessageQueue.push(msg);
|
|
|
|
|
|
|
|
if (m_guiMessageQueue) // forward to GUI if any
|
|
|
|
{
|
|
|
|
MsgConfigureAMMod *msgToGUI = MsgConfigureAMMod::create(settings, force);
|
|
|
|
m_guiMessageQueue->push(msgToGUI);
|
|
|
|
}
|
|
|
|
|
|
|
|
webapiFormatChannelSettings(response, settings);
|
|
|
|
|
|
|
|
return 200;
|
|
|
|
}
|
|
|
|
|
|
|
|
int AMMod::webapiReportGet(
|
|
|
|
SWGSDRangel::SWGChannelReport& response,
|
2018-11-12 23:45:03 +00:00
|
|
|
QString& errorMessage)
|
2018-04-05 22:54:18 +00:00
|
|
|
{
|
2018-11-12 23:45:03 +00:00
|
|
|
(void) errorMessage;
|
2018-04-05 22:54:18 +00:00
|
|
|
response.setAmModReport(new SWGSDRangel::SWGAMModReport());
|
|
|
|
response.getAmModReport()->init();
|
|
|
|
webapiFormatChannelReport(response);
|
|
|
|
return 200;
|
|
|
|
}
|
|
|
|
|
|
|
|
void AMMod::webapiFormatChannelSettings(SWGSDRangel::SWGChannelSettings& response, const AMModSettings& settings)
|
|
|
|
{
|
|
|
|
response.getAmModSettings()->setChannelMute(settings.m_channelMute ? 1 : 0);
|
|
|
|
response.getAmModSettings()->setInputFrequencyOffset(settings.m_inputFrequencyOffset);
|
|
|
|
response.getAmModSettings()->setModAfInput((int) settings.m_modAFInput);
|
|
|
|
response.getAmModSettings()->setPlayLoop(settings.m_playLoop ? 1 : 0);
|
|
|
|
response.getAmModSettings()->setRfBandwidth(settings.m_rfBandwidth);
|
|
|
|
response.getAmModSettings()->setModFactor(settings.m_modFactor);
|
|
|
|
response.getAmModSettings()->setRgbColor(settings.m_rgbColor);
|
|
|
|
|
|
|
|
if (response.getAmModSettings()->getTitle()) {
|
|
|
|
*response.getAmModSettings()->getTitle() = settings.m_title;
|
|
|
|
} else {
|
|
|
|
response.getAmModSettings()->setTitle(new QString(settings.m_title));
|
|
|
|
}
|
|
|
|
|
|
|
|
response.getAmModSettings()->setToneFrequency(settings.m_toneFrequency);
|
|
|
|
response.getAmModSettings()->setVolumeFactor(settings.m_volumeFactor);
|
|
|
|
|
|
|
|
if (!response.getAmModSettings()->getCwKeyer()) {
|
|
|
|
response.getAmModSettings()->setCwKeyer(new SWGSDRangel::SWGCWKeyerSettings);
|
|
|
|
}
|
|
|
|
|
|
|
|
SWGSDRangel::SWGCWKeyerSettings *apiCwKeyerSettings = response.getAmModSettings()->getCwKeyer();
|
|
|
|
const CWKeyerSettings& cwKeyerSettings = m_cwKeyer.getSettings();
|
2019-07-30 11:12:15 +00:00
|
|
|
m_cwKeyer.webapiFormatChannelSettings(apiCwKeyerSettings, cwKeyerSettings);
|
2018-04-05 22:54:18 +00:00
|
|
|
|
|
|
|
if (response.getAmModSettings()->getAudioDeviceName()) {
|
|
|
|
*response.getAmModSettings()->getAudioDeviceName() = settings.m_audioDeviceName;
|
|
|
|
} else {
|
|
|
|
response.getAmModSettings()->setAudioDeviceName(new QString(settings.m_audioDeviceName));
|
|
|
|
}
|
2018-12-20 07:29:48 +00:00
|
|
|
|
|
|
|
response.getAmModSettings()->setUseReverseApi(settings.m_useReverseAPI ? 1 : 0);
|
|
|
|
|
|
|
|
if (response.getAmModSettings()->getReverseApiAddress()) {
|
|
|
|
*response.getAmModSettings()->getReverseApiAddress() = settings.m_reverseAPIAddress;
|
|
|
|
} else {
|
|
|
|
response.getAmModSettings()->setReverseApiAddress(new QString(settings.m_reverseAPIAddress));
|
|
|
|
}
|
|
|
|
|
|
|
|
response.getAmModSettings()->setReverseApiPort(settings.m_reverseAPIPort);
|
|
|
|
response.getAmModSettings()->setReverseApiDeviceIndex(settings.m_reverseAPIDeviceIndex);
|
|
|
|
response.getAmModSettings()->setReverseApiChannelIndex(settings.m_reverseAPIChannelIndex);
|
2018-04-05 22:54:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void AMMod::webapiFormatChannelReport(SWGSDRangel::SWGChannelReport& response)
|
|
|
|
{
|
|
|
|
response.getAmModReport()->setChannelPowerDb(CalcDb::dbPower(getMagSq()));
|
|
|
|
response.getAmModReport()->setAudioSampleRate(m_audioSampleRate);
|
|
|
|
response.getAmModReport()->setChannelSampleRate(m_outputSampleRate);
|
|
|
|
}
|
2018-12-19 23:09:53 +00:00
|
|
|
|
|
|
|
void AMMod::webapiReverseSendSettings(QList<QString>& channelSettingsKeys, const AMModSettings& settings, bool force)
|
|
|
|
{
|
|
|
|
SWGSDRangel::SWGChannelSettings *swgChannelSettings = new SWGSDRangel::SWGChannelSettings();
|
2019-05-07 12:43:38 +00:00
|
|
|
swgChannelSettings->setDirection(1); // single source (Tx)
|
2019-03-25 00:15:27 +00:00
|
|
|
swgChannelSettings->setOriginatorChannelIndex(getIndexInDeviceSet());
|
|
|
|
swgChannelSettings->setOriginatorDeviceSetIndex(getDeviceSetIndex());
|
2018-12-19 23:09:53 +00:00
|
|
|
swgChannelSettings->setChannelType(new QString("AMMod"));
|
|
|
|
swgChannelSettings->setAmModSettings(new SWGSDRangel::SWGAMModSettings());
|
|
|
|
SWGSDRangel::SWGAMModSettings *swgAMModSettings = swgChannelSettings->getAmModSettings();
|
|
|
|
|
|
|
|
// transfer data that has been modified. When force is on transfer all data except reverse API data
|
|
|
|
|
|
|
|
if (channelSettingsKeys.contains("channelMute") || force) {
|
|
|
|
swgAMModSettings->setChannelMute(settings.m_channelMute ? 1 : 0);
|
|
|
|
}
|
|
|
|
if (channelSettingsKeys.contains("inputFrequencyOffset") || force) {
|
|
|
|
swgAMModSettings->setInputFrequencyOffset(settings.m_inputFrequencyOffset);
|
|
|
|
}
|
|
|
|
if (channelSettingsKeys.contains("modAFInput") || force) {
|
|
|
|
swgAMModSettings->setModAfInput((int) settings.m_modAFInput);
|
|
|
|
}
|
|
|
|
if (channelSettingsKeys.contains("audioDeviceName") || force) {
|
|
|
|
swgAMModSettings->setAudioDeviceName(new QString(settings.m_audioDeviceName));
|
|
|
|
}
|
|
|
|
if (channelSettingsKeys.contains("playLoop") || force) {
|
|
|
|
swgAMModSettings->setPlayLoop(settings.m_playLoop ? 1 : 0);
|
|
|
|
}
|
|
|
|
if (channelSettingsKeys.contains("rfBandwidth") || force) {
|
|
|
|
swgAMModSettings->setRfBandwidth(settings.m_rfBandwidth);
|
|
|
|
}
|
|
|
|
if (channelSettingsKeys.contains("rgbColor") || force) {
|
|
|
|
swgAMModSettings->setRgbColor(settings.m_rgbColor);
|
|
|
|
}
|
|
|
|
if (channelSettingsKeys.contains("title") || force) {
|
|
|
|
swgAMModSettings->setTitle(new QString(settings.m_title));
|
|
|
|
}
|
|
|
|
if (channelSettingsKeys.contains("toneFrequency") || force) {
|
|
|
|
swgAMModSettings->setToneFrequency(settings.m_toneFrequency);
|
|
|
|
}
|
|
|
|
if (channelSettingsKeys.contains("volumeFactor") || force) {
|
|
|
|
swgAMModSettings->setVolumeFactor(settings.m_volumeFactor);
|
|
|
|
}
|
|
|
|
if (channelSettingsKeys.contains("modFactor") || force) {
|
|
|
|
swgAMModSettings->setModFactor(settings.m_modFactor);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (force)
|
|
|
|
{
|
|
|
|
const CWKeyerSettings& cwKeyerSettings = m_cwKeyer.getSettings();
|
|
|
|
swgAMModSettings->setCwKeyer(new SWGSDRangel::SWGCWKeyerSettings());
|
|
|
|
SWGSDRangel::SWGCWKeyerSettings *apiCwKeyerSettings = swgAMModSettings->getCwKeyer();
|
2019-07-30 11:12:15 +00:00
|
|
|
m_cwKeyer.webapiFormatChannelSettings(apiCwKeyerSettings, cwKeyerSettings);
|
2018-12-19 23:09:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QString channelSettingsURL = QString("http://%1:%2/sdrangel/deviceset/%3/channel/%4/settings")
|
|
|
|
.arg(settings.m_reverseAPIAddress)
|
|
|
|
.arg(settings.m_reverseAPIPort)
|
|
|
|
.arg(settings.m_reverseAPIDeviceIndex)
|
|
|
|
.arg(settings.m_reverseAPIChannelIndex);
|
|
|
|
m_networkRequest.setUrl(QUrl(channelSettingsURL));
|
|
|
|
m_networkRequest.setHeader(QNetworkRequest::ContentTypeHeader, "application/json");
|
|
|
|
|
|
|
|
QBuffer *buffer=new QBuffer();
|
|
|
|
buffer->open((QBuffer::ReadWrite));
|
|
|
|
buffer->write(swgChannelSettings->asJson().toUtf8());
|
|
|
|
buffer->seek(0);
|
|
|
|
|
|
|
|
// Always use PATCH to avoid passing reverse API settings
|
|
|
|
m_networkManager->sendCustomRequest(m_networkRequest, "PATCH", buffer);
|
|
|
|
|
|
|
|
delete swgChannelSettings;
|
|
|
|
}
|
|
|
|
|
|
|
|
void AMMod::webapiReverseSendCWSettings(const CWKeyerSettings& cwKeyerSettings)
|
|
|
|
{
|
|
|
|
SWGSDRangel::SWGChannelSettings *swgChannelSettings = new SWGSDRangel::SWGChannelSettings();
|
2019-05-07 12:43:38 +00:00
|
|
|
swgChannelSettings->setDirection(1); // single source (Tx)
|
2018-12-19 23:09:53 +00:00
|
|
|
swgChannelSettings->setChannelType(new QString("AMMod"));
|
|
|
|
swgChannelSettings->setAmModSettings(new SWGSDRangel::SWGAMModSettings());
|
|
|
|
SWGSDRangel::SWGAMModSettings *swgAMModSettings = swgChannelSettings->getAmModSettings();
|
|
|
|
|
|
|
|
swgAMModSettings->setCwKeyer(new SWGSDRangel::SWGCWKeyerSettings());
|
|
|
|
SWGSDRangel::SWGCWKeyerSettings *apiCwKeyerSettings = swgAMModSettings->getCwKeyer();
|
2019-07-30 11:12:15 +00:00
|
|
|
m_cwKeyer.webapiFormatChannelSettings(apiCwKeyerSettings, cwKeyerSettings);
|
2018-12-19 23:09:53 +00:00
|
|
|
|
|
|
|
QString channelSettingsURL = QString("http://%1:%2/sdrangel/deviceset/%3/channel/%4/settings")
|
|
|
|
.arg(m_settings.m_reverseAPIAddress)
|
|
|
|
.arg(m_settings.m_reverseAPIPort)
|
|
|
|
.arg(m_settings.m_reverseAPIDeviceIndex)
|
|
|
|
.arg(m_settings.m_reverseAPIChannelIndex);
|
|
|
|
m_networkRequest.setUrl(QUrl(channelSettingsURL));
|
|
|
|
m_networkRequest.setHeader(QNetworkRequest::ContentTypeHeader, "application/json");
|
|
|
|
|
|
|
|
QBuffer *buffer=new QBuffer();
|
|
|
|
buffer->open((QBuffer::ReadWrite));
|
|
|
|
buffer->write(swgChannelSettings->asJson().toUtf8());
|
|
|
|
buffer->seek(0);
|
|
|
|
|
|
|
|
// Always use PATCH to avoid passing reverse API settings
|
|
|
|
m_networkManager->sendCustomRequest(m_networkRequest, "PATCH", buffer);
|
|
|
|
|
|
|
|
delete swgChannelSettings;
|
|
|
|
}
|
|
|
|
|
|
|
|
void AMMod::networkManagerFinished(QNetworkReply *reply)
|
|
|
|
{
|
|
|
|
QNetworkReply::NetworkError replyError = reply->error();
|
|
|
|
|
|
|
|
if (replyError)
|
|
|
|
{
|
|
|
|
qWarning() << "AMMod::networkManagerFinished:"
|
|
|
|
<< " error(" << (int) replyError
|
|
|
|
<< "): " << replyError
|
|
|
|
<< ": " << reply->errorString();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString answer = reply->readAll();
|
|
|
|
answer.chop(1); // remove last \n
|
|
|
|
qDebug("AMMod::networkManagerFinished: reply:\n%s", answer.toStdString().c_str());
|
|
|
|
}
|