1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-11-25 09:18:54 -05:00

HackRF: open device by serial number

This commit is contained in:
f4exb 2017-04-14 02:09:36 +02:00
parent 01b2c42a5f
commit 0a29f34b94
4 changed files with 32 additions and 7 deletions

View File

@ -33,6 +33,33 @@ hackrf_device *DeviceHackRF::open_hackrf(int sequence)
return open_hackrf_from_sequence(sequence);
}
hackrf_device *DeviceHackRF::open_hackrf(const char * const serial)
{
hackrf_error rc;
// TODO: this may not work if several HackRF Devices are running concurrently. It should be handled globally in the application
rc = (hackrf_error) hackrf_init();
if (rc != HACKRF_SUCCESS)
{
fprintf(stderr, "DeviceHackRF::open_hackrf: failed to initiate HackRF library %s\n", hackrf_error_name(rc));
return 0;
}
hackrf_device *hackrf_ptr;
rc = (hackrf_error) hackrf_open_by_serial(serial, &hackrf_ptr);
if (rc == HACKRF_SUCCESS)
{
return hackrf_ptr;
}
else
{
return 0;
}
}
hackrf_device *DeviceHackRF::open_hackrf_from_sequence(int sequence)
{
hackrf_device_list_t *hackrf_devices = hackrf_device_list();

View File

@ -23,6 +23,7 @@ class DeviceHackRF
{
public:
static hackrf_device *open_hackrf(int sequence);
static hackrf_device *open_hackrf(const char * const serial);
private:
static hackrf_device *open_hackrf_from_sequence(int sequence);
};

View File

@ -60,7 +60,6 @@ bool HackRFOutput::openDevice()
}
m_sampleSourceFifo.resize(m_settings.m_devSampleRate/(1<<(m_settings.m_log2Interp <= 4 ? m_settings.m_log2Interp : 4)));
int device = m_deviceAPI->getSampleSinkSequence();
if (m_deviceAPI->getSourceBuddies().size() > 0)
{
@ -84,9 +83,9 @@ bool HackRFOutput::openDevice()
}
else
{
if ((m_dev = DeviceHackRF::open_hackrf(device)) == 0)
if ((m_dev = DeviceHackRF::open_hackrf(qPrintable(m_deviceAPI->getSampleSinkSerial()))) == 0)
{
qCritical("HackRFOutput::openDevice: could not open HackRF #%d", device);
qCritical("HackRFOutput::openDevice: could not open HackRF %s", qPrintable(m_deviceAPI->getSampleSinkSerial()));
return false;
}

View File

@ -65,8 +65,6 @@ bool HackRFInput::openDevice()
return false;
}
int device = m_deviceAPI->getSampleSourceSequence();
if (m_deviceAPI->getSinkBuddies().size() > 0)
{
DeviceSinkAPI *buddy = m_deviceAPI->getSinkBuddies()[0];
@ -89,9 +87,9 @@ bool HackRFInput::openDevice()
}
else
{
if ((m_dev = DeviceHackRF::open_hackrf(device)) == 0)
if ((m_dev = DeviceHackRF::open_hackrf(qPrintable(m_deviceAPI->getSampleSourceSerial()))) == 0)
{
qCritical("HackRFInput::openDevice: could not open HackRF #%d", device);
qCritical("HackRFInput::openDevice: could not open HackRF %s", qPrintable(m_deviceAPI->getSampleSourceSerial()));
return false;
}