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

View File

@ -28,7 +28,7 @@ bool DeviceBladeRF1::open_bladerf(struct bladerf **dev, const char *serial)
if ((*dev = open_bladerf_from_serial(serial)) == 0) if ((*dev = open_bladerf_from_serial(serial)) == 0)
{ {
qCritical("DeviceBladeRF::open_bladerf: could not open BladeRF"); qCritical("DeviceBladeRF1::open_bladerf: could not open BladeRF");
return false; return false;
} }
@ -36,19 +36,66 @@ bool DeviceBladeRF1::open_bladerf(struct bladerf **dev, const char *serial)
if (fpga_loaded < 0) if (fpga_loaded < 0)
{ {
qCritical("DeviceBladeRF::open_bladerf: failed to check FPGA state: %s", qCritical("DeviceBladeRF1::open_bladerf: failed to check FPGA state: %s",
bladerf_strerror(fpga_loaded)); bladerf_strerror(fpga_loaded));
return false; return false;
} }
else if (fpga_loaded == 0) else if (fpga_loaded == 0)
{ {
qCritical("BladerfOutput::start: the device's FPGA is not loaded."); qCritical("DeviceBladeRF1::start: the device's FPGA is not loaded.");
return false; return false;
} }
return true; return true;
} }
void DeviceBladeRF1::enumOriginDevices(const QString& hardwareId, PluginInterface::OriginDevices& originDevices)
{
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("DeviceBladeRF1::enumSampleSources: No device at index %d", i);
continue;
}
else if (status != 0)
{
qCritical("DeviceBladeRF1::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(PluginInterface::OriginDevice(
displayableName,
hardwareId,
devinfo[i].serial,
i,
1, // nb Rx
1 // nb Tx
));
}
bladerf_close(dev);
}
bladerf_free_device_list(devinfo); // Valgrind memcheck
}
}
struct bladerf *DeviceBladeRF1::open_bladerf_from_serial(const char *serial) struct bladerf *DeviceBladeRF1::open_bladerf_from_serial(const char *serial)
{ {
int status; int status;
@ -73,12 +120,12 @@ struct bladerf *DeviceBladeRF1::open_bladerf_from_serial(const char *serial)
if (status == BLADERF_ERR_NODEV) if (status == BLADERF_ERR_NODEV)
{ {
qCritical("DeviceBladeRF::open_bladerf_from_serial: No devices available with serial %s", serial); qCritical("DeviceBladeRF1::open_bladerf_from_serial: No devices available with serial %s", serial);
return 0; return 0;
} }
else if (status != 0) else if (status != 0)
{ {
qCritical("DeviceBladeRF::open_bladerf_from_serial: Failed to open device with serial %s (%s)", qCritical("DeviceBladeRF1::open_bladerf_from_serial: Failed to open device with serial %s (%s)",
serial, bladerf_strerror(status)); serial, bladerf_strerror(status));
return 0; return 0;
} }

View File

@ -18,14 +18,18 @@
#ifndef DEVICES_BLADERF_DEVICESDBLADERF_H_ #ifndef DEVICES_BLADERF_DEVICESDBLADERF_H_
#define DEVICES_BLADERF_DEVICESDBLADERF_H_ #define DEVICES_BLADERF_DEVICESDBLADERF_H_
#include <QString>
#include <libbladeRF.h> #include <libbladeRF.h>
#include "plugin/plugininterface.h"
#include "export.h" #include "export.h"
class DEVICES_API DeviceBladeRF1 class DEVICES_API DeviceBladeRF1
{ {
public: public:
static bool open_bladerf(struct bladerf **dev, const char *serial); static bool open_bladerf(struct bladerf **dev, const char *serial);
static void enumOriginDevices(const QString& hardwareId, PluginInterface::OriginDevices& originDevices);
private: private:
static struct bladerf *open_bladerf_from_serial(const char *serial); static struct bladerf *open_bladerf_from_serial(const char *serial);

View File

@ -48,6 +48,57 @@ DeviceBladeRF2::~DeviceBladeRF2()
} }
} }
void DeviceBladeRF2::enumOriginDevices(const QString& hardwareId, PluginInterface::OriginDevices& originDevices)
{
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("DeviceBladeRF2::enumOriginDevices: No device at index %d", i);
continue;
}
else if (status != 0)
{
qCritical("DeviceBladeRF2::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);
// make the stream index a placeholder for future arg() hence the arg("%1")
QString displayableName(QString("BladeRF2[%1:%2] %3").arg(devinfo[i].instance).arg("%1").arg(devinfo[i].serial));
originDevices.append(PluginInterface::OriginDevice(
displayableName,
hardwareId,
QString(devinfo[i].serial),
i, // Sequence
nbRxChannels,
nbTxChannels
));
}
bladerf_close(dev);
}
bladerf_free_device_list(devinfo); // Valgrind memcheck
}
}
bool DeviceBladeRF2::open(const char *serial) bool DeviceBladeRF2::open(const char *serial)
{ {
int fpga_loaded; int fpga_loaded;

View File

@ -21,6 +21,7 @@
#include <stdint.h> #include <stdint.h>
#include <libbladeRF.h> #include <libbladeRF.h>
#include "plugin/plugininterface.h"
#include "export.h" #include "export.h"
class DEVICES_API DeviceBladeRF2 class DEVICES_API DeviceBladeRF2
@ -29,6 +30,7 @@ public:
DeviceBladeRF2(); DeviceBladeRF2();
~DeviceBladeRF2(); ~DeviceBladeRF2();
static void enumOriginDevices(const QString& hardwareId, PluginInterface::OriginDevices& originDevices);
bool open(const char *serial); bool open(const char *serial);
void close(); void close();

View File

@ -21,8 +21,6 @@
#include "util/message.h" #include "util/message.h"
#include "devicebladerf2.h" #include "devicebladerf2.h"
class SampleSinkFifo;
class SampleSourceFifo;
class BladeRF2Input; class BladeRF2Input;
class BladeRF2Output; class BladeRF2Output;

View File

@ -87,5 +87,56 @@ hackrf_device *DeviceHackRF::open_hackrf_from_sequence(int sequence)
} }
} }
void DeviceHackRF::enumOriginDevices(const QString& hardwareId, PluginInterface::OriginDevices& originDevices)
{
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("DeviceHackRF::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("DeviceHackRF::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(PluginInterface::OriginDevice(
displayedName,
hardwareId,
serial_str,
i,
1,
1
));
qDebug("DeviceHackRF::enumOriginDevices: enumerated HackRF device #%d", i);
hackrf_close(hackrf_ptr);
}
else
{
qDebug("DeviceHackRF::enumOriginDevices: failed to enumerate HackRF device #%d: %s", i, hackrf_error_name(rc));
}
}
hackrf_device_list_free(hackrf_devices);
}

