mirror of
https://github.com/f4exb/sdrangel.git
synced 2026-06-02 22:14:45 -04:00
Added support for HackRF. Interim state #3
This commit is contained in:
@@ -16,7 +16,7 @@
|
||||
|
||||
#include <QtPlugin>
|
||||
#include <QAction>
|
||||
#include <libhackrf/hackrf.h>
|
||||
#include "libhackrf/hackrf.h"
|
||||
|
||||
#include "hackrfplugin.h"
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
#include "util/simpleserializer.h"
|
||||
|
||||
const PluginDescriptor HackRFPlugin::m_pluginDescriptor = {
|
||||
QString("Airspy Input"),
|
||||
QString("HackRF Input"),
|
||||
QString("---"),
|
||||
QString("(c) Edouard Griffiths, F4EXB"),
|
||||
QString("https://github.com/f4exb/sdrangel"),
|
||||
@@ -47,70 +47,68 @@ const PluginDescriptor& HackRFPlugin::getPluginDescriptor() const
|
||||
void HackRFPlugin::initPlugin(PluginAPI* pluginAPI)
|
||||
{
|
||||
m_pluginAPI = pluginAPI;
|
||||
m_pluginAPI->registerSampleSource("org.osmocom.sdr.samplesource.airspy", this);
|
||||
m_pluginAPI->registerSampleSource("org.osmocom.sdr.samplesource.hackrf", this);
|
||||
}
|
||||
|
||||
PluginInterface::SampleSourceDevices HackRFPlugin::enumSampleSources()
|
||||
{
|
||||
SampleSourceDevices result;
|
||||
airspy_read_partid_serialno_t read_partid_serialno;
|
||||
struct airspy_device *devinfo;
|
||||
uint32_t serial_msb = 0;
|
||||
uint32_t serial_lsb = 0;
|
||||
airspy_error rc;
|
||||
hackrf_device_list_t *hackrf_devices = hackrf_device_list();
|
||||
hackrf_device *hackrf_ptr;
|
||||
read_partid_serialno_t read_partid_serialno;
|
||||
hackrf_error rc;
|
||||
int i;
|
||||
|
||||
rc = (airspy_error) airspy_init();
|
||||
rc = (hackrf_error) hackrf_init();
|
||||
|
||||
if (rc != AIRSPY_SUCCESS)
|
||||
if (rc != HACKRF_SUCCESS)
|
||||
{
|
||||
qCritical("AirspyPlugin::enumSampleSources: failed to initiate Airspy library: %s", airspy_error_name(rc));
|
||||
qCritical("HackRFPlugin::SampleSourceDevices: failed to initiate HackRF library: %s", hackrf_error_name(rc));
|
||||
}
|
||||
|
||||
for (i=0; i < AIRSPY_MAX_DEVICE; i++)
|
||||
|
||||
|
||||
|
||||
for (i=0; i < hackrf_devices->devicecount; i++)
|
||||
{
|
||||
rc = (airspy_error) airspy_open(&devinfo);
|
||||
rc = (hackrf_error) hackrf_device_list_open(hackrf_devices, i, &hackrf_ptr);
|
||||
|
||||
if (rc == AIRSPY_SUCCESS)
|
||||
if (rc == HACKRF_SUCCESS)
|
||||
{
|
||||
qDebug("AirspyPlugin::enumSampleSources: try to enumerate Airspy device #%d", i);
|
||||
qDebug("HackRFPlugin::enumSampleSources: try to enumerate HackRF device #%d", i);
|
||||
|
||||
rc = (airspy_error) airspy_board_partid_serialno_read(devinfo, &read_partid_serialno);
|
||||
rc = (hackrf_error) hackrf_board_partid_serialno_read(hackrf_ptr, &read_partid_serialno);
|
||||
|
||||
if (rc != AIRSPY_SUCCESS)
|
||||
if (rc != HACKRF_SUCCESS)
|
||||
{
|
||||
qDebug("AirspyPlugin::enumSampleSources: failed to read serial no: %s", airspy_error_name(rc));
|
||||
airspy_close(devinfo);
|
||||
qDebug("HackRFPlugin::enumSampleSources: failed to read serial no: %s", hackrf_error_name(rc));
|
||||
hackrf_close(hackrf_ptr);
|
||||
continue; // next
|
||||
}
|
||||
|
||||
if ((read_partid_serialno.serial_no[2] != serial_msb) && (read_partid_serialno.serial_no[3] != serial_lsb))
|
||||
{
|
||||
serial_msb = read_partid_serialno.serial_no[2];
|
||||
serial_lsb = read_partid_serialno.serial_no[3];
|
||||
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("Airspy #%1 0x%2").arg(i).arg(serial_str));
|
||||
SimpleSerializer s(1);
|
||||
s.writeS32(1, i);
|
||||
s.writeString(2, serial_str);
|
||||
s.writeU64(3, serial_num);
|
||||
result.append(SampleSourceDevice(displayedName, "org.osmocom.sdr.samplesource.airspy", s.final()));
|
||||
qDebug("AirspyPlugin::enumSampleSources: enumerated Airspy device #%d", i);
|
||||
}
|
||||
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 0x%2").arg(i).arg(serial_str));
|
||||
SimpleSerializer s(1);
|
||||
s.writeS32(1, i);
|
||||
s.writeString(2, serial_str);
|
||||
s.writeU64(3, serial_num);
|
||||
result.append(SampleSourceDevice(displayedName, "org.osmocom.sdr.samplesource.hackrf", s.final()));
|
||||
qDebug("HackRFPlugin::enumSampleSources: enumerated HackRF device #%d", i);
|
||||
|
||||
airspy_close(devinfo);
|
||||
hackrf_close(hackrf_ptr);
|
||||
}
|
||||
else
|
||||
{
|
||||
qDebug("AirspyPlugin::enumSampleSources: enumerated %d Airspy devices %s", i, airspy_error_name(rc));
|
||||
break; // finished
|
||||
qDebug("HackRFPlugin::enumSampleSources: failed to enumerate HackRF device #%d: %s", i, hackrf_error_name(rc));
|
||||
}
|
||||
}
|
||||
|
||||
rc = (airspy_error) airspy_exit();
|
||||
qDebug("AirspyPlugin::enumSampleSources: airspy_exit: %s", airspy_error_name(rc));
|
||||
rc = (hackrf_error) hackrf_exit();
|
||||
qDebug("HackRFPlugin::enumSampleSources: hackrf_exit: %s", hackrf_error_name(rc));
|
||||
|
||||
return result;
|
||||
}
|
||||
@@ -122,7 +120,7 @@ PluginGUI* HackRFPlugin::createSampleSourcePluginGUI(const QString& sourceName,
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(sourceName == "org.osmocom.sdr.samplesource.airspy")
|
||||
if(sourceName == "org.osmocom.sdr.samplesource.hackrf")
|
||||
{
|
||||
HackRFGui* gui = new HackRFGui(m_pluginAPI);
|
||||
m_pluginAPI->setInputGUI(gui);
|
||||
|
||||
Reference in New Issue
Block a user