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