View File

@ -20,6 +20,7 @@
#include "libhackrf/hackrf.h" #include "libhackrf/hackrf.h"
#include "plugin/plugininterface.h"
#include "export.h" #include "export.h"
class DEVICES_API DeviceHackRF class DEVICES_API DeviceHackRF
@ -28,6 +29,7 @@ public:
static DeviceHackRF& instance(); static DeviceHackRF& instance();
static hackrf_device *open_hackrf(int sequence); static hackrf_device *open_hackrf(int sequence);
static hackrf_device *open_hackrf(const char * const serial); static hackrf_device *open_hackrf(const char * const serial);
static void enumOriginDevices(const QString& hardwareId, PluginInterface::OriginDevices& originDevices);
protected: protected:
DeviceHackRF(); DeviceHackRF();
DeviceHackRF(const DeviceHackRF&) {} DeviceHackRF(const DeviceHackRF&) {}

View File

@ -18,8 +18,76 @@
#include <cstdio> #include <cstdio>
#include <cstring> #include <cstring>
#include <cmath> #include <cmath>
#include <regex>
#include "devicelimesdrparam.h"
#include "devicelimesdr.h" #include "devicelimesdr.h"
void DeviceLimeSDR::enumOriginDevices(const QString& hardwareId, PluginInterface::OriginDevices& originDevices)
{
lms_info_str_t* deviceList;
int nbDevices;
if ((nbDevices = LMS_GetDeviceList(0)) <= 0)
{
qDebug("DeviceLimeSDR::enumOriginDevices: Could not find any LimeSDR device");
return; // do nothing
}
deviceList = new lms_info_str_t[nbDevices];
if (LMS_GetDeviceList(deviceList) < 0)
{
qDebug("DeviceLimeSDR::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(PluginInterface::OriginDevice(
displayedName,
hardwareId,
QString(deviceList[i]),
i,
limeSDRParams.m_nbRxChannels,
limeSDRParams.m_nbTxChannels
));
}
}
delete[] deviceList;
}
bool DeviceLimeSDR::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;
}
}
bool DeviceLimeSDR::setNCOFrequency(lms_device_t *device, bool dir_tx, std::size_t chan, bool enable, float frequency) bool DeviceLimeSDR::setNCOFrequency(lms_device_t *device, bool dir_tx, std::size_t chan, bool enable, float frequency)
{ {
if (enable) if (enable)

View File

@ -18,8 +18,11 @@
#ifndef DEVICES_LIMESDR_DEVICELIMESDR_H_ #ifndef DEVICES_LIMESDR_DEVICELIMESDR_H_
#define DEVICES_LIMESDR_DEVICELIMESDR_H_ #define DEVICES_LIMESDR_DEVICELIMESDR_H_
#include <QString>
#include "lime/LimeSuite.h" #include "lime/LimeSuite.h"
#include "plugin/plugininterface.h"
#include "export.h" #include "export.h"
class DEVICES_API DeviceLimeSDR class DEVICES_API DeviceLimeSDR
@ -42,6 +45,8 @@ public:
PATH_RFE_TXRF2, PATH_RFE_TXRF2,
}; };
/** Enumeration of LimeSDR hardware devices */
static void enumOriginDevices(const QString& hardwareId, PluginInterface::OriginDevices& originDevices);
/** set NCO frequency with positive or negative frequency (deals with up/down convert). Enables or disables NCO */ /** set NCO frequency with positive or negative frequency (deals with up/down convert). Enables or disables NCO */
static bool setNCOFrequency(lms_device_t *device, bool dir_tx, std::size_t chan, bool enable, float frequency); static bool setNCOFrequency(lms_device_t *device, bool dir_tx, std::size_t chan, bool enable, float frequency);
/** set LNA gain Range: [1-30] (dB) **/ /** set LNA gain Range: [1-30] (dB) **/
@ -56,6 +61,9 @@ public:
static bool setTxAntennaPath(lms_device_t *device, std::size_t chan, int path); static bool setTxAntennaPath(lms_device_t *device, std::size_t chan, int path);
/** Set clock source and external clock frequency if required */ /** Set clock source and external clock frequency if required */
static bool setClockSource(lms_device_t *device, bool extClock, uint32_t extClockFrequency); static bool setClockSource(lms_device_t *device, bool extClock, uint32_t extClockFrequency);
private:
static bool findSerial(const char *lmsInfoStr, std::string& serial);
}; };
#endif /* DEVICES_LIMESDR_DEVICELIMESDR_H_ */ #endif /* DEVICES_LIMESDR_DEVICELIMESDR_H_ */

