2017-01-02 04:39:21 -05:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Copyright (C) 2015 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. //
|
2017-01-02 04:39:21 -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 <string.h>
|
|
|
|
#include <errno.h>
|
2018-12-26 13:22:52 -05:00
|
|
|
|
2017-01-02 04:39:21 -05:00
|
|
|
#include <QDebug>
|
2018-12-26 13:22:52 -05:00
|
|
|
#include <QNetworkReply>
|
|
|
|
#include <QBuffer>
|
2017-01-02 04:39:21 -05:00
|
|
|
|
2017-12-09 19:57:50 -05:00
|
|
|
#include "SWGDeviceSettings.h"
|
|
|
|
#include "SWGDeviceState.h"
|
|
|
|
|
2017-01-02 04:39:21 -05:00
|
|
|
#include "dsp/dspcommands.h"
|
2017-12-10 14:27:08 -05:00
|
|
|
#include "dsp/dspengine.h"
|
2017-01-02 04:39:21 -05:00
|
|
|
#include "device/devicesinkapi.h"
|
|
|
|
#include "device/devicesourceapi.h"
|
2018-09-28 23:49:14 -04:00
|
|
|
#include "bladerf1/devicebladerf1shared.h"
|
2018-09-19 02:42:59 -04:00
|
|
|
#include "bladerf1outputthread.h"
|
2018-12-26 13:22:52 -05:00
|
|
|
#include "bladerf1output.h"
|
2017-01-02 04:39:21 -05:00
|
|
|
|
2018-09-19 02:42:59 -04:00
|
|
|
MESSAGE_CLASS_DEFINITION(Bladerf1Output::MsgConfigureBladerf1, Message)
|
|
|
|
MESSAGE_CLASS_DEFINITION(Bladerf1Output::MsgStartStop, Message)
|
|
|
|
MESSAGE_CLASS_DEFINITION(Bladerf1Output::MsgReportBladerf1, Message)
|
2017-01-02 04:39:21 -05:00
|
|
|
|
2018-09-19 02:42:59 -04:00
|
|
|
Bladerf1Output::Bladerf1Output(DeviceSinkAPI *deviceAPI) :
|
2017-01-02 04:39:21 -05:00
|
|
|
m_deviceAPI(deviceAPI),
|
|
|
|
m_settings(),
|
|
|
|
m_dev(0),
|
|
|
|
m_bladerfThread(0),
|
2017-04-13 15:26:36 -04:00
|
|
|
m_deviceDescription("BladeRFOutput"),
|
|
|
|
m_running(false)
|
2017-01-02 04:39:21 -05:00
|
|
|
{
|
2017-10-15 11:37:53 -04:00
|
|
|
m_sampleSourceFifo.resize(16*BLADERFOUTPUT_BLOCKSIZE);
|
2017-04-13 15:26:36 -04:00
|
|
|
openDevice();
|
2017-01-02 04:39:21 -05:00
|
|
|
m_deviceAPI->setBuddySharedPtr(&m_sharedParams);
|
2018-12-26 13:22:52 -05:00
|
|
|
m_networkManager = new QNetworkAccessManager();
|
|
|
|
connect(m_networkManager, SIGNAL(finished(QNetworkReply*)), this, SLOT(networkManagerFinished(QNetworkReply*)));
|
2017-01-02 04:39:21 -05:00
|
|
|
}
|
|
|
|
|
2018-09-19 02:42:59 -04:00
|
|
|
Bladerf1Output::~Bladerf1Output()
|
2017-01-02 04:39:21 -05:00
|
|
|
{
|
2018-12-26 13:22:52 -05:00
|
|
|
disconnect(m_networkManager, SIGNAL(finished(QNetworkReply*)), this, SLOT(networkManagerFinished(QNetworkReply*)));
|
|
|
|
delete m_networkManager;
|
|
|
|
|
|
|
|
if (m_running) {
|
|
|
|
stop();
|
|
|
|
}
|
|
|
|
|
2017-04-13 15:26:36 -04:00
|
|
|
closeDevice();
|
2017-01-03 03:09:51 -05:00
|
|
|
m_deviceAPI->setBuddySharedPtr(0);
|
2017-01-02 04:39:21 -05:00
|
|
|
}
|
|
|
|
|
2018-09-19 02:42:59 -04:00
|
|
|
void Bladerf1Output::destroy()
|
2017-09-16 05:34:25 -04:00
|
|
|
{
|
|
|
|
delete this;
|
|
|
|
}
|
|
|
|
|
2018-09-19 02:42:59 -04:00
|
|
|
bool Bladerf1Output::openDevice()
|
2017-01-02 04:39:21 -05:00
|
|
|
{
|
2017-04-13 15:26:36 -04:00
|
|
|
if (m_dev != 0)
|
|
|
|
{
|
|
|
|
closeDevice();
|
|
|
|
}
|
2017-01-02 04:39:21 -05:00
|
|
|
|
2017-04-13 15:26:36 -04:00
|
|
|
int res;
|
2017-01-02 04:39:21 -05:00
|
|
|
|
2017-01-09 16:33:58 -05:00
|
|
|
m_sampleSourceFifo.resize(m_settings.m_devSampleRate/(1<<(m_settings.m_log2Interp <= 4 ? m_settings.m_log2Interp : 4)));
|
2017-01-02 04:39:21 -05:00
|
|
|
|
|
|
|
if (m_deviceAPI->getSourceBuddies().size() > 0)
|
|
|
|
{
|
2017-04-13 17:40:14 -04:00
|
|
|
DeviceSourceAPI *sourceBuddy = m_deviceAPI->getSourceBuddies()[0];
|
2018-09-18 23:26:18 -04:00
|
|
|
DeviceBladeRF1Params *buddySharedParams = (DeviceBladeRF1Params *) sourceBuddy->getBuddySharedPtr();
|
2017-01-02 04:39:21 -05:00
|
|
|
|
|
|
|
if (buddySharedParams == 0)
|
|
|
|
{
|
|
|
|
qCritical("BladerfOutput::start: could not get shared parameters from buddy");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-04-13 17:40:14 -04:00
|
|
|
if (buddySharedParams->m_dev == 0) // device is not opened by buddy
|
2017-01-02 04:39:21 -05:00
|
|
|
{
|
2017-04-13 17:40:14 -04:00
|
|
|
qCritical("BladerfOutput::start: could not get BladeRF handle from buddy");
|
|
|
|
return false;
|
2017-01-02 04:39:21 -05:00
|
|
|
}
|
|
|
|
|
2017-04-13 17:40:14 -04:00
|
|
|
m_sharedParams = *(buddySharedParams); // copy parameters from buddy
|
|
|
|
m_dev = m_sharedParams.m_dev; // get BladeRF handle
|
2017-01-02 04:39:21 -05:00
|
|
|
}
|
2017-04-13 17:40:14 -04:00
|
|
|
else
|
2017-01-02 04:39:21 -05:00
|
|
|
{
|
2018-09-18 23:26:18 -04:00
|
|
|
if (!DeviceBladeRF1::open_bladerf(&m_dev, qPrintable(m_deviceAPI->getSampleSinkSerial())))
|
2017-01-02 04:39:21 -05:00
|
|
|
{
|
2017-04-13 19:59:09 -04:00
|
|
|
qCritical("BladerfOutput::start: could not open BladeRF %s", qPrintable(m_deviceAPI->getSampleSinkSerial()));
|
2017-01-02 04:39:21 -05:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_sharedParams.m_dev = m_dev;
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: adjust USB transfer data according to sample rate
|
2018-09-18 17:12:00 -04:00
|
|
|
if ((res = bladerf_sync_config(m_dev, BLADERF_TX_X1, BLADERF_FORMAT_SC16_Q11, 64, 8192, 32, 10000)) < 0)
|
2017-01-02 04:39:21 -05:00
|
|
|
{
|
2017-04-13 15:26:36 -04:00
|
|
|
qCritical("BladerfOutput::start: bladerf_sync_config with return code %d", res);
|
|
|
|
return false;
|
2017-01-02 04:39:21 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
if ((res = bladerf_enable_module(m_dev, BLADERF_MODULE_TX, true)) < 0)
|
|
|
|
{
|
2017-04-13 15:26:36 -04:00
|
|
|
qCritical("BladerfOutput::start: bladerf_enable_module with return code %d", res);
|
|
|
|
return false;
|
2017-01-02 04:39:21 -05:00
|
|
|
}
|
|
|
|
|
2017-04-13 15:26:36 -04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-09-19 02:42:59 -04:00
|
|
|
void Bladerf1Output::init()
|
2017-12-25 06:59:44 -05:00
|
|
|
{
|
|
|
|
applySettings(m_settings, true);
|
|
|
|
}
|
|
|
|
|
2018-09-19 02:42:59 -04:00
|
|
|
bool Bladerf1Output::start()
|
2017-04-13 15:26:36 -04:00
|
|
|
{
|
|
|
|
// QMutexLocker mutexLocker(&m_mutex);
|
|
|
|
|
|
|
|
if (!m_dev) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (m_running) stop();
|
|
|
|
|
2018-09-19 02:42:59 -04:00
|
|
|
m_bladerfThread = new Bladerf1OutputThread(m_dev, &m_sampleSourceFifo);
|
2017-01-02 04:39:21 -05:00
|
|
|
|
2017-01-02 18:56:18 -05:00
|
|
|
// mutexLocker.unlock();
|
2017-01-02 04:39:21 -05:00
|
|
|
applySettings(m_settings, true);
|
|
|
|
|
2017-04-13 15:26:36 -04:00
|
|
|
m_bladerfThread->setLog2Interpolation(m_settings.m_log2Interp);
|
|
|
|
|
2017-01-09 16:33:58 -05:00
|
|
|
m_bladerfThread->startWork();
|
|
|
|
|
2017-01-02 04:39:21 -05:00
|
|
|
qDebug("BladerfOutput::start: started");
|
2017-04-13 15:26:36 -04:00
|
|
|
m_running = true;
|
2017-01-02 04:39:21 -05:00
|
|
|
|
2017-04-13 15:26:36 -04:00
|
|
|
return true;
|
2017-01-02 04:39:21 -05:00
|
|
|
}
|
|
|
|
|
2018-09-19 02:42:59 -04:00
|
|
|
void Bladerf1Output::closeDevice()
|
2017-01-02 04:39:21 -05:00
|
|
|
{
|
2017-01-02 18:56:18 -05:00
|
|
|
int res;
|
2017-01-02 04:39:21 -05:00
|
|
|
|
2017-04-17 06:00:13 -04:00
|
|
|
if (m_dev == 0) { // was never open
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-01-02 18:56:18 -05:00
|
|
|
if ((res = bladerf_enable_module(m_dev, BLADERF_MODULE_TX, false)) < 0)
|
|
|
|
{
|
2017-04-13 17:40:14 -04:00
|
|
|
qCritical("BladerfOutput::closeDevice: bladerf_enable_module with return code %d", res);
|
2017-01-02 18:56:18 -05:00
|
|
|
}
|
|
|
|
|
2017-04-13 17:40:14 -04:00
|
|
|
if (m_deviceAPI->getSourceBuddies().size() == 0)
|
2017-01-02 04:39:21 -05:00
|
|
|
{
|
2017-04-13 17:40:14 -04:00
|
|
|
qDebug("BladerfOutput::closeDevice: closing device since Rx side is not open");
|
2017-01-02 18:56:18 -05:00
|
|
|
|
2017-04-13 17:40:14 -04:00
|
|
|
if (m_dev != 0) // close BladeRF
|
2017-01-02 04:39:21 -05:00
|
|
|
{
|
|
|
|
bladerf_close(m_dev);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
m_sharedParams.m_dev = 0;
|
2017-01-03 03:09:51 -05:00
|
|
|
m_dev = 0;
|
2017-01-02 04:39:21 -05:00
|
|
|
}
|
|
|
|
|
2018-09-19 02:42:59 -04:00
|
|
|
void Bladerf1Output::stop()
|
2017-04-13 15:26:36 -04:00
|
|
|
{
|
|
|
|
// QMutexLocker mutexLocker(&m_mutex);
|
|
|
|
if (m_bladerfThread != 0)
|
|
|
|
{
|
|
|
|
m_bladerfThread->stopWork();
|
|
|
|
delete m_bladerfThread;
|
|
|
|
m_bladerfThread = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_running = false;
|
|
|
|
}
|
|
|
|
|
2018-09-19 02:42:59 -04:00
|
|
|
QByteArray Bladerf1Output::serialize() const
|
2017-12-27 22:04:50 -05:00
|
|
|
{
|
|
|
|
return m_settings.serialize();
|
|
|
|
}
|
|
|
|
|
2018-09-19 02:42:59 -04:00
|
|
|
bool Bladerf1Output::deserialize(const QByteArray& data)
|
2017-12-27 22:04:50 -05:00
|
|
|
{
|
|
|
|
bool success = true;
|
|
|
|
|
|
|
|
if (!m_settings.deserialize(data))
|
|
|
|
{
|
|
|
|
m_settings.resetToDefaults();
|
|
|
|
success = false;
|
|
|
|
}
|
|
|
|
|
2018-09-19 02:42:59 -04:00
|
|
|
MsgConfigureBladerf1* message = MsgConfigureBladerf1::create(m_settings, true);
|
2017-12-27 22:04:50 -05:00
|
|
|
m_inputMessageQueue.push(message);
|
|
|
|
|
|
|
|
if (m_guiMessageQueue)
|
|
|
|
{
|
2018-09-19 02:42:59 -04:00
|
|
|
MsgConfigureBladerf1* messageToGUI = MsgConfigureBladerf1::create(m_settings, true);
|
2017-12-27 22:04:50 -05:00
|
|
|
m_guiMessageQueue->push(messageToGUI);
|
|
|
|
}
|
|
|
|
|
|
|
|
return success;
|
|
|
|
}
|
|
|
|
|
2018-09-19 02:42:59 -04:00
|
|
|
const QString& Bladerf1Output::getDeviceDescription() const
|
2017-01-02 04:39:21 -05:00
|
|
|
{
|
|
|
|
return m_deviceDescription;
|
|
|
|
}
|
|
|
|
|
2018-09-19 02:42:59 -04:00
|
|
|
int Bladerf1Output::getSampleRate() const
|
2017-01-02 04:39:21 -05:00
|
|
|
{
|
|
|
|
int rate = m_settings.m_devSampleRate;
|
|
|
|
return (rate / (1<<m_settings.m_log2Interp));
|
|
|
|
}
|
|
|
|
|
2018-09-19 02:42:59 -04:00
|
|
|
quint64 Bladerf1Output::getCenterFrequency() const
|
2017-01-02 04:39:21 -05:00
|
|
|
{
|
|
|
|
return m_settings.m_centerFrequency;
|
|
|
|
}
|
|
|
|
|
2018-09-19 02:42:59 -04:00
|
|
|
void Bladerf1Output::setCenterFrequency(qint64 centerFrequency)
|
2017-12-27 22:04:50 -05:00
|
|
|
{
|
2018-09-19 02:42:59 -04:00
|
|
|
BladeRF1OutputSettings settings = m_settings;
|
2017-12-27 22:04:50 -05:00
|
|
|
settings.m_centerFrequency = centerFrequency;
|
|
|
|
|
2018-09-19 02:42:59 -04:00
|
|
|
MsgConfigureBladerf1* message = MsgConfigureBladerf1::create(settings, false);
|
2017-12-27 22:04:50 -05:00
|
|
|
m_inputMessageQueue.push(message);
|
|
|
|
|
|
|
|
if (m_guiMessageQueue)
|
|
|
|
{
|
2018-09-19 02:42:59 -04:00
|
|
|
MsgConfigureBladerf1* messageToGUI = MsgConfigureBladerf1::create(settings, false);
|
2017-12-27 22:04:50 -05:00
|
|
|
m_guiMessageQueue->push(messageToGUI);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-19 02:42:59 -04:00
|
|
|
bool Bladerf1Output::handleMessage(const Message& message)
|
2017-01-02 04:39:21 -05:00
|
|
|
{
|
2018-09-19 02:42:59 -04:00
|
|
|
if (MsgConfigureBladerf1::match(message))
|
2017-01-02 04:39:21 -05:00
|
|
|
{
|
2018-09-19 02:42:59 -04:00
|
|
|
MsgConfigureBladerf1& conf = (MsgConfigureBladerf1&) message;
|
2017-12-14 12:02:49 -05:00
|
|
|
qDebug() << "BladerfOutput::handleMessage: MsgConfigureBladerf";
|
2017-01-02 04:39:21 -05:00
|
|
|
|
2017-10-14 01:10:42 -04:00
|
|
|
if (!applySettings(conf.getSettings(), conf.getForce()))
|
2017-01-02 04:39:21 -05:00
|
|
|
{
|
|
|
|
qDebug("BladeRF config error");
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2017-12-13 18:38:22 -05:00
|
|
|
else if (MsgStartStop::match(message))
|
|
|
|
{
|
|
|
|
MsgStartStop& cmd = (MsgStartStop&) message;
|
2017-12-14 12:02:49 -05:00
|
|
|
qDebug() << "BladerfOutput::handleMessage: MsgStartStop: " << (cmd.getStartStop() ? "start" : "stop");
|
2017-12-13 18:38:22 -05:00
|
|
|
|
|
|
|
if (cmd.getStartStop())
|
|
|
|
{
|
|
|
|
if (m_deviceAPI->initGeneration())
|
|
|
|
{
|
|
|
|
m_deviceAPI->startGeneration();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_deviceAPI->stopGeneration();
|
|
|
|
}
|
|
|
|
|
2018-12-26 13:22:52 -05:00
|
|
|
if (m_settings.m_useReverseAPI) {
|
|
|
|
webapiReverseSendStartStop(cmd.getStartStop());
|
|
|
|
}
|
|
|
|
|
2017-12-13 18:38:22 -05:00
|
|
|
return true;
|
|
|
|
}
|
2017-01-02 04:39:21 -05:00
|
|
|
else
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-19 02:42:59 -04:00
|
|
|
bool Bladerf1Output::applySettings(const BladeRF1OutputSettings& settings, bool force)
|
2017-01-02 04:39:21 -05:00
|
|
|
{
|
2017-08-08 17:09:51 -04:00
|
|
|
bool forwardChange = false;
|
|
|
|
bool suspendOwnThread = false;
|
|
|
|
bool threadWasRunning = false;
|
2018-12-26 13:22:52 -05:00
|
|
|
QList<QString> reverseAPIKeys;
|
2017-01-02 18:56:18 -05:00
|
|
|
// QMutexLocker mutexLocker(&m_mutex);
|
2017-01-02 04:39:21 -05:00
|
|
|
|
|
|
|
qDebug() << "BladerfOutput::applySettings: m_dev: " << m_dev;
|
|
|
|
|
2018-12-26 13:22:52 -05:00
|
|
|
if ((m_settings.m_centerFrequency != settings.m_centerFrequency) || force) {
|
|
|
|
reverseAPIKeys.append("centerFrequency");
|
|
|
|
}
|
|
|
|
if ((m_settings.m_devSampleRate != settings.m_devSampleRate) || force) {
|
|
|
|
reverseAPIKeys.append("devSampleRate");
|
|
|
|
}
|
|
|
|
if ((m_settings.m_log2Interp != settings.m_log2Interp) || force) {
|
|
|
|
reverseAPIKeys.append("log2Interp");
|
|
|
|
}
|
|
|
|
|
2017-08-08 17:09:51 -04:00
|
|
|
if ((m_settings.m_devSampleRate != settings.m_devSampleRate) ||
|
|
|
|
(m_settings.m_log2Interp != settings.m_log2Interp) || force)
|
|
|
|
{
|
|
|
|
suspendOwnThread = true;
|
|
|
|
}
|
2017-01-09 16:33:58 -05:00
|
|
|
|
2017-08-08 17:09:51 -04:00
|
|
|
if (suspendOwnThread)
|
|
|
|
{
|
|
|
|
if (m_bladerfThread)
|
|
|
|
{
|
|
|
|
if (m_bladerfThread->isRunning())
|
|
|
|
{
|
|
|
|
m_bladerfThread->stopWork();
|
|
|
|
threadWasRunning = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-01-09 16:33:58 -05:00
|
|
|
|
2017-08-08 17:09:51 -04:00
|
|
|
if ((m_settings.m_devSampleRate != settings.m_devSampleRate) || (m_settings.m_log2Interp != settings.m_log2Interp) || force)
|
|
|
|
{
|
2017-08-08 18:31:23 -04:00
|
|
|
int fifoSize;
|
|
|
|
|
2017-08-09 16:59:46 -04:00
|
|
|
if (settings.m_log2Interp >= 5)
|
2017-08-08 18:31:23 -04:00
|
|
|
{
|
2018-09-18 23:26:18 -04:00
|
|
|
fifoSize = DeviceBladeRF1Shared::m_sampleFifoMinSize32;
|
2017-08-08 18:31:23 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-11-16 07:44:58 -05:00
|
|
|
fifoSize = (std::max)(
|
2018-09-18 23:26:18 -04:00
|
|
|
(int) ((settings.m_devSampleRate/(1<<settings.m_log2Interp)) * DeviceBladeRF1Shared::m_sampleFifoLengthInSeconds),
|
|
|
|
DeviceBladeRF1Shared::m_sampleFifoMinSize);
|
2017-08-08 18:31:23 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
m_sampleSourceFifo.resize(fifoSize);
|
2017-01-09 16:33:58 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
if ((m_settings.m_devSampleRate != settings.m_devSampleRate) || force)
|
|
|
|
{
|
|
|
|
forwardChange = true;
|
|
|
|
|
|
|
|
if (m_dev != 0)
|
|
|
|
{
|
|
|
|
unsigned int actualSamplerate;
|
2017-01-02 04:39:21 -05:00
|
|
|
|
2018-12-26 13:22:52 -05:00
|
|
|
if (bladerf_set_sample_rate(m_dev, BLADERF_MODULE_TX, settings.m_devSampleRate, &actualSamplerate) < 0) {
|
2017-01-09 16:33:58 -05:00
|
|
|
qCritical("BladerfOutput::applySettings: could not set sample rate: %d", settings.m_devSampleRate);
|
2018-12-26 13:22:52 -05:00
|
|
|
} else {
|
2017-01-09 16:33:58 -05:00
|
|
|
qDebug() << "BladerfOutput::applySettings: bladerf_set_sample_rate(BLADERF_MODULE_TX) actual sample rate is " << actualSamplerate;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((m_settings.m_log2Interp != settings.m_log2Interp) || force)
|
|
|
|
{
|
|
|
|
forwardChange = true;
|
|
|
|
|
|
|
|
if (m_bladerfThread != 0)
|
|
|
|
{
|
|
|
|
m_bladerfThread->setLog2Interpolation(settings.m_log2Interp);
|
|
|
|
qDebug() << "BladerfOutput::applySettings: set interpolation to " << (1<<settings.m_log2Interp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((m_settings.m_vga1 != settings.m_vga1) || force)
|
|
|
|
{
|
2018-12-26 13:22:52 -05:00
|
|
|
reverseAPIKeys.append("vga1");
|
|
|
|
|
2017-01-02 04:39:21 -05:00
|
|
|
if (m_dev != 0)
|
|
|
|
{
|
2018-12-26 13:22:52 -05:00
|
|
|
if (bladerf_set_txvga1(m_dev, settings.m_vga1) != 0) {
|
2017-01-02 04:39:21 -05:00
|
|
|
qDebug("BladerfOutput::applySettings: bladerf_set_txvga1() failed");
|
2018-12-26 13:22:52 -05:00
|
|
|
} else {
|
2017-01-09 16:33:58 -05:00
|
|
|
qDebug() << "BladerfOutput::applySettings: VGA1 gain set to " << settings.m_vga1;
|
2017-01-02 04:39:21 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((m_settings.m_vga2 != settings.m_vga2) || force)
|
|
|
|
{
|
2018-12-26 13:22:52 -05:00
|
|
|
reverseAPIKeys.append("vga2");
|
|
|
|
|
2017-01-02 04:39:21 -05:00
|
|
|
if(m_dev != 0)
|
|
|
|
{
|
2018-12-26 13:22:52 -05:00
|
|
|
if (bladerf_set_txvga2(m_dev, settings.m_vga2) != 0) {
|
2017-01-02 04:39:21 -05:00
|
|
|
qDebug("BladerfOutput::applySettings:bladerf_set_rxvga2() failed");
|
2018-12-26 13:22:52 -05:00
|
|
|
} else {
|
2017-01-09 16:33:58 -05:00
|
|
|
qDebug() << "BladerfOutput::applySettings: VGA2 gain set to " << settings.m_vga2;
|
2017-01-02 04:39:21 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((m_settings.m_xb200 != settings.m_xb200) || force)
|
|
|
|
{
|
2018-12-26 13:22:52 -05:00
|
|
|
reverseAPIKeys.append("xb200");
|
|
|
|
|
2017-01-02 04:39:21 -05:00
|
|
|
if (m_dev != 0)
|
|
|
|
{
|
|
|
|
bool changeSettings;
|
|
|
|
|
|
|
|
if (m_deviceAPI->getSourceBuddies().size() > 0)
|
|
|
|
{
|
|
|
|
DeviceSourceAPI *buddy = m_deviceAPI->getSourceBuddies()[0];
|
|
|
|
|
2018-12-26 13:22:52 -05:00
|
|
|
if (buddy->getDeviceSourceEngine()->state() == DSPDeviceSourceEngine::StRunning) { // Tx side running
|
2017-01-02 04:39:21 -05:00
|
|
|
changeSettings = false;
|
2018-12-26 13:22:52 -05:00
|
|
|
} else {
|
2017-01-02 04:39:21 -05:00
|
|
|
changeSettings = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else // No Rx open
|
|
|
|
{
|
|
|
|
changeSettings = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (changeSettings)
|
|
|
|
{
|
2017-01-09 16:33:58 -05:00
|
|
|
if (settings.m_xb200)
|
2017-01-02 04:39:21 -05:00
|
|
|
{
|
2018-12-26 13:22:52 -05:00
|
|
|
if (bladerf_expansion_attach(m_dev, BLADERF_XB_200) != 0) {
|
2017-01-02 04:39:21 -05:00
|
|
|
qDebug("BladerfOutput::applySettings: bladerf_expansion_attach(xb200) failed");
|
2018-12-26 13:22:52 -05:00
|
|
|
} else {
|
2017-01-02 04:39:21 -05:00
|
|
|
qDebug() << "BladerfOutput::applySettings: Attach XB200";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-12-26 13:22:52 -05:00
|
|
|
if (bladerf_expansion_attach(m_dev, BLADERF_XB_NONE) != 0) {
|
2017-01-02 04:39:21 -05:00
|
|
|
qDebug("BladerfOutput::applySettings: bladerf_expansion_attach(none) failed");
|
2018-12-26 13:22:52 -05:00
|
|
|
} else {
|
2017-01-02 04:39:21 -05:00
|
|
|
qDebug() << "BladerfOutput::applySettings: Detach XB200";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-09 16:33:58 -05:00
|
|
|
m_sharedParams.m_xb200Attached = settings.m_xb200;
|
2017-01-02 04:39:21 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((m_settings.m_xb200Path != settings.m_xb200Path) || force)
|
|
|
|
{
|
2018-12-26 13:22:52 -05:00
|
|
|
reverseAPIKeys.append("xb200Path");
|
|
|
|
|
2017-01-02 04:39:21 -05:00
|
|
|
if (m_dev != 0)
|
|
|
|
{
|
2018-12-26 13:22:52 -05:00
|
|
|
if (bladerf_xb200_set_path(m_dev, BLADERF_MODULE_TX, settings.m_xb200Path) != 0) {
|
2017-01-02 04:39:21 -05:00
|
|
|
qDebug("BladerfOutput::applySettings: bladerf_xb200_set_path(BLADERF_MODULE_TX) failed");
|
2018-12-26 13:22:52 -05:00
|
|
|
} else {
|
2017-01-09 16:33:58 -05:00
|
|
|
qDebug() << "BladerfOutput::applySettings: set xb200 path to " << settings.m_xb200Path;
|
2017-01-02 04:39:21 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((m_settings.m_xb200Filter != settings.m_xb200Filter) || force)
|
|
|
|
{
|
2018-12-26 13:22:52 -05:00
|
|
|
reverseAPIKeys.append("xb200Filter");
|
|
|
|
|
2017-01-02 04:39:21 -05:00
|
|
|
if (m_dev != 0)
|
|
|
|
{
|
2018-12-26 13:22:52 -05:00
|
|
|
if (bladerf_xb200_set_filterbank(m_dev, BLADERF_MODULE_TX, settings.m_xb200Filter) != 0) {
|
2017-01-02 04:39:21 -05:00
|
|
|
qDebug("BladerfOutput::applySettings: bladerf_xb200_set_filterbank(BLADERF_MODULE_TX) failed");
|
2018-12-26 13:22:52 -05:00
|
|
|
} else {
|
2017-01-09 16:33:58 -05:00
|
|
|
qDebug() << "BladerfOutput::applySettings: set xb200 filter to " << settings.m_xb200Filter;
|
2017-01-02 04:39:21 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((m_settings.m_bandwidth != settings.m_bandwidth) || force)
|
|
|
|
{
|
2018-12-26 13:22:52 -05:00
|
|
|
reverseAPIKeys.append("bandwidth");
|
|
|
|
|
|
|
|
if (m_dev != 0)
|
2017-01-02 04:39:21 -05:00
|
|
|
{
|
|
|
|
unsigned int actualBandwidth;
|
|
|
|
|
2018-12-26 13:22:52 -05:00
|
|
|
if (bladerf_set_bandwidth(m_dev, BLADERF_MODULE_TX, settings.m_bandwidth, &actualBandwidth) < 0) {
|
2017-01-09 16:33:58 -05:00
|
|
|
qCritical("BladerfOutput::applySettings: could not set bandwidth: %d", settings.m_bandwidth);
|
2018-12-26 13:22:52 -05:00
|
|
|
} else {
|
2017-01-02 04:39:21 -05:00
|
|
|
qDebug() << "BladerfOutput::applySettings: bladerf_set_bandwidth(BLADERF_MODULE_TX) actual bandwidth is " << actualBandwidth;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (m_settings.m_centerFrequency != settings.m_centerFrequency)
|
|
|
|
{
|
|
|
|
forwardChange = true;
|
|
|
|
}
|
|
|
|
|
2018-12-26 13:22:52 -05:00
|
|
|
if (m_dev != 0)
|
2017-01-02 04:39:21 -05:00
|
|
|
{
|
2017-01-09 16:33:58 -05:00
|
|
|
if (bladerf_set_frequency( m_dev, BLADERF_MODULE_TX, settings.m_centerFrequency ) != 0)
|
2017-01-02 04:39:21 -05:00
|
|
|
{
|
2017-01-09 16:33:58 -05:00
|
|
|
qDebug("BladerfOutput::applySettings: bladerf_set_frequency(%lld) failed", settings.m_centerFrequency);
|
2017-01-02 04:39:21 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-08 17:09:51 -04:00
|
|
|
if (threadWasRunning)
|
|
|
|
{
|
|
|
|
m_bladerfThread->startWork();
|
|
|
|
}
|
|
|
|
|
2018-12-26 13:22:52 -05: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);
|
|
|
|
webapiReverseSendSettings(reverseAPIKeys, settings, fullUpdate || force);
|
|
|
|
}
|
|
|
|
|
|
|
|
m_settings = settings;
|
2017-01-09 16:33:58 -05:00
|
|
|
|
2017-01-02 04:39:21 -05:00
|
|
|
if (forwardChange)
|
|
|
|
{
|
|
|
|
int sampleRate = m_settings.m_devSampleRate/(1<<m_settings.m_log2Interp);
|
|
|
|
DSPSignalNotification *notif = new DSPSignalNotification(sampleRate, m_settings.m_centerFrequency);
|
2017-09-13 17:42:28 -04:00
|
|
|
m_deviceAPI->getDeviceEngineInputMessageQueue()->push(notif);
|
2017-01-02 04:39:21 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
qDebug() << "BladerfOutput::applySettings: center freq: " << m_settings.m_centerFrequency << " Hz"
|
2017-04-01 22:34:58 -04:00
|
|
|
<< " device sample rate: " << m_settings.m_devSampleRate << "S/s"
|
|
|
|
<< " baseband sample rate: " << m_settings.m_devSampleRate/(1<<m_settings.m_log2Interp) << "S/s"
|
2017-01-09 16:33:58 -05:00
|
|
|
<< " BW: " << m_settings.m_bandwidth << "Hz";
|
2017-01-02 04:39:21 -05:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2017-12-09 19:57:50 -05:00
|
|
|
|
2018-09-19 02:42:59 -04:00
|
|
|
int Bladerf1Output::webapiSettingsGet(
|
2018-03-31 13:29:52 -04:00
|
|
|
SWGSDRangel::SWGDeviceSettings& response,
|
2018-11-13 02:51:14 -05:00
|
|
|
QString& errorMessage)
|
2018-03-31 13:29:52 -04:00
|
|
|
{
|
2018-11-13 02:51:14 -05:00
|
|
|
(void) errorMessage;
|
2018-09-18 23:54:07 -04:00
|
|
|
response.setBladeRf1OutputSettings(new SWGSDRangel::SWGBladeRF1OutputSettings());
|
|
|
|
response.getBladeRf1OutputSettings()->init();
|
2018-03-31 13:29:52 -04:00
|
|
|
webapiFormatDeviceSettings(response, m_settings);
|
|
|
|
return 200;
|
|
|
|
}
|
|
|
|
|
2018-09-19 02:42:59 -04:00
|
|
|
void Bladerf1Output::webapiFormatDeviceSettings(SWGSDRangel::SWGDeviceSettings& response, const BladeRF1OutputSettings& settings)
|
2018-03-31 13:29:52 -04:00
|
|
|
{
|
2018-09-18 23:54:07 -04:00
|
|
|
response.getBladeRf1OutputSettings()->setCenterFrequency(settings.m_centerFrequency);
|
|
|
|
response.getBladeRf1OutputSettings()->setDevSampleRate(settings.m_devSampleRate);
|
|
|
|
response.getBladeRf1OutputSettings()->setVga1(settings.m_vga1);
|
|
|
|
response.getBladeRf1OutputSettings()->setVga2(settings.m_vga2);
|
|
|
|
response.getBladeRf1OutputSettings()->setBandwidth(settings.m_bandwidth);
|
|
|
|
response.getBladeRf1OutputSettings()->setLog2Interp(settings.m_log2Interp);
|
|
|
|
response.getBladeRf1OutputSettings()->setXb200(settings.m_xb200 ? 1 : 0);
|
|
|
|
response.getBladeRf1OutputSettings()->setXb200Path((int) settings.m_xb200Path);
|
|
|
|
response.getBladeRf1OutputSettings()->setXb200Filter((int) settings.m_xb200Filter);
|
2019-01-11 08:45:00 -05:00
|
|
|
|
|
|
|
response.getBladeRf1OutputSettings()->setUseReverseApi(settings.m_useReverseAPI ? 1 : 0);
|
|
|
|
|
|
|
|
if (response.getBladeRf1OutputSettings()->getReverseApiAddress()) {
|
|
|
|
*response.getBladeRf1OutputSettings()->getReverseApiAddress() = settings.m_reverseAPIAddress;
|
|
|
|
} else {
|
|
|
|
response.getBladeRf1OutputSettings()->setReverseApiAddress(new QString(settings.m_reverseAPIAddress));
|
|
|
|
}
|
|
|
|
|
|
|
|
response.getBladeRf1OutputSettings()->setReverseApiPort(settings.m_reverseAPIPort);
|
|
|
|
response.getBladeRf1OutputSettings()->setReverseApiDeviceIndex(settings.m_reverseAPIDeviceIndex);
|
2018-03-31 13:29:52 -04:00
|
|
|
}
|
|
|
|
|
2018-09-19 02:42:59 -04:00
|
|
|
int Bladerf1Output::webapiSettingsPutPatch(
|
2018-03-31 13:29:52 -04:00
|
|
|
bool force,
|
|
|
|
const QStringList& deviceSettingsKeys,
|
|
|
|
SWGSDRangel::SWGDeviceSettings& response, // query + response
|
2018-11-13 02:51:14 -05:00
|
|
|
QString& errorMessage)
|
2018-03-31 13:29:52 -04:00
|
|
|
{
|
2018-11-13 02:51:14 -05:00
|
|
|
(void) errorMessage;
|
2018-09-19 02:42:59 -04:00
|
|
|
BladeRF1OutputSettings settings = m_settings;
|
2018-03-31 13:29:52 -04:00
|
|
|
|
|
|
|
if (deviceSettingsKeys.contains("centerFrequency")) {
|
2018-09-18 23:54:07 -04:00
|
|
|
settings.m_centerFrequency = response.getBladeRf1OutputSettings()->getCenterFrequency();
|
2018-03-31 13:29:52 -04:00
|
|
|
}
|
|
|
|
if (deviceSettingsKeys.contains("devSampleRate")) {
|
2018-09-18 23:54:07 -04:00
|
|
|
settings.m_devSampleRate = response.getBladeRf1OutputSettings()->getDevSampleRate();
|
2018-03-31 13:29:52 -04:00
|
|
|
}
|
|
|
|
if (deviceSettingsKeys.contains("vga1")) {
|
2018-09-18 23:54:07 -04:00
|
|
|
settings.m_vga1 = response.getBladeRf1OutputSettings()->getVga1();
|
2018-03-31 13:29:52 -04:00
|
|
|
}
|
|
|
|
if (deviceSettingsKeys.contains("vga2")) {
|
2018-09-18 23:54:07 -04:00
|
|
|
settings.m_vga2 = response.getBladeRf1OutputSettings()->getVga2();
|
2018-03-31 13:29:52 -04:00
|
|
|
}
|
|
|
|
if (deviceSettingsKeys.contains("bandwidth")) {
|
2018-09-18 23:54:07 -04:00
|
|
|
settings.m_bandwidth = response.getBladeRf1OutputSettings()->getBandwidth();
|
2018-03-31 13:29:52 -04:00
|
|
|
}
|
|
|
|
if (deviceSettingsKeys.contains("log2Interp")) {
|
2018-09-18 23:54:07 -04:00
|
|
|
settings.m_log2Interp = response.getBladeRf1OutputSettings()->getLog2Interp();
|
2018-03-31 13:29:52 -04:00
|
|
|
}
|
|
|
|
if (deviceSettingsKeys.contains("xb200")) {
|
2018-09-18 23:54:07 -04:00
|
|
|
settings.m_xb200 = response.getBladeRf1OutputSettings()->getXb200() == 0 ? 0 : 1;
|
2018-03-31 13:29:52 -04:00
|
|
|
}
|
|
|
|
if (deviceSettingsKeys.contains("xb200Path")) {
|
2018-09-18 23:54:07 -04:00
|
|
|
settings.m_xb200Path = static_cast<bladerf_xb200_path>(response.getBladeRf1OutputSettings()->getXb200Path());
|
2018-03-31 13:29:52 -04:00
|
|
|
}
|
|
|
|
if (deviceSettingsKeys.contains("xb200Filter")) {
|
2018-09-18 23:54:07 -04:00
|
|
|
settings.m_xb200Filter = static_cast<bladerf_xb200_filter>(response.getBladeRf1OutputSettings()->getXb200Filter());
|
2018-03-31 13:29:52 -04:00
|
|
|
}
|
2019-01-11 08:45:00 -05:00
|
|
|
if (deviceSettingsKeys.contains("useReverseAPI")) {
|
|
|
|
settings.m_useReverseAPI = response.getBladeRf1OutputSettings()->getUseReverseApi() != 0;
|
|
|
|
}
|
|
|
|
if (deviceSettingsKeys.contains("reverseAPIAddress")) {
|
|
|
|
settings.m_reverseAPIAddress = *response.getBladeRf1OutputSettings()->getReverseApiAddress();
|
|
|
|
}
|
|
|
|
if (deviceSettingsKeys.contains("reverseAPIPort")) {
|
|
|
|
settings.m_reverseAPIPort = response.getBladeRf1OutputSettings()->getReverseApiPort();
|
|
|
|
}
|
|
|
|
if (deviceSettingsKeys.contains("reverseAPIDeviceIndex")) {
|
|
|
|
settings.m_reverseAPIDeviceIndex = response.getBladeRf1OutputSettings()->getReverseApiDeviceIndex();
|
|
|
|
}
|
2018-03-31 13:29:52 -04:00
|
|
|
|
2018-09-19 02:42:59 -04:00
|
|
|
MsgConfigureBladerf1 *msg = MsgConfigureBladerf1::create(settings, force);
|
2018-03-31 13:29:52 -04:00
|
|
|
m_inputMessageQueue.push(msg);
|
|
|
|
|
|
|
|
if (m_guiMessageQueue) // forward to GUI if any
|
|
|
|
{
|
2018-09-19 02:42:59 -04:00
|
|
|
MsgConfigureBladerf1 *msgToGUI = MsgConfigureBladerf1::create(settings, force);
|
2018-03-31 13:29:52 -04:00
|
|
|
m_guiMessageQueue->push(msgToGUI);
|
|
|
|
}
|
|
|
|
|
|
|
|
webapiFormatDeviceSettings(response, settings);
|
|
|
|
return 200;
|
|
|
|
}
|
|
|
|
|
2018-09-19 02:42:59 -04:00
|
|
|
int Bladerf1Output::webapiRunGet(
|
2017-12-09 19:57:50 -05:00
|
|
|
SWGSDRangel::SWGDeviceState& response,
|
2018-11-13 02:51:14 -05:00
|
|
|
QString& errorMessage)
|
2017-12-09 19:57:50 -05:00
|
|
|
{
|
2018-11-13 02:51:14 -05:00
|
|
|
(void) errorMessage;
|
2017-12-09 19:57:50 -05:00
|
|
|
m_deviceAPI->getDeviceEngineStateStr(*response.getState());
|
|
|
|
return 200;
|
|
|
|
}
|
|
|
|
|
2018-09-19 02:42:59 -04:00
|
|
|
int Bladerf1Output::webapiRun(
|
2017-12-09 19:57:50 -05:00
|
|
|
bool run,
|
|
|
|
SWGSDRangel::SWGDeviceState& response,
|
2018-11-13 02:51:14 -05:00
|
|
|
QString& errorMessage)
|
2017-12-09 19:57:50 -05:00
|
|
|
{
|
2018-11-13 02:51:14 -05:00
|
|
|
(void) errorMessage;
|
2017-12-14 17:29:12 -05:00
|
|
|
m_deviceAPI->getDeviceEngineStateStr(*response.getState());
|
2017-12-13 18:38:22 -05:00
|
|
|
MsgStartStop *message = MsgStartStop::create(run);
|
|
|
|
m_inputMessageQueue.push(message);
|
|
|
|
|
|
|
|
if (m_guiMessageQueue)
|
2017-12-09 19:57:50 -05:00
|
|
|
{
|
2017-12-13 18:38:22 -05:00
|
|
|
MsgStartStop *messagetoGui = MsgStartStop::create(run);
|
|
|
|
m_guiMessageQueue->push(messagetoGui);
|
2017-12-09 19:57:50 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return 200;
|
|
|
|
}
|
|
|
|
|
2018-12-26 13:22:52 -05:00
|
|
|
void Bladerf1Output::webapiReverseSendSettings(QList<QString>& deviceSettingsKeys, const BladeRF1OutputSettings& settings, bool force)
|
|
|
|
{
|
|
|
|
SWGSDRangel::SWGDeviceSettings *swgDeviceSettings = new SWGSDRangel::SWGDeviceSettings();
|
|
|
|
swgDeviceSettings->setTx(1);
|
2019-03-25 08:46:42 -04:00
|
|
|
swgDeviceSettings->setOriginatorIndex(m_deviceAPI->getDeviceSetIndex());
|
2018-12-26 13:22:52 -05:00
|
|
|
swgDeviceSettings->setDeviceHwType(new QString("BladeRF1"));
|
|
|
|
swgDeviceSettings->setBladeRf1OutputSettings(new SWGSDRangel::SWGBladeRF1OutputSettings());
|
|
|
|
SWGSDRangel::SWGBladeRF1OutputSettings *swgBladeRF1OutputSettings = swgDeviceSettings->getBladeRf1OutputSettings();
|
|
|
|
|
|
|
|
// transfer data that has been modified. When force is on transfer all data except reverse API data
|
|
|
|
|
|
|
|
if (deviceSettingsKeys.contains("centerFrequency") || force) {
|
|
|
|
swgBladeRF1OutputSettings->setCenterFrequency(settings.m_centerFrequency);
|
|
|
|
}
|
|
|
|
if (deviceSettingsKeys.contains("devSampleRate") || force) {
|
|
|
|
swgBladeRF1OutputSettings->setDevSampleRate(settings.m_devSampleRate);
|
|
|
|
}
|
|
|
|
if (deviceSettingsKeys.contains("vga1") || force) {
|
|
|
|
swgBladeRF1OutputSettings->setVga1(settings.m_vga1);
|
|
|
|
}
|
|
|
|
if (deviceSettingsKeys.contains("vga2") || force) {
|
|
|
|
swgBladeRF1OutputSettings->setVga2(settings.m_vga2);
|
|
|
|
}
|
|
|
|
if (deviceSettingsKeys.contains("bandwidth") || force) {
|
|
|
|
swgBladeRF1OutputSettings->setBandwidth(settings.m_bandwidth);
|
|
|
|
}
|
|
|
|
if (deviceSettingsKeys.contains("log2Interp") || force) {
|
|
|
|
swgBladeRF1OutputSettings->setLog2Interp(settings.m_log2Interp);
|
|
|
|
}
|
|
|
|
if (deviceSettingsKeys.contains("xb200") || force) {
|
|
|
|
swgBladeRF1OutputSettings->setXb200(settings.m_xb200 ? 1 : 0);
|
|
|
|
}
|
|
|
|
if (deviceSettingsKeys.contains("xb200Path") || force) {
|
|
|
|
swgBladeRF1OutputSettings->setXb200Path((int) settings.m_xb200Path);
|
|
|
|
}
|
|
|
|
if (deviceSettingsKeys.contains("xb200Filter") || force) {
|
|
|
|
swgBladeRF1OutputSettings->setXb200Filter((int) settings.m_xb200Filter);
|
|
|
|
}
|
|
|
|
|
|
|
|
QString deviceSettingsURL = QString("http://%1:%2/sdrangel/deviceset/%3/device/settings")
|
|
|
|
.arg(settings.m_reverseAPIAddress)
|
|
|
|
.arg(settings.m_reverseAPIPort)
|
|
|
|
.arg(settings.m_reverseAPIDeviceIndex);
|
|
|
|
m_networkRequest.setUrl(QUrl(deviceSettingsURL));
|
|
|
|
m_networkRequest.setHeader(QNetworkRequest::ContentTypeHeader, "application/json");
|
|
|
|
|
|
|
|
QBuffer *buffer=new QBuffer();
|
|
|
|
buffer->open((QBuffer::ReadWrite));
|
|
|
|
buffer->write(swgDeviceSettings->asJson().toUtf8());
|
|
|
|
buffer->seek(0);
|
|
|
|
|
|
|
|
// Always use PATCH to avoid passing reverse API settings
|
|
|
|
m_networkManager->sendCustomRequest(m_networkRequest, "PATCH", buffer);
|
|
|
|
|
|
|
|
delete swgDeviceSettings;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Bladerf1Output::webapiReverseSendStartStop(bool start)
|
|
|
|
{
|
2019-03-25 10:26:01 -04:00
|
|
|
SWGSDRangel::SWGDeviceSettings *swgDeviceSettings = new SWGSDRangel::SWGDeviceSettings();
|
|
|
|
swgDeviceSettings->setTx(1);
|
|
|
|
swgDeviceSettings->setOriginatorIndex(m_deviceAPI->getDeviceSetIndex());
|
|
|
|
swgDeviceSettings->setDeviceHwType(new QString("BladeRF1"));
|
|
|
|
|
2018-12-26 13:22:52 -05:00
|
|
|
QString deviceSettingsURL = QString("http://%1:%2/sdrangel/deviceset/%3/device/run")
|
|
|
|
.arg(m_settings.m_reverseAPIAddress)
|
|
|
|
.arg(m_settings.m_reverseAPIPort)
|
|
|
|
.arg(m_settings.m_reverseAPIDeviceIndex);
|
|
|
|
m_networkRequest.setUrl(QUrl(deviceSettingsURL));
|
2019-03-25 10:26:01 -04:00
|
|
|
m_networkRequest.setHeader(QNetworkRequest::ContentTypeHeader, "application/json");
|
|
|
|
|
|
|
|
QBuffer *buffer=new QBuffer();
|
|
|
|
buffer->open((QBuffer::ReadWrite));
|
|
|
|
buffer->write(swgDeviceSettings->asJson().toUtf8());
|
|
|
|
buffer->seek(0);
|
2018-12-26 13:22:52 -05:00
|
|
|
|
|
|
|
if (start) {
|
2019-03-25 10:26:01 -04:00
|
|
|
m_networkManager->sendCustomRequest(m_networkRequest, "POST", buffer);
|
2018-12-26 13:22:52 -05:00
|
|
|
} else {
|
2019-03-25 10:26:01 -04:00
|
|
|
m_networkManager->sendCustomRequest(m_networkRequest, "DELETE", buffer);
|
2018-12-26 13:22:52 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Bladerf1Output::networkManagerFinished(QNetworkReply *reply)
|
|
|
|
{
|
|
|
|
QNetworkReply::NetworkError replyError = reply->error();
|
|
|
|
|
|
|
|
if (replyError)
|
|
|
|
{
|
|
|
|
qWarning() << "Bladerf1Output::networkManagerFinished:"
|
|
|
|
<< " error(" << (int) replyError
|
|
|
|
<< "): " << replyError
|
|
|
|
<< ": " << reply->errorString();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString answer = reply->readAll();
|
|
|
|
answer.chop(1); // remove last \n
|
|
|
|
qDebug("Bladerf1Output::networkManagerFinished: reply:\n%s", answer.toStdString().c_str());
|
|
|
|
}
|