mirror of
https://github.com/f4exb/sdrangel.git
synced 2026-06-05 15:34:57 -04:00
Plugins device enumeration optimization: factorization of common code for Rx/Tx devices
This commit is contained in:
@@ -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)
|
||||
{
|
||||
int fpga_loaded;
|
||||
|
||||
Reference in New Issue
Block a user