View File

@ -122,4 +122,3 @@ void DeviceLimeSDRParams::getHardwareType(const char *device_str)
m_type = LimeUndefined; m_type = LimeUndefined;
} }
} }

View File

@ -36,6 +36,9 @@ public:
const std::string* getSerialAt(unsigned int index) const { return m_scan.getSerialAt(index); } const std::string* getSerialAt(unsigned int index) const { return m_scan.getSerialAt(index); }
DevicePlutoSDRBox* getDeviceFromURI(const std::string& uri); DevicePlutoSDRBox* getDeviceFromURI(const std::string& uri);
DevicePlutoSDRBox* getDeviceFromSerial(const std::string& serial); DevicePlutoSDRBox* getDeviceFromSerial(const std::string& serial);
void enumOriginDevices(const QString& hardwareId, PluginInterface::OriginDevices& originDevices) {
m_scan.enumOriginDevices(hardwareId, originDevices);
}
static const uint64_t rxLOLowLimitFreq; //!< Rx LO hard coded lower frequency limit (Hz) static const uint64_t rxLOLowLimitFreq; //!< Rx LO hard coded lower frequency limit (Hz)
static const uint64_t rxLOHighLimitFreq; //!< Rx LO hard coded lower frequency limit (Hz) static const uint64_t rxLOHighLimitFreq; //!< Rx LO hard coded lower frequency limit (Hz)

