1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-11-14 12:22:00 -05:00
sdrangel/plugins/samplesource/airspy/airspyplugin.cpp

170 lines
5.0 KiB
C++
Raw Normal View History

2015-09-09 03:13:24 -04:00
///////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2015 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 <QtPlugin>
#include <libairspy/airspy.h>
2018-05-29 10:48:41 -04:00
#ifdef SERVER_MODE
#include "airspyinput.h"
#else
2015-09-09 03:13:24 -04:00
#include "airspygui.h"
2018-05-29 10:48:41 -04:00
#endif
2015-09-09 03:13:24 -04:00
#include "airspyplugin.h"
#include <device/devicesourceapi.h>
2015-09-09 03:13:24 -04:00
#include "plugin/pluginapi.h"
#include "util/simpleserializer.h"
2018-01-10 18:17:06 -05:00
const int AirspyPlugin::m_maxDevices = 32;
2015-09-09 03:13:24 -04:00
const PluginDescriptor AirspyPlugin::m_pluginDescriptor = {
QString("Airspy Input"),
2018-05-26 04:27:28 -04:00
QString("4.0.0"),
2015-09-09 03:13:24 -04:00
QString("(c) Edouard Griffiths, F4EXB"),
QString("https://github.com/f4exb/sdrangel"),
true,
QString("https://github.com/f4exb/sdrangel")
};
2016-12-29 06:41:10 -05:00
const QString AirspyPlugin::m_hardwareID = "Airspy";
2015-09-30 07:53:09 -04:00
const QString AirspyPlugin::m_deviceTypeID = AIRSPY_DEVICE_TYPE_ID;
2015-09-09 03:13:24 -04:00
AirspyPlugin::AirspyPlugin(QObject* parent) :
QObject(parent)
2015-09-09 03:13:24 -04:00
{
}
const PluginDescriptor& AirspyPlugin::getPluginDescriptor() const
{
return m_pluginDescriptor;
}
void AirspyPlugin::initPlugin(PluginAPI* pluginAPI)
{
pluginAPI->registerSampleSource(m_deviceTypeID, this);
2015-09-09 03:13:24 -04:00
}
2016-10-13 16:23:43 -04:00
PluginInterface::SamplingDevices AirspyPlugin::enumSampleSources()
2015-09-09 03:13:24 -04:00
{
2016-10-13 16:23:43 -04:00
SamplingDevices result;
2015-09-09 03:13:24 -04:00
airspy_read_partid_serialno_t read_partid_serialno;
struct airspy_device *devinfo;
uint32_t serial_msb = 0;
uint32_t serial_lsb = 0;
2015-09-09 03:13:24 -04:00
airspy_error rc;
int i;
2015-09-09 03:13:24 -04:00
2015-09-09 23:53:37 -04:00
rc = (airspy_error) airspy_init();
2015-09-09 03:13:24 -04:00
if (rc != AIRSPY_SUCCESS)
{
2015-09-09 23:53:37 -04:00
qCritical("AirspyPlugin::enumSampleSources: failed to initiate Airspy library: %s", airspy_error_name(rc));
2015-09-09 03:13:24 -04:00
}
2018-01-10 18:17:06 -05:00
for (i=0; i < m_maxDevices; i++)
2015-09-09 03:13:24 -04:00
{
2015-09-09 23:53:37 -04:00
rc = (airspy_error) airspy_open(&devinfo);
2015-09-09 03:13:24 -04:00
if (rc == AIRSPY_SUCCESS)
{
qDebug("AirspyPlugin::enumSampleSources: try to enumerate Airspy device #%d", i);
2015-09-09 23:53:37 -04:00
rc = (airspy_error) airspy_board_partid_serialno_read(devinfo, &read_partid_serialno);
2015-09-09 03:13:24 -04:00
if (rc != AIRSPY_SUCCESS)
{
qDebug("AirspyPlugin::enumSampleSources: failed to read serial no: %s", airspy_error_name(rc));
airspy_close(devinfo);
2015-09-09 03:13:24 -04:00
continue; // next
}
if ((read_partid_serialno.serial_no[2] != serial_msb) && (read_partid_serialno.serial_no[3] != serial_lsb))
{
serial_msb = read_partid_serialno.serial_no[2];
serial_lsb = read_partid_serialno.serial_no[3];
QString serial_str = QString::number(serial_msb, 16) + QString::number(serial_lsb, 16);
2017-05-25 14:13:34 -04:00
//uint64_t serial_num = (((uint64_t) serial_msb)<<32) + serial_lsb;
2015-09-30 23:44:33 -04:00
QString displayedName(QString("Airspy[%1] %2").arg(i).arg(serial_str));
2016-10-13 16:23:43 -04:00
result.append(SamplingDevice(displayedName,
2016-12-29 06:41:10 -05:00
m_hardwareID,
2015-09-30 07:53:09 -04:00
m_deviceTypeID,
serial_str,
i,
PluginInterface::SamplingDevice::PhysicalDevice,
true,
1,
0));
qDebug("AirspyPlugin::enumSampleSources: enumerated Airspy device #%d", i);
}
2015-09-09 03:13:24 -04:00
airspy_close(devinfo);
2015-09-09 03:13:24 -04:00
}
else
{
qDebug("AirspyPlugin::enumSampleSources: enumerated %d Airspy devices %s", i, airspy_error_name(rc));
2015-09-09 03:13:24 -04:00
break; // finished
}
}
rc = (airspy_error) airspy_exit();
qDebug("AirspyPlugin::enumSampleSources: airspy_exit: %s", airspy_error_name(rc));
2015-09-09 03:13:24 -04:00
return result;
}
2018-05-29 10:48:41 -04:00
#ifdef SERVER_MODE
PluginInstanceGUI* AirspyPlugin::createSampleSourcePluginInstanceGUI(
const QString& sourceId __attribute__((unused)),
QWidget **widget __attribute__((unused)),
DeviceUISet *deviceUISet __attribute__((unused)))
{
return 0;
}
#else
PluginInstanceGUI* AirspyPlugin::createSampleSourcePluginInstanceGUI(
const QString& sourceId,
QWidget **widget,
DeviceUISet *deviceUISet)
2015-09-09 03:13:24 -04:00
{
if (sourceId == m_deviceTypeID)
2015-09-09 03:13:24 -04:00
{
AirspyGui* gui = new AirspyGui(deviceUISet);
*widget = gui;
2015-09-09 03:13:24 -04:00
return gui;
}
else
{
return 0;
}
}
2018-05-29 10:48:41 -04:00
#endif
DeviceSampleSource *AirspyPlugin::createSampleSourcePluginInstanceInput(const QString& sourceId, DeviceSourceAPI *deviceAPI)
{
if (sourceId == m_deviceTypeID)
{
AirspyInput* input = new AirspyInput(deviceAPI);
return input;
}
else
{
return 0;
}
}