1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-11-22 16:08:39 -05:00

On Android, list USB devices by VID/PID and open using file descriptor.

This commit is contained in:
Jon Beniston 2022-12-22 11:04:12 +00:00
parent 897ecc4d88
commit 7aea12e6fe
9 changed files with 187 additions and 1 deletions

View File

@ -58,6 +58,7 @@ target_link_libraries(${TARGET_NAME}
${TARGET_LIB_GUI}
swagger
${LIBAIRSPY_LIBRARIES}
${LIBUSB_LIBRARIES}
)
install(TARGETS ${TARGET_NAME} DESTINATION ${INSTALL_FOLDER})

View File

@ -37,6 +37,9 @@
#include "dsp/dspengine.h"
#include "airspysettings.h"
#include "airspyworker.h"
#ifdef ANDROID
#include "util/android.h"
#endif
MESSAGE_CLASS_DEFINITION(AirspyInput::MsgConfigureAirspy, Message)
MESSAGE_CLASS_DEFINITION(AirspyInput::MsgStartStop, Message)
@ -110,6 +113,20 @@ bool AirspyInput::openDevice()
return false;
}
#ifdef ANDROID
int fd;
QString serial = m_deviceAPI->getSamplingDeviceSerial();
if ((fd = Android::openUSBDevice(serial)) < 0)
{
qCritical("AirspyInput::openDevice: could not open USB device %s", qPrintable(serial));
return false;
}
if (airspy_open_fd(&m_dev, fd) != AIRSPY_SUCCESS)
{
qCritical("AirspyInput::openDevice: could not open Airspy: %s", qPrintable(serial));
return false;
}
#else
int device = m_deviceAPI->getSamplingDeviceSequence();
if ((m_dev = open_airspy_from_sequence(device)) == 0)
@ -117,6 +134,7 @@ bool AirspyInput::openDevice()
qCritical("AirspyInput::start: could not open Airspy #%d", device);
return false;
}
#endif
#ifdef LIBAIRSPY_DEFAULT_RATES
qDebug("AirspyInput::start: detault rates");

View File

@ -28,6 +28,9 @@
#include "plugin/pluginapi.h"
#include "util/simpleserializer.h"
#ifdef ANDROID
#include "util/android.h"
#endif
const int AirspyPlugin::m_maxDevices = 32;
@ -65,6 +68,29 @@ void AirspyPlugin::enumOriginDevices(QStringList& listedHwIds, OriginDevices& or
return;
}
#ifdef ANDROID
QStringList serialStrings = Android::listUSBDeviceSerials(0x1d50, 0x60a1);
int deviceNo = 0;
for (const auto serialString : serialStrings)
{
QString displayableName(QString("Airspy[%1] %2").arg(deviceNo).arg(serialString));
originDevices.append(OriginDevice(
displayableName,
m_hardwareID,
serialString,
deviceNo,
1,
0
));
deviceNo++;
}
listedHwIds.append(m_hardwareID);
#else
airspy_read_partid_serialno_t read_partid_serialno;
struct airspy_device *devinfo;
uint32_t serial_msb = 0;
@ -130,6 +156,8 @@ void AirspyPlugin::enumOriginDevices(QStringList& listedHwIds, OriginDevices& or
qDebug("AirspyPlugin::enumOriginDevices: airspy_exit: %s", airspy_error_name(rc));
listedHwIds.append(m_hardwareID);
#endif
}
PluginInterface::SamplingDevices AirspyPlugin::enumSampleSources(const OriginDevices& originDevices)

View File