View File

@ -134,3 +134,30 @@ void DevicePlutoSDRScan::getSerials(std::vector<std::string>& serials) const
} }
} }
void DevicePlutoSDRScan::enumOriginDevices(const QString& hardwareId, PluginInterface::OriginDevices& originDevices)
{
scan();
std::vector<std::string> serials;
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(PluginInterface::OriginDevice(
displayableName,
hardwareId,
serial_str,
i, // sequence
1, // Nb Rx
1 // Nb Tx
));
qDebug("DevicePlutoSDRScan::enumOriginDevices: enumerated PlutoSDR device #%d", i);
}
}

View File

@ -18,10 +18,13 @@
#ifndef DEVICES_PLUTOSDR_DEVICEPLUTOSDRSCAN_H_ #ifndef DEVICES_PLUTOSDR_DEVICEPLUTOSDRSCAN_H_
#define DEVICES_PLUTOSDR_DEVICEPLUTOSDRSCAN_H_ #define DEVICES_PLUTOSDR_DEVICEPLUTOSDRSCAN_H_
#include <QString>
#include <string> #include <string>
#include <vector> #include <vector>
#include <map> #include <map>
#include "plugin/plugininterface.h"
#include "export.h" #include "export.h"
class DEVICES_API DevicePlutoSDRScan class DEVICES_API DevicePlutoSDRScan
@ -40,6 +43,7 @@ public:
const std::string* getSerialAt(unsigned int index) const ; const std::string* getSerialAt(unsigned int index) const ;
const std::string* getURIFromSerial(const std::string& serial) const; const std::string* getURIFromSerial(const std::string& serial) const;
void getSerials(std::vector<std::string>& serials) const; void getSerials(std::vector<std::string>& serials) const;
void enumOriginDevices(const QString& hardwareId, PluginInterface::OriginDevices& originDevices);
private: private:
std::vector<DeviceScan> m_scans; std::vector<DeviceScan> m_scans;

View File

@ -93,3 +93,25 @@ SoapySDR::Device *DeviceSoapySDR::openopenSoapySDRFromSequence(uint32_t sequence
} }
} }
} }
void DeviceSoapySDR::enumOriginDevices(const QString& hardwareId, PluginInterface::OriginDevices& originDevices)
{
const std::vector<DeviceSoapySDRScan::SoapySDRDeviceEnum>& devicesEnumeration = getDevicesEnumeration();
qDebug("SoapySDROutputPlugin::enumOriginDevices: %lu SoapySDR devices", devicesEnumeration.size());
std::vector<DeviceSoapySDRScan::SoapySDRDeviceEnum>::const_iterator it = devicesEnumeration.begin();
for (int idev = 0; it != devicesEnumeration.end(); ++it, idev++)
{
QString displayedName(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));
originDevices.append(PluginInterface::OriginDevice(
displayedName,
hardwareId,
serial,
idev, // Sequence
it->m_nbRx, // nb Rx
it->m_nbTx // nb Tx
));
}
}

View File

