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/>. //
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#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"
|
2015-06-06 21:30:28 -04:00
|
|
|
#include "bladerfgui.h"
|
|
|
|
#include "bladerfinput.h"
|
|
|
|
#include "bladerfthread.h"
|
2015-08-27 20:27:05 -04:00
|
|
|
#include "bladerfserializer.h"
|
2015-06-06 21:30:28 -04:00
|
|
|
|
|
|
|
MESSAGE_CLASS_DEFINITION(BladerfInput::MsgConfigureBladerf, Message)
|
|
|
|
MESSAGE_CLASS_DEFINITION(BladerfInput::MsgReportBladerf, Message)
|
|
|
|
|
|
|
|
BladerfInput::Settings::Settings() :
|
2015-08-17 02:29:34 -04:00
|
|
|
m_centerFrequency(435000*1000),
|
|
|
|
m_devSampleRate(3072000),
|
2015-06-06 21:30:28 -04:00
|
|
|
m_lnaGain(0),
|
|
|
|
m_vga1(20),
|
|
|
|
m_vga2(9),
|
|
|
|
m_bandwidth(1500000),
|
|
|
|
m_log2Decim(0),
|
2015-07-01 19:00:27 -04:00
|
|
|
m_fcPos(FC_POS_INFRA),
|
2015-06-06 21:30:28 -04:00
|
|
|
m_xb200(false),
|
|
|
|
m_xb200Path(BLADERF_XB200_MIX),
|
|
|
|
m_xb200Filter(BLADERF_XB200_AUTO_1DB)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void BladerfInput::Settings::resetToDefaults()
|
|
|
|
{
|
2015-08-17 02:29:34 -04:00
|
|
|
m_centerFrequency = 435000*1000;
|
|
|
|
m_devSampleRate = 3072000;
|
2015-06-06 21:30:28 -04:00
|
|
|
m_lnaGain = 0;
|
|
|
|
m_vga1 = 20;
|
|
|
|
m_vga2 = 9;
|
2015-06-09 02:18:32 -04:00
|
|
|
m_bandwidth = 1500000;
|
2015-06-06 21:30:28 -04:00
|
|
|
m_log2Decim = 0;
|
2015-07-01 19:00:27 -04:00
|
|
|
m_fcPos = FC_POS_INFRA;
|
2015-08-27 20:27:05 -04:00
|
|
|
m_xb200 = false;
|
|
|
|
m_xb200Path = BLADERF_XB200_MIX;
|
|
|
|
m_xb200Filter = BLADERF_XB200_AUTO_1DB;
|
2015-06-06 21:30:28 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
QByteArray BladerfInput::Settings::serialize() const
|
|
|
|
{
|
2015-08-27 20:27:05 -04:00
|
|
|
BladeRFSerializer::BladeRFData data;
|
|
|
|
|
|
|
|
data.m_data.m_lnaGain = m_lnaGain;
|
|
|
|
data.m_data.m_RxGain1 = m_vga1;
|
|
|
|
data.m_data.m_RxGain2 = m_vga2;
|
|
|
|
data.m_data.m_log2Decim = m_log2Decim;
|
|
|
|
data.m_xb200 = m_xb200;
|
|
|
|
data.m_xb200Path = (int) m_xb200Path;
|
|
|
|
data.m_xb200Filter = (int) m_xb200Filter;
|
|
|
|
data.m_data.m_bandwidth = m_bandwidth;
|
|
|
|
data.m_data.m_fcPosition = (int) m_fcPos;
|
|
|
|
data.m_data.m_frequency = m_centerFrequency;
|
|
|
|
data.m_data.m_rate = m_devSampleRate;
|
|
|
|
|
|
|
|
QByteArray byteArray;
|
|
|
|
|
|
|
|
BladeRFSerializer::writeSerializedData(data, byteArray);
|
|
|
|
|
|
|
|
return byteArray;
|
2015-06-06 21:30:28 -04:00
|
|
|
}
|
|
|
|
|
2015-08-27 20:27:05 -04:00
|
|
|
bool BladerfInput::Settings::deserialize(const QByteArray& serializedData)
|
2015-06-06 21:30:28 -04:00
|
|
|
{
|
2015-08-27 20:27:05 -04:00
|
|
|
BladeRFSerializer::BladeRFData data;
|
|
|
|
|
|
|
|
bool valid = BladeRFSerializer::readSerializedData(serializedData, data);
|
|
|
|
|
|
|
|
m_lnaGain = data.m_data.m_lnaGain;
|
|
|
|
m_vga1 = data.m_data.m_RxGain1;
|
|
|
|
m_vga2 = data.m_data.m_RxGain2;
|
|
|
|
m_log2Decim = data.m_data.m_log2Decim;
|
|
|
|
m_xb200 = data.m_xb200;
|
|
|
|
m_xb200Path = (bladerf_xb200_path) data.m_xb200Path;
|
|
|
|
m_xb200Filter = (bladerf_xb200_filter) data.m_xb200Filter;
|
|
|
|
m_bandwidth = data.m_data.m_bandwidth;
|
|
|
|
m_fcPos = (fcPos_t) data.m_data.m_fcPosition;
|
|
|
|
m_centerFrequency = data.m_data.m_frequency;
|
|
|
|
m_devSampleRate = data.m_data.m_rate;
|
|
|
|
|
|
|
|
return valid;
|
2015-06-06 21:30:28 -04:00
|
|
|
}
|
|
|
|
|
2015-08-17 02:29:34 -04:00
|
|
|
BladerfInput::BladerfInput() :
|
2015-06-06 21:30:28 -04:00
|
|
|
m_settings(),
|
2015-08-17 02:29:34 -04:00
|
|
|
m_dev(0),
|
|
|
|
m_bladerfThread(0),
|
2015-08-12 03:03:02 -04:00
|
|
|
m_deviceDescription("BladeRF")
|
2015-06-06 21:30:28 -04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
BladerfInput::~BladerfInput()
|
|
|
|
{
|
2015-08-17 02:29:34 -04:00
|
|
|
stop();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool BladerfInput::init(const Message& cmd)
|
|
|
|
{
|
|
|
|
return false;
|
2015-06-06 21:30:28 -04:00
|
|
|
}
|
|
|
|
|
2015-08-17 02:29:34 -04:00
|
|
|
bool BladerfInput::start(int device)
|
2015-06-06 21:30:28 -04:00
|
|
|
{
|
|
|
|
QMutexLocker mutexLocker(&m_mutex);
|
|
|
|
|
2015-08-17 02:29:34 -04:00
|
|
|
if (m_dev != 0)
|
|
|
|
{
|
|
|
|
stop();
|
|
|
|
}
|
2015-06-06 21:30:28 -04:00
|
|
|
|
|
|
|
int res;
|
|
|
|
int fpga_loaded;
|
|
|
|
|
2015-08-17 02:29:34 -04:00
|
|
|
if (!m_sampleFifo.setSize(96000 * 4))
|
|
|
|
{
|
2015-06-06 21:30:28 -04:00
|
|
|
qCritical("Could not allocate SampleFifo");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-08-17 02:29:34 -04:00
|
|
|
if ((m_dev = open_bladerf_from_serial(0)) == 0) // TODO: fix; Open first available device as there is no proper handling for multiple devices
|
2015-06-06 21:30:28 -04:00
|
|
|
{
|
|
|
|
qCritical("could not open BladeRF");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
fpga_loaded = bladerf_is_fpga_configured(m_dev);
|
|
|
|
|
2015-08-17 02:29:34 -04:00
|
|
|
if (fpga_loaded < 0)
|
|
|
|
{
|
2015-06-06 21:30:28 -04:00
|
|
|
qCritical("Failed to check FPGA state: %s",
|
|
|
|
bladerf_strerror(fpga_loaded));
|
|
|
|
return false;
|
2015-08-17 02:29:34 -04:00
|
|
|
}
|
|
|
|
else if (fpga_loaded == 0)
|
|
|
|
{
|
2015-06-06 21:30:28 -04:00
|
|
|
qCritical("The device's FPGA is not loaded.");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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)
|
|
|
|
{
|
|
|
|
qCritical("bladerf_sync_config with return code %d", res);
|
|
|
|
goto failed;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((res = bladerf_enable_module(m_dev, BLADERF_MODULE_RX, true)) < 0)
|
|
|
|
{
|
|
|
|
qCritical("bladerf_enable_module with return code %d", res);
|
|
|
|
goto failed;
|
|
|
|
}
|
|
|
|
|
|
|
|
if((m_bladerfThread = new BladerfThread(m_dev, &m_sampleFifo)) == NULL) {
|
|
|
|
qFatal("out of memory");
|
|
|
|
goto failed;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_bladerfThread->startWork();
|
|
|
|
|
|
|
|
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");
|
2015-06-06 21:30:28 -04:00
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
failed:
|
2015-08-17 02:29:34 -04:00
|
|
|
stop();
|
2015-06-06 21:30:28 -04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-08-17 02:29:34 -04:00
|
|
|
void BladerfInput::stop()
|
2015-06-06 21:30:28 -04:00
|
|
|
{
|
|
|
|
QMutexLocker mutexLocker(&m_mutex);
|
|
|
|
|
2015-08-17 02:29:34 -04:00
|
|
|
if(m_bladerfThread != 0)
|
|
|
|
{
|
2015-06-06 21:30:28 -04:00
|
|
|
m_bladerfThread->stopWork();
|
|
|
|
delete m_bladerfThread;
|
2015-08-17 02:29:34 -04:00
|
|
|
m_bladerfThread = 0;
|
2015-06-06 21:30:28 -04:00
|
|
|
}
|
2015-08-17 02:29:34 -04:00
|
|
|
|
|
|
|
if(m_dev != 0)
|
|
|
|
{
|
2015-06-06 21:30:28 -04:00
|
|
|
bladerf_close(m_dev);
|
2015-08-17 02:29:34 -04:00
|
|
|
m_dev = 0;
|
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
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-06-06 21:30:28 -04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-17 02:29:34 -04:00
|
|
|
bool BladerfInput::applySettings(const Settings& settings, bool force)
|
2015-06-06 21:30:28 -04:00
|
|
|
{
|
2015-08-19 03:24:44 -04:00
|
|
|
bool forwardChange = false;
|
2015-06-06 21:30:28 -04:00
|
|
|
QMutexLocker mutexLocker(&m_mutex);
|
|
|
|
|
2015-08-12 03:03:02 -04:00
|
|
|
qDebug() << "BladerfInput::applySettings: m_dev: " << m_dev;
|
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
2015-06-06 21:30:28 -04:00
|
|
|
qDebug("bladerf_set_lna_gain() failed");
|
2015-08-17 02:29:34 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-08-09 04:33:04 -04:00
|
|
|
qDebug() << "BladerfInput: 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)
|
|
|
|
{
|
2015-06-06 21:30:28 -04:00
|
|
|
qDebug("bladerf_set_rxvga1() failed");
|
2015-08-17 02:29:34 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-08-09 04:33:04 -04:00
|
|
|
qDebug() << "BladerfInput: 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)
|
|
|
|
{
|
2015-06-06 21:30:28 -04:00
|
|
|
qDebug("bladerf_set_rxvga2() failed");
|
2015-08-17 02:29:34 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-08-09 04:33:04 -04:00
|
|
|
qDebug() << "BladerfInput: 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
|
|
|
{
|
|
|
|
if (m_settings.m_xb200)
|
|
|
|
{
|
2015-08-17 02:29:34 -04:00
|
|
|
if (bladerf_expansion_attach(m_dev, BLADERF_XB_200) != 0)
|
|
|
|
{
|
2015-06-06 21:30:28 -04:00
|
|
|
qDebug("bladerf_expansion_attach(xb200) failed");
|
2015-08-17 02:29:34 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-08-09 04:33:04 -04:00
|
|
|
qDebug() << "BladerfInput: Attach XB200";
|
2015-06-06 21:30:28 -04:00
|
|
|
}
|
2015-08-12 03:03:02 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-08-17 02:29:34 -04:00
|
|
|
if (bladerf_expansion_attach(m_dev, BLADERF_XB_NONE) != 0)
|
|
|
|
{
|
2015-06-06 21:30:28 -04:00
|
|
|
qDebug("bladerf_expansion_attach(none) failed");
|
2015-08-17 02:29:34 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-08-09 04:33:04 -04:00
|
|
|
qDebug() << "BladerfInput: Detach 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)
|
|
|
|
{
|
2015-06-06 21:30:28 -04:00
|
|
|
qDebug("bladerf_xb200_set_path(BLADERF_MODULE_RX) failed");
|
2015-08-17 02:29:34 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-08-09 04:33:04 -04:00
|
|
|
qDebug() << "BladerfInput: 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)
|
|
|
|
{
|
2015-06-06 21:30:28 -04:00
|
|
|
qDebug("bladerf_xb200_set_filterbank(BLADERF_MODULE_RX) failed");
|
2015-08-17 02:29:34 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-08-09 04:33:04 -04:00
|
|
|
qDebug() << "BladerfInput: 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
|
|
|
{
|
2015-08-17 02:29:34 -04:00
|
|
|
qCritical("could not set sample rate: %d", m_settings.m_devSampleRate);
|
2015-08-12 03:03:02 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-08-09 04:33:04 -04:00
|
|
|
qDebug() << "bladerf_set_sample_rate(BLADERF_MODULE_RX) actual sample rate is " << actualSamplerate;
|
2015-08-17 02:29:34 -04:00
|
|
|
m_bladerfThread->setSamplerate(m_settings.m_devSampleRate);
|
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
|
|
|
{
|
|
|
|
qCritical("could not set bandwidth: %d", m_settings.m_bandwidth);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-08-09 04:33:04 -04:00
|
|
|
qDebug() << "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
|
|
|
|
2015-08-17 02:29:34 -04:00
|
|
|
if(m_dev != 0)
|
2015-08-12 03:03:02 -04:00
|
|
|
{
|
2015-07-26 19:09:24 -04:00
|
|
|
m_bladerfThread->setLog2Decimation(m_settings.m_log2Decim);
|
2015-08-12 03:03:02 -04:00
|
|
|
qDebug() << "BladerfInput: 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
|
|
|
|
2015-08-17 02:29:34 -04:00
|
|
|
if(m_dev != 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);
|
2015-08-09 04:33:04 -04:00
|
|
|
qDebug() << "BladerfInput: 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
|
|
|
|
|
|
|
if ((m_settings.m_log2Decim == 0) || (m_settings.m_fcPos == FC_POS_CENTER))
|
|
|
|
{
|
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
|
|
|
|
{
|
|
|
|
if (m_settings.m_fcPos == 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
|
|
|
}
|
2015-08-12 03:03:02 -04:00
|
|
|
else if (m_settings.m_fcPos == 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
|
|
|
{
|
|
|
|
qDebug("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);
|
2015-09-27 06:50:38 -04:00
|
|
|
DSPEngine::instance()->getInputMessageQueue()->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"
|
|
|
|
<< " device sample rate: " << m_settings.m_devSampleRate << "Hz"
|
2015-08-17 02:29:34 -04:00
|
|
|
<< " Actual sample rate: " << m_settings.m_devSampleRate/(1<<m_settings.m_log2Decim) << "Hz"
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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 */
|
2015-08-17 02:29:34 -04:00
|
|
|
if (serial != NULL)
|
|
|
|
{
|
2015-06-06 21:30:28 -04:00
|
|
|
strncpy(info.serial, serial, BLADERF_SERIAL_LENGTH - 1);
|
|
|
|
info.serial[BLADERF_SERIAL_LENGTH - 1] = '\0';
|
|
|
|
}
|
|
|
|
|
|
|
|
status = bladerf_open_with_devinfo(&dev, &info);
|
|
|
|
|
2015-08-17 02:29:34 -04:00
|
|
|
if (status == BLADERF_ERR_NODEV)
|
|
|
|
{
|
2015-06-06 21:30:28 -04:00
|
|
|
fprintf(stderr, "No devices available with serial=%s\n", serial);
|
|
|
|
return NULL;
|
2015-08-17 02:29:34 -04:00
|
|
|
}
|
|
|
|
else if (status != 0)
|
|
|
|
{
|
2015-06-06 21:30:28 -04:00
|
|
|
fprintf(stderr, "Failed to open device with serial=%s (%s)\n",
|
|
|
|
serial, bladerf_strerror(status));
|
|
|
|
return NULL;
|
2015-08-17 02:29:34 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-06-06 21:30:28 -04:00
|
|
|
return dev;
|
|
|
|
}
|
|
|
|
}
|