@ -36,6 +36,9 @@
#include "airspyhfplugin.h"
#include "airspyhfsettings.h"
#include "airspyhfworker.h"
#ifdef ANDROID
#include "util/android.h"
#endif
MESSAGE_CLASS_DEFINITION(AirspyHFInput::MsgConfigureAirspyHF, Message)
MESSAGE_CLASS_DEFINITION(AirspyHFInput::MsgStartStop, Message)
@ -581,7 +584,13 @@ airspyhf_device_t *AirspyHFInput::open_airspyhf_from_serial(const QString& seria
}
else
{
#ifdef ANDROID
QString serialString = QString("AIRSPYHF SN:%1").arg(serial, 0, 16).toUpper();
int fd = Android::openUSBDevice(serialString);
rc = (airspyhf_error) airspyhf_open_fd(&devinfo, fd);
#else
rc = (airspyhf_error) airspyhf_open_sn(&devinfo, serial);
#endif
if (rc == AIRSPYHF_SUCCESS) {
return devinfo;

View File

@ -27,7 +27,9 @@
#else
#include "airspyhfgui.h"
#endif
#ifdef ANDROID
#include "util/android.h"
#endif
const PluginDescriptor AirspyHFPlugin::m_pluginDescriptor = {
QStringLiteral("AirspyHF"),
@ -67,7 +69,35 @@ void AirspyHFPlugin::enumOriginDevices(QStringList& listedHwIds, OriginDevices&
int nbDevices;
uint64_t deviceSerials[m_maxDevices];
#ifdef ANDROID
QStringList serialStrings = Android::listUSBDeviceSerials(0x03EB, 0x800C);
nbDevices = 0;
for (const auto serialString : serialStrings)
{
// Serials are of the form: "AIRSPYHF SN:12345678ABCDEF00"
int idx = serialString.indexOf(':');
if (idx != -1)
{
bool ok;
uint64_t serialInt = serialString.mid(idx+1).toULongLong(&ok, 16);
if (ok)
{
deviceSerials[nbDevices] = serialInt;
nbDevices++;
}
else
{
qDebug() << "AirspyHFPlugin::enumOriginDevices: Couldn't convert " << serialString.mid(idx+1) << " to integer";
}
}
else
{
qDebug() << "AirspyHFPlugin::enumOriginDevices: No : in serial " << serialString;
}
}
#else
nbDevices = airspyhf_list_devices(deviceSerials, m_maxDevices);
#endif
if (nbDevices < 0)
{

View File

@ -73,6 +73,7 @@ void AudioInputPlugin::enumOriginDevices(QStringList& listedHwIds, OriginDevices
1, // nb Rx
0 // nb Tx
));
listedHwIds.append(m_hardwareID);
}
PluginInterface::SamplingDevices AudioInputPlugin::enumSampleSources(const OriginDevices& originDevices)

View File

@ -54,6 +54,7 @@ target_link_libraries(${TARGET_NAME}
${TARGET_LIB_GUI}
swagger
${LIBRTLSDR_LIBRARIES}
${LIBUSB_LIBRARIES}
)
install(TARGETS ${TARGET_NAME} DESTINATION ${INSTALL_FOLDER})

View File

@ -35,6 +35,9 @@
#include "rtlsdrthread.h"
#include "dsp/dspcommands.h"
#include "dsp/dspengine.h"
#ifdef ANDROID
#include "util/android.h"
#endif
MESSAGE_CLASS_DEFINITION(RTLSDRInput::MsgConfigureRTLSDR, Message)
MESSAGE_CLASS_DEFINITION(RTLSDRInput::MsgStartStop, Message)
@ -115,6 +118,19 @@ bool RTLSDRInput::openDevice()
int device;
#ifdef ANDROID
int fd;
if ((fd = Android::openUSBDevice(m_deviceAPI->getSamplingDeviceSerial())) < 0)
{
qCritical("RTLSDRInput::openDevice: could not open USB device %s", qPrintable(m_deviceAPI->getSamplingDeviceSerial()));
return false;
}
if ((res = rtlsdr_open_fd(&m_dev, fd)) < 0)
{
qCritical("RTLSDRInput::openDevice: could not open RTLSDR: %s", strerror(errno));
return false;
}
#else
if ((device = rtlsdr_get_index_by_serial(qPrintable(m_deviceAPI->getSamplingDeviceSerial()))) < 0)
{
qCritical("RTLSDRInput::openDevice: could not get RTLSDR serial number");
@ -126,6 +142,7 @@ bool RTLSDRInput::openDevice()
qCritical("RTLSDRInput::openDevice: could not open RTLSDR #%d: %s", device, strerror(errno));
return false;
}
#endif
vendor[0] = '\0';
product[0] = '\0';

View File

@ -11,6 +11,9 @@
#endif
#include "rtlsdrplugin.h"
#include "rtlsdrwebapiadapter.h"
#ifdef ANDROID
#include "util/android.h"
#endif
const PluginDescriptor RTLSDRPlugin::m_pluginDescriptor = {
QStringLiteral("RTLSDR"),
@ -46,6 +49,83 @@ void RTLSDRPlugin::enumOriginDevices(QStringList& listedHwIds, OriginDevices& or
return;
}
#ifdef ANDROID
typedef struct rtlsdr_dongle {
uint16_t vid;
uint16_t pid;
const char *name;
} rtlsdr_dongle_t;
// This list comes from librtlsdr.c
rtlsdr_dongle_t known_devices[] = {
{ 0x0bda, 0x2832, "Generic RTL2832U" },
{ 0x0bda, 0x2838, "Generic RTL2832U OEM" },
{ 0x0413, 0x6680, "DigitalNow Quad DVB-T PCI-E card" },
{ 0x0413, 0x6f0f, "Leadtek WinFast DTV Dongle mini D" },
{ 0x0458, 0x707f, "Genius TVGo DVB-T03 USB dongle (Ver. B)" },
{ 0x0ccd, 0x00a9, "Terratec Cinergy T Stick Black (rev 1)" },
{ 0x0ccd, 0x00b3, "Terratec NOXON DAB/DAB+ USB dongle (rev 1)" },
{ 0x0ccd, 0x00b4, "Terratec Deutschlandradio DAB Stick" },
{ 0x0ccd, 0x00b5, "Terratec NOXON DAB Stick - Radio Energy" },
{ 0x0ccd, 0x00b7, "Terratec Media Broadcast DAB Stick" },
{ 0x0ccd, 0x00b8, "Terratec BR DAB Stick" },
{ 0x0ccd, 0x00b9, "Terratec WDR DAB Stick" },
{ 0x0ccd, 0x00c0, "Terratec MuellerVerlag DAB Stick" },
{ 0x0ccd, 0x00c6, "Terratec Fraunhofer DAB Stick" },
{ 0x0ccd, 0x00d3, "Terratec Cinergy T Stick RC (Rev.3)" },
{ 0x0ccd, 0x00d7, "Terratec T Stick PLUS" },
{ 0x0ccd, 0x00e0, "Terratec NOXON DAB/DAB+ USB dongle (rev 2)" },
{ 0x1554, 0x5020, "PixelView PV-DT235U(RN)" },
{ 0x15f4, 0x0131, "Astrometa DVB-T/DVB-T2" },
{ 0x15f4, 0x0133, "HanfTek DAB+FM+DVB-T" },
{ 0x185b, 0x0620, "Compro Videomate U620F"},
{ 0x185b, 0x0650, "Compro Videomate U650F"},
{ 0x185b, 0x0680, "Compro Videomate U680F"},
{ 0x1b80, 0xd393, "GIGABYTE GT-U7300" },
{ 0x1b80, 0xd394, "DIKOM USB-DVBT HD" },
{ 0x1b80, 0xd395, "Peak 102569AGPK" },
{ 0x1b80, 0xd397, "KWorld KW-UB450-T USB DVB-T Pico TV" },
{ 0x1b80, 0xd398, "Zaapa ZT-MINDVBZP" },
{ 0x1b80, 0xd39d, "SVEON STV20 DVB-T USB & FM" },
{ 0x1b80, 0xd3a4, "Twintech UT-40" },
{ 0x1b80, 0xd3a8, "ASUS U3100MINI_PLUS_V2" },
{ 0x1b80, 0xd3af, "SVEON STV27 DVB-T USB & FM" },
{ 0x1b80, 0xd3b0, "SVEON STV21 DVB-T USB & FM" },
{ 0x1d19, 0x1101, "Dexatek DK DVB-T Dongle (Logilink VG0002A)" },
{ 0x1d19, 0x1102, "Dexatek DK DVB-T Dongle (MSI DigiVox mini II V3.0)" },
{ 0x1d19, 0x1103, "Dexatek Technology Ltd. DK 5217 DVB-T Dongle" },
{ 0x1d19, 0x1104, "MSI DigiVox Micro HD" },
{ 0x1f4d, 0xa803, "Sweex DVB-T USB" },
{ 0x1f4d, 0xb803, "GTek T803" },
{ 0x1f4d, 0xc803, "Lifeview LV5TDeluxe" },
{ 0x1f4d, 0xd286, "MyGica TD312" },
{ 0x1f4d, 0xd803, "PROlectrix DV107669" },
};
int deviceNo = 0;
for (int i = 0; i < sizeof(known_devices)/sizeof(rtlsdr_dongle_t); i++)
{
QStringList serialStrings = Android::listUSBDeviceSerials(known_devices[i].vid, known_devices[i].pid);
for (const auto serial : serialStrings)
{
QString displayableName(QString("RTL-SDR[%1] %2").arg(deviceNo).arg(serial));
originDevices.append(OriginDevice(
displayableName,
m_hardwareID,
serial,
deviceNo, // sequence
1, // Nb Rx
0 // Nb Tx
));
deviceNo++;
}
}
listedHwIds.append(m_hardwareID);
#else
int count = rtlsdr_get_device_count();
char vendor[256];
char product[256];
@ -72,6 +152,7 @@ void RTLSDRPlugin::enumOriginDevices(QStringList& listedHwIds, OriginDevices& or
}
listedHwIds.append(m_hardwareID);
#endif
}
PluginInterface::SamplingDevices RTLSDRPlugin::enumSampleSources(const OriginDevices& originDevices)