2018-09-28 23:49:14 -04:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////
|
2023-11-18 03:58:55 -05:00
|
|
|
// Copyright (C) 2018-2020, 2022 Edouard Griffiths, F4EXB <f4exb06@gmail.com> //
|
2018-09-28 23:49:14 -04:00
|
|
|
// //
|
|
|
|
// 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-09-28 23:49:14 -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 <string.h>
|
|
|
|
#include <errno.h>
|
2018-12-26 13:22:52 -05:00
|
|
|
|
2018-09-28 23:49:14 -04:00
|
|
|
#include <QDebug>
|
2018-12-26 13:22:52 -05:00
|
|
|
#include <QNetworkReply>
|
|
|
|
#include <QBuffer>
|
2018-09-28 23:49:14 -04:00
|
|
|
|
|
|
|
#include "SWGDeviceState.h"
|
|
|
|
#include "SWGDeviceSettings.h"
|
|
|
|
#include "SWGDeviceReport.h"
|
|
|
|
#include "SWGBladeRF2OutputReport.h"
|
|
|
|
|
|
|
|
#include "dsp/dspcommands.h"
|
2019-05-08 16:11:53 -04:00
|
|
|
#include "device/deviceapi.h"
|
2018-09-28 23:49:14 -04:00
|
|
|
#include "bladerf2/devicebladerf2shared.h"
|
|
|
|
#include "bladerf2/devicebladerf2.h"
|
|
|
|
|
|
|
|
#include "bladerf2outputthread.h"
|
|
|
|
#include "bladerf2output.h"
|
|
|
|
|
|
|
|
MESSAGE_CLASS_DEFINITION(BladeRF2Output::MsgConfigureBladeRF2, Message)
|
|
|
|
MESSAGE_CLASS_DEFINITION(BladeRF2Output::MsgStartStop, Message)
|
|
|
|
MESSAGE_CLASS_DEFINITION(BladeRF2Output::MsgReportGainRange, Message)
|
|
|
|
|
2019-05-08 16:11:53 -04:00
|
|
|
BladeRF2Output::BladeRF2Output(DeviceAPI *deviceAPI) :
|
2018-09-28 23:49:14 -04:00
|
|
|
m_deviceAPI(deviceAPI),
|
|
|
|
m_settings(),
|
2019-11-14 19:04:24 -05:00
|
|
|
m_dev(nullptr),
|
|
|
|
m_thread(nullptr),
|
2018-09-28 23:49:14 -04:00
|
|
|
m_deviceDescription("BladeRF2Output"),
|
|
|
|
m_running(false)
|
|
|
|
{
|
|
|
|
openDevice();
|
2019-05-20 18:27:08 -04:00
|
|
|
m_deviceAPI->setNbSinkStreams(1);
|
2018-12-26 13:22:52 -05:00
|
|
|
m_networkManager = new QNetworkAccessManager();
|
2022-03-23 17:32:23 -04:00
|
|
|
QObject::connect(
|
|
|
|
m_networkManager,
|
|
|
|
&QNetworkAccessManager::finished,
|
|
|
|
this,
|
|
|
|
&BladeRF2Output::networkManagerFinished
|
|
|
|
);
|
2018-09-28 23:49:14 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
BladeRF2Output::~BladeRF2Output()
|
|
|
|
{
|
2022-03-23 17:32:23 -04:00
|
|
|
QObject::disconnect(
|
|
|
|
m_networkManager,
|
|
|
|
&QNetworkAccessManager::finished,
|
|
|
|
this,
|
|
|
|
&BladeRF2Output::networkManagerFinished
|
|
|
|
);
|
2018-12-26 13:22:52 -05:00
|
|
|
delete m_networkManager;
|
|
|
|
|
2018-09-28 23:49:14 -04:00
|
|
|
if (m_running) {
|
|
|
|
stop();
|
|
|
|
}
|
|
|
|
|
|
|
|
closeDevice();
|
|
|
|
}
|
|
|
|
|
|
|
|
void BladeRF2Output::destroy()
|
|
|
|
{
|
|
|
|
delete this;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool BladeRF2Output::openDevice()
|
|
|
|
{
|
2019-11-14 19:04:24 -05:00
|
|
|
m_sampleSourceFifo.resize(SampleSourceFifo::getSizePolicy(m_settings.m_devSampleRate));
|
2018-09-28 23:49:14 -04:00
|
|
|
|
|
|
|
// look for Tx buddies and get reference to the device object
|
|
|
|
if (m_deviceAPI->getSinkBuddies().size() > 0) // look sink sibling first
|
|
|
|
{
|
|
|
|
qDebug("BladeRF2Output::openDevice: look in Tx buddies");
|
|
|
|
|
2019-05-08 16:11:53 -04:00
|
|
|
DeviceAPI *sinkBuddy = m_deviceAPI->getSinkBuddies()[0];
|
2018-09-28 23:49:14 -04:00
|
|
|
DeviceBladeRF2Shared *deviceBladeRF2Shared = (DeviceBladeRF2Shared*) sinkBuddy->getBuddySharedPtr();
|
|
|
|
|
|
|
|
if (deviceBladeRF2Shared == 0)
|
|
|
|
{
|
|
|
|
qCritical("BladeRF2Output::openDevice: the sink buddy shared pointer is null");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
DeviceBladeRF2 *device = deviceBladeRF2Shared->m_dev;
|
|
|
|
|
|
|
|
if (device == 0)
|
|
|
|
{
|
|
|
|
qCritical("BladeRF2Output::openDevice: cannot get device pointer from Tx buddy");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_deviceShared.m_dev = device;
|
|
|
|
}
|
|
|
|
// look for Rx buddies and get reference to the device object
|
|
|
|
else if (m_deviceAPI->getSourceBuddies().size() > 0) // then source
|
|
|
|
{
|
|
|
|
qDebug("BladeRF2Output::openDevice: look in Rx buddies");
|
|
|
|
|
2019-05-08 16:11:53 -04:00
|
|
|
DeviceAPI *sourceBuddy = m_deviceAPI->getSourceBuddies()[0];
|
2018-09-28 23:49:14 -04:00
|
|
|
DeviceBladeRF2Shared *deviceBladeRF2Shared = (DeviceBladeRF2Shared*) sourceBuddy->getBuddySharedPtr();
|
|
|
|
|
|
|
|
if (deviceBladeRF2Shared == 0)
|
|
|
|
{
|
|
|
|
qCritical("BladeRF2Output::openDevice: the source buddy shared pointer is null");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
DeviceBladeRF2 *device = deviceBladeRF2Shared->m_dev;
|
|
|
|
|
|
|
|
if (device == 0)
|
|
|
|
{
|
|
|
|
qCritical("BladeRF2Output::openDevice: cannot get device pointer from Rx buddy");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_deviceShared.m_dev = device;
|
|
|
|
}
|
|
|
|
// There are no buddies then create the first BladeRF2 device
|
|
|
|
else
|
|
|
|
{
|
|
|
|
qDebug("BladeRF2Output::openDevice: open device here");
|
|
|
|
|
|
|
|
m_deviceShared.m_dev = new DeviceBladeRF2();
|
|
|
|
char serial[256];
|
2019-05-08 16:11:53 -04:00
|
|
|
strcpy(serial, qPrintable(m_deviceAPI->getSamplingDeviceSerial()));
|
2018-09-28 23:49:14 -04:00
|
|
|
|
|
|
|
if (!m_deviceShared.m_dev->open(serial))
|
|
|
|
{
|
|
|
|
qCritical("BladeRF2Output::openDevice: cannot open BladeRF2 device");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-20 18:27:08 -04:00
|
|
|
m_deviceShared.m_channel = m_deviceAPI->getDeviceItemIndex(); // publicly allocate channel
|
2018-09-28 23:49:14 -04:00
|
|
|
m_deviceShared.m_sink = this;
|
|
|
|
m_deviceAPI->setBuddySharedPtr(&m_deviceShared); // propagate common parameters to API
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void BladeRF2Output::closeDevice()
|
|
|
|
{
|
|
|
|
if (m_deviceShared.m_dev == 0) { // was never open
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (m_running) {
|
|
|
|
stop();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (m_thread) { // stills own the thread => transfer to a buddy
|
|
|
|
moveThreadToBuddy();
|
|
|
|
}
|
|
|
|
|
|
|
|
m_deviceShared.m_channel = -1; // publicly release channel
|
|
|
|
m_deviceShared.m_sink = 0;
|
|
|
|
|
|
|
|
// No buddies so effectively close the device
|
|
|
|
|
|
|
|
if ((m_deviceAPI->getSinkBuddies().size() == 0) && (m_deviceAPI->getSourceBuddies().size() == 0))
|
|
|
|
{
|
|
|
|
m_deviceShared.m_dev->close();
|
|
|
|
delete m_deviceShared.m_dev;
|
|
|
|
m_deviceShared.m_dev = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void BladeRF2Output::init()
|
|
|
|
{
|
2022-10-29 23:50:53 -04:00
|
|
|
applySettings(m_settings, QList<QString>(), true);
|
2018-09-28 23:49:14 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
BladeRF2OutputThread *BladeRF2Output::findThread()
|
|
|
|
{
|
|
|
|
if (m_thread == 0) // this does not own the thread
|
|
|
|
{
|
2018-11-04 05:45:59 -05:00
|
|
|
BladeRF2OutputThread *bladeRF2OutputThread = 0;
|
2018-09-28 23:49:14 -04:00
|
|
|
|
|
|
|
// find a buddy that has allocated the thread
|
2019-05-08 16:11:53 -04:00
|
|
|
const std::vector<DeviceAPI*>& sinkBuddies = m_deviceAPI->getSinkBuddies();
|
|
|
|
std::vector<DeviceAPI*>::const_iterator it = sinkBuddies.begin();
|
2018-09-28 23:49:14 -04:00
|
|
|
|
|
|
|
for (; it != sinkBuddies.end(); ++it)
|
|
|
|
{
|
|
|
|
BladeRF2Output *buddySink = ((DeviceBladeRF2Shared*) (*it)->getBuddySharedPtr())->m_sink;
|
|
|
|
|
|
|
|
if (buddySink)
|
|
|
|
{
|
2018-11-04 05:45:59 -05:00
|
|
|
bladeRF2OutputThread = buddySink->getThread();
|
2018-09-28 23:49:14 -04:00
|
|
|
|
2018-11-04 05:45:59 -05:00
|
|
|
if (bladeRF2OutputThread) {
|
2018-09-28 23:49:14 -04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-04 05:45:59 -05:00
|
|
|
return bladeRF2OutputThread;
|
2018-09-28 23:49:14 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return m_thread; // own thread
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void BladeRF2Output::moveThreadToBuddy()
|
|
|
|
{
|
2019-05-08 16:11:53 -04:00
|
|
|
const std::vector<DeviceAPI*>& sinkBuddies = m_deviceAPI->getSinkBuddies();
|
|
|
|
std::vector<DeviceAPI*>::const_iterator it = sinkBuddies.begin();
|
2018-09-28 23:49:14 -04:00
|
|
|
|
|
|
|
for (; it != sinkBuddies.end(); ++it)
|
|
|
|
{
|
|
|
|
BladeRF2Output *buddySink = ((DeviceBladeRF2Shared*) (*it)->getBuddySharedPtr())->m_sink;
|
|
|
|
|
|
|
|
if (buddySink)
|
|
|
|
{
|
|
|
|
buddySink->setThread(m_thread);
|
|
|
|
m_thread = 0; // zero for others
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool BladeRF2Output::start()
|
|
|
|
{
|
|
|
|
// There is a single thread per physical device (Tx side). This thread is unique and referenced by a unique
|
|
|
|
// buddy in the group of sink buddies associated with this physical device.
|
|
|
|
//
|
|
|
|
// This start method is responsible for managing the thread and channel enabling when the streaming of a Tx channel is started
|
|
|
|
//
|
|
|
|
// It checks the following conditions
|
|
|
|
// - the thread is allocated or not (by itself or one of its buddies). If it is it grabs the thread pointer.
|
|
|
|
// - the requested channel is the first (0) or the following (just 1 in BladeRF 2 case)
|
|
|
|
//
|
|
|
|
// The BladeRF support library lets you work in two possible modes:
|
|
|
|
// - Single Output (SO) with only one channel streaming. This HAS to be channel 0.
|
|
|
|
// - Multiple Output (MO) with two channels streaming using interleaved samples. It MUST be in this configuration if channel 1
|
|
|
|
// is used. When we will run with only channel 1 streaming from the client perspective the channel 0 will actually be enabled
|
|
|
|
// and streaming but zero samples will be sent to it.
|
|
|
|
//
|
|
|
|
// It manages the transition form SO where only one channel (the first or channel 0) should be running to the
|
|
|
|
// Multiple Output (MO) if the requested channel is 1. More generally it checks if the requested channel is within the current
|
|
|
|
// channel range allocated in the thread or past it. To perform the transition it stops the thread, deletes it and creates a new one.
|
|
|
|
// It marks the thread as needing start.
|
|
|
|
//
|
|
|
|
// If the requested channel is within the thread channel range (this thread being already allocated) it simply removes its FIFO reference
|
|
|
|
// so that the samples are not taken from the FIFO anymore and leaves the thread unchanged (no stop, no delete/new)
|
|
|
|
//
|
|
|
|
// If there is no thread allocated it creates a new one with a number of channels that fits the requested channel. That is
|
|
|
|
// 1 if channel 0 is requested (SO mode) and 2 if channel 1 is requested (MO mode). It marks the thread as needing start.
|
|
|
|
//
|
|
|
|
// Eventually it registers the FIFO in the thread. If the thread has to be started it enables the channels up to the number of channels
|
|
|
|
// allocated in the thread and starts the thread.
|
|
|
|
|
|
|
|
if (!m_deviceShared.m_dev)
|
|
|
|
{
|
|
|
|
qDebug("BladeRF2Output::start: no device object");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-05-20 18:27:08 -04:00
|
|
|
int requestedChannel = m_deviceAPI->getDeviceItemIndex();
|
2018-09-28 23:49:14 -04:00
|
|
|
BladeRF2OutputThread *bladeRF2OutputThread = findThread();
|
|
|
|
bool needsStart = false;
|
|
|
|
|
|
|
|
if (bladeRF2OutputThread) // if thread is already allocated
|
|
|
|
{
|
|
|
|
qDebug("BladeRF2Output::start: thread is already allocated");
|
|
|
|
|
|
|
|
int nbOriginalChannels = bladeRF2OutputThread->getNbChannels();
|
|
|
|
|
|
|
|
if (requestedChannel+1 > nbOriginalChannels) // expansion by deleting and re-creating the thread
|
|
|
|
{
|
|
|
|
qDebug("BladeRF2Output::start: expand channels. Re-allocate thread and take ownership");
|
|
|
|
|
2019-11-14 19:04:24 -05:00
|
|
|
SampleSourceFifo **fifos = new SampleSourceFifo*[nbOriginalChannels];
|
2018-09-28 23:49:14 -04:00
|
|
|
unsigned int *log2Interps = new unsigned int[nbOriginalChannels];
|
|
|
|
|
|
|
|
for (int i = 0; i < nbOriginalChannels; i++) // save original FIFO references and data
|
|
|
|
{
|
|
|
|
fifos[i] = bladeRF2OutputThread->getFifo(i);
|
|
|
|
log2Interps[i] = bladeRF2OutputThread->getLog2Interpolation(i);
|
|
|
|
}
|
|
|
|
|
|
|
|
bladeRF2OutputThread->stopWork();
|
|
|
|
delete bladeRF2OutputThread;
|
|
|
|
bladeRF2OutputThread = new BladeRF2OutputThread(m_deviceShared.m_dev->getDev(), requestedChannel+1);
|
|
|
|
m_thread = bladeRF2OutputThread; // take ownership
|
|
|
|
|
|
|
|
for (int i = 0; i < nbOriginalChannels; i++) // restore original FIFO references
|
|
|
|
{
|
|
|
|
bladeRF2OutputThread->setFifo(i, fifos[i]);
|
|
|
|
bladeRF2OutputThread->setLog2Interpolation(i, log2Interps[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
// remove old thread address from buddies (reset in all buddies)
|
2019-05-08 16:11:53 -04:00
|
|
|
const std::vector<DeviceAPI*>& sinkBuddies = m_deviceAPI->getSinkBuddies();
|
|
|
|
std::vector<DeviceAPI*>::const_iterator it = sinkBuddies.begin();
|
2018-09-28 23:49:14 -04:00
|
|
|
|
|
|
|
for (; it != sinkBuddies.end(); ++it) {
|
|
|
|
((DeviceBladeRF2Shared*) (*it)->getBuddySharedPtr())->m_sink->setThread(0);
|
|
|
|
}
|
|
|
|
|
2018-10-02 00:11:34 -04:00
|
|
|
// close all channels
|
|
|
|
for (int i = bladeRF2OutputThread->getNbChannels()-1; i >= 0; i--) {
|
|
|
|
m_deviceShared.m_dev->closeTx(i);
|
|
|
|
}
|
|
|
|
|
2018-11-18 03:39:22 -05:00
|
|
|
// was used as temporary storage:
|
|
|
|
delete[] fifos;
|
|
|
|
delete[] log2Interps;
|
|
|
|
|
2018-09-28 23:49:14 -04:00
|
|
|
needsStart = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
qDebug("BladeRF2Output::start: keep buddy thread");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else // first allocation
|
|
|
|
{
|
|
|
|
qDebug("BladeRF2Output::start: allocate thread and take ownership");
|
|
|
|
bladeRF2OutputThread = new BladeRF2OutputThread(m_deviceShared.m_dev->getDev(), requestedChannel+1);
|
|
|
|
m_thread = bladeRF2OutputThread; // take ownership
|
|
|
|
needsStart = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bladeRF2OutputThread->setFifo(requestedChannel, &m_sampleSourceFifo);
|
|
|
|
bladeRF2OutputThread->setLog2Interpolation(requestedChannel, m_settings.m_log2Interp);
|
|
|
|
|
2022-10-29 23:50:53 -04:00
|
|
|
applySettings(m_settings, QList<QString>(), true); // re-apply forcibly to set sample rate with the new number of channels
|
2018-09-30 17:42:52 -04:00
|
|
|
|
2018-09-28 23:49:14 -04:00
|
|
|
if (needsStart)
|
|
|
|
{
|
2018-10-02 00:11:34 -04:00
|
|
|
qDebug("BladeRF2Output::start: enabling channel(s) and (re)starting the thread");
|
2018-09-28 23:49:14 -04:00
|
|
|
|
2018-10-02 00:11:34 -04:00
|
|
|
for (unsigned int i = 0; i < bladeRF2OutputThread->getNbChannels(); i++) // open all channels
|
2018-09-28 23:49:14 -04:00
|
|
|
{
|
|
|
|
if (!m_deviceShared.m_dev->openTx(i)) {
|
|
|
|
qCritical("BladeRF2Output::start: channel %u cannot be enabled", i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bladeRF2OutputThread->startWork();
|
|
|
|
}
|
|
|
|
|
|
|
|
qDebug("BladeRF2Output::start: started");
|
|
|
|
m_running = true;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void BladeRF2Output::stop()
|
|
|
|
{
|
|
|
|
// This stop method is responsible for managing the thread and channel disabling when the streaming of
|
|
|
|
// a Tx channel is stopped
|
|
|
|
//
|
|
|
|
// If the thread is currently managing only one channel (SO mode). The thread can be just stopped and deleted.
|
|
|
|
// Then the channel is closed (disabled).
|
|
|
|
//
|
|
|
|
// If the thread is currently managing many channels (MO mode) and we are removing the last channel. The transition
|
|
|
|
// from MO to SO or reduction of MO size is handled by stopping the thread, deleting it and creating a new one
|
|
|
|
// with one channel less if (and only if) there is still a channel active.
|
|
|
|
//
|
|
|
|
// If the thread is currently managing many channels (MO mode) but the channel being stopped is not the last
|
|
|
|
// channel then the FIFO reference is simply removed from the thread so that this FIFO will not be used anymore.
|
|
|
|
// In this case the channel is not closed (disabled) so that other channels can continue with the
|
|
|
|
// same configuration. The device continues streaming on this channel but the samples are set to all zeros.
|
|
|
|
|
|
|
|
if (!m_running) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-05-20 18:27:08 -04:00
|
|
|
int requestedChannel = m_deviceAPI->getDeviceItemIndex();
|
2018-09-28 23:49:14 -04:00
|
|
|
BladeRF2OutputThread *bladeRF2OutputThread = findThread();
|
|
|
|
|
|
|
|
if (bladeRF2OutputThread == 0) { // no thread allocated
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
int nbOriginalChannels = bladeRF2OutputThread->getNbChannels();
|
|
|
|
|
|
|
|
if (nbOriginalChannels == 1) // SO mode => just stop and delete the thread
|
|
|
|
{
|
|
|
|
qDebug("BladeRF2Output::stop: SO mode. Just stop and delete the thread");
|
|
|
|
bladeRF2OutputThread->stopWork();
|
|
|
|
delete bladeRF2OutputThread;
|
2024-08-18 18:42:57 -04:00
|
|
|
m_thread = nullptr;
|
2018-09-28 23:49:14 -04:00
|
|
|
|
|
|
|
// remove old thread address from buddies (reset in all buddies)
|
2019-05-08 16:11:53 -04:00
|
|
|
const std::vector<DeviceAPI*>& sinkBuddies = m_deviceAPI->getSinkBuddies();
|
|
|
|
std::vector<DeviceAPI*>::const_iterator it = sinkBuddies.begin();
|
2018-09-28 23:49:14 -04:00
|
|
|
|
|
|
|
for (; it != sinkBuddies.end(); ++it) {
|
2024-08-18 18:42:57 -04:00
|
|
|
((DeviceBladeRF2Shared*) (*it)->getBuddySharedPtr())->m_sink->setThread(nullptr);
|
2018-09-28 23:49:14 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
m_deviceShared.m_dev->closeTx(0); // close the unique channel
|
|
|
|
}
|
|
|
|
else if (requestedChannel == nbOriginalChannels - 1) // remove last MO channel => reduce by deleting and re-creating the thread
|
|
|
|
{
|
|
|
|
qDebug("BladeRF2Output::stop: MO mode. Reduce by deleting and re-creating the thread");
|
|
|
|
bladeRF2OutputThread->stopWork();
|
2019-11-14 19:04:24 -05:00
|
|
|
SampleSourceFifo **fifos = new SampleSourceFifo*[nbOriginalChannels-1];
|
2018-09-28 23:49:14 -04:00
|
|
|
unsigned int *log2Interps = new unsigned int[nbOriginalChannels-1];
|
|
|
|
bool stillActiveFIFO = false;
|
|
|
|
|
|
|
|
for (int i = 0; i < nbOriginalChannels-1; i++) // save original FIFO references
|
|
|
|
{
|
|
|
|
fifos[i] = bladeRF2OutputThread->getFifo(i);
|
2024-08-18 18:42:57 -04:00
|
|
|
stillActiveFIFO = stillActiveFIFO || (bladeRF2OutputThread->getFifo(i) != nullptr);
|
2018-09-28 23:49:14 -04:00
|
|
|
log2Interps[i] = bladeRF2OutputThread->getLog2Interpolation(i);
|
|
|
|
}
|
|
|
|
|
|
|
|
delete bladeRF2OutputThread;
|
|
|
|
m_thread = 0;
|
|
|
|
|
|
|
|
if (stillActiveFIFO)
|
|
|
|
{
|
|
|
|
bladeRF2OutputThread = new BladeRF2OutputThread(m_deviceShared.m_dev->getDev(), nbOriginalChannels-1);
|
|
|
|
m_thread = bladeRF2OutputThread; // take ownership
|
|
|
|
|
|
|
|
for (int i = 0; i < nbOriginalChannels-1; i++) // restore original FIFO references
|
|
|
|
{
|
|
|
|
bladeRF2OutputThread->setFifo(i, fifos[i]);
|
|
|
|
bladeRF2OutputThread->setLog2Interpolation(i, log2Interps[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
qDebug("BladeRF2Output::stop: do not re-create thread as there are no more FIFOs active");
|
|
|
|
}
|
|
|
|
|
|
|
|
// remove old thread address from buddies (reset in all buddies)
|
2019-05-08 16:11:53 -04:00
|
|
|
const std::vector<DeviceAPI*>& sinkBuddies = m_deviceAPI->getSinkBuddies();
|
|
|
|
std::vector<DeviceAPI*>::const_iterator it = sinkBuddies.begin();
|
2018-09-28 23:49:14 -04:00
|
|
|
|
|
|
|
for (; it != sinkBuddies.end(); ++it) {
|
2024-08-18 18:42:57 -04:00
|
|
|
((DeviceBladeRF2Shared*) (*it)->getBuddySharedPtr())->m_sink->setThread(nullptr);
|
2018-09-28 23:49:14 -04:00
|
|
|
}
|
|
|
|
|
2018-10-02 00:11:34 -04:00
|
|
|
// close all channels
|
|
|
|
for (int i = nbOriginalChannels-1; i >= 0; i--) {
|
|
|
|
m_deviceShared.m_dev->closeTx(i);
|
2018-09-30 17:42:52 -04:00
|
|
|
}
|
|
|
|
|
2018-10-02 00:11:34 -04:00
|
|
|
if (stillActiveFIFO)
|
|
|
|
{
|
|
|
|
qDebug("BladeRF2Output::stop: enabling channel(s) and restarting the thread");
|
|
|
|
|
|
|
|
for (unsigned int i = 0; i < bladeRF2OutputThread->getNbChannels(); i++) // open all channels
|
|
|
|
{
|
|
|
|
if (!m_deviceShared.m_dev->openTx(i)) {
|
|
|
|
qCritical("BladeRF2Output::start: channel %u cannot be enabled", i);
|
|
|
|
}
|
|
|
|
}
|
2018-09-28 23:49:14 -04:00
|
|
|
|
|
|
|
bladeRF2OutputThread->startWork();
|
|
|
|
}
|
2018-11-18 03:39:22 -05:00
|
|
|
|
|
|
|
// was used as temporary storage:
|
|
|
|
delete[] fifos;
|
|
|
|
delete[] log2Interps;
|
2018-09-28 23:49:14 -04:00
|
|
|
}
|
|
|
|
else // remove channel from existing thread
|
|
|
|
{
|
|
|
|
qDebug("BladeRF2Output::stop: MO mode. Not changing MO configuration. Just remove FIFO reference");
|
2024-08-18 18:42:57 -04:00
|
|
|
bladeRF2OutputThread->setFifo(requestedChannel, nullptr); // remove FIFO
|
2018-09-28 23:49:14 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
m_running = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
QByteArray BladeRF2Output::serialize() const
|
|
|
|
{
|
|
|
|
return m_settings.serialize();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool BladeRF2Output::deserialize(const QByteArray& data)
|
|
|
|
{
|
|
|
|
bool success = true;
|
|
|
|
|
|
|
|
if (!m_settings.deserialize(data))
|
|
|
|
{
|
|
|
|
m_settings.resetToDefaults();
|
|
|
|
success = false;
|
|
|
|
}
|
|
|
|
|
2022-10-29 23:50:53 -04:00
|
|
|
MsgConfigureBladeRF2* message = MsgConfigureBladeRF2::create(m_settings, QList<QString>(), true);
|
2018-09-28 23:49:14 -04:00
|
|
|
m_inputMessageQueue.push(message);
|
|
|
|
|
|
|
|
if (m_guiMessageQueue)
|
|
|
|
{
|
2022-10-29 23:50:53 -04:00
|
|
|
MsgConfigureBladeRF2* messageToGUI = MsgConfigureBladeRF2::create(m_settings, QList<QString>(), true);
|
2018-09-28 23:49:14 -04:00
|
|
|
m_guiMessageQueue->push(messageToGUI);
|
|
|
|
}
|
|
|
|
|
|
|
|
return success;
|
|
|
|
}
|
|
|
|
|
|
|
|
const QString& BladeRF2Output::getDeviceDescription() const
|
|
|
|
{
|
|
|
|
return m_deviceDescription;
|
|
|
|
}
|
|
|
|
|
|
|
|
int BladeRF2Output::getSampleRate() const
|
|
|
|
{
|
|
|
|
int rate = m_settings.m_devSampleRate;
|
|
|
|
return (rate / (1<<m_settings.m_log2Interp));
|
|
|
|
}
|
|
|
|
|
|
|
|
quint64 BladeRF2Output::getCenterFrequency() const
|
|
|
|
{
|
|
|
|
return m_settings.m_centerFrequency;
|
|
|
|
}
|
|
|
|
|
|
|
|
void BladeRF2Output::setCenterFrequency(qint64 centerFrequency)
|
|
|
|
{
|
|
|
|
BladeRF2OutputSettings settings = m_settings;
|
|
|
|
settings.m_centerFrequency = centerFrequency;
|
|
|
|
|
2022-10-29 23:50:53 -04:00
|
|
|
MsgConfigureBladeRF2* message = MsgConfigureBladeRF2::create(settings, QList<QString>{"centerFrequency"}, false);
|
2018-09-28 23:49:14 -04:00
|
|
|
m_inputMessageQueue.push(message);
|
|
|
|
|
|
|
|
if (m_guiMessageQueue)
|
|
|
|
{
|
2022-10-29 23:50:53 -04:00
|
|
|
MsgConfigureBladeRF2* messageToGUI = MsgConfigureBladeRF2::create(settings, QList<QString>{"centerFrequency"}, false);
|
2018-09-28 23:49:14 -04:00
|
|
|
m_guiMessageQueue->push(messageToGUI);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-04 12:42:51 -05:00
|
|
|
bool BladeRF2Output::setDeviceCenterFrequency(struct bladerf *dev, int requestedChannel, quint64 freq_hz, int loPpmTenths)
|
2018-09-30 04:59:52 -04:00
|
|
|
{
|
2018-11-04 12:42:51 -05:00
|
|
|
qint64 df = ((qint64)freq_hz * loPpmTenths) / 10000000LL;
|
2018-09-30 04:59:52 -04:00
|
|
|
freq_hz += df;
|
|
|
|
|
|
|
|
int status = bladerf_set_frequency(dev, BLADERF_CHANNEL_TX(requestedChannel), freq_hz);
|
|
|
|
|
|
|
|
if (status < 0) {
|
|
|
|
qWarning("BladeRF2Output::setDeviceCenterFrequency: bladerf_set_frequency(%lld) failed: %s",
|
|
|
|
freq_hz, bladerf_strerror(status));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
qDebug("BladeRF2Output::setDeviceCenterFrequency: bladerf_set_frequency(%lld)", freq_hz);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-14 17:19:05 -04:00
|
|
|
void BladeRF2Output::getFrequencyRange(uint64_t& min, uint64_t& max, int& step, float& scale)
|
2018-09-28 23:49:14 -04:00
|
|
|
{
|
|
|
|
if (m_deviceShared.m_dev) {
|
2020-09-14 17:19:05 -04:00
|
|
|
m_deviceShared.m_dev->getFrequencyRangeTx(min, max, step, scale);
|
2018-09-28 23:49:14 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-14 17:19:05 -04:00
|
|
|
void BladeRF2Output::getSampleRateRange(int& min, int& max, int& step, float& scale)
|
2018-09-28 23:49:14 -04:00
|
|
|
{
|
|
|
|
if (m_deviceShared.m_dev) {
|
2020-09-14 17:19:05 -04:00
|
|
|
m_deviceShared.m_dev->getSampleRateRangeTx(min, max, step, scale);
|
2018-09-28 23:49:14 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-14 17:19:05 -04:00
|
|
|
void BladeRF2Output::getBandwidthRange(int& min, int& max, int& step, float& scale)
|
2018-09-28 23:49:14 -04:00
|
|
|
{
|
|
|
|
if (m_deviceShared.m_dev) {
|
2020-09-14 17:19:05 -04:00
|
|
|
m_deviceShared.m_dev->getBandwidthRangeTx(min, max, step, scale);
|
2018-09-28 23:49:14 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-14 17:04:35 -04:00
|
|
|
void BladeRF2Output::getGlobalGainRange(int& min, int& max, int& step, float& scale)
|
2018-09-28 23:49:14 -04:00
|
|
|
{
|
|
|
|
if (m_deviceShared.m_dev) {
|
2020-09-14 17:04:35 -04:00
|
|
|
m_deviceShared.m_dev->getGlobalGainRangeTx(min, max, step, scale);
|
2018-09-28 23:49:14 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool BladeRF2Output::handleMessage(const Message& message)
|
|
|
|
{
|
|
|
|
if (MsgConfigureBladeRF2::match(message))
|
|
|
|
{
|
|
|
|
MsgConfigureBladeRF2& conf = (MsgConfigureBladeRF2&) message;
|
|
|
|
qDebug() << "BladeRF2Output::handleMessage: MsgConfigureBladeRF2";
|
|
|
|
|
2022-10-29 23:50:53 -04:00
|
|
|
if (!applySettings(conf.getSettings(), conf.getSettingsKeys(), conf.getForce()))
|
2018-09-28 23:49:14 -04:00
|
|
|
{
|
|
|
|
qDebug("BladeRF2Output::handleMessage: MsgConfigureBladeRF2 config error");
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else if (DeviceBladeRF2Shared::MsgReportBuddyChange::match(message))
|
|
|
|
{
|
|
|
|
DeviceBladeRF2Shared::MsgReportBuddyChange& report = (DeviceBladeRF2Shared::MsgReportBuddyChange&) message;
|
|
|
|
struct bladerf *dev = m_deviceShared.m_dev->getDev();
|
|
|
|
BladeRF2OutputSettings settings = m_settings;
|
|
|
|
int status;
|
|
|
|
unsigned int tmp_uint;
|
|
|
|
bool tmp_bool;
|
|
|
|
|
|
|
|
// evaluate changes that may have been introduced by changes in a buddy
|
|
|
|
|
|
|
|
if (dev) // The BladeRF device must have been open to do so
|
|
|
|
{
|
2019-05-20 18:27:08 -04:00
|
|
|
int requestedChannel = m_deviceAPI->getDeviceItemIndex();
|
2022-10-29 23:50:53 -04:00
|
|
|
QList<QString> settingsKeys;
|
2018-09-28 23:49:14 -04:00
|
|
|
|
|
|
|
if (report.getRxElseTx()) // Rx buddy change: check for sample rate change only
|
|
|
|
{
|
2018-10-08 20:08:06 -04:00
|
|
|
settings.m_devSampleRate = report.getDevSampleRate();
|
2022-10-29 23:50:53 -04:00
|
|
|
settingsKeys.append("devSampleRate");
|
2018-09-30 17:42:52 -04:00
|
|
|
// status = bladerf_get_sample_rate(dev, BLADERF_CHANNEL_TX(requestedChannel), &tmp_uint);
|
|
|
|
//
|
|
|
|
// if (status < 0) {
|
|
|
|
// qCritical("BladeRF2Output::handleMessage: MsgReportBuddyChange: bladerf_get_sample_rate error: %s", bladerf_strerror(status));
|
|
|
|
// } else {
|
2018-10-08 20:08:06 -04:00
|
|
|
// settings.m_devSampleRate = tmp_uint;
|
2018-09-30 17:42:52 -04:00
|
|
|
// }
|
2018-09-28 23:49:14 -04:00
|
|
|
}
|
|
|
|
else // Tx buddy change: check for: frequency, gain mode and value, bias tee, sample rate, bandwidth
|
|
|
|
{
|
|
|
|
settings.m_devSampleRate = report.getDevSampleRate();
|
2018-09-30 04:59:52 -04:00
|
|
|
settings.m_LOppmTenths = report.getLOppmTenths();
|
2018-09-28 23:49:14 -04:00
|
|
|
settings.m_centerFrequency = report.getCenterFrequency();
|
2022-10-29 23:50:53 -04:00
|
|
|
settingsKeys.append("devSampleRate");
|
|
|
|
settingsKeys.append("LOppmTenths");
|
|
|
|
settingsKeys.append("centerFrequency");
|
2018-09-28 23:49:14 -04:00
|
|
|
|
|
|
|
status = bladerf_get_bandwidth(dev, BLADERF_CHANNEL_TX(requestedChannel), &tmp_uint);
|
|
|
|
|
|
|
|
if (status < 0) {
|
|
|
|
qCritical("BladeRF2Output::handleMessage: MsgReportBuddyChange: bladerf_get_bandwidth error: %s", bladerf_strerror(status));
|
|
|
|
} else {
|
|
|
|
settings.m_bandwidth = tmp_uint;
|
2022-10-29 23:50:53 -04:00
|
|
|
settingsKeys.append("bandwidth");
|
2018-09-28 23:49:14 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
status = bladerf_get_bias_tee(dev, BLADERF_CHANNEL_TX(requestedChannel), &tmp_bool);
|
|
|
|
|
|
|
|
if (status < 0) {
|
|
|
|
qCritical("BladeRF2Output::handleMessage: MsgReportBuddyChange: bladerf_get_bias_tee error: %s", bladerf_strerror(status));
|
|
|
|
} else {
|
|
|
|
settings.m_biasTee = tmp_bool;
|
2022-10-29 23:50:53 -04:00
|
|
|
settingsKeys.append("biasTee");
|
2018-09-28 23:49:14 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// change DSP settings if buddy change introduced a change in center frequency or base rate
|
2022-10-29 23:50:53 -04:00
|
|
|
if (settingsKeys.contains("centerFrequency") || settingsKeys.contains("devSampleRate"))
|
2018-09-28 23:49:14 -04:00
|
|
|
{
|
|
|
|
int sampleRate = settings.m_devSampleRate/(1<<settings.m_log2Interp);
|
|
|
|
DSPSignalNotification *notif = new DSPSignalNotification(sampleRate, settings.m_centerFrequency);
|
|
|
|
m_deviceAPI->getDeviceEngineInputMessageQueue()->push(notif);
|
|
|
|
}
|
|
|
|
|
2022-10-29 23:50:53 -04:00
|
|
|
m_settings.applySettings(settingsKeys, settings); // acknowledge the new settings
|
2018-09-28 23:49:14 -04:00
|
|
|
|
|
|
|
// propagate settings to GUI if any
|
|
|
|
if (getMessageQueueToGUI())
|
|
|
|
{
|
2022-10-29 23:50:53 -04:00
|
|
|
MsgConfigureBladeRF2 *reportToGUI = MsgConfigureBladeRF2::create(m_settings, settingsKeys, false);
|
2018-09-28 23:49:14 -04:00
|
|
|
getMessageQueueToGUI()->push(reportToGUI);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else if (MsgStartStop::match(message))
|
|
|
|
{
|
|
|
|
MsgStartStop& cmd = (MsgStartStop&) message;
|
|
|
|
qDebug() << "BladeRF2Input::handleMessage: MsgStartStop: " << (cmd.getStartStop() ? "start" : "stop");
|
|
|
|
|
|
|
|
if (cmd.getStartStop())
|
|
|
|
{
|
2022-10-29 23:50:53 -04:00
|
|
|
if (m_deviceAPI->initDeviceEngine()) {
|
2019-05-08 16:11:53 -04:00
|
|
|
m_deviceAPI->startDeviceEngine();
|
2018-09-28 23:49:14 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-05-08 16:11:53 -04:00
|
|
|
m_deviceAPI->stopDeviceEngine();
|
2018-09-28 23:49:14 -04:00
|
|
|
}
|
|
|
|
|
2018-12-26 13:22:52 -05:00
|
|
|
if (m_settings.m_useReverseAPI) {
|
|
|
|
webapiReverseSendStartStop(cmd.getStartStop());
|
|
|
|
}
|
|
|
|
|
2018-09-28 23:49:14 -04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-29 23:50:53 -04:00
|
|
|
bool BladeRF2Output::applySettings(const BladeRF2OutputSettings& settings, const QList<QString>& settingsKeys, bool force)
|
2018-09-28 23:49:14 -04:00
|
|
|
{
|
2022-10-29 23:50:53 -04:00
|
|
|
qDebug() << "BladeRF2Output::applySettings: force:" << force << settings.getDebugString(settingsKeys, force);
|
2018-09-28 23:49:14 -04:00
|
|
|
bool forwardChangeOwnDSP = false;
|
|
|
|
bool forwardChangeRxBuddies = false;
|
|
|
|
bool forwardChangeTxBuddies = false;
|
|
|
|
|
|
|
|
struct bladerf *dev = m_deviceShared.m_dev->getDev();
|
2019-05-20 18:27:08 -04:00
|
|
|
int requestedChannel = m_deviceAPI->getDeviceItemIndex();
|
2018-10-03 00:14:26 -04:00
|
|
|
qint64 deviceCenterFrequency = settings.m_centerFrequency;
|
|
|
|
deviceCenterFrequency -= settings.m_transverterMode ? settings.m_transverterDeltaFrequency : 0;
|
|
|
|
deviceCenterFrequency = deviceCenterFrequency < 0 ? 0 : deviceCenterFrequency;
|
2018-09-28 23:49:14 -04:00
|
|
|
|
2022-10-29 23:50:53 -04:00
|
|
|
// if ((m_settings.m_devSampleRate != settings.m_devSampleRate) ||
|
|
|
|
// (m_settings.m_log2Interp != settings.m_log2Interp) || force)
|
|
|
|
if (settingsKeys.contains("devSampleRate") ||
|
|
|
|
settingsKeys.contains("log2Interp") || force)
|
2018-09-29 15:40:22 -04:00
|
|
|
{
|
|
|
|
BladeRF2OutputThread *bladeRF2OutputThread = findThread();
|
2019-11-14 19:04:24 -05:00
|
|
|
SampleSourceFifo *fifo = nullptr;
|
2018-09-29 15:40:22 -04:00
|
|
|
|
|
|
|
if (bladeRF2OutputThread)
|
|
|
|
{
|
|
|
|
fifo = bladeRF2OutputThread->getFifo(requestedChannel);
|
|
|
|
bladeRF2OutputThread->setFifo(requestedChannel, 0);
|
|
|
|
}
|
|
|
|
|
2019-11-15 03:37:14 -05:00
|
|
|
#if defined(_MSC_VER)
|
|
|
|
unsigned int fifoRate = (unsigned int) settings.m_devSampleRate / (1<<settings.m_log2Interp);
|
|
|
|
fifoRate = fifoRate < 48000U ? 48000U : fifoRate;
|
|
|
|
#else
|
2019-11-14 19:04:24 -05:00
|
|
|
unsigned int fifoRate = std::max(
|
|
|
|
(unsigned int) settings.m_devSampleRate / (1<<settings.m_log2Interp),
|
|
|
|
DeviceBladeRF2Shared::m_sampleFifoMinRate);
|
2019-11-15 03:37:14 -05:00
|
|
|
#endif
|
2019-11-14 19:04:24 -05:00
|
|
|
m_sampleSourceFifo.resize(SampleSourceFifo::getSizePolicy(fifoRate));
|
2018-09-29 15:40:22 -04:00
|
|
|
|
|
|
|
if (fifo) {
|
|
|
|
bladeRF2OutputThread->setFifo(requestedChannel, &m_sampleSourceFifo);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-29 23:50:53 -04:00
|
|
|
if (settingsKeys.contains("devSampleRate") || force)
|
2018-09-28 23:49:14 -04:00
|
|
|
{
|
|
|
|
forwardChangeOwnDSP = true;
|
|
|
|
forwardChangeRxBuddies = true;
|
|
|
|
forwardChangeTxBuddies = true;
|
|
|
|
|
|
|
|
if (dev != 0)
|
|
|
|
{
|
|
|
|
unsigned int actualSamplerate;
|
2018-09-30 17:42:52 -04:00
|
|
|
|
|
|
|
int status = bladerf_set_sample_rate(dev, BLADERF_CHANNEL_TX(requestedChannel),
|
2018-10-08 20:08:06 -04:00
|
|
|
settings.m_devSampleRate,
|
2018-09-30 17:42:52 -04:00
|
|
|
&actualSamplerate);
|
2018-09-28 23:49:14 -04:00
|
|
|
|
|
|
|
if (status < 0)
|
|
|
|
{
|
|
|
|
qCritical("BladeRF2Output::applySettings: could not set sample rate: %d: %s",
|
|
|
|
settings.m_devSampleRate, bladerf_strerror(status));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-09-29 15:40:22 -04:00
|
|
|
qDebug() << "BladeRF2Output::applySettings: bladerf_set_sample_rate: actual sample rate is " << actualSamplerate;
|
2018-09-28 23:49:14 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-29 23:50:53 -04:00
|
|
|
if (settingsKeys.contains("bandwidth") || force)
|
2018-09-28 23:49:14 -04:00
|
|
|
{
|
|
|
|
forwardChangeTxBuddies = true;
|
|
|
|
|
|
|
|
if (dev != 0)
|
|
|
|
{
|
|
|
|
unsigned int actualBandwidth;
|
|
|
|
int status = bladerf_set_bandwidth(dev, BLADERF_CHANNEL_TX(requestedChannel), settings.m_bandwidth, &actualBandwidth);
|
|
|
|
|
|
|
|
if(status < 0)
|
|
|
|
{
|
|
|
|
qCritical("BladeRF2Output::applySettings: could not set bandwidth: %d: %s",
|
|
|
|
settings.m_bandwidth, bladerf_strerror(status));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-09-29 15:40:22 -04:00
|
|
|
qDebug() << "BladeRF2Output::applySettings: bladerf_set_bandwidth: actual bandwidth is " << actualBandwidth;
|
2018-09-28 23:49:14 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-29 23:50:53 -04:00
|
|
|
if (settingsKeys.contains("log2Interp") || force)
|
2018-09-28 23:49:14 -04:00
|
|
|
{
|
|
|
|
forwardChangeOwnDSP = true;
|
|
|
|
BladeRF2OutputThread *outputThread = findThread();
|
|
|
|
|
|
|
|
if (outputThread != 0)
|
|
|
|
{
|
|
|
|
outputThread->setLog2Interpolation(requestedChannel, settings.m_log2Interp);
|
|
|
|
qDebug() << "BladeRF2Output::applySettings: set interpolation to " << (1<<settings.m_log2Interp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-29 23:50:53 -04:00
|
|
|
if (settingsKeys.contains("centerFrequency")
|
|
|
|
|| settingsKeys.contains("transverterMode")
|
|
|
|
|| settingsKeys.contains("transverterDeltaFrequency")
|
|
|
|
|| settingsKeys.contains("LOppmTenths")
|
|
|
|
|| settingsKeys.contains("devSampleRate") || force)
|
2018-09-28 23:49:14 -04:00
|
|
|
{
|
|
|
|
forwardChangeOwnDSP = true;
|
|
|
|
forwardChangeTxBuddies = true;
|
|
|
|
|
|
|
|
if (dev != 0)
|
|
|
|
{
|
2018-11-04 12:42:51 -05:00
|
|
|
if (setDeviceCenterFrequency(dev, requestedChannel, deviceCenterFrequency, settings.m_LOppmTenths))
|
2018-09-28 23:49:14 -04:00
|
|
|
{
|
|
|
|
if (getMessageQueueToGUI())
|
|
|
|
{
|
|
|
|
int min, max, step;
|
2020-09-14 17:04:35 -04:00
|
|
|
float scale;
|
|
|
|
getGlobalGainRange(min, max, step, scale);
|
|
|
|
MsgReportGainRange *msg = MsgReportGainRange::create(min, max, step, scale);
|
2018-09-28 23:49:14 -04:00
|
|
|
getMessageQueueToGUI()->push(msg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-29 23:50:53 -04:00
|
|
|
if (settingsKeys.contains("biasTee") || force)
|
2018-09-28 23:49:14 -04:00
|
|
|
{
|
|
|
|
forwardChangeTxBuddies = true;
|
|
|
|
m_deviceShared.m_dev->setBiasTeeTx(settings.m_biasTee);
|
|
|
|
}
|
|
|
|
|
2022-10-29 23:50:53 -04:00
|
|
|
if (settingsKeys.contains("globalGain") || force)
|
2018-09-28 23:49:14 -04:00
|
|
|
{
|
|
|
|
forwardChangeTxBuddies = true;
|
|
|
|
|
|
|
|
if (dev)
|
|
|
|
{
|
|
|
|
// qDebug("BladeRF2Output::applySettings: channel: %d gain: %d", requestedChannel, settings.m_globalGain);
|
|
|
|
int status = bladerf_set_gain(dev, BLADERF_CHANNEL_TX(requestedChannel), settings.m_globalGain);
|
|
|
|
|
|
|
|
if (status < 0) {
|
|
|
|
qWarning("BladeRF2Output::applySettings: bladerf_set_gain(%d) failed: %s",
|
|
|
|
settings.m_globalGain, bladerf_strerror(status));
|
|
|
|
} else {
|
|
|
|
qDebug("BladeRF2Output::applySettings: bladerf_set_gain(%d)", settings.m_globalGain);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (forwardChangeOwnDSP)
|
|
|
|
{
|
|
|
|
int sampleRate = settings.m_devSampleRate/(1<<settings.m_log2Interp);
|
|
|
|
DSPSignalNotification *notif = new DSPSignalNotification(sampleRate, settings.m_centerFrequency);
|
|
|
|
m_deviceAPI->getDeviceEngineInputMessageQueue()->push(notif);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (forwardChangeRxBuddies)
|
|
|
|
{
|
|
|
|
// send to source buddies
|
2019-05-08 16:11:53 -04:00
|
|
|
const std::vector<DeviceAPI*>& sourceBuddies = m_deviceAPI->getSourceBuddies();
|
|
|
|
std::vector<DeviceAPI*>::const_iterator itSource = sourceBuddies.begin();
|
2018-09-28 23:49:14 -04:00
|
|
|
|
|
|
|
for (; itSource != sourceBuddies.end(); ++itSource)
|
|
|
|
{
|
|
|
|
DeviceBladeRF2Shared::MsgReportBuddyChange *report = DeviceBladeRF2Shared::MsgReportBuddyChange::create(
|
|
|
|
settings.m_centerFrequency,
|
2018-09-30 04:59:52 -04:00
|
|
|
settings.m_LOppmTenths,
|
|
|
|
2,
|
2018-10-08 20:08:06 -04:00
|
|
|
settings.m_devSampleRate, // need to forward actual rate to the Rx side
|
2018-09-28 23:49:14 -04:00
|
|
|
false);
|
2019-05-08 16:11:53 -04:00
|
|
|
(*itSource)->getSamplingDeviceInputMessageQueue()->push(report);
|
2018-09-28 23:49:14 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (forwardChangeTxBuddies)
|
|
|
|
{
|
|
|
|
// send to sink buddies
|
2019-05-08 16:11:53 -04:00
|
|
|
const std::vector<DeviceAPI*>& sinkBuddies = m_deviceAPI->getSinkBuddies();
|
|
|
|
std::vector<DeviceAPI*>::const_iterator itSink = sinkBuddies.begin();
|
2018-09-28 23:49:14 -04:00
|
|
|
|
|
|
|
for (; itSink != sinkBuddies.end(); ++itSink)
|
|
|
|
{
|
|
|
|
DeviceBladeRF2Shared::MsgReportBuddyChange *report = DeviceBladeRF2Shared::MsgReportBuddyChange::create(
|
|
|
|
settings.m_centerFrequency,
|
2018-09-30 04:59:52 -04:00
|
|
|
settings.m_LOppmTenths,
|
|
|
|
2,
|
2018-09-28 23:49:14 -04:00
|
|
|
settings.m_devSampleRate,
|
|
|
|
false);
|
2019-05-08 16:11:53 -04:00
|
|
|
(*itSink)->getSamplingDeviceInputMessageQueue()->push(report);
|
2018-09-28 23:49:14 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-04-14 12:58:12 -04:00
|
|
|
if (settings.m_useReverseAPI)
|
2018-12-26 13:22:52 -05:00
|
|
|
{
|
2022-10-29 23:50:53 -04:00
|
|
|
bool fullUpdate = (settingsKeys.contains("useReverseAPI") && settings.m_useReverseAPI) ||
|
|
|
|
settingsKeys.contains("reverseAPIAddress") ||
|
|
|
|
settingsKeys.contains("reverseAPIPort") ||
|
|
|
|
settingsKeys.contains("reverseAPIDeviceIndex");
|
|
|
|
webapiReverseSendSettings(settingsKeys, settings, fullUpdate || force);
|
2018-12-26 13:22:52 -05:00
|
|
|
}
|
|
|
|
|
2022-10-29 23:50:53 -04:00
|
|
|
if (force) {
|
|
|
|
m_settings = settings;
|
|
|
|
} else {
|
|
|
|
m_settings.applySettings(settingsKeys, settings);
|
|
|
|
}
|
2018-09-28 23:49:14 -04:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-09-30 17:42:52 -04:00
|
|
|
int BladeRF2Output::getNbChannels()
|
|
|
|
{
|
|
|
|
BladeRF2OutputThread *bladeRF2OutputThread = findThread();
|
|
|
|
|
|
|
|
if (bladeRF2OutputThread) {
|
|
|
|
return bladeRF2OutputThread->getNbChannels();
|
|
|
|
} else {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-28 23:49:14 -04:00
|
|
|
int BladeRF2Output::webapiSettingsGet(
|
|
|
|
SWGSDRangel::SWGDeviceSettings& response,
|
2018-11-13 02:51:14 -05:00
|
|
|
QString& errorMessage)
|
2018-09-28 23:49:14 -04:00
|
|
|
{
|
2018-11-13 02:51:14 -05:00
|
|
|
(void) errorMessage;
|
2018-09-28 23:49:14 -04:00
|
|
|
response.setBladeRf2OutputSettings(new SWGSDRangel::SWGBladeRF2OutputSettings());
|
|
|
|
response.getBladeRf2OutputSettings()->init();
|
|
|
|
webapiFormatDeviceSettings(response, m_settings);
|
|
|
|
return 200;
|
|
|
|
}
|
|
|
|
|
|
|
|
int BladeRF2Output::webapiSettingsPutPatch(
|
|
|
|
bool force,
|
|
|
|
const QStringList& deviceSettingsKeys,
|
|
|
|
SWGSDRangel::SWGDeviceSettings& response, // query + response
|
2018-11-13 02:51:14 -05:00
|
|
|
QString& errorMessage)
|
2018-09-28 23:49:14 -04:00
|
|
|
{
|
2018-11-13 02:51:14 -05:00
|
|
|
(void) errorMessage;
|
2018-09-28 23:49:14 -04:00
|
|
|
BladeRF2OutputSettings settings = m_settings;
|
2019-08-04 14:24:44 -04:00
|
|
|
webapiUpdateDeviceSettings(settings, deviceSettingsKeys, response);
|
2018-09-28 23:49:14 -04:00
|
|
|
|
2022-10-29 23:50:53 -04:00
|
|
|
MsgConfigureBladeRF2 *msg = MsgConfigureBladeRF2::create(settings, deviceSettingsKeys, force);
|
2019-08-04 14:24:44 -04:00
|
|
|
m_inputMessageQueue.push(msg);
|
|
|
|
|
|
|
|
if (m_guiMessageQueue) // forward to GUI if any
|
|
|
|
{
|
2022-10-29 23:50:53 -04:00
|
|
|
MsgConfigureBladeRF2 *msgToGUI = MsgConfigureBladeRF2::create(settings, deviceSettingsKeys, force);
|
2019-08-04 14:24:44 -04:00
|
|
|
m_guiMessageQueue->push(msgToGUI);
|
|
|
|
}
|
|
|
|
|
|
|
|
webapiFormatDeviceSettings(response, settings);
|
|
|
|
return 200;
|
|
|
|
}
|
|
|
|
|
2019-08-05 12:29:09 -04:00
|
|
|
void BladeRF2Output::webapiUpdateDeviceSettings(
|
2019-08-04 14:24:44 -04:00
|
|
|
BladeRF2OutputSettings& settings,
|
|
|
|
const QStringList& deviceSettingsKeys,
|
|
|
|
SWGSDRangel::SWGDeviceSettings& response)
|
|
|
|
{
|
2018-09-28 23:49:14 -04:00
|
|
|
if (deviceSettingsKeys.contains("centerFrequency")) {
|
|
|
|
settings.m_centerFrequency = response.getBladeRf2OutputSettings()->getCenterFrequency();
|
|
|
|
}
|
2018-09-30 05:10:07 -04:00
|
|
|
if (deviceSettingsKeys.contains("LOppmTenths")) {
|
|
|
|
settings.m_LOppmTenths = response.getBladeRf2OutputSettings()->getLOppmTenths();
|
|
|
|
}
|
2018-09-28 23:49:14 -04:00
|
|
|
if (deviceSettingsKeys.contains("devSampleRate")) {
|
|
|
|
settings.m_devSampleRate = response.getBladeRf2OutputSettings()->getDevSampleRate();
|
|
|
|
}
|
|
|
|
if (deviceSettingsKeys.contains("bandwidth")) {
|
|
|
|
settings.m_bandwidth = response.getBladeRf2OutputSettings()->getBandwidth();
|
|
|
|
}
|
|
|
|
if (deviceSettingsKeys.contains("log2Interp")) {
|
|
|
|
settings.m_log2Interp = response.getBladeRf2OutputSettings()->getLog2Interp();
|
|
|
|
}
|
|
|
|
if (deviceSettingsKeys.contains("biasTee")) {
|
|
|
|
settings.m_biasTee = response.getBladeRf2OutputSettings()->getBiasTee() != 0;
|
|
|
|
}
|
|
|
|
if (deviceSettingsKeys.contains("globalGain")) {
|
|
|
|
settings.m_globalGain = response.getBladeRf2OutputSettings()->getGlobalGain();
|
|
|
|
}
|
2018-10-03 00:14:26 -04:00
|
|
|
if (deviceSettingsKeys.contains("transverterDeltaFrequency")) {
|
|
|
|
settings.m_transverterDeltaFrequency = response.getBladeRf2OutputSettings()->getTransverterDeltaFrequency();
|
|
|
|
}
|
|
|
|
if (deviceSettingsKeys.contains("transverterMode")) {
|
|
|
|
settings.m_transverterMode = response.getBladeRf2OutputSettings()->getTransverterMode() != 0;
|
|
|
|
}
|
2019-01-11 08:45:00 -05:00
|
|
|
if (deviceSettingsKeys.contains("useReverseAPI")) {
|
|
|
|
settings.m_useReverseAPI = response.getBladeRf2OutputSettings()->getUseReverseApi() != 0;
|
|
|
|
}
|
|
|
|
if (deviceSettingsKeys.contains("reverseAPIAddress")) {
|
|
|
|
settings.m_reverseAPIAddress = *response.getBladeRf2OutputSettings()->getReverseApiAddress();
|
|
|
|
}
|
|
|
|
if (deviceSettingsKeys.contains("reverseAPIPort")) {
|
|
|
|
settings.m_reverseAPIPort = response.getBladeRf2OutputSettings()->getReverseApiPort();
|
|
|
|
}
|
|
|
|
if (deviceSettingsKeys.contains("reverseAPIDeviceIndex")) {
|
|
|
|
settings.m_reverseAPIDeviceIndex = response.getBladeRf2OutputSettings()->getReverseApiDeviceIndex();
|
|
|
|
}
|
2018-09-28 23:49:14 -04:00
|
|
|
}
|
|
|
|
|
2018-11-13 02:51:14 -05:00
|
|
|
int BladeRF2Output::webapiReportGet(SWGSDRangel::SWGDeviceReport& response, QString& errorMessage)
|
2018-09-28 23:49:14 -04:00
|
|
|
{
|
2018-11-13 02:51:14 -05:00
|
|
|
(void) errorMessage;
|
2018-09-28 23:49:14 -04:00
|
|
|
response.setBladeRf2OutputReport(new SWGSDRangel::SWGBladeRF2OutputReport());
|
|
|
|
response.getBladeRf2OutputReport()->init();
|
|
|
|
webapiFormatDeviceReport(response);
|
|
|
|
return 200;
|
|
|
|
}
|
|
|
|
|
|
|
|
void BladeRF2Output::webapiFormatDeviceSettings(SWGSDRangel::SWGDeviceSettings& response, const BladeRF2OutputSettings& settings)
|
|
|
|
{
|
|
|
|
response.getBladeRf2OutputSettings()->setCenterFrequency(settings.m_centerFrequency);
|
2018-09-30 05:10:07 -04:00
|
|
|
response.getBladeRf2OutputSettings()->setLOppmTenths(settings.m_LOppmTenths);
|
2018-09-28 23:49:14 -04:00
|
|
|
response.getBladeRf2OutputSettings()->setDevSampleRate(settings.m_devSampleRate);
|
|
|
|
response.getBladeRf2OutputSettings()->setBandwidth(settings.m_bandwidth);
|
|
|
|
response.getBladeRf2OutputSettings()->setLog2Interp(settings.m_log2Interp);
|
|
|
|
response.getBladeRf2OutputSettings()->setBiasTee(settings.m_biasTee ? 1 : 0);
|
|
|
|
response.getBladeRf2OutputSettings()->setGlobalGain(settings.m_globalGain);
|
2018-10-03 00:14:26 -04:00
|
|
|
response.getBladeRf2OutputSettings()->setTransverterDeltaFrequency(settings.m_transverterDeltaFrequency);
|
|
|
|
response.getBladeRf2OutputSettings()->setTransverterMode(settings.m_transverterMode ? 1 : 0);
|
2019-01-11 08:45:00 -05:00
|
|
|
|
|
|
|
response.getBladeRf2OutputSettings()->setUseReverseApi(settings.m_useReverseAPI ? 1 : 0);
|
|
|
|
|
|
|
|
if (response.getBladeRf2OutputSettings()->getReverseApiAddress()) {
|
|
|
|
*response.getBladeRf2OutputSettings()->getReverseApiAddress() = settings.m_reverseAPIAddress;
|
|
|
|
} else {
|
|
|
|
response.getBladeRf2OutputSettings()->setReverseApiAddress(new QString(settings.m_reverseAPIAddress));
|
|
|
|
}
|
|
|
|
|
|
|
|
response.getBladeRf2OutputSettings()->setReverseApiPort(settings.m_reverseAPIPort);
|
|
|
|
response.getBladeRf2OutputSettings()->setReverseApiDeviceIndex(settings.m_reverseAPIDeviceIndex);
|
2018-09-28 23:49:14 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void BladeRF2Output::webapiFormatDeviceReport(SWGSDRangel::SWGDeviceReport& response)
|
|
|
|
{
|
|
|
|
DeviceBladeRF2 *device = m_deviceShared.m_dev;
|
|
|
|
|
|
|
|
if (device)
|
|
|
|
{
|
|
|
|
int min, max, step;
|
2020-09-14 17:04:35 -04:00
|
|
|
float scale;
|
2018-09-28 23:49:14 -04:00
|
|
|
uint64_t f_min, f_max;
|
|
|
|
|
2020-09-14 17:19:05 -04:00
|
|
|
device->getBandwidthRangeTx(min, max, step, scale);
|
2018-09-28 23:49:14 -04:00
|
|
|
|
|
|
|
response.getBladeRf2OutputReport()->setBandwidthRange(new SWGSDRangel::SWGRange);
|
|
|
|
response.getBladeRf2OutputReport()->getBandwidthRange()->setMin(min);
|
|
|
|
response.getBladeRf2OutputReport()->getBandwidthRange()->setMax(max);
|
|
|
|
response.getBladeRf2OutputReport()->getBandwidthRange()->setStep(step);
|
2020-09-14 17:38:06 -04:00
|
|
|
response.getBladeRf2OutputReport()->getBandwidthRange()->setScale(scale);
|
2018-09-28 23:49:14 -04:00
|
|
|
|
2020-09-14 17:19:05 -04:00
|
|
|
device->getFrequencyRangeTx(f_min, f_max, step, scale);
|
2018-09-28 23:49:14 -04:00
|
|
|
|
|
|
|
response.getBladeRf2OutputReport()->setFrequencyRange(new SWGSDRangel::SWGFrequencyRange);
|
|
|
|
response.getBladeRf2OutputReport()->getFrequencyRange()->setMin(f_min);
|
|
|
|
response.getBladeRf2OutputReport()->getFrequencyRange()->setMax(f_max);
|
|
|
|
response.getBladeRf2OutputReport()->getFrequencyRange()->setStep(step);
|
2020-09-14 17:38:06 -04:00
|
|
|
response.getBladeRf2OutputReport()->getBandwidthRange()->setScale(scale);
|
2018-09-28 23:49:14 -04:00
|
|
|
|
2020-09-14 17:04:35 -04:00
|
|
|
device->getGlobalGainRangeTx(min, max, step, scale);
|
2018-09-28 23:49:14 -04:00
|
|
|
|
|
|
|
response.getBladeRf2OutputReport()->setGlobalGainRange(new SWGSDRangel::SWGRange);
|
|
|
|
response.getBladeRf2OutputReport()->getGlobalGainRange()->setMin(min);
|
|
|
|
response.getBladeRf2OutputReport()->getGlobalGainRange()->setMax(max);
|
|
|
|
response.getBladeRf2OutputReport()->getGlobalGainRange()->setStep(step);
|
2020-09-14 17:38:06 -04:00
|
|
|
response.getBladeRf2OutputReport()->getBandwidthRange()->setScale(scale);
|
2018-09-28 23:49:14 -04:00
|
|
|
|
2020-09-14 17:19:05 -04:00
|
|
|
device->getSampleRateRangeTx(min, max, step, scale);
|
2018-09-28 23:49:14 -04:00
|
|
|
|
|
|
|
response.getBladeRf2OutputReport()->setSampleRateRange(new SWGSDRangel::SWGRange);
|
|
|
|
response.getBladeRf2OutputReport()->getSampleRateRange()->setMin(min);
|
|
|
|
response.getBladeRf2OutputReport()->getSampleRateRange()->setMax(max);
|
|
|
|
response.getBladeRf2OutputReport()->getSampleRateRange()->setStep(step);
|
2020-09-14 17:38:06 -04:00
|
|
|
response.getBladeRf2OutputReport()->getBandwidthRange()->setScale(scale);
|
2018-09-28 23:49:14 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int BladeRF2Output::webapiRunGet(
|
|
|
|
SWGSDRangel::SWGDeviceState& response,
|
2018-11-13 02:51:14 -05:00
|
|
|
QString& errorMessage)
|
2018-09-28 23:49:14 -04:00
|
|
|
{
|
2018-11-13 02:51:14 -05:00
|
|
|
(void) errorMessage;
|
2018-09-28 23:49:14 -04:00
|
|
|
m_deviceAPI->getDeviceEngineStateStr(*response.getState());
|
|
|
|
return 200;
|
|
|
|
}
|
|
|
|
|
|
|
|
int BladeRF2Output::webapiRun(
|
|
|
|
bool run,
|
|
|
|
SWGSDRangel::SWGDeviceState& response,
|
2018-11-13 02:51:14 -05:00
|
|
|
QString& errorMessage)
|
2018-09-28 23:49:14 -04:00
|
|
|
{
|
2018-11-13 02:51:14 -05:00
|
|
|
(void) errorMessage;
|
2018-09-28 23:49:14 -04:00
|
|
|
m_deviceAPI->getDeviceEngineStateStr(*response.getState());
|
|
|
|
MsgStartStop *message = MsgStartStop::create(run);
|
|
|
|
m_inputMessageQueue.push(message);
|
|
|
|
|
|
|
|
if (m_guiMessageQueue) // forward to GUI if any
|
|
|
|
{
|
|
|
|
MsgStartStop *msgToGUI = MsgStartStop::create(run);
|
|
|
|
m_guiMessageQueue->push(msgToGUI);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 200;
|
|
|
|
}
|
|
|
|
|
2022-10-29 23:50:53 -04:00
|
|
|
void BladeRF2Output::webapiReverseSendSettings(const QList<QString>& deviceSettingsKeys, const BladeRF2OutputSettings& settings, bool force)
|
2018-12-26 13:22:52 -05:00
|
|
|
{
|
|
|
|
SWGSDRangel::SWGDeviceSettings *swgDeviceSettings = new SWGSDRangel::SWGDeviceSettings();
|
2019-05-07 08:43:38 -04:00
|
|
|
swgDeviceSettings->setDirection(1); // single Tx
|
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("BladeRF2"));
|
|
|
|
swgDeviceSettings->setBladeRf2OutputSettings(new SWGSDRangel::SWGBladeRF2OutputSettings());
|
|
|
|
SWGSDRangel::SWGBladeRF2OutputSettings *swgBladeRF2OutputSettings = swgDeviceSettings->getBladeRf2OutputSettings();
|
|
|
|
|
|
|
|
// transfer data that has been modified. When force is on transfer all data except reverse API data
|
|
|
|
|
|
|
|
if (deviceSettingsKeys.contains("centerFrequency") || force) {
|
|
|
|
swgBladeRF2OutputSettings->setCenterFrequency(settings.m_centerFrequency);
|
|
|
|
}
|
|
|
|
if (deviceSettingsKeys.contains("LOppmTenths") || force) {
|
|
|
|
swgBladeRF2OutputSettings->setLOppmTenths(settings.m_LOppmTenths);
|
|
|
|
}
|
|
|
|
if (deviceSettingsKeys.contains("devSampleRate") || force) {
|
|
|
|
swgBladeRF2OutputSettings->setDevSampleRate(settings.m_devSampleRate);
|
|
|
|
}
|
|
|
|
if (deviceSettingsKeys.contains("bandwidth") || force) {
|
|
|
|
swgBladeRF2OutputSettings->setBandwidth(settings.m_bandwidth);
|
|
|
|
}
|
|
|
|
if (deviceSettingsKeys.contains("log2Interp") || force) {
|
|
|
|
swgBladeRF2OutputSettings->setLog2Interp(settings.m_log2Interp);
|
|
|
|
}
|
|
|
|
if (deviceSettingsKeys.contains("biasTee") || force) {
|
|
|
|
swgBladeRF2OutputSettings->setBiasTee(settings.m_biasTee ? 1 : 0);
|
|
|
|
}
|
|
|
|
if (deviceSettingsKeys.contains("globalGain") || force) {
|
|
|
|
swgBladeRF2OutputSettings->setGlobalGain(settings.m_globalGain);
|
|
|
|
}
|
|
|
|
if (deviceSettingsKeys.contains("transverterDeltaFrequency") || force) {
|
|
|
|
swgBladeRF2OutputSettings->setTransverterDeltaFrequency(settings.m_transverterDeltaFrequency);
|
|
|
|
}
|
|
|
|
if (deviceSettingsKeys.contains("transverterMode") || force) {
|
|
|
|
swgBladeRF2OutputSettings->setTransverterMode(settings.m_transverterMode ? 1 : 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
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");
|
|
|
|
|
2019-11-14 19:04:24 -05:00
|
|
|
QBuffer *buffer = new QBuffer();
|
2018-12-26 13:22:52 -05:00
|
|
|
buffer->open((QBuffer::ReadWrite));
|
|
|
|
buffer->write(swgDeviceSettings->asJson().toUtf8());
|
|
|
|
buffer->seek(0);
|
|
|
|
|
|
|
|
// Always use PATCH to avoid passing reverse API settings
|
2019-11-14 19:04:24 -05:00
|
|
|
QNetworkReply *reply = m_networkManager->sendCustomRequest(m_networkRequest, "PATCH", buffer);
|
|
|
|
buffer->setParent(reply);
|
2018-12-26 13:22:52 -05:00
|
|
|
|
|
|
|
delete swgDeviceSettings;
|
|
|
|
}
|
|
|
|
|
|
|
|
void BladeRF2Output::webapiReverseSendStartStop(bool start)
|
|
|
|
{
|
2019-03-25 10:26:01 -04:00
|
|
|
SWGSDRangel::SWGDeviceSettings *swgDeviceSettings = new SWGSDRangel::SWGDeviceSettings();
|
2019-05-07 08:43:38 -04:00
|
|
|
swgDeviceSettings->setDirection(1); // single Tx
|
2019-03-25 10:26:01 -04:00
|
|
|
swgDeviceSettings->setOriginatorIndex(m_deviceAPI->getDeviceSetIndex());
|
|
|
|
swgDeviceSettings->setDeviceHwType(new QString("BladeRF2"));
|
|
|
|
|
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");
|
|
|
|
|
2019-11-14 19:04:24 -05:00
|
|
|
QBuffer *buffer = new QBuffer();
|
2019-03-25 10:26:01 -04:00
|
|
|
buffer->open((QBuffer::ReadWrite));
|
|
|
|
buffer->write(swgDeviceSettings->asJson().toUtf8());
|
|
|
|
buffer->seek(0);
|
2019-11-14 19:04:24 -05:00
|
|
|
QNetworkReply *reply;
|
2018-12-26 13:22:52 -05:00
|
|
|
|
|
|
|
if (start) {
|
2019-11-14 19:04:24 -05:00
|
|
|
reply = m_networkManager->sendCustomRequest(m_networkRequest, "POST", buffer);
|
2018-12-26 13:22:52 -05:00
|
|
|
} else {
|
2019-11-14 19:04:24 -05:00
|
|
|
reply = m_networkManager->sendCustomRequest(m_networkRequest, "DELETE", buffer);
|
2018-12-26 13:22:52 -05:00
|
|
|
}
|
2019-06-14 10:58:09 -04:00
|
|
|
|
2019-11-14 19:04:24 -05:00
|
|
|
buffer->setParent(reply);
|
2019-06-14 10:58:09 -04:00
|
|
|
delete swgDeviceSettings;
|
2018-12-26 13:22:52 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void BladeRF2Output::networkManagerFinished(QNetworkReply *reply)
|
|
|
|
{
|
|
|
|
QNetworkReply::NetworkError replyError = reply->error();
|
|
|
|
|
|
|
|
if (replyError)
|
|
|
|
{
|
|
|
|
qWarning() << "BladeRF2Output::networkManagerFinished:"
|
|
|
|
<< " error(" << (int) replyError
|
|
|
|
<< "): " << replyError
|
|
|
|
<< ": " << reply->errorString();
|
|
|
|
}
|
2019-11-14 19:04:24 -05:00
|
|
|
else
|
|
|
|
{
|
|
|
|
QString answer = reply->readAll();
|
|
|
|
answer.chop(1); // remove last \n
|
|
|
|
qDebug("BladeRF2Output::networkManagerFinished: reply:\n%s", answer.toStdString().c_str());
|
|
|
|
}
|
2018-12-26 13:22:52 -05:00
|
|
|
}
|