@ -21,6 +21,7 @@
#include <stdint.h> #include <stdint.h>
#include <SoapySDR/Device.hpp> #include <SoapySDR/Device.hpp>
#include "plugin/plugininterface.h"
#include "export.h" #include "export.h"
#include "devicesoapysdrscan.h" #include "devicesoapysdrscan.h"
@ -30,6 +31,7 @@ public:
static DeviceSoapySDR& instance(); static DeviceSoapySDR& instance();
SoapySDR::Device *openSoapySDR(uint32_t sequence, const QString& hardwareUserArguments); SoapySDR::Device *openSoapySDR(uint32_t sequence, const QString& hardwareUserArguments);
void closeSoapySdr(SoapySDR::Device *device); void closeSoapySdr(SoapySDR::Device *device);
void enumOriginDevices(const QString& hardwareId, PluginInterface::OriginDevices& originDevices);
uint32_t getNbDevices() const { return m_scanner.getNbDevices(); } uint32_t getNbDevices() const { return m_scanner.getNbDevices(); }
const std::vector<DeviceSoapySDRScan::SoapySDRDeviceEnum>& getDevicesEnumeration() const { return m_scanner.getDevicesEnumeration(); } const std::vector<DeviceSoapySDRScan::SoapySDRDeviceEnum>& getDevicesEnumeration() const { return m_scanner.getDevicesEnumeration(); }

View File

@ -18,6 +18,7 @@
#include <QDebug> #include <QDebug>
#include "xtrx_api.h" #include "xtrx_api.h"
#include "devicextrxparam.h"
#include "devicextrx.h" #include "devicextrx.h"
const uint32_t DeviceXTRX::m_lnaTbl[m_nbGains] = { const uint32_t DeviceXTRX::m_lnaTbl[m_nbGains] = {
@ -76,6 +77,28 @@ void DeviceXTRX::close()
} }
} }
void DeviceXTRX::enumOriginDevices(const QString& hardwareId, PluginInterface::OriginDevices& originDevices)
{
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(PluginInterface::OriginDevice(
displayableName,
hardwareId,
QString(devs[i].uniqname),
i,
XTRXParams.m_nbRxChannels,
XTRXParams.m_nbTxChannels
));
}
}
void DeviceXTRX::getAutoGains(uint32_t autoGain, uint32_t& lnaGain, uint32_t& tiaGain, uint32_t& pgaGain) void DeviceXTRX::getAutoGains(uint32_t autoGain, uint32_t& lnaGain, uint32_t& tiaGain, uint32_t& pgaGain)
{ {
uint32_t value = autoGain + 12 > 73 ? 73 : autoGain + 12; uint32_t value = autoGain + 12 > 73 ? 73 : autoGain + 12;

View File

@ -18,8 +18,10 @@
#ifndef DEVICES_XTRX_DEVICEXTRX_H_ #ifndef DEVICES_XTRX_DEVICEXTRX_H_
#define DEVICES_XTRX_DEVICEXTRX_H_ #define DEVICES_XTRX_DEVICEXTRX_H_
#include <QString>
#include <stdint.h> #include <stdint.h>
#include "plugin/plugininterface.h"
#include "export.h" #include "export.h"
struct strx_dev; struct strx_dev;
@ -32,6 +34,7 @@ public:
bool open(const char* deviceStr); bool open(const char* deviceStr);
void close(); void close();
static void enumOriginDevices(const QString& hardwareId, PluginInterface::OriginDevices& originDevices);
struct xtrx_dev *getDevice() { return m_dev; } struct xtrx_dev *getDevice() { return m_dev; }
double set_samplerate(double rate, double master, bool output); double set_samplerate(double rate, double master, bool output);
double getMasterRate() const { return m_masterRate; } double getMasterRate() const { return m_masterRate; }

View File

@ -62,51 +62,7 @@ void Bladerf1OutputPlugin::enumOriginDevices(QStringList& listedHwIds, OriginDev
return; return;
} }
struct bladerf_devinfo *devinfo = 0; DeviceBladeRF1::enumOriginDevices(m_hardwareID, originDevices);
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("BladerfOutputPlugin::enumOriginDevices: No device at index %d", i);
continue;
}
else if (status != 0)
{
qCritical("BladerfOutputPlugin::enumOriginDevices: 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,
QString(devinfo[i].serial),
i, // Sequence
1, // Has 1 Rx known by construction
1 // Has 1 Tx known by construction
));
}
bladerf_close(dev);
}
bladerf_free_device_list(devinfo); // Valgrind memcheck
}
listedHwIds.append(m_hardwareID); listedHwIds.append(m_hardwareID);
} }

