HackRF: open device by serial number

pull/27/head
f4exb 2017-04-14 02:09:36 +02:00
rodzic 01b2c42a5f
commit 0a29f34b94
4 zmienionych plików z 32 dodań i 7 usunięć

Wyświetl plik

@ -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();

Wyświetl plik

@ -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);
};

Wyświetl plik

@ -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;
}

Wyświetl plik

@ -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;
}