2018-09-23 13:56:24 -04:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Copyright (C) 2018 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:57:41 -04:00
|
|
|
// (at your option) any later version. //
|
2018-09-23 13:56:24 -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 <QDebug>
|
2018-12-25 15:05:24 -05:00
|
|
|
#include <QNetworkReply>
|
|
|
|
#include <QBuffer>
|
2018-09-23 13:56:24 -04:00
|
|
|
|
2018-09-25 11:03:34 -04:00
|
|
|
#include "libbladeRF.h"
|
|
|
|
|
2018-09-23 13:56:24 -04:00
|
|
|
#include "SWGDeviceSettings.h"
|
|
|
|
#include "SWGBladeRF2InputSettings.h"
|
|
|
|
#include "SWGDeviceState.h"
|
|
|
|
#include "SWGDeviceReport.h"
|
|
|
|
#include "SWGBladeRF2InputReport.h"
|
|
|
|
|
2019-05-08 16:11:53 -04:00
|
|
|
#include "device/deviceapi.h"
|
2018-09-23 13:56:24 -04:00
|
|
|
#include "dsp/dspcommands.h"
|
|
|
|
#include "dsp/filerecord.h"
|
|
|
|
#include "dsp/dspengine.h"
|
|
|
|
|
|
|
|
#include "bladerf2/devicebladerf2shared.h"
|
|
|
|
#include "bladerf2/devicebladerf2.h"
|
2018-09-23 20:01:10 -04:00
|
|
|
#include "bladerf2inputthread.h"
|
2018-09-23 13:56:24 -04:00
|
|
|
#include "bladerf2input.h"
|
|
|
|
|
|
|
|
|
|
|
|
MESSAGE_CLASS_DEFINITION(BladeRF2Input::MsgConfigureBladeRF2, Message)
|
|
|
|
MESSAGE_CLASS_DEFINITION(BladeRF2Input::MsgFileRecord, Message)
|
|
|
|
MESSAGE_CLASS_DEFINITION(BladeRF2Input::MsgStartStop, Message)
|
2018-09-25 17:43:52 -04:00
|
|
|
MESSAGE_CLASS_DEFINITION(BladeRF2Input::MsgReportGainRange, Message)
|
2018-09-23 13:56:24 -04:00
|
|
|
|
2019-05-08 16:11:53 -04:00
|
|
|
BladeRF2Input::BladeRF2Input(DeviceAPI *deviceAPI) :
|
2018-09-23 13:56:24 -04:00
|
|
|
m_deviceAPI(deviceAPI),
|
|
|
|
m_settings(),
|
|
|
|
m_deviceDescription("BladeRF2Input"),
|
2018-09-25 02:45:57 -04:00
|
|
|
m_running(false),
|
|
|
|
m_thread(0)
|
2018-09-23 13:56:24 -04:00
|
|
|
{
|
|
|
|
openDevice();
|
|
|
|
|
2018-09-25 19:54:23 -04:00
|
|
|
if (m_deviceShared.m_dev)
|
|
|
|
{
|
|
|
|
const bladerf_gain_modes *modes = 0;
|
|
|
|
int nbModes = m_deviceShared.m_dev->getGainModesRx(&modes);
|
|
|
|
|
|
|
|
if (modes)
|
|
|
|
{
|
|
|
|
for (int i = 0; i < nbModes; i++) {
|
|
|
|
m_gainModes.push_back(GainMode{QString(modes[i].name), modes[i].mode});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-23 13:56:24 -04:00
|
|
|
m_fileSink = new FileRecord(QString("test_%1.sdriq").arg(m_deviceAPI->getDeviceUID()));
|
2019-05-20 18:27:08 -04:00
|
|
|
m_deviceAPI->setNbSourceStreams(1);
|
2019-05-08 16:11:53 -04:00
|
|
|
m_deviceAPI->addAncillarySink(m_fileSink);
|
2018-12-25 15:05:24 -05:00
|
|
|
m_networkManager = new QNetworkAccessManager();
|
|
|
|
connect(m_networkManager, SIGNAL(finished(QNetworkReply*)), this, SLOT(networkManagerFinished(QNetworkReply*)));
|
2018-09-23 13:56:24 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
BladeRF2Input::~BladeRF2Input()
|
|
|
|
{
|
2018-12-25 15:05:24 -05:00
|
|
|
disconnect(m_networkManager, SIGNAL(finished(QNetworkReply*)), this, SLOT(networkManagerFinished(QNetworkReply*)));
|
|
|
|
delete m_networkManager;
|
|
|
|
|
2018-09-23 13:56:24 -04:00
|
|
|
if (m_running) {
|
|
|
|
stop();
|
|
|
|
}
|
|
|
|
|
2019-05-08 16:11:53 -04:00
|
|
|
m_deviceAPI->removeAncillarySink(m_fileSink);
|
2018-09-23 13:56:24 -04:00
|
|
|
delete m_fileSink;
|
|
|
|
closeDevice();
|
|
|
|
}
|
|
|
|
|
|
|
|
void BladeRF2Input::destroy()
|
|
|
|
{
|
|
|
|
delete this;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool BladeRF2Input::openDevice()
|
|
|
|
{
|
|
|
|
if (!m_sampleFifo.setSize(96000 * 4))
|
|
|
|
{
|
|
|
|
qCritical("BladeRF2Input::openDevice: could not allocate SampleFifo");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
qDebug("BladeRF2Input::openDevice: allocated SampleFifo");
|
|
|
|
}
|
|
|
|
|
|
|
|
// look for Rx buddies and get reference to the device object
|
|
|
|
if (m_deviceAPI->getSourceBuddies().size() > 0) // look source sibling first
|
|
|
|
{
|
|
|
|
qDebug("BladeRF2Input::openDevice: look in Rx buddies");
|
|
|
|
|
2019-05-08 16:11:53 -04:00
|
|
|
DeviceAPI *sourceBuddy = m_deviceAPI->getSourceBuddies()[0];
|
2018-09-23 13:56:24 -04:00
|
|
|
DeviceBladeRF2Shared *deviceBladeRF2Shared = (DeviceBladeRF2Shared*) sourceBuddy->getBuddySharedPtr();
|
|
|
|
|
|
|
|
if (deviceBladeRF2Shared == 0)
|
|
|
|
{
|
|
|
|
qCritical("BladeRF2Input::openDevice: the source buddy shared pointer is null");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
DeviceBladeRF2 *device = deviceBladeRF2Shared->m_dev;
|
|
|
|
|
|
|
|
if (device == 0)
|
|
|
|
{
|
|
|
|
qCritical("BladeRF2Input::openDevice: cannot get device pointer from Rx buddy");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_deviceShared.m_dev = device;
|
|
|
|
}
|
|
|
|
// look for Tx buddies and get reference to the device object
|
|
|
|
else if (m_deviceAPI->getSinkBuddies().size() > 0) // then sink
|
|
|
|
{
|
|
|
|
qDebug("BladeRF2Input::openDevice: look in Tx buddies");
|
|
|
|
|
2019-05-08 16:11:53 -04:00
|
|
|
DeviceAPI *sinkBuddy = m_deviceAPI->getSinkBuddies()[0];
|
2018-09-23 13:56:24 -04:00
|
|
|
DeviceBladeRF2Shared *deviceBladeRF2Shared = (DeviceBladeRF2Shared*) sinkBuddy->getBuddySharedPtr();
|
|
|
|
|
|
|
|
if (deviceBladeRF2Shared == 0)
|
|
|
|
{
|
|
|
|
qCritical("BladeRF2Input::openDevice: the sink buddy shared pointer is null");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
DeviceBladeRF2 *device = deviceBladeRF2Shared->m_dev;
|
|
|
|
|
|
|
|
if (device == 0)
|
|
|
|
{
|
2018-09-28 23:49:14 -04:00
|
|
|
qCritical("BladeRF2Input::openDevice: cannot get device pointer from Tx buddy");
|
2018-09-23 13:56:24 -04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_deviceShared.m_dev = device;
|
|
|
|
}
|
|
|
|
// There are no buddies then create the first BladeRF2 device
|
|
|
|
else
|
|
|
|
{
|
|
|
|
qDebug("BladeRF2Input::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-23 13:56:24 -04:00
|
|
|
|
|
|
|
if (!m_deviceShared.m_dev->open(serial))
|
|
|
|
{
|
|
|
|
qCritical("BladeRF2Input::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-25 08:19:57 -04:00
|
|
|
m_deviceShared.m_source = this;
|
2018-09-23 13:56:24 -04:00
|
|
|
m_deviceAPI->setBuddySharedPtr(&m_deviceShared); // propagate common parameters to API
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void BladeRF2Input::closeDevice()
|
|
|
|
{
|
|
|
|
if (m_deviceShared.m_dev == 0) { // was never open
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (m_running) {
|
|
|
|
stop();
|
|
|
|
}
|
|
|
|
|
2018-09-25 08:31:57 -04:00
|
|
|
if (m_thread) { // stills own the thread => transfer to a buddy
|
|
|
|
moveThreadToBuddy();
|
|
|
|
}
|
|
|
|
|
2018-09-26 02:54:40 -04:00
|
|
|
m_deviceShared.m_channel = -1; // publicly release channel
|
2018-09-25 08:19:57 -04:00
|
|
|
m_deviceShared.m_source = 0;
|
2018-09-23 13:56:24 -04:00
|
|
|
|
|
|
|
// 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 BladeRF2Input::init()
|
|
|
|
{
|
|
|
|
applySettings(m_settings, true);
|
|
|
|
}
|
|
|
|
|
2018-09-25 08:19:57 -04:00
|
|
|
BladeRF2InputThread *BladeRF2Input::findThread()
|
|
|
|
{
|
|
|
|
if (m_thread == 0) // this does not own the thread
|
|
|
|
{
|
|
|
|
BladeRF2InputThread *bladerf2InputThread = 0;
|
|
|
|
|
|
|
|
// find a buddy that has allocated the thread
|
2019-05-08 16:11:53 -04:00
|
|
|
const std::vector<DeviceAPI*>& sourceBuddies = m_deviceAPI->getSourceBuddies();
|
|
|
|
std::vector<DeviceAPI*>::const_iterator it = sourceBuddies.begin();
|
2018-09-25 08:19:57 -04:00
|
|
|
|
|
|
|
for (; it != sourceBuddies.end(); ++it)
|
|
|
|
{
|
|
|
|
BladeRF2Input *buddySource = ((DeviceBladeRF2Shared*) (*it)->getBuddySharedPtr())->m_source;
|
|
|
|
|
|
|
|
if (buddySource)
|
|
|
|
{
|
|
|
|
bladerf2InputThread = buddySource->getThread();
|
|
|
|
|
|
|
|
if (bladerf2InputThread) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return bladerf2InputThread;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return m_thread; // own thread
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-25 08:31:57 -04:00
|
|
|
void BladeRF2Input::moveThreadToBuddy()
|
|
|
|
{
|
2019-05-08 16:11:53 -04:00
|
|
|
const std::vector<DeviceAPI*>& sourceBuddies = m_deviceAPI->getSourceBuddies();
|
|
|
|
std::vector<DeviceAPI*>::const_iterator it = sourceBuddies.begin();
|
2018-09-25 08:31:57 -04:00
|
|
|
|
|
|
|
for (; it != sourceBuddies.end(); ++it)
|
|
|
|
{
|
|
|
|
BladeRF2Input *buddySource = ((DeviceBladeRF2Shared*) (*it)->getBuddySharedPtr())->m_source;
|
|
|
|
|
|
|
|
if (buddySource)
|
|
|
|
{
|
|
|
|
buddySource->setThread(m_thread);
|
|
|
|
m_thread = 0; // zero for others
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-23 20:01:10 -04:00
|
|
|
bool BladeRF2Input::start()
|
|
|
|
{
|
2018-09-26 08:56:33 -04:00
|
|
|
// There is a single thread per physical device (Rx side). This thread is unique and referenced by a unique
|
|
|
|
// buddy in the group of source buddies associated with this physical device.
|
|
|
|
//
|
|
|
|
// This start method is responsible for managing the thread and channel enabling when the streaming of a Rx 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 Input (SI) with only one channel streaming. This HAS to be channel 0.
|
|
|
|
// - Multiple Input (MI) with two channels streaming using interleaved samples. It MUST be in this configuration if channel 1
|
|
|
|
// is used irrespective of what you actually do with samples coming from channel 0. When we will run with only channel 1
|
|
|
|
// streaming from the client perspective the channel 0 will actually be enabled and streaming but its samples will
|
|
|
|
// just be disregarded.
|
|
|
|
//
|
|
|
|
// It manages the transition form SI where only one channel (the first or channel 0) should be running to the
|
|
|
|
// Multiple Input (MI) 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.
|
|
|
|
//
|
2018-11-02 05:16:14 -04:00
|
|
|
// If the requested channel is within the thread channel range (this thread being already allocated) it simply adds its FIFO reference
|
|
|
|
// so that the samples are fed to the FIFO and leaves the thread unchanged (no stop, no delete/new)
|
2018-09-26 08:56:33 -04:00
|
|
|
//
|
|
|
|
// 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 (SI mode) and 2 if channel 1 is requested (MI 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.
|
|
|
|
|
2018-09-23 20:01:10 -04:00
|
|
|
if (!m_deviceShared.m_dev)
|
|
|
|
{
|
2018-09-28 23:49:14 -04:00
|
|
|
qDebug("BladeRF2Input::start: no device object");
|
2018-09-23 20:01:10 -04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-05-20 18:27:08 -04:00
|
|
|
int requestedChannel = m_deviceAPI->getDeviceItemIndex();
|
2018-09-25 08:19:57 -04:00
|
|
|
BladeRF2InputThread *bladerf2InputThread = findThread();
|
2018-09-23 20:01:10 -04:00
|
|
|
bool needsStart = false;
|
|
|
|
|
2018-09-25 08:19:57 -04:00
|
|
|
if (bladerf2InputThread) // if thread is already allocated
|
2018-09-23 20:01:10 -04:00
|
|
|
{
|
2018-09-28 23:49:14 -04:00
|
|
|
qDebug("BladeRF2Input::start: thread is already allocated");
|
2018-09-25 21:07:55 -04:00
|
|
|
|
2018-09-23 20:01:10 -04:00
|
|
|
int nbOriginalChannels = bladerf2InputThread->getNbChannels();
|
|
|
|
|
2018-09-25 21:20:24 -04:00
|
|
|
if (requestedChannel+1 > nbOriginalChannels) // expansion by deleting and re-creating the thread
|
2018-09-23 20:01:10 -04:00
|
|
|
{
|
2018-09-28 23:49:14 -04:00
|
|
|
qDebug("BladeRF2Input::start: expand channels. Re-allocate thread and take ownership");
|
2018-09-25 21:07:55 -04:00
|
|
|
|
2018-09-23 20:01:10 -04:00
|
|
|
SampleSinkFifo **fifos = new SampleSinkFifo*[nbOriginalChannels];
|
|
|
|
unsigned int *log2Decims = new unsigned int[nbOriginalChannels];
|
|
|
|
int *fcPoss = new int[nbOriginalChannels];
|
|
|
|
|
2018-09-25 08:19:57 -04:00
|
|
|
for (int i = 0; i < nbOriginalChannels; i++) // save original FIFO references and data
|
|
|
|
{
|
2018-09-23 20:01:10 -04:00
|
|
|
fifos[i] = bladerf2InputThread->getFifo(i);
|
|
|
|
log2Decims[i] = bladerf2InputThread->getLog2Decimation(i);
|
|
|
|
fcPoss[i] = bladerf2InputThread->getFcPos(i);
|
|
|
|
}
|
|
|
|
|
|
|
|
bladerf2InputThread->stopWork();
|
|
|
|
delete bladerf2InputThread;
|
2018-09-25 21:20:24 -04:00
|
|
|
bladerf2InputThread = new BladeRF2InputThread(m_deviceShared.m_dev->getDev(), requestedChannel+1);
|
2018-09-25 08:19:57 -04:00
|
|
|
m_thread = bladerf2InputThread; // take ownership
|
2018-09-23 20:01:10 -04:00
|
|
|
|
2018-09-25 08:19:57 -04:00
|
|
|
for (int i = 0; i < nbOriginalChannels; i++) // restore original FIFO references
|
|
|
|
{
|
2018-09-23 20:01:10 -04:00
|
|
|
bladerf2InputThread->setFifo(i, fifos[i]);
|
|
|
|
bladerf2InputThread->setLog2Decimation(i, log2Decims[i]);
|
|
|
|
bladerf2InputThread->setFcPos(i, fcPoss[i]);
|
|
|
|
}
|
|
|
|
|
2018-11-02 05:16:14 -04:00
|
|
|
// remove old thread address from buddies (reset in all buddies). The address being held only in the owning source.
|
2019-05-08 16:11:53 -04:00
|
|
|
const std::vector<DeviceAPI*>& sourceBuddies = m_deviceAPI->getSourceBuddies();
|
|
|
|
std::vector<DeviceAPI*>::const_iterator it = sourceBuddies.begin();
|
2018-09-23 20:01:10 -04:00
|
|
|
|
|
|
|
for (; it != sourceBuddies.end(); ++it) {
|
2018-09-25 08:31:57 -04:00
|
|
|
((DeviceBladeRF2Shared*) (*it)->getBuddySharedPtr())->m_source->setThread(0);
|
2018-09-23 20:01:10 -04:00
|
|
|
}
|
|
|
|
|
2018-11-18 03:39:22 -05:00
|
|
|
// was used as temporary storage:
|
|
|
|
delete[] fifos;
|
|
|
|
delete[] log2Decims;
|
|
|
|
delete[] fcPoss;
|
|
|
|
|
2018-09-23 20:01:10 -04:00
|
|
|
needsStart = true;
|
|
|
|
}
|
2018-09-25 21:07:55 -04:00
|
|
|
else
|
|
|
|
{
|
2018-09-28 23:49:14 -04:00
|
|
|
qDebug("BladeRF2Input::start: keep buddy thread");
|
2018-09-25 21:07:55 -04:00
|
|
|
}
|
2018-09-23 20:01:10 -04:00
|
|
|
}
|
|
|
|
else // first allocation
|
|
|
|
{
|
2018-09-28 23:49:14 -04:00
|
|
|
qDebug("BladeRF2Input::start: allocate thread and take ownership");
|
2018-09-25 21:20:24 -04:00
|
|
|
bladerf2InputThread = new BladeRF2InputThread(m_deviceShared.m_dev->getDev(), requestedChannel+1);
|
2018-09-25 08:19:57 -04:00
|
|
|
m_thread = bladerf2InputThread; // take ownership
|
2018-09-23 20:01:10 -04:00
|
|
|
needsStart = true;
|
|
|
|
}
|
|
|
|
|
2018-09-25 21:20:24 -04:00
|
|
|
bladerf2InputThread->setFifo(requestedChannel, &m_sampleFifo);
|
|
|
|
bladerf2InputThread->setLog2Decimation(requestedChannel, m_settings.m_log2Decim);
|
|
|
|
bladerf2InputThread->setFcPos(requestedChannel, (int) m_settings.m_fcPos);
|
2018-09-23 20:01:10 -04:00
|
|
|
|
2018-09-26 02:54:40 -04:00
|
|
|
if (needsStart)
|
|
|
|
{
|
2018-09-28 23:49:14 -04:00
|
|
|
qDebug("BladeRF2Input::start: enabling channel(s) and (re)sart buddy thread");
|
2018-09-26 02:54:40 -04:00
|
|
|
|
|
|
|
int nbChannels = bladerf2InputThread->getNbChannels();
|
|
|
|
|
|
|
|
for (int i = 0; i < nbChannels; i++)
|
|
|
|
{
|
|
|
|
if (!m_deviceShared.m_dev->openRx(i)) {
|
|
|
|
qCritical("BladeRF2Input::start: channel %u cannot be enabled", i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-23 20:01:10 -04:00
|
|
|
bladerf2InputThread->startWork();
|
|
|
|
}
|
|
|
|
|
|
|
|
applySettings(m_settings, true);
|
|
|
|
|
2018-09-25 08:19:57 -04:00
|
|
|
qDebug("BladeRF2Input::start: started");
|
2018-09-23 20:01:10 -04:00
|
|
|
m_running = true;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void BladeRF2Input::stop()
|
|
|
|
{
|
2018-09-26 08:56:33 -04:00
|
|
|
// This stop method is responsible for managing the thread and channel disabling when the streaming of
|
|
|
|
// a Rx channel is stopped
|
|
|
|
//
|
|
|
|
// If the thread is currently managing only one channel (SI mode). The thread can be just stopped and deleted.
|
|
|
|
// Then the channel is closed (disabled).
|
|
|
|
//
|
|
|
|
// If the thread is currently managing many channels (MI mode) and we are removing the last channel. The transition
|
|
|
|
// from MI to SI or reduction of MI size is handled by stopping the thread, deleting it and creating a new one
|
2018-09-27 00:37:31 -04:00
|
|
|
// with one channel less if (and only if) there is still a channel active.
|
2018-09-26 08:56:33 -04:00
|
|
|
//
|
|
|
|
// If the thread is currently managing many channels (MI mode) but the channel being stopped is not the last
|
|
|
|
// channel then the FIFO reference is simply removed from the thread so that it will not stream into this FIFO
|
|
|
|
// 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 simply dropped (by
|
|
|
|
// removing FIFO reference).
|
|
|
|
|
2018-09-23 20:01:10 -04:00
|
|
|
if (!m_running) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-05-20 18:27:08 -04:00
|
|
|
int requestedChannel = m_deviceAPI->getDeviceItemIndex();
|
2018-09-25 08:19:57 -04:00
|
|
|
BladeRF2InputThread *bladerf2InputThread = findThread();
|
2018-09-23 20:01:10 -04:00
|
|
|
|
2018-09-26 02:54:40 -04:00
|
|
|
if (bladerf2InputThread == 0) { // no thread allocated
|
2018-09-25 08:19:57 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
int nbOriginalChannels = bladerf2InputThread->getNbChannels();
|
|
|
|
|
|
|
|
if (nbOriginalChannels == 1) // SI mode => just stop and delete the thread
|
|
|
|
{
|
2018-09-25 21:07:55 -04:00
|
|
|
qDebug("BladeRF2Input::stop: SI mode. Just stop and delete the thread");
|
2018-09-25 08:19:57 -04:00
|
|
|
bladerf2InputThread->stopWork();
|
2018-09-25 02:45:57 -04:00
|
|
|
delete bladerf2InputThread;
|
2018-09-25 08:19:57 -04:00
|
|
|
m_thread = 0;
|
|
|
|
|
|
|
|
// remove old thread address from buddies (reset in all buddies)
|
2019-05-08 16:11:53 -04:00
|
|
|
const std::vector<DeviceAPI*>& sourceBuddies = m_deviceAPI->getSourceBuddies();
|
|
|
|
std::vector<DeviceAPI*>::const_iterator it = sourceBuddies.begin();
|
2018-09-25 08:19:57 -04:00
|
|
|
|
|
|
|
for (; it != sourceBuddies.end(); ++it) {
|
2018-09-25 08:31:57 -04:00
|
|
|
((DeviceBladeRF2Shared*) (*it)->getBuddySharedPtr())->m_source->setThread(0);
|
2018-09-25 08:19:57 -04:00
|
|
|
}
|
2018-09-26 02:54:40 -04:00
|
|
|
|
|
|
|
m_deviceShared.m_dev->closeRx(0); // close the unique channel
|
2018-09-23 20:01:10 -04:00
|
|
|
}
|
2018-09-25 21:20:24 -04:00
|
|
|
else if (requestedChannel == nbOriginalChannels - 1) // remove last MI channel => reduce by deleting and re-creating the thread
|
2018-09-23 20:01:10 -04:00
|
|
|
{
|
2018-09-25 21:07:55 -04:00
|
|
|
qDebug("BladeRF2Input::stop: MI mode. Reduce by deleting and re-creating the thread");
|
2018-09-25 08:19:57 -04:00
|
|
|
bladerf2InputThread->stopWork();
|
2018-09-23 20:01:10 -04:00
|
|
|
SampleSinkFifo **fifos = new SampleSinkFifo*[nbOriginalChannels-1];
|
|
|
|
unsigned int *log2Decims = new unsigned int[nbOriginalChannels-1];
|
|
|
|
int *fcPoss = new int[nbOriginalChannels-1];
|
2018-09-27 00:37:31 -04:00
|
|
|
bool stillActiveFIFO = false;
|
2018-09-23 20:01:10 -04:00
|
|
|
|
2018-09-25 08:19:57 -04:00
|
|
|
for (int i = 0; i < nbOriginalChannels-1; i++) // save original FIFO references
|
|
|
|
{
|
|
|
|
fifos[i] = bladerf2InputThread->getFifo(i);
|
2018-09-27 00:37:31 -04:00
|
|
|
stillActiveFIFO = stillActiveFIFO || (bladerf2InputThread->getFifo(i) != 0);
|
2018-09-25 08:19:57 -04:00
|
|
|
log2Decims[i] = bladerf2InputThread->getLog2Decimation(i);
|
|
|
|
fcPoss[i] = bladerf2InputThread->getFcPos(i);
|
2018-09-23 20:01:10 -04:00
|
|
|
}
|
|
|
|
|
2018-09-25 02:45:57 -04:00
|
|
|
delete bladerf2InputThread;
|
2018-09-27 00:37:31 -04:00
|
|
|
m_thread = 0;
|
2018-09-23 20:01:10 -04:00
|
|
|
|
2018-09-27 00:37:31 -04:00
|
|
|
if (stillActiveFIFO)
|
2018-09-25 08:19:57 -04:00
|
|
|
{
|
2018-09-27 00:37:31 -04:00
|
|
|
bladerf2InputThread = new BladeRF2InputThread(m_deviceShared.m_dev->getDev(), nbOriginalChannels-1);
|
|
|
|
m_thread = bladerf2InputThread; // take ownership
|
|
|
|
|
|
|
|
for (int i = 0; i < nbOriginalChannels-1; i++) // restore original FIFO references
|
|
|
|
{
|
|
|
|
bladerf2InputThread->setFifo(i, fifos[i]);
|
|
|
|
bladerf2InputThread->setLog2Decimation(i, log2Decims[i]);
|
|
|
|
bladerf2InputThread->setFcPos(i, fcPoss[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
qDebug("BladeRF2Input::stop: do not re-create thread as there are no more FIFOs active");
|
2018-09-23 20:01:10 -04:00
|
|
|
}
|
|
|
|
|
2018-11-02 05:16:14 -04:00
|
|
|
// remove old thread address from buddies (reset in all buddies). The address being held only in the owning source.
|
2019-05-08 16:11:53 -04:00
|
|
|
const std::vector<DeviceAPI*>& sourceBuddies = m_deviceAPI->getSourceBuddies();
|
|
|
|
std::vector<DeviceAPI*>::const_iterator it = sourceBuddies.begin();
|
2018-09-23 20:01:10 -04:00
|
|
|
|
|
|
|
for (; it != sourceBuddies.end(); ++it) {
|
2018-09-25 08:31:57 -04:00
|
|
|
((DeviceBladeRF2Shared*) (*it)->getBuddySharedPtr())->m_source->setThread(0);
|
2018-09-23 20:01:10 -04:00
|
|
|
}
|
|
|
|
|
2018-09-26 02:54:40 -04:00
|
|
|
m_deviceShared.m_dev->closeRx(requestedChannel); // close the last channel
|
2018-09-27 00:37:31 -04:00
|
|
|
|
|
|
|
if (stillActiveFIFO) {
|
|
|
|
bladerf2InputThread->startWork();
|
|
|
|
}
|
2018-11-18 03:39:22 -05:00
|
|
|
|
|
|
|
// was used as temporary storage:
|
|
|
|
delete[] fifos;
|
|
|
|
delete[] log2Decims;
|
|
|
|
delete[] fcPoss;
|
2018-09-23 20:01:10 -04:00
|
|
|
}
|
2018-09-25 08:19:57 -04:00
|
|
|
else // remove channel from existing thread
|
2018-09-23 20:01:10 -04:00
|
|
|
{
|
2018-09-26 08:56:33 -04:00
|
|
|
qDebug("BladeRF2Input::stop: MI mode. Not changing MI configuration. Just remove FIFO reference");
|
2018-09-25 21:20:24 -04:00
|
|
|
bladerf2InputThread->setFifo(requestedChannel, 0); // remove FIFO
|
2018-09-23 20:01:10 -04:00
|
|
|
}
|
2018-09-25 08:19:57 -04:00
|
|
|
|
|
|
|
m_running = false;
|
2018-09-23 20:01:10 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
QByteArray BladeRF2Input::serialize() const
|
|
|
|
{
|
|
|
|
return m_settings.serialize();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool BladeRF2Input::deserialize(const QByteArray& data)
|
|
|
|
{
|
|
|
|
bool success = true;
|
|
|
|
|
|
|
|
if (!m_settings.deserialize(data))
|
|
|
|
{
|
|
|
|
m_settings.resetToDefaults();
|
|
|
|
success = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
MsgConfigureBladeRF2* message = MsgConfigureBladeRF2::create(m_settings, true);
|
|
|
|
m_inputMessageQueue.push(message);
|
|
|
|
|
|
|
|
if (m_guiMessageQueue)
|
|
|
|
{
|
|
|
|
MsgConfigureBladeRF2* messageToGUI = MsgConfigureBladeRF2::create(m_settings, true);
|
|
|
|
m_guiMessageQueue->push(messageToGUI);
|
|
|
|
}
|
|
|
|
|
|
|
|
return success;
|
|
|
|
}
|
|
|
|
|
|
|
|
const QString& BladeRF2Input::getDeviceDescription() const
|
|
|
|
{
|
|
|
|
return m_deviceDescription;
|
|
|
|
}
|
|
|
|
|
|
|
|
int BladeRF2Input::getSampleRate() const
|
|
|
|
{
|
|
|
|
int rate = m_settings.m_devSampleRate;
|
|
|
|
return (rate / (1<<m_settings.m_log2Decim));
|
|
|
|
}
|
|
|
|
|
|
|
|
quint64 BladeRF2Input::getCenterFrequency() const
|
|
|
|
{
|
|
|
|
return m_settings.m_centerFrequency;
|
|
|
|
}
|
|
|
|
|
|
|
|
void BladeRF2Input::setCenterFrequency(qint64 centerFrequency)
|
|
|
|
{
|
|
|
|
BladeRF2InputSettings settings = m_settings;
|
|
|
|
settings.m_centerFrequency = centerFrequency;
|
|
|
|
|
|
|
|
MsgConfigureBladeRF2* message = MsgConfigureBladeRF2::create(settings, false);
|
|
|
|
m_inputMessageQueue.push(message);
|
|
|
|
|
|
|
|
if (m_guiMessageQueue)
|
|
|
|
{
|
|
|
|
MsgConfigureBladeRF2* messageToGUI = MsgConfigureBladeRF2::create(settings, false);
|
|
|
|
m_guiMessageQueue->push(messageToGUI);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-01 21:33:04 -04:00
|
|
|
bool BladeRF2Input::setDeviceCenterFrequency(struct bladerf *dev, int requestedChannel, quint64 freq_hz, int loPpmTenths)
|
2018-09-30 04:26:53 -04:00
|
|
|
{
|
2018-11-01 21:33:04 -04:00
|
|
|
qint64 df = ((qint64)freq_hz * loPpmTenths) / 10000000LL;
|
2018-09-30 04:26:53 -04:00
|
|
|
freq_hz += df;
|
|
|
|
|
|
|
|
int status = bladerf_set_frequency(dev, BLADERF_CHANNEL_RX(requestedChannel), freq_hz);
|
|
|
|
|
|
|
|
if (status < 0) {
|
|
|
|
qWarning("BladeRF2Input::setDeviceCenterFrequency: bladerf_set_frequency(%lld) failed: %s",
|
|
|
|
freq_hz, bladerf_strerror(status));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
qDebug("BladeRF2Input::setDeviceCenterFrequency: bladerf_set_frequency(%lld)", freq_hz);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-24 18:38:38 -04:00
|
|
|
void BladeRF2Input::getFrequencyRange(uint64_t& min, uint64_t& max, int& step)
|
|
|
|
{
|
|
|
|
if (m_deviceShared.m_dev) {
|
|
|
|
m_deviceShared.m_dev->getFrequencyRangeRx(min, max, step);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void BladeRF2Input::getSampleRateRange(int& min, int& max, int& step)
|
|
|
|
{
|
|
|
|
if (m_deviceShared.m_dev) {
|
|
|
|
m_deviceShared.m_dev->getSampleRateRangeRx(min, max, step);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void BladeRF2Input::getBandwidthRange(int& min, int& max, int& step)
|
|
|
|
{
|
|
|
|
if (m_deviceShared.m_dev) {
|
|
|
|
m_deviceShared.m_dev->getBandwidthRangeRx(min, max, step);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void BladeRF2Input::getGlobalGainRange(int& min, int& max, int& step)
|
|
|
|
{
|
|
|
|
if (m_deviceShared.m_dev) {
|
|
|
|
m_deviceShared.m_dev->getGlobalGainRangeRx(min, max, step);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-23 20:01:10 -04:00
|
|
|
bool BladeRF2Input::handleMessage(const Message& message)
|
|
|
|
{
|
|
|
|
if (MsgConfigureBladeRF2::match(message))
|
|
|
|
{
|
|
|
|
MsgConfigureBladeRF2& conf = (MsgConfigureBladeRF2&) message;
|
|
|
|
qDebug() << "BladeRF2Input::handleMessage: MsgConfigureBladeRF2";
|
|
|
|
|
|
|
|
if (!applySettings(conf.getSettings(), conf.getForce()))
|
|
|
|
{
|
|
|
|
qDebug("BladeRF2Input::handleMessage: MsgConfigureBladeRF2 config error");
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2018-09-24 02:43:16 -04:00
|
|
|
else if (DeviceBladeRF2Shared::MsgReportBuddyChange::match(message))
|
|
|
|
{
|
|
|
|
DeviceBladeRF2Shared::MsgReportBuddyChange& report = (DeviceBladeRF2Shared::MsgReportBuddyChange&) message;
|
2018-09-24 11:32:40 -04:00
|
|
|
struct bladerf *dev = m_deviceShared.m_dev->getDev();
|
|
|
|
BladeRF2InputSettings 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
|
2018-09-24 02:43:16 -04:00
|
|
|
{
|
2019-05-20 18:27:08 -04:00
|
|
|
int requestedChannel = m_deviceAPI->getDeviceItemIndex();
|
2018-09-25 21:20:24 -04:00
|
|
|
|
2018-09-30 04:26:53 -04:00
|
|
|
if (report.getRxElseTx()) // Rx buddy change: check for: frequency, LO correction, gain mode and value, bias tee, sample rate, bandwidth
|
2018-09-24 11:32:40 -04:00
|
|
|
{
|
2018-09-26 23:17:34 -04:00
|
|
|
settings.m_devSampleRate = report.getDevSampleRate();
|
2018-09-30 04:26:53 -04:00
|
|
|
settings.m_LOppmTenths = report.getLOppmTenths();
|
2018-09-26 23:17:34 -04:00
|
|
|
settings.m_centerFrequency = report.getCenterFrequency();
|
2018-09-27 17:38:23 -04:00
|
|
|
settings.m_fcPos = (BladeRF2InputSettings::fcPos_t) report.getFcPos();
|
|
|
|
|
|
|
|
BladeRF2InputThread *inputThread = findThread();
|
|
|
|
|
|
|
|
if (inputThread) {
|
|
|
|
inputThread->setFcPos(requestedChannel, (int) settings.m_fcPos);
|
|
|
|
}
|
2018-09-24 11:32:40 -04:00
|
|
|
|
2018-09-25 21:20:24 -04:00
|
|
|
status = bladerf_get_bandwidth(dev, BLADERF_CHANNEL_RX(requestedChannel), &tmp_uint);
|
2018-09-24 11:32:40 -04:00
|
|
|
|
|
|
|
if (status < 0) {
|
|
|
|
qCritical("BladeRF2Input::handleMessage: MsgReportBuddyChange: bladerf_get_bandwidth error: %s", bladerf_strerror(status));
|
|
|
|
} else {
|
|
|
|
settings.m_bandwidth = tmp_uint;
|
|
|
|
}
|
|
|
|
|
2018-09-25 21:20:24 -04:00
|
|
|
status = bladerf_get_bias_tee(dev, BLADERF_CHANNEL_RX(requestedChannel), &tmp_bool);
|
2018-09-24 11:32:40 -04:00
|
|
|
|
|
|
|
if (status < 0) {
|
|
|
|
qCritical("BladeRF2Input::handleMessage: MsgReportBuddyChange: bladerf_get_bias_tee error: %s", bladerf_strerror(status));
|
|
|
|
} else {
|
|
|
|
settings.m_biasTee = tmp_bool;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else // Tx buddy change: check for sample rate change only
|
|
|
|
{
|
2018-09-30 17:42:52 -04:00
|
|
|
settings.m_devSampleRate = report.getDevSampleRate();
|
|
|
|
// status = bladerf_get_sample_rate(dev, BLADERF_CHANNEL_RX(requestedChannel), &tmp_uint);
|
|
|
|
//
|
|
|
|
// if (status < 0) {
|
|
|
|
// qCritical("BladeRF2Input::handleMessage: MsgReportBuddyChange: bladerf_get_sample_rate error: %s", bladerf_strerror(status));
|
|
|
|
// } else {
|
|
|
|
// settings.m_devSampleRate = tmp_uint;
|
|
|
|
// }
|
|
|
|
|
|
|
|
qint64 deviceCenterFrequency = DeviceSampleSource::calculateDeviceCenterFrequency(
|
|
|
|
settings.m_centerFrequency,
|
|
|
|
0,
|
|
|
|
settings.m_log2Decim,
|
|
|
|
(DeviceSampleSource::fcPos_t) settings.m_fcPos,
|
2019-04-01 19:10:03 -04:00
|
|
|
settings.m_devSampleRate,
|
|
|
|
DeviceSampleSource::FrequencyShiftScheme::FSHIFT_STD,
|
|
|
|
false);
|
2018-09-30 17:42:52 -04:00
|
|
|
|
2018-11-01 21:33:04 -04:00
|
|
|
if (setDeviceCenterFrequency(dev, requestedChannel, deviceCenterFrequency, settings.m_LOppmTenths))
|
2018-09-30 17:42:52 -04:00
|
|
|
{
|
|
|
|
if (getMessageQueueToGUI())
|
|
|
|
{
|
|
|
|
int min, max, step;
|
|
|
|
getGlobalGainRange(min, max, step);
|
|
|
|
MsgReportGainRange *msg = MsgReportGainRange::create(min, max, step);
|
|
|
|
getMessageQueueToGUI()->push(msg);
|
|
|
|
}
|
2018-09-24 11:32:40 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// change DSP settings if buddy change introduced a change in center frequency or base rate
|
|
|
|
if ((settings.m_centerFrequency != m_settings.m_centerFrequency) || (settings.m_devSampleRate != m_settings.m_devSampleRate))
|
|
|
|
{
|
|
|
|
int sampleRate = settings.m_devSampleRate/(1<<settings.m_log2Decim);
|
|
|
|
DSPSignalNotification *notif = new DSPSignalNotification(sampleRate, settings.m_centerFrequency);
|
|
|
|
m_fileSink->handleMessage(*notif); // forward to file sink
|
|
|
|
m_deviceAPI->getDeviceEngineInputMessageQueue()->push(notif);
|
|
|
|
}
|
|
|
|
|
|
|
|
m_settings = settings; // acknowledge the new settings
|
|
|
|
|
|
|
|
// propagate settings to GUI if any
|
|
|
|
if (getMessageQueueToGUI())
|
|
|
|
{
|
|
|
|
MsgConfigureBladeRF2 *reportToGUI = MsgConfigureBladeRF2::create(m_settings, false);
|
|
|
|
getMessageQueueToGUI()->push(reportToGUI);
|
|
|
|
}
|
2018-09-24 02:43:16 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2018-09-23 20:01:10 -04:00
|
|
|
else if (MsgFileRecord::match(message))
|
|
|
|
{
|
|
|
|
MsgFileRecord& conf = (MsgFileRecord&) message;
|
|
|
|
qDebug() << "BladeRF2Input::handleMessage: MsgFileRecord: " << conf.getStartStop();
|
|
|
|
|
|
|
|
if (conf.getStartStop())
|
|
|
|
{
|
|
|
|
if (m_settings.m_fileRecordName.size() != 0) {
|
|
|
|
m_fileSink->setFileName(m_settings.m_fileRecordName);
|
|
|
|
} else {
|
|
|
|
m_fileSink->genUniqueFileName(m_deviceAPI->getDeviceUID());
|
|
|
|
}
|
|
|
|
|
|
|
|
m_fileSink->startRecording();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_fileSink->stopRecording();
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else if (MsgStartStop::match(message))
|
|
|
|
{
|
|
|
|
MsgStartStop& cmd = (MsgStartStop&) message;
|
|
|
|
qDebug() << "BladeRF2Input::handleMessage: MsgStartStop: " << (cmd.getStartStop() ? "start" : "stop");
|
|
|
|
|
|
|
|
if (cmd.getStartStop())
|
|
|
|
{
|
2019-05-08 16:11:53 -04:00
|
|
|
if (m_deviceAPI->initDeviceEngine())
|
2018-09-23 20:01:10 -04:00
|
|
|
{
|
2019-05-08 16:11:53 -04:00
|
|
|
m_deviceAPI->startDeviceEngine();
|
2018-09-23 20:01:10 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-05-08 16:11:53 -04:00
|
|
|
m_deviceAPI->stopDeviceEngine();
|
2018-09-23 20:01:10 -04:00
|
|
|
}
|
|
|
|
|
2018-12-25 15:05:24 -05:00
|
|
|
if (m_settings.m_useReverseAPI) {
|
|
|
|
webapiReverseSendStartStop(cmd.getStartStop());
|
|
|
|
}
|
|
|
|
|
2018-09-23 20:01:10 -04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool BladeRF2Input::applySettings(const BladeRF2InputSettings& settings, bool force)
|
|
|
|
{
|
2018-09-24 02:43:16 -04:00
|
|
|
bool forwardChangeOwnDSP = false;
|
2018-09-24 11:32:40 -04:00
|
|
|
bool forwardChangeRxBuddies = false;
|
|
|
|
bool forwardChangeTxBuddies = false;
|
2018-09-23 20:01:10 -04:00
|
|
|
|
|
|
|
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 xlatedDeviceCenterFrequency = settings.m_centerFrequency;
|
|
|
|
xlatedDeviceCenterFrequency -= settings.m_transverterMode ? settings.m_transverterDeltaFrequency : 0;
|
|
|
|
xlatedDeviceCenterFrequency = xlatedDeviceCenterFrequency < 0 ? 0 : xlatedDeviceCenterFrequency;
|
2018-12-25 15:05:24 -05:00
|
|
|
QList<QString> reverseAPIKeys;
|
|
|
|
|
|
|
|
if ((m_settings.m_dcBlock != settings.m_dcBlock) || force) {
|
|
|
|
reverseAPIKeys.append("dcBlock");
|
|
|
|
}
|
|
|
|
if ((m_settings.m_iqCorrection != settings.m_iqCorrection) || force) {
|
|
|
|
reverseAPIKeys.append("iqCorrection");
|
|
|
|
}
|
2018-09-23 20:01:10 -04:00
|
|
|
|
|
|
|
if ((m_settings.m_dcBlock != settings.m_dcBlock) ||
|
|
|
|
(m_settings.m_iqCorrection != settings.m_iqCorrection) || force)
|
|
|
|
{
|
|
|
|
m_deviceAPI->configureCorrections(settings.m_dcBlock, settings.m_iqCorrection);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((m_settings.m_devSampleRate != settings.m_devSampleRate) || force)
|
|
|
|
{
|
2018-12-25 15:05:24 -05:00
|
|
|
reverseAPIKeys.append("devSampleRate");
|
2018-09-24 02:43:16 -04:00
|
|
|
forwardChangeOwnDSP = true;
|
2018-09-24 11:32:40 -04:00
|
|
|
forwardChangeRxBuddies = true;
|
|
|
|
forwardChangeTxBuddies = true;
|
2018-09-23 20:01:10 -04:00
|
|
|
|
|
|
|
if (dev != 0)
|
|
|
|
{
|
|
|
|
unsigned int actualSamplerate;
|
2018-09-25 21:20:24 -04:00
|
|
|
int status = bladerf_set_sample_rate(dev, BLADERF_CHANNEL_RX(requestedChannel), settings.m_devSampleRate, &actualSamplerate);
|
2018-09-23 20:01:10 -04:00
|
|
|
|
|
|
|
if (status < 0)
|
|
|
|
{
|
|
|
|
qCritical("BladeRF2Input::applySettings: could not set sample rate: %d: %s",
|
|
|
|
settings.m_devSampleRate, bladerf_strerror(status));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-09-29 15:40:22 -04:00
|
|
|
qDebug() << "BladeRF2Input::applySettings: bladerf_set_sample_rate: actual sample rate is " << actualSamplerate;
|
2018-09-23 20:01:10 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((m_settings.m_bandwidth != settings.m_bandwidth) || force)
|
|
|
|
{
|
2018-12-25 15:05:24 -05:00
|
|
|
reverseAPIKeys.append("bandwidth");
|
2018-09-24 11:32:40 -04:00
|
|
|
forwardChangeRxBuddies = true;
|
|
|
|
|
2018-09-23 20:01:10 -04:00
|
|
|
if (dev != 0)
|
|
|
|
{
|
|
|
|
unsigned int actualBandwidth;
|
2018-09-25 21:20:24 -04:00
|
|
|
int status = bladerf_set_bandwidth(dev, BLADERF_CHANNEL_RX(requestedChannel), settings.m_bandwidth, &actualBandwidth);
|
2018-09-23 20:01:10 -04:00
|
|
|
|
|
|
|
if(status < 0)
|
|
|
|
{
|
|
|
|
qCritical("BladeRF2Input::applySettings: could not set bandwidth: %d: %s",
|
|
|
|
settings.m_bandwidth, bladerf_strerror(status));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-09-29 15:40:22 -04:00
|
|
|
qDebug() << "BladeRF2Input::applySettings: bladerf_set_bandwidth: actual bandwidth is " << actualBandwidth;
|
2018-09-23 20:01:10 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((m_settings.m_fcPos != settings.m_fcPos) || force)
|
|
|
|
{
|
2018-12-25 15:05:24 -05:00
|
|
|
reverseAPIKeys.append("fcPos");
|
2018-09-25 08:19:57 -04:00
|
|
|
BladeRF2InputThread *inputThread = findThread();
|
|
|
|
|
|
|
|
if (inputThread != 0)
|
2018-09-23 20:01:10 -04:00
|
|
|
{
|
2018-09-25 21:20:24 -04:00
|
|
|
inputThread->setFcPos(requestedChannel, (int) settings.m_fcPos);
|
2018-09-23 20:01:10 -04:00
|
|
|
qDebug() << "BladeRF2Input::applySettings: set fc pos (enum) to " << (int) settings.m_fcPos;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((m_settings.m_log2Decim != settings.m_log2Decim) || force)
|
|
|
|
{
|
2018-12-25 15:05:24 -05:00
|
|
|
reverseAPIKeys.append("log2Decim");
|
2018-09-24 02:43:16 -04:00
|
|
|
forwardChangeOwnDSP = true;
|
2018-09-25 08:19:57 -04:00
|
|
|
BladeRF2InputThread *inputThread = findThread();
|
2018-09-23 20:01:10 -04:00
|
|
|
|
2018-09-25 08:19:57 -04:00
|
|
|
if (inputThread != 0)
|
2018-09-23 20:01:10 -04:00
|
|
|
{
|
2018-09-25 21:20:24 -04:00
|
|
|
inputThread->setLog2Decimation(requestedChannel, settings.m_log2Decim);
|
2018-09-23 20:01:10 -04:00
|
|
|
qDebug() << "BladeRF2Input::applySettings: set decimation to " << (1<<settings.m_log2Decim);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-25 15:05:24 -05:00
|
|
|
if ((m_settings.m_centerFrequency != settings.m_centerFrequency) || force) {
|
|
|
|
reverseAPIKeys.append("centerFrequency");
|
|
|
|
}
|
|
|
|
if ((m_settings.m_transverterMode != settings.m_transverterMode) || force) {
|
|
|
|
reverseAPIKeys.append("transverterMode");
|
|
|
|
}
|
|
|
|
if ((m_settings.m_transverterDeltaFrequency != settings.m_transverterDeltaFrequency) || force) {
|
|
|
|
reverseAPIKeys.append("transverterDeltaFrequency");
|
|
|
|
}
|
|
|
|
if ((m_settings.m_LOppmTenths != settings.m_LOppmTenths) || force) {
|
|
|
|
reverseAPIKeys.append("LOppmTenths");
|
|
|
|
}
|
|
|
|
if ((m_settings.m_devSampleRate != settings.m_devSampleRate) || force) {
|
|
|
|
reverseAPIKeys.append("devSampleRate");
|
|
|
|
}
|
|
|
|
|
2018-09-23 20:01:10 -04:00
|
|
|
if ((m_settings.m_centerFrequency != settings.m_centerFrequency)
|
2018-10-03 00:14:26 -04:00
|
|
|
|| (m_settings.m_transverterMode != settings.m_transverterMode)
|
|
|
|
|| (m_settings.m_transverterDeltaFrequency != settings.m_transverterDeltaFrequency)
|
2018-09-30 04:26:53 -04:00
|
|
|
|| (m_settings.m_LOppmTenths != settings.m_LOppmTenths)
|
2018-09-23 20:01:10 -04:00
|
|
|
|| (m_settings.m_devSampleRate != settings.m_devSampleRate)
|
|
|
|
|| (m_settings.m_fcPos != settings.m_fcPos)
|
|
|
|
|| (m_settings.m_log2Decim != settings.m_log2Decim) || force)
|
|
|
|
{
|
|
|
|
qint64 deviceCenterFrequency = DeviceSampleSource::calculateDeviceCenterFrequency(
|
2018-10-03 00:14:26 -04:00
|
|
|
xlatedDeviceCenterFrequency,
|
2018-09-23 20:01:10 -04:00
|
|
|
0,
|
|
|
|
settings.m_log2Decim,
|
|
|
|
(DeviceSampleSource::fcPos_t) settings.m_fcPos,
|
2019-04-01 19:10:03 -04:00
|
|
|
settings.m_devSampleRate,
|
|
|
|
DeviceSampleSource::FrequencyShiftScheme::FSHIFT_STD,
|
|
|
|
false);
|
2018-09-23 20:01:10 -04:00
|
|
|
|
2018-09-24 02:43:16 -04:00
|
|
|
forwardChangeOwnDSP = true;
|
2018-09-24 11:32:40 -04:00
|
|
|
forwardChangeRxBuddies = true;
|
2018-09-23 20:01:10 -04:00
|
|
|
|
|
|
|
if (dev != 0)
|
|
|
|
{
|
2018-11-01 21:33:04 -04:00
|
|
|
if (setDeviceCenterFrequency(dev, requestedChannel, deviceCenterFrequency, settings.m_LOppmTenths))
|
2018-09-25 17:43:52 -04:00
|
|
|
{
|
|
|
|
if (getMessageQueueToGUI())
|
|
|
|
{
|
|
|
|
int min, max, step;
|
|
|
|
getGlobalGainRange(min, max, step);
|
|
|
|
MsgReportGainRange *msg = MsgReportGainRange::create(min, max, step);
|
|
|
|
getMessageQueueToGUI()->push(msg);
|
|
|
|
}
|
2018-09-23 20:01:10 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-24 02:43:16 -04:00
|
|
|
if ((m_settings.m_biasTee != settings.m_biasTee) || force)
|
|
|
|
{
|
2018-12-25 15:05:24 -05:00
|
|
|
reverseAPIKeys.append("biasTee");
|
2018-09-24 11:32:40 -04:00
|
|
|
forwardChangeRxBuddies = true;
|
2018-09-24 02:43:16 -04:00
|
|
|
m_deviceShared.m_dev->setBiasTeeRx(settings.m_biasTee);
|
|
|
|
}
|
|
|
|
|
2018-09-26 23:44:20 -04:00
|
|
|
if ((m_settings.m_gainMode != settings.m_gainMode) || force)
|
2018-09-24 02:43:16 -04:00
|
|
|
{
|
2018-12-25 15:05:24 -05:00
|
|
|
reverseAPIKeys.append("gainMode");
|
2018-09-24 11:32:40 -04:00
|
|
|
forwardChangeRxBuddies = true;
|
|
|
|
|
2018-09-24 02:43:16 -04:00
|
|
|
if (dev)
|
|
|
|
{
|
2018-09-26 23:44:20 -04:00
|
|
|
int status = bladerf_set_gain_mode(dev, BLADERF_CHANNEL_RX(requestedChannel), (bladerf_gain_mode) settings.m_gainMode);
|
2018-09-24 02:43:16 -04:00
|
|
|
|
|
|
|
if (status < 0) {
|
2018-09-26 23:44:20 -04:00
|
|
|
qWarning("BladeRF2Input::applySettings: bladerf_set_gain_mode(%d) failed: %s",
|
|
|
|
settings.m_gainMode, bladerf_strerror(status));
|
2018-09-24 02:43:16 -04:00
|
|
|
} else {
|
2018-09-26 23:44:20 -04:00
|
|
|
qDebug("BladeRF2Input::applySettings: bladerf_set_gain_mode(%d)", settings.m_gainMode);
|
2018-09-24 02:43:16 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-25 15:05:24 -05:00
|
|
|
if ((m_settings.m_globalGain != settings.m_globalGain) || force) {
|
|
|
|
reverseAPIKeys.append("globalGain");
|
|
|
|
}
|
|
|
|
if ((m_settings.m_gainMode != settings.m_gainMode) || force) {
|
|
|
|
reverseAPIKeys.append("gainMode");
|
|
|
|
}
|
|
|
|
|
2018-09-26 23:44:20 -04:00
|
|
|
if ((m_settings.m_globalGain != settings.m_globalGain)
|
|
|
|
|| ((m_settings.m_gainMode != settings.m_gainMode) && (settings.m_gainMode == BLADERF_GAIN_MANUAL)) || force)
|
2018-09-24 02:43:16 -04:00
|
|
|
{
|
2018-09-24 11:32:40 -04:00
|
|
|
forwardChangeRxBuddies = true;
|
|
|
|
|
2018-09-24 02:43:16 -04:00
|
|
|
if (dev)
|
|
|
|
{
|
2018-09-26 23:44:20 -04:00
|
|
|
// qDebug("BladeRF2Input::applySettings: channel: %d gain: %d", requestedChannel, settings.m_globalGain);
|
|
|
|
int status = bladerf_set_gain(dev, BLADERF_CHANNEL_RX(requestedChannel), settings.m_globalGain);
|
2018-09-24 02:43:16 -04:00
|
|
|
|
|
|
|
if (status < 0) {
|
2018-09-26 23:44:20 -04:00
|
|
|
qWarning("BladeRF2Input::applySettings: bladerf_set_gain(%d) failed: %s",
|
|
|
|
settings.m_globalGain, bladerf_strerror(status));
|
2018-09-24 02:43:16 -04:00
|
|
|
} else {
|
2018-09-26 23:44:20 -04:00
|
|
|
qDebug("BladeRF2Input::applySettings: bladerf_set_gain(%d)", settings.m_globalGain);
|
2018-09-24 02:43:16 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (forwardChangeOwnDSP)
|
2018-09-23 20:01:10 -04:00
|
|
|
{
|
|
|
|
int sampleRate = settings.m_devSampleRate/(1<<settings.m_log2Decim);
|
|
|
|
DSPSignalNotification *notif = new DSPSignalNotification(sampleRate, settings.m_centerFrequency);
|
|
|
|
m_fileSink->handleMessage(*notif); // forward to file sink
|
|
|
|
m_deviceAPI->getDeviceEngineInputMessageQueue()->push(notif);
|
|
|
|
}
|
|
|
|
|
2018-09-24 11:32:40 -04:00
|
|
|
if (forwardChangeRxBuddies)
|
2018-09-24 02:43:16 -04:00
|
|
|
{
|
|
|
|
// 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-24 02:43:16 -04:00
|
|
|
|
|
|
|
for (; itSource != sourceBuddies.end(); ++itSource)
|
|
|
|
{
|
2018-09-26 23:17:34 -04:00
|
|
|
DeviceBladeRF2Shared::MsgReportBuddyChange *report = DeviceBladeRF2Shared::MsgReportBuddyChange::create(
|
|
|
|
settings.m_centerFrequency,
|
2018-09-30 04:26:53 -04:00
|
|
|
settings.m_LOppmTenths,
|
2018-09-27 17:38:23 -04:00
|
|
|
(int) settings.m_fcPos,
|
2018-09-26 23:17:34 -04:00
|
|
|
settings.m_devSampleRate,
|
|
|
|
true);
|
2019-05-08 16:11:53 -04:00
|
|
|
(*itSource)->getSamplingDeviceInputMessageQueue()->push(report);
|
2018-09-24 02:43:16 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-24 11:32:40 -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-24 11:32:40 -04:00
|
|
|
|
|
|
|
for (; itSink != sinkBuddies.end(); ++itSink)
|
|
|
|
{
|
2018-09-26 23:17:34 -04:00
|
|
|
DeviceBladeRF2Shared::MsgReportBuddyChange *report = DeviceBladeRF2Shared::MsgReportBuddyChange::create(
|
|
|
|
settings.m_centerFrequency,
|
2018-09-30 04:26:53 -04:00
|
|
|
settings.m_LOppmTenths,
|
2018-09-27 17:38:23 -04:00
|
|
|
(int) settings.m_fcPos,
|
2018-09-26 23:17:34 -04:00
|
|
|
settings.m_devSampleRate,
|
|
|
|
true);
|
2019-05-08 16:11:53 -04:00
|
|
|
(*itSink)->getSamplingDeviceInputMessageQueue()->push(report);
|
2018-09-24 11:32:40 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-25 15:05:24 -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);
|
|
|
|
}
|
|
|
|
|
2018-09-23 20:01:10 -04:00
|
|
|
m_settings = settings;
|
|
|
|
|
|
|
|
qDebug() << "BladeRF2Input::applySettings: "
|
2018-10-03 00:14:26 -04:00
|
|
|
<< " m_transverterMode: " << m_settings.m_transverterMode
|
|
|
|
<< " m_transverterDeltaFrequency: " << m_settings.m_transverterDeltaFrequency
|
2018-09-23 20:01:10 -04:00
|
|
|
<< " m_centerFrequency: " << m_settings.m_centerFrequency << " Hz"
|
2018-09-30 04:26:53 -04:00
|
|
|
<< " m_LOppmTenths: " << m_settings.m_LOppmTenths
|
2018-09-23 20:01:10 -04:00
|
|
|
<< " m_bandwidth: " << m_settings.m_bandwidth
|
|
|
|
<< " m_log2Decim: " << m_settings.m_log2Decim
|
|
|
|
<< " m_fcPos: " << m_settings.m_fcPos
|
|
|
|
<< " m_devSampleRate: " << m_settings.m_devSampleRate
|
2018-09-24 02:43:16 -04:00
|
|
|
<< " m_globalGain: " << m_settings.m_globalGain
|
|
|
|
<< " m_gainMode: " << m_settings.m_gainMode
|
2018-09-23 20:01:10 -04:00
|
|
|
<< " m_dcBlock: " << m_settings.m_dcBlock
|
2018-09-24 02:43:16 -04:00
|
|
|
<< " m_iqCorrection: " << m_settings.m_iqCorrection
|
|
|
|
<< " m_biasTee: " << m_settings.m_biasTee;
|
2018-09-23 20:01:10 -04:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2018-09-24 11:59:52 -04:00
|
|
|
|
|
|
|
int BladeRF2Input::webapiSettingsGet(
|
|
|
|
SWGSDRangel::SWGDeviceSettings& response,
|
2018-11-13 02:51:14 -05:00
|
|
|
QString& errorMessage)
|
2018-09-24 11:59:52 -04:00
|
|
|
{
|
2018-11-13 02:51:14 -05:00
|
|
|
(void) errorMessage;
|
2018-09-24 11:59:52 -04:00
|
|
|
response.setBladeRf2InputSettings(new SWGSDRangel::SWGBladeRF2InputSettings());
|
|
|
|
response.getBladeRf2InputSettings()->init();
|
|
|
|
webapiFormatDeviceSettings(response, m_settings);
|
|
|
|
return 200;
|
|
|
|
}
|
|
|
|
|
|
|
|
int BladeRF2Input::webapiSettingsPutPatch(
|
|
|
|
bool force,
|
|
|
|
const QStringList& deviceSettingsKeys,
|
|
|
|
SWGSDRangel::SWGDeviceSettings& response, // query + response
|
2018-11-13 02:51:14 -05:00
|
|
|
QString& errorMessage)
|
2018-09-24 11:59:52 -04:00
|
|
|
{
|
2018-11-13 02:51:14 -05:00
|
|
|
(void) errorMessage;
|
2018-09-24 11:59:52 -04:00
|
|
|
BladeRF2InputSettings settings = m_settings;
|
|
|
|
|
|
|
|
if (deviceSettingsKeys.contains("centerFrequency")) {
|
|
|
|
settings.m_centerFrequency = response.getBladeRf2InputSettings()->getCenterFrequency();
|
|
|
|
}
|
2018-09-30 05:10:07 -04:00
|
|
|
if (deviceSettingsKeys.contains("LOppmTenths")) {
|
|
|
|
settings.m_LOppmTenths = response.getBladeRf2InputSettings()->getLOppmTenths();
|
|
|
|
}
|
2018-09-24 11:59:52 -04:00
|
|
|
if (deviceSettingsKeys.contains("devSampleRate")) {
|
|
|
|
settings.m_devSampleRate = response.getBladeRf2InputSettings()->getDevSampleRate();
|
|
|
|
}
|
|
|
|
if (deviceSettingsKeys.contains("bandwidth")) {
|
|
|
|
settings.m_bandwidth = response.getBladeRf2InputSettings()->getBandwidth();
|
|
|
|
}
|
|
|
|
if (deviceSettingsKeys.contains("log2Decim")) {
|
|
|
|
settings.m_log2Decim = response.getBladeRf2InputSettings()->getLog2Decim();
|
|
|
|
}
|
|
|
|
if (deviceSettingsKeys.contains("fcPos")) {
|
|
|
|
settings.m_fcPos = static_cast<BladeRF2InputSettings::fcPos_t>(response.getBladeRf2InputSettings()->getFcPos());
|
|
|
|
}
|
|
|
|
if (deviceSettingsKeys.contains("dcBlock")) {
|
|
|
|
settings.m_dcBlock = response.getBladeRf2InputSettings()->getDcBlock() != 0;
|
|
|
|
}
|
|
|
|
if (deviceSettingsKeys.contains("iqCorrection")) {
|
|
|
|
settings.m_iqCorrection = response.getBladeRf2InputSettings()->getIqCorrection() != 0;
|
|
|
|
}
|
|
|
|
if (deviceSettingsKeys.contains("biasTee")) {
|
|
|
|
settings.m_biasTee = response.getBladeRf2InputSettings()->getBiasTee() != 0;
|
|
|
|
}
|
|
|
|
if (deviceSettingsKeys.contains("gainMode")) {
|
|
|
|
settings.m_gainMode = response.getBladeRf2InputSettings()->getGainMode();
|
|
|
|
}
|
|
|
|
if (deviceSettingsKeys.contains("globalGain")) {
|
|
|
|
settings.m_globalGain = response.getBladeRf2InputSettings()->getGlobalGain();
|
|
|
|
}
|
2018-10-03 00:14:26 -04:00
|
|
|
if (deviceSettingsKeys.contains("transverterDeltaFrequency")) {
|
|
|
|
settings.m_transverterDeltaFrequency = response.getBladeRf2InputSettings()->getTransverterDeltaFrequency();
|
|
|
|
}
|
|
|
|
if (deviceSettingsKeys.contains("transverterMode")) {
|
|
|
|
settings.m_transverterMode = response.getBladeRf2InputSettings()->getTransverterMode() != 0;
|
|
|
|
}
|
2018-09-24 11:59:52 -04:00
|
|
|
if (deviceSettingsKeys.contains("fileRecordName")) {
|
2019-01-11 02:50:47 -05:00
|
|
|
settings.m_fileRecordName = *response.getBladeRf2InputSettings()->getFileRecordName();
|
2018-09-24 11:59:52 -04:00
|
|
|
}
|
2019-01-10 16:35:38 -05:00
|
|
|
if (deviceSettingsKeys.contains("useReverseAPI")) {
|
2019-01-11 02:50:47 -05:00
|
|
|
settings.m_useReverseAPI = response.getBladeRf2InputSettings()->getUseReverseApi() != 0;
|
2019-01-10 16:35:38 -05:00
|
|
|
}
|
|
|
|
if (deviceSettingsKeys.contains("reverseAPIAddress")) {
|
2019-01-11 02:50:47 -05:00
|
|
|
settings.m_reverseAPIAddress = *response.getBladeRf2InputSettings()->getReverseApiAddress();
|
2019-01-10 16:35:38 -05:00
|
|
|
}
|
|
|
|
if (deviceSettingsKeys.contains("reverseAPIPort")) {
|
2019-01-11 02:50:47 -05:00
|
|
|
settings.m_reverseAPIPort = response.getBladeRf2InputSettings()->getReverseApiPort();
|
2019-01-10 16:35:38 -05:00
|
|
|
}
|
|
|
|
if (deviceSettingsKeys.contains("reverseAPIDeviceIndex")) {
|
2019-01-11 02:50:47 -05:00
|
|
|
settings.m_reverseAPIDeviceIndex = response.getBladeRf2InputSettings()->getReverseApiDeviceIndex();
|
2019-01-10 16:35:38 -05:00
|
|
|
}
|
2018-09-24 11:59:52 -04:00
|
|
|
|
|
|
|
MsgConfigureBladeRF2 *msg = MsgConfigureBladeRF2::create(settings, force);
|
|
|
|
m_inputMessageQueue.push(msg);
|
|
|
|
|
|
|
|
if (m_guiMessageQueue) // forward to GUI if any
|
|
|
|
{
|
|
|
|
MsgConfigureBladeRF2 *msgToGUI = MsgConfigureBladeRF2::create(settings, force);
|
|
|
|
m_guiMessageQueue->push(msgToGUI);
|
|
|
|
}
|
|
|
|
|
|
|
|
webapiFormatDeviceSettings(response, settings);
|
|
|
|
return 200;
|
|
|
|
}
|
|
|
|
|
2018-11-13 02:51:14 -05:00
|
|
|
int BladeRF2Input::webapiReportGet(SWGSDRangel::SWGDeviceReport& response, QString& errorMessage)
|
2018-09-24 11:59:52 -04:00
|
|
|
{
|
2018-11-13 02:51:14 -05:00
|
|
|
(void) errorMessage;
|
2018-09-24 11:59:52 -04:00
|
|
|
response.setBladeRf2InputReport(new SWGSDRangel::SWGBladeRF2InputReport());
|
|
|
|
response.getBladeRf2InputReport()->init();
|
|
|
|
webapiFormatDeviceReport(response);
|
|
|
|
return 200;
|
|
|
|
}
|
|
|
|
|
|
|
|
void BladeRF2Input::webapiFormatDeviceSettings(SWGSDRangel::SWGDeviceSettings& response, const BladeRF2InputSettings& settings)
|
|
|
|
{
|
|
|
|
response.getBladeRf2InputSettings()->setCenterFrequency(settings.m_centerFrequency);
|
2018-09-30 05:10:07 -04:00
|
|
|
response.getBladeRf2InputSettings()->setLOppmTenths(settings.m_LOppmTenths);
|
2018-09-24 11:59:52 -04:00
|
|
|
response.getBladeRf2InputSettings()->setDevSampleRate(settings.m_devSampleRate);
|
|
|
|
response.getBladeRf2InputSettings()->setBandwidth(settings.m_bandwidth);
|
|
|
|
response.getBladeRf2InputSettings()->setLog2Decim(settings.m_log2Decim);
|
|
|
|
response.getBladeRf2InputSettings()->setFcPos((int) settings.m_fcPos);
|
|
|
|
response.getBladeRf2InputSettings()->setDcBlock(settings.m_dcBlock ? 1 : 0);
|
|
|
|
response.getBladeRf2InputSettings()->setIqCorrection(settings.m_iqCorrection ? 1 : 0);
|
|
|
|
response.getBladeRf2InputSettings()->setBiasTee(settings.m_biasTee ? 1 : 0);
|
|
|
|
response.getBladeRf2InputSettings()->setGainMode(settings.m_gainMode);
|
|
|
|
response.getBladeRf2InputSettings()->setGlobalGain(settings.m_globalGain);
|
2018-10-03 00:14:26 -04:00
|
|
|
response.getBladeRf2InputSettings()->setTransverterDeltaFrequency(settings.m_transverterDeltaFrequency);
|
|
|
|
response.getBladeRf2InputSettings()->setTransverterMode(settings.m_transverterMode ? 1 : 0);
|
2018-09-24 11:59:52 -04:00
|
|
|
|
|
|
|
if (response.getBladeRf2InputSettings()->getFileRecordName()) {
|
|
|
|
*response.getBladeRf2InputSettings()->getFileRecordName() = settings.m_fileRecordName;
|
|
|
|
} else {
|
|
|
|
response.getBladeRf2InputSettings()->setFileRecordName(new QString(settings.m_fileRecordName));
|
|
|
|
}
|
2019-01-10 16:35:38 -05:00
|
|
|
|
2019-01-11 02:50:47 -05:00
|
|
|
response.getBladeRf2InputSettings()->setUseReverseApi(settings.m_useReverseAPI ? 1 : 0);
|
2019-01-10 16:35:38 -05:00
|
|
|
|
2019-01-11 02:50:47 -05:00
|
|
|
if (response.getBladeRf2InputSettings()->getReverseApiAddress()) {
|
|
|
|
*response.getBladeRf2InputSettings()->getReverseApiAddress() = settings.m_reverseAPIAddress;
|
2019-01-10 16:35:38 -05:00
|
|
|
} else {
|
2019-01-11 02:50:47 -05:00
|
|
|
response.getBladeRf2InputSettings()->setReverseApiAddress(new QString(settings.m_reverseAPIAddress));
|
2019-01-10 16:35:38 -05:00
|
|
|
}
|
|
|
|
|
2019-01-11 02:50:47 -05:00
|
|
|
response.getBladeRf2InputSettings()->setReverseApiPort(settings.m_reverseAPIPort);
|
|
|
|
response.getBladeRf2InputSettings()->setReverseApiDeviceIndex(settings.m_reverseAPIDeviceIndex);
|
2018-09-24 11:59:52 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void BladeRF2Input::webapiFormatDeviceReport(SWGSDRangel::SWGDeviceReport& response)
|
|
|
|
{
|
|
|
|
DeviceBladeRF2 *device = m_deviceShared.m_dev;
|
|
|
|
|
|
|
|
if (device)
|
|
|
|
{
|
|
|
|
int min, max, step;
|
|
|
|
uint64_t f_min, f_max;
|
|
|
|
|
|
|
|
device->getBandwidthRangeRx(min, max, step);
|
|
|
|
|
|
|
|
response.getBladeRf2InputReport()->setBandwidthRange(new SWGSDRangel::SWGRange);
|
|
|
|
response.getBladeRf2InputReport()->getBandwidthRange()->setMin(min);
|
|
|
|
response.getBladeRf2InputReport()->getBandwidthRange()->setMax(max);
|
|
|
|
response.getBladeRf2InputReport()->getBandwidthRange()->setStep(step);
|
|
|
|
|
|
|
|
device->getFrequencyRangeRx(f_min, f_max, step);
|
|
|
|
|
2018-09-25 11:03:34 -04:00
|
|
|
response.getBladeRf2InputReport()->setFrequencyRange(new SWGSDRangel::SWGFrequencyRange);
|
2018-09-24 11:59:52 -04:00
|
|
|
response.getBladeRf2InputReport()->getFrequencyRange()->setMin(f_min);
|
|
|
|
response.getBladeRf2InputReport()->getFrequencyRange()->setMax(f_max);
|
|
|
|
response.getBladeRf2InputReport()->getFrequencyRange()->setStep(step);
|
|
|
|
|
|
|
|
device->getGlobalGainRangeRx(min, max, step);
|
|
|
|
|
|
|
|
response.getBladeRf2InputReport()->setGlobalGainRange(new SWGSDRangel::SWGRange);
|
|
|
|
response.getBladeRf2InputReport()->getGlobalGainRange()->setMin(min);
|
|
|
|
response.getBladeRf2InputReport()->getGlobalGainRange()->setMax(max);
|
|
|
|
response.getBladeRf2InputReport()->getGlobalGainRange()->setStep(step);
|
|
|
|
|
|
|
|
device->getSampleRateRangeRx(min, max, step);
|
|
|
|
|
|
|
|
response.getBladeRf2InputReport()->setSampleRateRange(new SWGSDRangel::SWGRange);
|
|
|
|
response.getBladeRf2InputReport()->getSampleRateRange()->setMin(min);
|
|
|
|
response.getBladeRf2InputReport()->getSampleRateRange()->setMax(max);
|
|
|
|
response.getBladeRf2InputReport()->getSampleRateRange()->setStep(step);
|
2018-09-25 11:03:34 -04:00
|
|
|
|
|
|
|
response.getBladeRf2InputReport()->setGainModes(new QList<SWGSDRangel::SWGNamedEnum*>);
|
|
|
|
|
2018-09-25 19:54:23 -04:00
|
|
|
const std::vector<GainMode>& modes = getGainModes();
|
|
|
|
std::vector<GainMode>::const_iterator it = modes.begin();
|
2018-09-25 11:03:34 -04:00
|
|
|
|
2018-09-25 19:54:23 -04:00
|
|
|
for (; it != modes.end(); ++it)
|
2018-09-25 11:03:34 -04:00
|
|
|
{
|
2018-09-25 19:54:23 -04:00
|
|
|
response.getBladeRf2InputReport()->getGainModes()->append(new SWGSDRangel::SWGNamedEnum);
|
|
|
|
response.getBladeRf2InputReport()->getGainModes()->back()->setName(new QString(it->m_name));
|
|
|
|
response.getBladeRf2InputReport()->getGainModes()->back()->setValue(it->m_value);
|
2018-09-25 11:03:34 -04:00
|
|
|
}
|
2018-09-24 11:59:52 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int BladeRF2Input::webapiRunGet(
|
|
|
|
SWGSDRangel::SWGDeviceState& response,
|
2018-11-13 02:51:14 -05:00
|
|
|
QString& errorMessage)
|
2018-09-24 11:59:52 -04:00
|
|
|
{
|
2018-11-13 02:51:14 -05:00
|
|
|
(void) errorMessage;
|
2018-09-24 11:59:52 -04:00
|
|
|
m_deviceAPI->getDeviceEngineStateStr(*response.getState());
|
|
|
|
return 200;
|
|
|
|
}
|
|
|
|
|
|
|
|
int BladeRF2Input::webapiRun(
|
|
|
|
bool run,
|
|
|
|
SWGSDRangel::SWGDeviceState& response,
|
2018-11-13 02:51:14 -05:00
|
|
|
QString& errorMessage)
|
2018-09-24 11:59:52 -04:00
|
|
|
{
|
2018-11-13 02:51:14 -05:00
|
|
|
(void) errorMessage;
|
2018-09-24 11:59:52 -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;
|
2018-09-24 18:38:38 -04:00
|
|
|
}
|
2018-12-25 15:05:24 -05:00
|
|
|
|
|
|
|
void BladeRF2Input::webapiReverseSendSettings(QList<QString>& deviceSettingsKeys, const BladeRF2InputSettings& settings, bool force)
|
|
|
|
{
|
|
|
|
SWGSDRangel::SWGDeviceSettings *swgDeviceSettings = new SWGSDRangel::SWGDeviceSettings();
|
2019-05-07 08:43:38 -04:00
|
|
|
swgDeviceSettings->setDirection(0); // single Rx
|
2019-03-25 08:41:38 -04:00
|
|
|
swgDeviceSettings->setOriginatorIndex(m_deviceAPI->getDeviceSetIndex());
|
2018-12-25 15:05:24 -05:00
|
|
|
swgDeviceSettings->setDeviceHwType(new QString("BladeRF2"));
|
|
|
|
swgDeviceSettings->setBladeRf2InputSettings(new SWGSDRangel::SWGBladeRF2InputSettings());
|
|
|
|
SWGSDRangel::SWGBladeRF2InputSettings *swgBladeRF2Settings = swgDeviceSettings->getBladeRf2InputSettings();
|
|
|
|
|
|
|
|
// transfer data that has been modified. When force is on transfer all data except reverse API data
|
|
|
|
|
|
|
|
if (deviceSettingsKeys.contains("centerFrequency") || force) {
|
|
|
|
swgBladeRF2Settings->setCenterFrequency(settings.m_centerFrequency);
|
|
|
|
}
|
|
|
|
if (deviceSettingsKeys.contains("LOppmTenths") || force) {
|
|
|
|
swgBladeRF2Settings->setLOppmTenths(settings.m_LOppmTenths);
|
|
|
|
}
|
|
|
|
if (deviceSettingsKeys.contains("log2Decim") || force) {
|
|
|
|
swgBladeRF2Settings->setLog2Decim(settings.m_log2Decim);
|
|
|
|
}
|
|
|
|
if (deviceSettingsKeys.contains("fcPos") || force) {
|
|
|
|
swgBladeRF2Settings->setFcPos((int) settings.m_fcPos);
|
|
|
|
}
|
|
|
|
if (deviceSettingsKeys.contains("dcBlock") || force) {
|
|
|
|
swgBladeRF2Settings->setDcBlock(settings.m_dcBlock ? 1 : 0);
|
|
|
|
}
|
|
|
|
if (deviceSettingsKeys.contains("iqCorrection") || force) {
|
|
|
|
swgBladeRF2Settings->setIqCorrection(settings.m_iqCorrection ? 1 : 0);
|
|
|
|
}
|
|
|
|
if (deviceSettingsKeys.contains("transverterDeltaFrequency") || force) {
|
|
|
|
swgBladeRF2Settings->setTransverterDeltaFrequency(settings.m_transverterDeltaFrequency);
|
|
|
|
}
|
|
|
|
if (deviceSettingsKeys.contains("transverterMode") || force) {
|
|
|
|
swgBladeRF2Settings->setTransverterMode(settings.m_transverterMode ? 1 : 0);
|
|
|
|
}
|
|
|
|
if (deviceSettingsKeys.contains("fileRecordName") || force) {
|
|
|
|
swgBladeRF2Settings->setFileRecordName(new QString(settings.m_fileRecordName));
|
|
|
|
}
|
|
|
|
if (deviceSettingsKeys.contains("devSampleRate")) {
|
|
|
|
swgBladeRF2Settings->setDevSampleRate(settings.m_devSampleRate);
|
|
|
|
}
|
|
|
|
if (deviceSettingsKeys.contains("bandwidth")) {
|
|
|
|
swgBladeRF2Settings->setBandwidth(settings.m_bandwidth);
|
|
|
|
}
|
|
|
|
if (deviceSettingsKeys.contains("biasTee")) {
|
|
|
|
swgBladeRF2Settings->setBiasTee(settings.m_biasTee);
|
|
|
|
}
|
|
|
|
if (deviceSettingsKeys.contains("gainMode")) {
|
|
|
|
swgBladeRF2Settings->setGainMode(settings.m_gainMode);
|
|
|
|
}
|
|
|
|
if (deviceSettingsKeys.contains("globalGain")) {
|
|
|
|
swgBladeRF2Settings->setGlobalGain(settings.m_globalGain);
|
|
|
|
}
|
|
|
|
|
|
|
|
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 BladeRF2Input::webapiReverseSendStartStop(bool start)
|
|
|
|
{
|
2019-03-25 10:21:17 -04:00
|
|
|
SWGSDRangel::SWGDeviceSettings *swgDeviceSettings = new SWGSDRangel::SWGDeviceSettings();
|
2019-05-07 08:43:38 -04:00
|
|
|
swgDeviceSettings->setDirection(0); // single Rx
|
2019-03-25 10:21:17 -04:00
|
|
|
swgDeviceSettings->setOriginatorIndex(m_deviceAPI->getDeviceSetIndex());
|
|
|
|
swgDeviceSettings->setDeviceHwType(new QString("BladeRF2"));
|
|
|
|
|
2018-12-25 15:05:24 -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:21:17 -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-25 15:05:24 -05:00
|
|
|
|
|
|
|
if (start) {
|
2019-03-25 10:21:17 -04:00
|
|
|
m_networkManager->sendCustomRequest(m_networkRequest, "POST", buffer);
|
2018-12-25 15:05:24 -05:00
|
|
|
} else {
|
2019-03-25 10:21:17 -04:00
|
|
|
m_networkManager->sendCustomRequest(m_networkRequest, "DELETE", buffer);
|
2018-12-25 15:05:24 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void BladeRF2Input::networkManagerFinished(QNetworkReply *reply)
|
|
|
|
{
|
|
|
|
QNetworkReply::NetworkError replyError = reply->error();
|
|
|
|
|
|
|
|
if (replyError)
|
|
|
|
{
|
|
|
|
qWarning() << "BladeRF2Input::networkManagerFinished:"
|
|
|
|
<< " error(" << (int) replyError
|
|
|
|
<< "): " << replyError
|
|
|
|
<< ": " << reply->errorString();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString answer = reply->readAll();
|
|
|
|
answer.chop(1); // remove last \n
|
|
|
|
qDebug("BladeRF2Input::networkManagerFinished: reply:\n%s", answer.toStdString().c_str());
|
|
|
|
}
|