View File

@ -62,54 +62,7 @@ void BladeRF2OutputPlugin::enumOriginDevices(QStringList& listedHwIds, OriginDev
return; return;
} }
struct bladerf_devinfo *devinfo = 0; DeviceBladeRF2::enumOriginDevices(m_hardwareID, originDevices);
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("Bladerf2OutputPlugin::enumOriginDevices: No device at index %d", i);
continue;
}
else if (status != 0)
{
qCritical("Bladerf2OutputPlugin::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);
// make the stream index a placeholder for future arg() hence the arg("%1")
QString displayableName(QString("BladeRF2[%1:%2] %3").arg(devinfo[i].instance).arg("%1").arg(devinfo[i].serial));
originDevices.append(OriginDevice(
displayableName,
m_hardwareID,
QString(devinfo[i].serial),
i, // Sequence
nbRxChannels,
nbTxChannels
));
}
bladerf_close(dev);
}
bladerf_free_device_list(devinfo); // Valgrind memcheck
}
listedHwIds.append(m_hardwareID); listedHwIds.append(m_hardwareID);
} }

View File

@ -26,7 +26,7 @@
#include "bladerf2/devicebladerf2shared.h" #include "bladerf2/devicebladerf2shared.h"
#include "dsp/interpolators.h" #include "dsp/interpolators.h"
class SampleSinkFifo; class SampleSourceFifo;
class BladeRF2OutputThread : public QThread { class BladeRF2OutputThread : public QThread {
Q_OBJECT Q_OBJECT

View File

@ -62,55 +62,7 @@ void HackRFOutputPlugin::enumOriginDevices(QStringList& listedHwIds, OriginDevic
return; return;
} }
hackrf_device_list_t *hackrf_devices = hackrf_device_list(); DeviceHackRF::enumOriginDevices(m_hardwareID, originDevices);
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("HackRFOutputPlugin::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("HackRFOutputPlugin::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("HackRFOutputPlugin::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);
listedHwIds.append(m_hardwareID); listedHwIds.append(m_hardwareID);
} }

View File

@ -17,13 +17,12 @@
#include <QtPlugin> #include <QtPlugin>
#include <regex>
#include <string> #include <string>
#include "lime/LimeSuite.h" #include "lime/LimeSuite.h"
#include "plugin/pluginapi.h" #include "plugin/pluginapi.h"
#include "util/simpleserializer.h" #include "util/simpleserializer.h"
#include "limesdr/devicelimesdrparam.h" #include "limesdr/devicelimesdr.h"
#ifdef SERVER_MODE #ifdef SERVER_MODE
#include "limesdroutput.h" #include "limesdroutput.h"
@ -66,50 +65,7 @@ void LimeSDROutputPlugin::enumOriginDevices(QStringList& listedHwIds, OriginDevi
return; return;
} }
lms_info_str_t* deviceList; DeviceLimeSDR::enumOriginDevices(m_hardwareID, originDevices);
int nbDevices;
SamplingDevices result;
if ((nbDevices = LMS_GetDeviceList(0)) <= 0)
{
qDebug("LimeSDROutputPlugin::enumOriginDevices: Could not find any LimeSDR device");
return; // do nothing
}
deviceList = new lms_info_str_t[nbDevices];
if (LMS_GetDeviceList(deviceList) < 0)
{
qDebug("LimeSDROutputPlugin::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;
listedHwIds.append(m_hardwareID); listedHwIds.append(m_hardwareID);
} }
@ -173,24 +129,6 @@ PluginInstanceGUI* LimeSDROutputPlugin::createSampleSinkPluginInstanceGUI(
} }
#endif #endif
bool LimeSDROutputPlugin::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;
}
}
DeviceSampleSink* LimeSDROutputPlugin::createSampleSinkPluginInstance(const QString& sinkId, DeviceAPI *deviceAPI) DeviceSampleSink* LimeSDROutputPlugin::createSampleSinkPluginInstance(const QString& sinkId, DeviceAPI *deviceAPI)
{ {
if(sinkId == m_deviceTypeID) if(sinkId == m_deviceTypeID)

View File

@ -50,7 +50,6 @@ public:
private: private:
static const PluginDescriptor m_pluginDescriptor; static const PluginDescriptor m_pluginDescriptor;
static bool findSerial(const char *lmsInfoStr, std::string& serial);
}; };

