mirror of
https://github.com/f4exb/sdrangel.git
synced 2026-06-01 21:54:55 -04:00
BladerRF2 input support (1)
This commit is contained in:
@@ -0,0 +1,152 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
// 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 //
|
||||
// //
|
||||
// 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 "bladerf2inputplugin.h"
|
||||
|
||||
#include <QtPlugin>
|
||||
#include <libbladeRF.h>
|
||||
#include "plugin/pluginapi.h"
|
||||
#include "util/simpleserializer.h"
|
||||
#include <device/devicesourceapi.h>
|
||||
|
||||
#ifdef SERVER_MODE
|
||||
#include "bladerf2input.h"
|
||||
#else
|
||||
#include "bladerf2inputgui.h"
|
||||
#endif
|
||||
|
||||
const PluginDescriptor Blderf2InputPlugin::m_pluginDescriptor = {
|
||||
QString("BladeRF2 Input"),
|
||||
QString("4.2.0"),
|
||||
QString("(c) Edouard Griffiths, F4EXB"),
|
||||
QString("https://github.com/f4exb/sdrangel"),
|
||||
true,
|
||||
QString("https://github.com/f4exb/sdrangel")
|
||||
};
|
||||
|
||||
const QString Blderf2InputPlugin::m_hardwareID = "BladeRF2";
|
||||
const QString Blderf2InputPlugin::m_deviceTypeID = BLADERF2INPUT_DEVICE_TYPE_ID;
|
||||
|
||||
Blderf2InputPlugin::Blderf2InputPlugin(QObject* parent) :
|
||||
QObject(parent)
|
||||
{
|
||||
}
|
||||
|
||||
const PluginDescriptor& Blderf2InputPlugin::getPluginDescriptor() const
|
||||
{
|
||||
return m_pluginDescriptor;
|
||||
}
|
||||
|
||||
void Blderf2InputPlugin::initPlugin(PluginAPI* pluginAPI)
|
||||
{
|
||||
pluginAPI->registerSampleSource(m_deviceTypeID, this);
|
||||
}
|
||||
|
||||
PluginInterface::SamplingDevices Blderf2InputPlugin::enumSampleSources()
|
||||
{
|
||||
SamplingDevices result;
|
||||
struct bladerf_devinfo *devinfo = 0;
|
||||
|
||||
int count = bladerf_get_device_list(&devinfo);
|
||||
|
||||
if (devinfo)
|
||||
{
|
||||
for(int i = 0; i < count; i++)
|
||||
{
|
||||
struct bladerf *dev;
|
||||
|
||||
int status = bladerf_open_with_devinfo(&dev, &devinfo[i]);
|
||||
|
||||
if (status == BLADERF_ERR_NODEV)
|
||||
{
|
||||
qCritical("Blderf2InputPlugin::enumSampleSources: No device at index %d", i);
|
||||
continue;
|
||||
}
|
||||
else if (status != 0)
|
||||
{
|
||||
qCritical("Blderf2InputPlugin::enumSampleSources: Failed to open device at index %d", i);
|
||||
continue;
|
||||
}
|
||||
|
||||
const char *boardName = bladerf_get_board_name(dev);
|
||||
|
||||
if (strcmp(boardName, "bladerf2") == 0)
|
||||
{
|
||||
QString displayedName(QString("BladeRF2[%1] %2").arg(devinfo[i].instance).arg(devinfo[i].serial));
|
||||
|
||||
result.append(SamplingDevice(displayedName,
|
||||
m_hardwareID,
|
||||
m_deviceTypeID,
|
||||
QString(devinfo[i].serial),
|
||||
i,
|
||||
PluginInterface::SamplingDevice::PhysicalDevice,
|
||||
true,
|
||||
1,
|
||||
0));
|
||||
}
|
||||
|
||||
bladerf_close(dev);
|
||||
}
|
||||
|
||||
bladerf_free_device_list(devinfo); // Valgrind memcheck
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
#ifdef SERVER_MODE
|
||||
PluginInstanceGUI* Blderf2InputPlugin::createSampleSourcePluginInstanceGUI(
|
||||
const QString& sourceId __attribute__((unused)),
|
||||
QWidget **widget __attribute__((unused)),
|
||||
DeviceUISet *deviceUISet __attribute__((unused)))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
#else
|
||||
PluginInstanceGUI* Blderf2InputPlugin::createSampleSourcePluginInstanceGUI(
|
||||
const QString& sourceId,
|
||||
QWidget **widget,
|
||||
DeviceUISet *deviceUISet)
|
||||
{
|
||||
if(sourceId == m_deviceTypeID)
|
||||
{
|
||||
Bladerf2InputGui* gui = new Bladerf2InputGui(deviceUISet);
|
||||
*widget = gui;
|
||||
return gui;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
DeviceSampleSource *Blderf2InputPlugin::createSampleSourcePluginInstanceInput(const QString& sourceId, DeviceSourceAPI *deviceAPI)
|
||||
{
|
||||
if (sourceId == m_deviceTypeID)
|
||||
{
|
||||
Bladerf2Input *input = new Bladerf2Input(deviceAPI);
|
||||
return input;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
// 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 //
|
||||
// //
|
||||
// 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/>. //
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef PLUGINS_SAMPLESOURCE_BLADERF2INPUT_BLADERF2INPUTPLUGIN_H_
|
||||
#define PLUGINS_SAMPLESOURCE_BLADERF2INPUT_BLADERF2INPUTPLUGIN_H_
|
||||
|
||||
#include <QObject>
|
||||
#include "plugin/plugininterface.h"
|
||||
|
||||
class PluginAPI;
|
||||
class DeviceSourceAPI;
|
||||
class DeviceUISet;
|
||||
|
||||
#define BLADERF2INPUT_DEVICE_TYPE_ID "sdrangel.samplesource.bladerf2input"
|
||||
|
||||
class Blderf2InputPlugin : public QObject, public PluginInterface {
|
||||
Q_OBJECT
|
||||
Q_INTERFACES(PluginInterface)
|
||||
Q_PLUGIN_METADATA(IID BLADERF2INPUT_DEVICE_TYPE_ID)
|
||||
|
||||
public:
|
||||
explicit Blderf2InputPlugin(QObject* parent = 0);
|
||||
|
||||
const PluginDescriptor& getPluginDescriptor() const;
|
||||
void initPlugin(PluginAPI* pluginAPI);
|
||||
|
||||
virtual SamplingDevices enumSampleSources();
|
||||
virtual PluginInstanceGUI* createSampleSourcePluginInstanceGUI(
|
||||
const QString& sourceId,
|
||||
QWidget **widget,
|
||||
DeviceUISet *deviceUISet);
|
||||
virtual DeviceSampleSource* createSampleSourcePluginInstanceInput(const QString& sourceId, DeviceSourceAPI *deviceAPI);
|
||||
|
||||
static const QString m_hardwareID;
|
||||
static const QString m_deviceTypeID;
|
||||
|
||||
private:
|
||||
static const PluginDescriptor m_pluginDescriptor;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
#endif /* PLUGINS_SAMPLESOURCE_BLADERF2INPUT_BLADERF2INPUTPLUGIN_H_ */
|
||||
@@ -0,0 +1,92 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
// 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 //
|
||||
// //
|
||||
// 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 "bladerf2inputsettings.h"
|
||||
|
||||
#include "util/simpleserializer.h"
|
||||
|
||||
BladeRF2InputSettings::BladeRF2InputSettings()
|
||||
{
|
||||
resetToDefaults();
|
||||
}
|
||||
|
||||
void BladeRF2InputSettings::resetToDefaults()
|
||||
{
|
||||
m_centerFrequency = 435000*1000;
|
||||
m_devSampleRate = 3072000;
|
||||
m_bandwidth = 1500000;
|
||||
m_gainMode = 0;
|
||||
m_globalGain = 0;
|
||||
m_biasTee = false;
|
||||
m_log2Decim = 0;
|
||||
m_fcPos = FC_POS_INFRA;
|
||||
m_dcBlock = false;
|
||||
m_iqCorrection = false;
|
||||
m_fileRecordName = "";
|
||||
}
|
||||
|
||||
QByteArray BladeRF2InputSettings::serialize() const
|
||||
{
|
||||
SimpleSerializer s(1);
|
||||
|
||||
s.writeS32(1, m_devSampleRate);
|
||||
s.writeS32(2, m_bandwidth);
|
||||
s.writeS32(3, m_gainMode);
|
||||
s.writeS32(4, m_globalGain);
|
||||
s.writeBool(5, m_biasTee);
|
||||
s.writeU32(6, m_log2Decim);
|
||||
s.writeS32(7, (int) m_fcPos);
|
||||
s.writeBool(8, m_dcBlock);
|
||||
s.writeBool(9, m_iqCorrection);
|
||||
|
||||
return s.final();
|
||||
}
|
||||
|
||||
bool BladeRF2InputSettings::deserialize(const QByteArray& data)
|
||||
{
|
||||
SimpleDeserializer d(data);
|
||||
|
||||
if (!d.isValid())
|
||||
{
|
||||
resetToDefaults();
|
||||
return false;
|
||||
}
|
||||
|
||||
if (d.getVersion() == 1)
|
||||
{
|
||||
int intval;
|
||||
|
||||
d.readS32(1, &m_devSampleRate, 3072000);
|
||||
d.readS32(2, &m_bandwidth);
|
||||
d.readS32(3, &m_gainMode);
|
||||
d.readS32(4, &m_globalGain);
|
||||
d.readBool(5, &m_biasTee);
|
||||
d.readU32(6, &m_log2Decim);
|
||||
d.readS32(7, &intval);
|
||||
m_fcPos = (fcPos_t) intval;
|
||||
d.readBool(8, &m_dcBlock);
|
||||
d.readBool(9, &m_iqCorrection);
|
||||
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
resetToDefaults();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
// 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 //
|
||||
// //
|
||||
// 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/>. //
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef PLUGINS_SAMPLESOURCE_BLADERF2INPUT_BLADERF2INPUTSETTINGS_H_
|
||||
#define PLUGINS_SAMPLESOURCE_BLADERF2INPUT_BLADERF2INPUTSETTINGS_H_
|
||||
|
||||
#include <QtGlobal>
|
||||
#include <QString>
|
||||
#include <libbladeRF.h>
|
||||
|
||||
struct BladeRF2InputSettings {
|
||||
typedef enum {
|
||||
FC_POS_INFRA = 0,
|
||||
FC_POS_SUPRA,
|
||||
FC_POS_CENTER
|
||||
} fcPos_t;
|
||||
|
||||
quint64 m_centerFrequency;
|
||||
qint32 m_devSampleRate;
|
||||
qint32 m_bandwidth;
|
||||
int m_gainMode;
|
||||
int m_globalGain;
|
||||
bool m_biasTee;
|
||||
quint32 m_log2Decim;
|
||||
fcPos_t m_fcPos;
|
||||
bool m_dcBlock;
|
||||
bool m_iqCorrection;
|
||||
QString m_fileRecordName;
|
||||
|
||||
BladeRF2InputSettings();
|
||||
void resetToDefaults();
|
||||
QByteArray serialize() const;
|
||||
bool deserialize(const QByteArray& data);
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
#endif /* PLUGINS_SAMPLESOURCE_BLADERF2INPUT_BLADERF2INPUTSETTINGS_H_ */
|
||||
Reference in New Issue
Block a user