1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2026-06-02 22:14:45 -04:00

Plugins device enumeration optimization: factorization of common code for Rx/Tx devices

This commit is contained in:
f4exb
2019-09-17 19:54:13 +02:00
parent e9bbf0b266
commit ee3313dc82
34 changed files with 341 additions and 550 deletions
@@ -62,50 +62,7 @@ void Blderf1InputPlugin::enumOriginDevices(QStringList& listedHwIds, OriginDevic
return;
}
struct bladerf_devinfo *devinfo = nullptr;
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("BlderfInputPlugin::enumSampleSources: No device at index %d", i);
continue;
}
else if (status != 0)
{
qCritical("BlderfInputPlugin::enumSampleSources: Failed to open device at index %d", i);
continue;
}
const char *boardName = bladerf_get_board_name(dev);
if (strcmp(boardName, "bladerf1") == 0)
{
QString displayableName(QString("BladeRF1[%1] %2").arg(devinfo[i].instance).arg(devinfo[i].serial));
originDevices.append(OriginDevice(
displayableName,
m_hardwareID,
devinfo[i].serial,
i,
1, // nb Rx
1 // nb Tx
));
}
bladerf_close(dev);
}
bladerf_free_device_list(devinfo); // Valgrind memcheck
}
DeviceBladeRF1::enumOriginDevices(m_hardwareID, originDevices);
listedHwIds.append(m_hardwareID);
}
@@ -62,54 +62,7 @@ void Blderf2InputPlugin::enumOriginDevices(QStringList& listedHwIds, OriginDevic
return;
}
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::enumOriginDevices: No device at index %d", i);
continue;
}
else if (status != 0)
{
qCritical("Blderf2InputPlugin::enumOriginDevices: Failed to open device at index %d", i);
continue;
}
const char *boardName = bladerf_get_board_name(dev);
if (strcmp(boardName, "bladerf2") == 0)
{
unsigned int nbRxChannels = bladerf_get_channel_count(dev, BLADERF_RX);
unsigned int nbTxChannels = bladerf_get_channel_count(dev, BLADERF_TX);
qDebug("Blderf2InputPlugin::enumOriginDevices: device #%d (%s)", i, devinfo[i].serial);
QString displayableName(QString("BladeRF2[%1:%2] %3").arg(devinfo[i].instance).arg("%1").arg(devinfo[i].serial));
originDevices.append(OriginDevice(
displayableName,
m_hardwareID,
devinfo[i].serial,
i,
2, // nb Rx
2 // nb Tx
));
}
bladerf_close(dev);
}
bladerf_free_device_list(devinfo); // Valgrind memcheck
}
DeviceBladeRF2::enumOriginDevices(m_hardwareID, originDevices);
listedHwIds.append(m_hardwareID);
}
@@ -63,55 +63,7 @@ void HackRFInputPlugin::enumOriginDevices(QStringList& listedHwIds, OriginDevice
return;
}
hackrf_device_list_t *hackrf_devices = hackrf_device_list();
hackrf_device *hackrf_ptr;
read_partid_serialno_t read_partid_serialno;
int i;
for (i=0; i < hackrf_devices->devicecount; i++)
{
hackrf_error rc = (hackrf_error) hackrf_device_list_open(hackrf_devices, i, &hackrf_ptr);
if (rc == HACKRF_SUCCESS)
{
qDebug("HackRFInputPlugin::enumOriginDevices: try to enumerate HackRF device #%d", i);
rc = (hackrf_error) hackrf_board_partid_serialno_read(hackrf_ptr, &read_partid_serialno);
if (rc != HACKRF_SUCCESS)
{
qDebug("HackRFInputPlugin::enumOriginDevices: failed to read serial no: %s", hackrf_error_name(rc));
hackrf_close(hackrf_ptr);
continue; // next
}
uint32_t serial_msb = read_partid_serialno.serial_no[2];
uint32_t serial_lsb = read_partid_serialno.serial_no[3];
QString serial_str = QString::number(serial_msb, 16) + QString::number(serial_lsb, 16);
//uint64_t serial_num = (((uint64_t) serial_msb)<<32) + serial_lsb;
QString displayedName(QString("HackRF[%1] %2").arg(i).arg(serial_str));
originDevices.append(OriginDevice(
displayedName,
m_hardwareID,
serial_str,
i,
1,
1
));
qDebug("HackRFInputPlugin::enumOriginDevices: enumerated HackRF device #%d", i);
hackrf_close(hackrf_ptr);
}
else
{
qDebug("HackRFOutputPlugin::enumOriginDevices: failed to enumerate HackRF device #%d: %s", i, hackrf_error_name(rc));
}
}
hackrf_device_list_free(hackrf_devices);
DeviceHackRF::enumOriginDevices(m_hardwareID, originDevices);
listedHwIds.append(m_hardwareID);
}
@@ -17,12 +17,12 @@
#include <QtPlugin>
#include <regex>
#include <string>
#include "lime/LimeSuite.h"
#include "plugin/pluginapi.h"
#include "util/simpleserializer.h"
#include "limesdr/devicelimesdr.h"
#ifdef SERVER_MODE
#include "limesdrinput.h"
@@ -65,50 +65,7 @@ void LimeSDRInputPlugin::enumOriginDevices(QStringList& listedHwIds, OriginDevic
return;
}
lms_info_str_t* deviceList;
int nbDevices;
SamplingDevices result;
if ((nbDevices = LMS_GetDeviceList(0)) <= 0)
{
qDebug("LimeSDRInputPlugin::enumOriginDevices: Could not find any LimeSDR device");
return; // do nothing
}
deviceList = new lms_info_str_t[nbDevices];
if (LMS_GetDeviceList(deviceList) < 0)
{
qDebug("LimeSDRInputPlugin::enumOriginDevices: Could not obtain LimeSDR devices information");
delete[] deviceList;
return; // do nothing
}
else
{
for (int i = 0; i < nbDevices; i++)
{
std::string serial("N/D");
findSerial((const char *) deviceList[i], serial);
DeviceLimeSDRParams limeSDRParams;
limeSDRParams.open(deviceList[i]);
limeSDRParams.close();
QString displayedName(QString("LimeSDR[%1:%2] %3").arg(i).arg("%1").arg(serial.c_str()));
originDevices.append(OriginDevice(
displayedName,
m_hardwareID,
QString(deviceList[i]),
i,
limeSDRParams.m_nbRxChannels,
limeSDRParams.m_nbTxChannels
));
}
}
delete[] deviceList;
DeviceLimeSDR::enumOriginDevices(m_hardwareID, originDevices);
listedHwIds.append(m_hardwareID);
}
@@ -172,24 +129,6 @@ PluginInstanceGUI* LimeSDRInputPlugin::createSampleSourcePluginInstanceGUI(
}
#endif
bool LimeSDRInputPlugin::findSerial(const char *lmsInfoStr, std::string& serial)
{
std::regex serial_reg("serial=([0-9,A-F]+)");
std::string input(lmsInfoStr);
std::smatch result;
std::regex_search(input, result, serial_reg);
if (result[1].str().length()>0)
{
serial = result[1].str();
return true;
}
else
{
return false;
}
}
DeviceSampleSource *LimeSDRInputPlugin::createSampleSourcePluginInstance(const QString& sourceId, DeviceAPI *deviceAPI)
{
if (sourceId == m_deviceTypeID)
@@ -50,7 +50,6 @@ public:
private:
static const PluginDescriptor m_pluginDescriptor;
static bool findSerial(const char *lmsInfoStr, std::string& serial);
};
@@ -64,30 +64,7 @@ void PlutoSDRInputPlugin::enumOriginDevices(QStringList& listedHwIds, OriginDevi
return;
}
DevicePlutoSDR::instance().scan();
std::vector<std::string> serials;
DevicePlutoSDR::instance().getSerials(serials);
std::vector<std::string>::const_iterator it = serials.begin();
int i;
for (i = 0; it != serials.end(); ++it, ++i)
{
QString serial_str = QString::fromLocal8Bit(it->c_str());
QString displayableName(QString("PlutoSDR[%1] %2").arg(i).arg(serial_str));
originDevices.append(OriginDevice(
displayableName,
m_hardwareID,
serial_str,
i, // sequence
1, // Nb Rx
1 // Nb Tx
));
qDebug("PlutoSDRInputPlugin::enumOriginDevices: enumerated PlutoSDR device #%d", i);
}
DevicePlutoSDR::instance().enumOriginDevices(m_hardwareID, originDevices);
listedHwIds.append(m_hardwareID);
}
@@ -63,29 +63,7 @@ void SoapySDRInputPlugin::enumOriginDevices(QStringList& listedHwIds, OriginDevi
}
DeviceSoapySDR& deviceSoapySDR = DeviceSoapySDR::instance();
const std::vector<DeviceSoapySDRScan::SoapySDRDeviceEnum>& devicesEnumeration = deviceSoapySDR.getDevicesEnumeration();
qDebug("SoapySDRInputPlugin::enumOriginDevices: %lu SoapySDR devices", devicesEnumeration.size());
std::vector<DeviceSoapySDRScan::SoapySDRDeviceEnum>::const_iterator it = devicesEnumeration.begin();
for (int idev = 0; it != devicesEnumeration.end(); ++it, idev++)
{
unsigned int nbRxChannels = it->m_nbRx;
unsigned int nbTxChannels = it->m_nbTx;
QString displayableName(QString("SoapySDR[%1:%2] %3").arg(idev).arg("%1").arg(it->m_label));
QString serial(QString("%1-%2").arg(it->m_driverName).arg(it->m_sequence));
qDebug("SoapySDRInputPlugin::enumOriginDevices: device #%d (%s) serial %s",
idev, it->m_label.toStdString().c_str(), serial.toStdString().c_str());
originDevices.append(OriginDevice(
displayableName,
m_hardwareID,
serial,
idev, // sequence
nbRxChannels, // Nb Rx
nbTxChannels // Nb Tx
));
}
deviceSoapySDR.enumOriginDevices(m_hardwareID, originDevices);
listedHwIds.append(m_hardwareID);
}
@@ -27,6 +27,7 @@
#include "xtrx_api.h"
#include "plugin/pluginapi.h"
#include "util/simpleserializer.h"
#include "xtrx/devicextrx.h"
#ifdef SERVER_MODE
#include "xtrxinput.h"
@@ -67,25 +68,7 @@ void XTRXInputPlugin::enumOriginDevices(QStringList& listedHwIds, OriginDevices&
return;
}
xtrx_device_info_t devs[32];
int res = xtrx_discovery(devs, 32);
int i;
for (i = 0; i < res; i++)
{
DeviceXTRXParams XTRXParams;
QString displayableName(QString("XTRX[%1:%2] %3").arg(i).arg("%1").arg(devs[i].uniqname));
originDevices.append(OriginDevice(
displayableName,
m_hardwareID,
QString(devs[i].uniqname),
i,
XTRXParams.m_nbRxChannels,
XTRXParams.m_nbTxChannels
));
}
DeviceXTRX::enumOriginDevices(m_hardwareID, originDevices);
listedHwIds.append(m_hardwareID);
}