View File

@ -62,30 +62,7 @@ void PlutoSDROutputPlugin::enumOriginDevices(QStringList& listedHwIds, OriginDev
return; return;
} }
DevicePlutoSDR::instance().scan(); DevicePlutoSDR::instance().enumOriginDevices(m_hardwareID, originDevices);
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("PlutoSDROutputPlugin::enumOriginDevices: enumerated PlutoSDR device #%d", i);
}
listedHwIds.append(m_hardwareID); listedHwIds.append(m_hardwareID);
} }

View File

@ -64,25 +64,7 @@ void SoapySDROutputPlugin::enumOriginDevices(QStringList& listedHwIds, OriginDev
} }
DeviceSoapySDR& deviceSoapySDR = DeviceSoapySDR::instance(); DeviceSoapySDR& deviceSoapySDR = DeviceSoapySDR::instance();
const std::vector<DeviceSoapySDRScan::SoapySDRDeviceEnum>& devicesEnumeration = deviceSoapySDR.getDevicesEnumeration(); deviceSoapySDR.enumOriginDevices(m_hardwareID, originDevices);
qDebug("SoapySDROutputPlugin::enumOriginDevices: %lu SoapySDR devices", devicesEnumeration.size());
std::vector<DeviceSoapySDRScan::SoapySDRDeviceEnum>::const_iterator it = devicesEnumeration.begin();
for (int idev = 0; it != devicesEnumeration.end(); ++it, idev++)
{
QString displayedName(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));
originDevices.append(OriginDevice(
displayedName,
m_hardwareID,
serial,
idev, // Sequence
it->m_nbRx, // nb Rx
it->m_nbTx // nb Tx
));
}
listedHwIds.append(m_hardwareID); listedHwIds.append(m_hardwareID);
} }

View File

@ -23,7 +23,7 @@
#include "xtrx_api.h" #include "xtrx_api.h"
#include "plugin/pluginapi.h" #include "plugin/pluginapi.h"
#include "util/simpleserializer.h" #include "util/simpleserializer.h"
#include "xtrx/devicextrxparam.h" #include "xtrx/devicextrx.h"
#ifdef SERVER_MODE #ifdef SERVER_MODE
#include "xtrxoutput.h" #include "xtrxoutput.h"
@ -66,25 +66,7 @@ void XTRXOutputPlugin::enumOriginDevices(QStringList& listedHwIds, OriginDevices
return; return;
} }
xtrx_device_info_t devs[32]; DeviceXTRX::enumOriginDevices(m_hardwareID, originDevices);
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
));
}
listedHwIds.append(m_hardwareID); listedHwIds.append(m_hardwareID);
} }

View File

@ -62,50 +62,7 @@ void Blderf1InputPlugin::enumOriginDevices(QStringList& listedHwIds, OriginDevic
return; return;
} }
struct bladerf_devinfo *devinfo = nullptr; DeviceBladeRF1::enumOriginDevices(m_hardwareID, originDevices);
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
}
listedHwIds.append(m_hardwareID); listedHwIds.append(m_hardwareID);
} }

View File

@ -62,54 +62,7 @@ void Blderf2InputPlugin::enumOriginDevices(QStringList& listedHwIds, OriginDevic
return; return;
} }
struct bladerf_devinfo *devinfo = 0; DeviceBladeRF2::enumOriginDevices(m_hardwareID, originDevices);
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
}
listedHwIds.append(m_hardwareID); listedHwIds.append(m_hardwareID);
} }

