2015-06-06 21:30:28 -04:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////
|
2015-06-07 11:56:19 -04:00
|
|
|
// Copyright (C) 2015 Edouard Griffiths, F4EXB //
|
2015-06-06 21:30:28 -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 //
|
|
|
|
// //
|
|
|
|
// 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/>. //
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2017-01-01 21:14:46 -05:00
|
|
|
#include "bladerfinput.h"
|
2016-12-26 21:11:57 -05:00
|
|
|
|
2015-06-06 21:30:28 -04:00
|
|
|
#include <string.h>
|
|
|
|
#include <errno.h>
|
2015-08-09 04:33:04 -04:00
|
|
|
#include <QDebug>
|
2015-06-06 21:30:28 -04:00
|
|
|
|
|
|
|
#include "util/simpleserializer.h"
|
2015-08-12 03:03:02 -04:00
|
|
|
#include "dsp/dspcommands.h"
|
2015-09-27 06:50:38 -04:00
|
|
|
#include "dsp/dspengine.h"
|
2017-09-04 16:45:07 -04:00
|
|
|
#include "dsp/filerecord.h"
|
2016-12-30 10:13:28 -05:00
|
|
|
#include "device/devicesourceapi.h"
|
|
|
|
#include "device/devicesinkapi.h"
|
2016-10-10 19:17:55 -04:00
|
|
|
|
2016-12-30 10:13:28 -05:00
|
|
|
#include "bladerfinputgui.h"
|
|
|
|
#include "bladerfinputthread.h"
|
2015-06-06 21:30:28 -04:00
|
|
|
|
|
|
|
MESSAGE_CLASS_DEFINITION(BladerfInput::MsgConfigureBladerf, Message)
|
2017-09-04 16:45:07 -04:00
|
|
|
MESSAGE_CLASS_DEFINITION(BladerfInput::MsgFileRecord, Message)
|
2015-06-06 21:30:28 -04:00
|
|
|
|
2016-10-10 19:17:55 -04:00
|
|
|
BladerfInput::BladerfInput(DeviceSourceAPI *deviceAPI) :
|
2016-05-15 20:14:36 -04:00
|
|
|
m_deviceAPI(deviceAPI),
|
2015-06-06 21:30:28 -04:00
|
|
|
m_settings(),
|
2015-08-17 02:29:34 -04:00
|
|
|
m_dev(0),
|
|
|
|
m_bladerfThread(0),
|
2017-04-13 14:16:33 -04:00
|
|
|
m_deviceDescription("BladeRFInput"),
|
|
|
|
m_running(false)
|
2015-06-06 21:30:28 -04:00
|
|
|
{
|
2017-04-13 14:16:33 -04:00
|
|
|
openDevice();
|
2017-09-04 16:45:07 -04:00
|
|
|
|
|
|
|
char recFileNameCStr[30];
|
|
|
|
sprintf(recFileNameCStr, "test_%d.sdriq", m_deviceAPI->getDeviceUID());
|
|
|
|
m_fileSink = new FileRecord(std::string(recFileNameCStr));
|
|
|
|
m_deviceAPI->addSink(m_fileSink);
|
|
|
|
|
2016-12-30 10:13:28 -05:00
|
|
|
m_deviceAPI->setBuddySharedPtr(&m_sharedParams);
|
2015-06-06 21:30:28 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
BladerfInput::~BladerfInput()
|
|
|
|
{
|
2017-04-13 14:16:33 -04:00
|
|
|
if (m_running) stop();
|
2017-09-04 16:45:07 -04:00
|
|
|
m_deviceAPI->removeSink(m_fileSink);
|
|
|
|
delete m_fileSink;
|
2017-04-13 14:16:33 -04:00
|
|
|
closeDevice();
|
2017-01-03 03:09:51 -05:00
|
|
|
m_deviceAPI->setBuddySharedPtr(0);
|
2015-08-17 02:29:34 -04:00
|
|
|
}
|
|
|
|
|
2017-04-13 14:16:33 -04:00
|
|
|
bool BladerfInput::openDevice()
|
2015-06-06 21:30:28 -04:00
|
|
|
{
|
2017-04-13 14:16:33 -04:00
|
|
|
if (m_dev != 0)
|
|
|
|
{
|
|
|
|
closeDevice();
|
|
|
|
}
|
2015-06-06 21:30:28 -04:00
|
|
|
|
2017-04-13 14:16:33 -04:00
|
|
|
int res;
|
2015-06-06 21:30:28 -04:00
|
|
|
|
2017-04-13 14:16:33 -04:00
|
|
|
if (!m_sampleFifo.setSize(96000 * 4))
|
|
|
|
{
|
2017-04-13 17:40:14 -04:00
|
|
|
qCritical("BladerfInput::openDevice: could not allocate SampleFifo");
|
2017-04-13 14:16:33 -04:00
|
|
|
return false;
|
|
|
|
}
|
2015-06-06 21:30:28 -04:00
|
|
|
|
2017-04-13 14:16:33 -04:00
|
|
|
if (m_deviceAPI->getSinkBuddies().size() > 0)
|
|
|
|
{
|
2017-04-13 17:40:14 -04:00
|
|
|
DeviceSinkAPI *sinkBuddy = m_deviceAPI->getSinkBuddies()[0];
|
|
|
|
DeviceBladeRFParams *buddySharedParams = (DeviceBladeRFParams *) sinkBuddy->getBuddySharedPtr();
|
2016-12-30 10:13:28 -05:00
|
|
|
|
2017-04-13 14:16:33 -04:00
|
|
|
if (buddySharedParams == 0)
|
|
|
|
{
|
2017-04-13 17:40:14 -04:00
|
|
|
qCritical("BladerfInput::openDevice: could not get shared parameters from buddy");
|
2016-12-30 10:13:28 -05:00
|
|
|
return false;
|
2017-04-13 14:16:33 -04:00
|
|
|
}
|
2016-12-30 10:13:28 -05:00
|
|
|
|
2017-04-13 17:40:14 -04:00
|
|
|
if (buddySharedParams->m_dev == 0) // device is not opened by buddy
|
2017-04-13 14:16:33 -04:00
|
|
|
{
|
2017-04-13 17:40:14 -04:00
|
|
|
qCritical("BladerfInput::openDevice: could not get BladeRF handle from buddy");
|
|
|
|
return false;
|
2017-04-13 14:16:33 -04:00
|
|
|
}
|
2016-12-30 10:13:28 -05:00
|
|
|
|
2017-04-13 17:40:14 -04:00
|
|
|
m_sharedParams = *(buddySharedParams); // copy parameters from buddy
|
|
|
|
m_dev = m_sharedParams.m_dev; // get BladeRF handle
|
2017-04-13 14:16:33 -04:00
|
|
|
}
|
2017-04-13 17:40:14 -04:00
|
|
|
else
|
2017-04-13 14:16:33 -04:00
|
|
|
{
|
2017-04-13 19:59:09 -04:00
|
|
|
if (!DeviceBladeRF::open_bladerf(&m_dev, qPrintable(m_deviceAPI->getSampleSourceSerial())))
|
2016-12-30 10:13:28 -05:00
|
|
|
{
|
2017-04-13 19:59:09 -04:00
|
|
|
qCritical("BladerfInput::start: could not open BladeRF %s", qPrintable(m_deviceAPI->getSampleSourceSerial()));
|
2016-12-30 10:13:28 -05:00
|
|
|
return false;
|
|
|
|
}
|
2015-06-06 21:30:28 -04:00
|
|
|
|
2016-12-30 10:13:28 -05:00
|
|
|
m_sharedParams.m_dev = m_dev;
|
2017-04-13 14:16:33 -04:00
|
|
|
}
|
2015-06-06 21:30:28 -04:00
|
|
|
|
|
|
|
// TODO: adjust USB transfer data according to sample rate
|
|
|
|
if ((res = bladerf_sync_config(m_dev, BLADERF_MODULE_RX, BLADERF_FORMAT_SC16_Q11, 64, 8192, 32, 10000)) < 0)
|
|
|
|
{
|
2017-04-13 14:16:33 -04:00
|
|
|
qCritical("BladerfInput::start: bladerf_sync_config with return code %d", res);
|
|
|
|
return false;
|
2015-06-06 21:30:28 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
if ((res = bladerf_enable_module(m_dev, BLADERF_MODULE_RX, true)) < 0)
|
|
|
|
{
|
2017-04-13 14:16:33 -04:00
|
|
|
qCritical("BladerfInput::start: bladerf_enable_module with return code %d", res);
|
|
|
|
return false;
|
2015-06-06 21:30:28 -04:00
|
|
|
}
|
|
|
|
|
2017-04-13 14:16:33 -04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-04-13 21:40:45 -04:00
|
|
|
bool BladerfInput::start()
|
2017-04-13 14:16:33 -04:00
|
|
|
{
|
|
|
|
// QMutexLocker mutexLocker(&m_mutex);
|
|
|
|
|
|
|
|
if (!m_dev) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (m_running) stop();
|
|
|
|
|
|
|
|
if((m_bladerfThread = new BladerfInputThread(m_dev, &m_sampleFifo)) == 0) {
|
2017-01-01 21:14:46 -05:00
|
|
|
qFatal("BladerfInput::start: out of memory");
|
2017-04-13 14:16:33 -04:00
|
|
|
stop();
|
|
|
|
return false;
|
2015-06-06 21:30:28 -04:00
|
|
|
}
|
|
|
|
|
2017-04-13 14:16:33 -04:00
|
|
|
m_bladerfThread->setLog2Decimation(m_settings.m_log2Decim);
|
|
|
|
m_bladerfThread->setFcPos((int) m_settings.m_fcPos);
|
|
|
|
|
2015-06-06 21:30:28 -04:00
|
|
|
m_bladerfThread->startWork();
|
|
|
|
|
2017-01-02 18:56:18 -05:00
|
|
|
// mutexLocker.unlock();
|
2015-08-17 02:29:34 -04:00
|
|
|
applySettings(m_settings, true);
|
2015-06-06 21:30:28 -04:00
|
|
|
|
2015-08-10 16:15:16 -04:00
|
|
|
qDebug("BladerfInput::startInput: started");
|
2017-04-13 14:16:33 -04:00
|
|
|
m_running = true;
|
2015-06-06 21:30:28 -04:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-04-13 14:16:33 -04:00
|
|
|
void BladerfInput::closeDevice()
|
2015-06-06 21:30:28 -04:00
|
|
|
{
|
2017-01-02 18:56:18 -05:00
|
|
|
int res;
|
2015-06-06 21:30:28 -04:00
|
|
|
|
2017-04-17 06:00:13 -04:00
|
|
|
if (m_dev == 0) { // was never open
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-01-02 18:56:18 -05:00
|
|
|
if ((res = bladerf_enable_module(m_dev, BLADERF_MODULE_RX, false)) < 0)
|
|
|
|
{
|
|
|
|
qCritical("BladerfInput::stop: bladerf_enable_module with return code %d", res);
|
|
|
|
}
|
|
|
|
|
2017-04-13 17:40:14 -04:00
|
|
|
if (m_deviceAPI->getSinkBuddies().size() == 0)
|
2016-12-30 10:13:28 -05:00
|
|
|
{
|
2017-04-13 17:40:14 -04:00
|
|
|
qDebug("BladerfInput::closeDevice: closing device since Tx side is not open");
|
2016-12-30 10:13:28 -05:00
|
|
|
|
|
|
|
if(m_dev != 0) // close BladeRF
|
|
|
|
{
|
|
|
|
bladerf_close(m_dev);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
m_sharedParams.m_dev = 0;
|
2017-01-03 03:09:51 -05:00
|
|
|
m_dev = 0;
|
2017-04-13 14:16:33 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void BladerfInput::stop()
|
|
|
|
{
|
|
|
|
// QMutexLocker mutexLocker(&m_mutex);
|
2016-12-30 10:13:28 -05:00
|
|
|
|
2017-04-13 14:16:33 -04:00
|
|
|
if(m_bladerfThread != 0)
|
|
|
|
{
|
|
|
|
m_bladerfThread->stopWork();
|
|
|
|
delete m_bladerfThread;
|
|
|
|
m_bladerfThread = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_running = false;
|
2015-06-06 21:30:28 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
const QString& BladerfInput::getDeviceDescription() const
|
|
|
|
{
|
|
|
|
return m_deviceDescription;
|
|
|
|
}
|
|
|
|
|
|
|
|
int BladerfInput::getSampleRate() const
|
|
|
|
{
|
2015-08-17 02:29:34 -04:00
|
|
|
int rate = m_settings.m_devSampleRate;
|
2015-06-06 21:30:28 -04:00
|
|
|
return (rate / (1<<m_settings.m_log2Decim));
|
|
|
|
}
|
|
|
|
|
|
|
|
quint64 BladerfInput::getCenterFrequency() const
|
|
|
|
{
|
2015-08-17 02:29:34 -04:00
|
|
|
return m_settings.m_centerFrequency;
|
2015-06-06 21:30:28 -04:00
|
|
|
}
|
|
|
|
|
2015-08-17 02:29:34 -04:00
|
|
|
bool BladerfInput::handleMessage(const Message& message)
|
2015-06-06 21:30:28 -04:00
|
|
|
{
|
2015-08-12 03:03:02 -04:00
|
|
|
if (MsgConfigureBladerf::match(message))
|
|
|
|
{
|
2015-08-17 02:29:34 -04:00
|
|
|
MsgConfigureBladerf& conf = (MsgConfigureBladerf&) message;
|
2015-08-30 17:22:18 -04:00
|
|
|
qDebug() << "BladerfInput::handleMessage: MsgConfigureBladerf";
|
2015-08-12 03:03:02 -04:00
|
|
|
|
2015-08-17 02:29:34 -04:00
|
|
|
if (!applySettings(conf.getSettings(), false))
|
|
|
|
{
|
2015-06-06 21:30:28 -04:00
|
|
|
qDebug("BladeRF config error");
|
2015-08-12 03:03:02 -04:00
|
|
|
}
|
|
|
|
|
2015-06-06 21:30:28 -04:00
|
|
|
return true;
|
2015-08-12 03:03:02 -04:00
|
|
|
}
|
2017-09-04 16:45:07 -04:00
|
|
|
else if (MsgFileRecord::match(message))
|
|
|
|
{
|
|
|
|
MsgFileRecord& conf = (MsgFileRecord&) message;
|
|
|
|
qDebug() << "BladerfInput::handleMessage: MsgFileRecord: " << conf.getStartStop();
|
|
|
|
|
|
|
|
if (conf.getStartStop()) {
|
|
|
|
m_fileSink->startRecording();
|
|
|
|
} else {
|
|
|
|
m_fileSink->stopRecording();
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2015-08-12 03:03:02 -04:00
|
|
|
else
|
|
|
|
{
|
2015-06-06 21:30:28 -04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-26 20:14:31 -05:00
|
|
|
bool BladerfInput::applySettings(const BladeRFInputSettings& settings, bool force)
|
2015-06-06 21:30:28 -04:00
|
|
|
{
|
2015-08-19 03:24:44 -04:00
|
|
|
bool forwardChange = false;
|
2017-01-02 18:56:18 -05:00
|
|
|
// QMutexLocker mutexLocker(&m_mutex);
|
2015-06-06 21:30:28 -04:00
|
|
|
|
2015-08-12 03:03:02 -04:00
|
|
|
qDebug() << "BladerfInput::applySettings: m_dev: " << m_dev;
|
|
|
|
|
2015-09-30 21:18:20 -04:00
|
|
|
if (m_settings.m_dcBlock != settings.m_dcBlock)
|
|
|
|
{
|
|
|
|
m_settings.m_dcBlock = settings.m_dcBlock;
|
2016-05-15 20:14:36 -04:00
|
|
|
m_deviceAPI->configureCorrections(m_settings.m_dcBlock, m_settings.m_iqCorrection);
|
2015-09-30 21:18:20 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (m_settings.m_iqCorrection != settings.m_iqCorrection)
|
|
|
|
{
|
|
|
|
m_settings.m_iqCorrection = settings.m_iqCorrection;
|
2016-05-15 20:14:36 -04:00
|
|
|
m_deviceAPI->configureCorrections(m_settings.m_dcBlock, m_settings.m_iqCorrection);
|
2015-09-30 21:18:20 -04:00
|
|
|
}
|
|
|
|
|
2015-08-12 03:03:02 -04:00
|
|
|
if ((m_settings.m_lnaGain != settings.m_lnaGain) || force)
|
|
|
|
{
|
2015-06-06 21:30:28 -04:00
|
|
|
m_settings.m_lnaGain = settings.m_lnaGain;
|
2015-08-12 03:03:02 -04:00
|
|
|
|
2015-08-17 02:29:34 -04:00
|
|
|
if (m_dev != 0)
|
2015-08-12 03:03:02 -04:00
|
|
|
{
|
2015-08-17 02:29:34 -04:00
|
|
|
if(bladerf_set_lna_gain(m_dev, getLnaGain(m_settings.m_lnaGain)) != 0)
|
|
|
|
{
|
2017-01-01 21:14:46 -05:00
|
|
|
qDebug("BladerfInput::applySettings: bladerf_set_lna_gain() failed");
|
2015-08-17 02:29:34 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-01-01 21:14:46 -05:00
|
|
|
qDebug() << "BladerfInput::applySettings: LNA gain set to " << getLnaGain(m_settings.m_lnaGain);
|
2015-06-06 21:30:28 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-12 03:03:02 -04:00
|
|
|
if ((m_settings.m_vga1 != settings.m_vga1) || force)
|
|
|
|
{
|
2015-06-06 21:30:28 -04:00
|
|
|
m_settings.m_vga1 = settings.m_vga1;
|
2015-08-12 03:03:02 -04:00
|
|
|
|
2015-08-17 02:29:34 -04:00
|
|
|
if (m_dev != 0)
|
2015-08-12 03:03:02 -04:00
|
|
|
{
|
2015-08-17 02:29:34 -04:00
|
|
|
if(bladerf_set_rxvga1(m_dev, m_settings.m_vga1) != 0)
|
|
|
|
{
|
2017-01-01 21:14:46 -05:00
|
|
|
qDebug("BladerfInput::applySettings: bladerf_set_rxvga1() failed");
|
2015-08-17 02:29:34 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-01-01 21:14:46 -05:00
|
|
|
qDebug() << "BladerfInput::applySettings: VGA1 gain set to " << m_settings.m_vga1;
|
2015-06-06 21:30:28 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-12 03:03:02 -04:00
|
|
|
if ((m_settings.m_vga2 != settings.m_vga2) || force)
|
|
|
|
{
|
2015-06-06 21:30:28 -04:00
|
|
|
m_settings.m_vga2 = settings.m_vga2;
|
2015-08-12 03:03:02 -04:00
|
|
|
|
2015-08-17 02:29:34 -04:00
|
|
|
if(m_dev != 0)
|
2015-08-12 03:03:02 -04:00
|
|
|
{
|
2015-08-17 02:29:34 -04:00
|
|
|
if(bladerf_set_rxvga2(m_dev, m_settings.m_vga2) != 0)
|
|
|
|
{
|
2017-01-01 21:14:46 -05:00
|
|
|
qDebug("BladerfInput::applySettings: bladerf_set_rxvga2() failed");
|
2015-08-17 02:29:34 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-01-01 21:14:46 -05:00
|
|
|
qDebug() << "BladerfInput::applySettings: VGA2 gain set to " << m_settings.m_vga2;
|
2015-06-06 21:30:28 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-12 03:03:02 -04:00
|
|
|
if ((m_settings.m_xb200 != settings.m_xb200) || force)
|
|
|
|
{
|
2015-06-06 21:30:28 -04:00
|
|
|
m_settings.m_xb200 = settings.m_xb200;
|
2015-08-12 03:03:02 -04:00
|
|
|
|
2015-08-17 02:29:34 -04:00
|
|
|
if (m_dev != 0)
|
2015-08-12 03:03:02 -04:00
|
|
|
{
|
2016-12-30 10:13:28 -05:00
|
|
|
bool changeSettings;
|
|
|
|
|
|
|
|
if (m_deviceAPI->getSinkBuddies().size() > 0)
|
|
|
|
{
|
|
|
|
DeviceSinkAPI *buddy = m_deviceAPI->getSinkBuddies()[0];
|
|
|
|
|
|
|
|
if (buddy->getDeviceSinkEngine()->state() == DSPDeviceSinkEngine::StRunning) // Tx side running
|
|
|
|
{
|
|
|
|
changeSettings = false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
changeSettings = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else // No Tx open
|
|
|
|
{
|
|
|
|
changeSettings = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (changeSettings)
|
|
|
|
{
|
|
|
|
if (m_settings.m_xb200)
|
|
|
|
{
|
|
|
|
if (bladerf_expansion_attach(m_dev, BLADERF_XB_200) != 0)
|
|
|
|
{
|
2017-01-01 21:14:46 -05:00
|
|
|
qDebug("BladerfInput::applySettings: bladerf_expansion_attach(xb200) failed");
|
2016-12-30 10:13:28 -05:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-01-01 21:14:46 -05:00
|
|
|
qDebug() << "BladerfInput::applySettings: Attach XB200";
|
2016-12-30 10:13:28 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (bladerf_expansion_attach(m_dev, BLADERF_XB_NONE) != 0)
|
|
|
|
{
|
2017-01-01 21:14:46 -05:00
|
|
|
qDebug("BladerfInput::applySettings: bladerf_expansion_attach(none) failed");
|
2016-12-30 10:13:28 -05:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-01-01 21:14:46 -05:00
|
|
|
qDebug() << "BladerfInput::applySettings: Detach XB200";
|
2016-12-30 10:13:28 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
m_sharedParams.m_xb200Attached = m_settings.m_xb200;
|
|
|
|
}
|
2015-06-06 21:30:28 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-12 03:03:02 -04:00
|
|
|
if ((m_settings.m_xb200Path != settings.m_xb200Path) || force)
|
|
|
|
{
|
2015-06-06 21:30:28 -04:00
|
|
|
m_settings.m_xb200Path = settings.m_xb200Path;
|
2015-08-17 02:29:34 -04:00
|
|
|
|
|
|
|
if (m_dev != 0)
|
2015-08-12 03:03:02 -04:00
|
|
|
{
|
2015-08-17 02:29:34 -04:00
|
|
|
if(bladerf_xb200_set_path(m_dev, BLADERF_MODULE_RX, m_settings.m_xb200Path) != 0)
|
|
|
|
{
|
2017-01-01 21:14:46 -05:00
|
|
|
qDebug("BladerfInput::applySettings: bladerf_xb200_set_path(BLADERF_MODULE_RX) failed");
|
2015-08-17 02:29:34 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-01-01 21:14:46 -05:00
|
|
|
qDebug() << "BladerfInput::applySettings: set xb200 path to " << m_settings.m_xb200Path;
|
2015-06-06 21:30:28 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-12 03:03:02 -04:00
|
|
|
if ((m_settings.m_xb200Filter != settings.m_xb200Filter) || force)
|
|
|
|
{
|
2015-06-06 21:30:28 -04:00
|
|
|
m_settings.m_xb200Filter = settings.m_xb200Filter;
|
2015-08-12 03:03:02 -04:00
|
|
|
|
2015-08-17 02:29:34 -04:00
|
|
|
if (m_dev != 0)
|
2015-08-12 03:03:02 -04:00
|
|
|
{
|
2015-08-17 02:29:34 -04:00
|
|
|
if(bladerf_xb200_set_filterbank(m_dev, BLADERF_MODULE_RX, m_settings.m_xb200Filter) != 0)
|
|
|
|
{
|
2017-01-01 21:14:46 -05:00
|
|
|
qDebug("BladerfInput::applySettings: bladerf_xb200_set_filterbank(BLADERF_MODULE_RX) failed");
|
2015-08-17 02:29:34 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-01-01 21:14:46 -05:00
|
|
|
qDebug() << "BladerfInput::applySettings: set xb200 filter to " << m_settings.m_xb200Filter;
|
2015-06-06 21:30:28 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-17 02:29:34 -04:00
|
|
|
if ((m_settings.m_devSampleRate != settings.m_devSampleRate) || force)
|
2015-08-12 03:03:02 -04:00
|
|
|
{
|
2015-08-17 02:29:34 -04:00
|
|
|
m_settings.m_devSampleRate = settings.m_devSampleRate;
|
2015-08-19 03:24:44 -04:00
|
|
|
forwardChange = true;
|
2015-08-12 03:03:02 -04:00
|
|
|
|
2015-08-17 02:29:34 -04:00
|
|
|
if (m_dev != 0)
|
2015-08-12 03:03:02 -04:00
|
|
|
{
|
2015-06-06 21:30:28 -04:00
|
|
|
unsigned int actualSamplerate;
|
2015-08-12 03:03:02 -04:00
|
|
|
|
2015-08-17 02:29:34 -04:00
|
|
|
if (bladerf_set_sample_rate(m_dev, BLADERF_MODULE_RX, m_settings.m_devSampleRate, &actualSamplerate) < 0)
|
2015-08-12 03:03:02 -04:00
|
|
|
{
|
2017-01-01 21:14:46 -05:00
|
|
|
qCritical("BladerfInput::applySettings: could not set sample rate: %d", m_settings.m_devSampleRate);
|
2015-08-12 03:03:02 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-01-01 21:14:46 -05:00
|
|
|
qDebug() << "BladerfInput::applySettings: bladerf_set_sample_rate(BLADERF_MODULE_RX) actual sample rate is " << actualSamplerate;
|
2015-06-06 21:30:28 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-12 03:03:02 -04:00
|
|
|
if ((m_settings.m_bandwidth != settings.m_bandwidth) || force)
|
|
|
|
{
|
2015-07-28 18:08:27 -04:00
|
|
|
m_settings.m_bandwidth = settings.m_bandwidth;
|
2015-08-12 03:03:02 -04:00
|
|
|
|
2015-08-17 02:29:34 -04:00
|
|
|
if(m_dev != 0)
|
2015-08-12 03:03:02 -04:00
|
|
|
{
|
2015-06-06 21:30:28 -04:00
|
|
|
unsigned int actualBandwidth;
|
2015-08-12 03:03:02 -04:00
|
|
|
|
2015-07-28 18:08:27 -04:00
|
|
|
if( bladerf_set_bandwidth(m_dev, BLADERF_MODULE_RX, m_settings.m_bandwidth, &actualBandwidth) < 0)
|
2015-08-17 02:29:34 -04:00
|
|
|
{
|
2017-01-01 21:14:46 -05:00
|
|
|
qCritical("BladerfInput::applySettings: could not set bandwidth: %d", m_settings.m_bandwidth);
|
2015-08-17 02:29:34 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-01-01 21:14:46 -05:00
|
|
|
qDebug() << "BladerfInput::applySettings: bladerf_set_bandwidth(BLADERF_MODULE_RX) actual bandwidth is " << actualBandwidth;
|
2015-06-06 21:30:28 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-12 03:03:02 -04:00
|
|
|
if ((m_settings.m_log2Decim != settings.m_log2Decim) || force)
|
|
|
|
{
|
2015-07-26 19:09:24 -04:00
|
|
|
m_settings.m_log2Decim = settings.m_log2Decim;
|
2015-08-19 03:24:44 -04:00
|
|
|
forwardChange = true;
|
2015-08-12 03:03:02 -04:00
|
|
|
|
2017-04-13 14:16:33 -04:00
|
|
|
if (m_bladerfThread != 0)
|
2015-08-12 03:03:02 -04:00
|
|
|
{
|
2015-07-26 19:09:24 -04:00
|
|
|
m_bladerfThread->setLog2Decimation(m_settings.m_log2Decim);
|
2017-01-01 21:14:46 -05:00
|
|
|
qDebug() << "BladerfInput::applySettings: set decimation to " << (1<<m_settings.m_log2Decim);
|
2015-06-06 21:30:28 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-12 03:03:02 -04:00
|
|
|
if ((m_settings.m_fcPos != settings.m_fcPos) || force)
|
|
|
|
{
|
2015-07-26 19:09:24 -04:00
|
|
|
m_settings.m_fcPos = settings.m_fcPos;
|
2015-08-12 03:03:02 -04:00
|
|
|
|
2017-04-13 14:16:33 -04:00
|
|
|
if (m_bladerfThread != 0)
|
2015-08-12 03:03:02 -04:00
|
|
|
{
|
2015-07-26 19:09:24 -04:00
|
|
|
m_bladerfThread->setFcPos((int) m_settings.m_fcPos);
|
2017-01-01 21:14:46 -05:00
|
|
|
qDebug() << "BladerfInput::applySettings: set fc pos (enum) to " << (int) m_settings.m_fcPos;
|
2015-07-01 19:00:27 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-19 03:24:44 -04:00
|
|
|
if (m_settings.m_centerFrequency != settings.m_centerFrequency)
|
|
|
|
{
|
|
|
|
forwardChange = true;
|
|
|
|
}
|
|
|
|
|
2015-08-17 02:29:34 -04:00
|
|
|
m_settings.m_centerFrequency = settings.m_centerFrequency;
|
2015-06-06 21:30:28 -04:00
|
|
|
|
2015-08-19 03:24:44 -04:00
|
|
|
qint64 deviceCenterFrequency = m_settings.m_centerFrequency;
|
|
|
|
qint64 f_img = deviceCenterFrequency;
|
|
|
|
qint64 f_cut = deviceCenterFrequency + m_settings.m_bandwidth/2;
|
2015-08-12 03:03:02 -04:00
|
|
|
|
2016-12-26 20:14:31 -05:00
|
|
|
if ((m_settings.m_log2Decim == 0) || (m_settings.m_fcPos == BladeRFInputSettings::FC_POS_CENTER))
|
2015-08-12 03:03:02 -04:00
|
|
|
{
|
2015-08-19 03:24:44 -04:00
|
|
|
deviceCenterFrequency = m_settings.m_centerFrequency;
|
|
|
|
f_img = deviceCenterFrequency;
|
|
|
|
f_cut = deviceCenterFrequency + m_settings.m_bandwidth/2;
|
2015-08-12 03:03:02 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-12-26 20:14:31 -05:00
|
|
|
if (m_settings.m_fcPos == BladeRFInputSettings::FC_POS_INFRA)
|
2015-07-01 20:10:14 -04:00
|
|
|
{
|
2015-08-19 03:24:44 -04:00
|
|
|
deviceCenterFrequency = m_settings.m_centerFrequency + (m_settings.m_devSampleRate / 4);
|
|
|
|
f_img = deviceCenterFrequency + m_settings.m_devSampleRate/2;
|
|
|
|
f_cut = deviceCenterFrequency + m_settings.m_bandwidth/2;
|
2015-07-01 19:00:27 -04:00
|
|
|
}
|
2016-12-26 20:14:31 -05:00
|
|
|
else if (m_settings.m_fcPos == BladeRFInputSettings::FC_POS_SUPRA)
|
2015-07-01 19:00:27 -04:00
|
|
|
{
|
2015-08-19 03:24:44 -04:00
|
|
|
deviceCenterFrequency = m_settings.m_centerFrequency - (m_settings.m_devSampleRate / 4);
|
|
|
|
f_img = deviceCenterFrequency - m_settings.m_devSampleRate/2;
|
|
|
|
f_cut = deviceCenterFrequency - m_settings.m_bandwidth/2;
|
2015-06-06 21:30:28 -04:00
|
|
|
}
|
2015-08-12 03:03:02 -04:00
|
|
|
}
|
2015-06-06 21:30:28 -04:00
|
|
|
|
2015-08-12 03:03:02 -04:00
|
|
|
if (m_dev != NULL)
|
|
|
|
{
|
2015-08-19 03:24:44 -04:00
|
|
|
if (bladerf_set_frequency( m_dev, BLADERF_MODULE_RX, deviceCenterFrequency ) != 0)
|
2015-08-17 02:29:34 -04:00
|
|
|
{
|
2017-01-01 21:14:46 -05:00
|
|
|
qDebug("BladerfInput::applySettings: bladerf_set_frequency(%lld) failed", m_settings.m_centerFrequency);
|
2015-06-06 21:30:28 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-19 03:24:44 -04:00
|
|
|
if (forwardChange)
|
|
|
|
{
|
|
|
|
int sampleRate = m_settings.m_devSampleRate/(1<<m_settings.m_log2Decim);
|
|
|
|
DSPSignalNotification *notif = new DSPSignalNotification(sampleRate, m_settings.m_centerFrequency);
|
2017-09-04 16:45:07 -04:00
|
|
|
m_fileSink->handleMessage(*notif); // forward to file sink
|
2017-09-04 18:47:12 -04:00
|
|
|
m_deviceAPI->getDeviceInputMessageQueue()->push(notif);
|
2015-08-19 03:24:44 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
qDebug() << "BladerfInput::applySettings: center freq: " << m_settings.m_centerFrequency << " Hz"
|
|
|
|
<< " device center freq: " << deviceCenterFrequency << " Hz"
|
2017-04-01 21:24:11 -04:00
|
|
|
<< " device sample rate: " << m_settings.m_devSampleRate << "S/s"
|
|
|
|
<< " Actual sample rate: " << m_settings.m_devSampleRate/(1<<m_settings.m_log2Decim) << "S/s"
|
2015-08-12 03:03:02 -04:00
|
|
|
<< " BW: " << m_settings.m_bandwidth << "Hz"
|
|
|
|
<< " img: " << f_img << "Hz"
|
|
|
|
<< " cut: " << f_cut << "Hz"
|
|
|
|
<< " img - cut: " << f_img - f_cut;
|
|
|
|
|
2015-06-06 21:30:28 -04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bladerf_lna_gain BladerfInput::getLnaGain(int lnaGain)
|
|
|
|
{
|
2015-08-17 02:29:34 -04:00
|
|
|
if (lnaGain == 2)
|
|
|
|
{
|
2015-06-06 21:30:28 -04:00
|
|
|
return BLADERF_LNA_GAIN_MAX;
|
2015-08-17 02:29:34 -04:00
|
|
|
}
|
|
|
|
else if (lnaGain == 1)
|
|
|
|
{
|
2015-06-06 21:30:28 -04:00
|
|
|
return BLADERF_LNA_GAIN_MID;
|
2015-08-17 02:29:34 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-06-06 21:30:28 -04:00
|
|
|
return BLADERF_LNA_GAIN_BYPASS;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-30 10:13:28 -05:00
|
|
|
//struct bladerf *BladerfInput::open_bladerf_from_serial(const char *serial)
|
|
|
|
//{
|
|
|
|
// int status;
|
|
|
|
// struct bladerf *dev;
|
|
|
|
// struct bladerf_devinfo info;
|
|
|
|
//
|
|
|
|
// /* Initialize all fields to "don't care" wildcard values.
|
|
|
|
// *
|
|
|
|
// * Immediately passing this to bladerf_open_with_devinfo() would cause
|
|
|
|
// * libbladeRF to open any device on any available backend. */
|
|
|
|
// bladerf_init_devinfo(&info);
|
|
|
|
//
|
|
|
|
// /* Specify the desired device's serial number, while leaving all other
|
|
|
|
// * fields in the info structure wildcard values */
|
|
|
|
// if (serial != NULL)
|
|
|
|
// {
|
|
|
|
// strncpy(info.serial, serial, BLADERF_SERIAL_LENGTH - 1);
|
|
|
|
// info.serial[BLADERF_SERIAL_LENGTH - 1] = '\0';
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// status = bladerf_open_with_devinfo(&dev, &info);
|
|
|
|
//
|
|
|
|
// if (status == BLADERF_ERR_NODEV)
|
|
|
|
// {
|
|
|
|
// fprintf(stderr, "No devices available with serial=%s\n", serial);
|
|
|
|
// return NULL;
|
|
|
|
// }
|
|
|
|
// else if (status != 0)
|
|
|
|
// {
|
|
|
|
// fprintf(stderr, "Failed to open device with serial=%s (%s)\n",
|
|
|
|
// serial, bladerf_strerror(status));
|
|
|
|
// return NULL;
|
|
|
|
// }
|
|
|
|
// else
|
|
|
|
// {
|
|
|
|
// return dev;
|
|
|
|
// }
|
|
|
|
//}
|