View File

@ -63,55 +63,7 @@ void HackRFInputPlugin::enumOriginDevices(QStringList& listedHwIds, OriginDevice
return; return;
} }
hackrf_device_list_t *hackrf_devices = hackrf_device_list(); DeviceHackRF::enumOriginDevices(m_hardwareID, originDevices);
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);
listedHwIds.append(m_hardwareID); listedHwIds.append(m_hardwareID);
} }

View File

@ -17,12 +17,12 @@
#include <QtPlugin> #include <QtPlugin>
#include <regex>
#include <string> #include <string>
#include "lime/LimeSuite.h" #include "lime/LimeSuite.h"
#include "plugin/pluginapi.h" #include "plugin/pluginapi.h"
#include "util/simpleserializer.h" #include "util/simpleserializer.h"
#include "limesdr/devicelimesdr.h"
#ifdef SERVER_MODE #ifdef SERVER_MODE
#include "limesdrinput.h" #include "limesdrinput.h"
@ -65,50 +65,7 @@ void LimeSDRInputPlugin::enumOriginDevices(QStringList& listedHwIds, OriginDevic
return; return;
} }
lms_info_str_t* deviceList; DeviceLimeSDR::enumOriginDevices(m_hardwareID, originDevices);
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;
listedHwIds.append(m_hardwareID); listedHwIds.append(m_hardwareID);
} }
@ -172,24 +129,6 @@ PluginInstanceGUI* LimeSDRInputPlugin::createSampleSourcePluginInstanceGUI(
} }
#endif #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) DeviceSampleSource *LimeSDRInputPlugin::createSampleSourcePluginInstance(const QString& sourceId, DeviceAPI *deviceAPI)
{ {
if (sourceId == m_deviceTypeID) if (sourceId == m_deviceTypeID)

View File

@ -50,7 +50,6 @@ public:
private: private:
static const PluginDescriptor m_pluginDescriptor; static const PluginDescriptor m_pluginDescriptor;
static bool findSerial(const char *lmsInfoStr, std::string& serial);
}; };

View File

@ -64,30 +64,7 @@ void PlutoSDRInputPlugin::enumOriginDevices(QStringList& listedHwIds, OriginDevi
return; return;
} }
DevicePlutoSDR::instance().scan(); DevicePlutoSDR::instance().enumOriginDevices(m_hardwareID, originDevices);
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);
}
listedHwIds.append(m_hardwareID); listedHwIds.append(m_hardwareID);
} }

View File

@ -63,29 +63,7 @@ void SoapySDRInputPlugin::enumOriginDevices(QStringList& listedHwIds, OriginDevi
} }
DeviceSoapySDR& deviceSoapySDR = DeviceSoapySDR::instance(); DeviceSoapySDR& deviceSoapySDR = DeviceSoapySDR::instance();
const std::vector<DeviceSoapySDRScan::SoapySDRDeviceEnum>& devicesEnumeration = deviceSoapySDR.getDevicesEnumeration(); deviceSoapySDR.enumOriginDevices(m_hardwareID, originDevices);
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
));
}
listedHwIds.append(m_hardwareID); listedHwIds.append(m_hardwareID);
} }

View File

@ -27,6 +27,7 @@
#include "xtrx_api.h" #include "xtrx_api.h"
#include "plugin/pluginapi.h" #include "plugin/pluginapi.h"
#include "util/simpleserializer.h" #include "util/simpleserializer.h"
#include "xtrx/devicextrx.h"
#ifdef SERVER_MODE #ifdef SERVER_MODE
#include "xtrxinput.h" #include "xtrxinput.h"
@ -67,25 +68,7 @@ void XTRXInputPlugin::enumOriginDevices(QStringList& listedHwIds, OriginDevices&
return; return;
} }
xtrx_device_info_t devs[32]; DeviceXTRX::enumOriginDevices(m_hardwareID, originDevices);
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
));
}
listedHwIds.append(m_hardwareID); listedHwIds.append(m_hardwareID);
} }