mirror of
https://github.com/f4exb/sdrangel.git
synced 2024-12-23 01:55:48 -05:00
Deep redesign: Better support for FCD dongles #9: use fcd_traits template instead of hardcoded values
This commit is contained in:
parent
f56a3d9385
commit
208d3deb6e
@ -330,3 +330,4 @@ qt5_use_modules(sdrangel Widgets Multimedia)
|
||||
|
||||
add_subdirectory(plugins)
|
||||
add_subdirectory(fcdhid)
|
||||
add_subdirectory(fcdlib)
|
||||
|
25
fcdlib/CMakeLists.txt
Normal file
25
fcdlib/CMakeLists.txt
Normal file
@ -0,0 +1,25 @@
|
||||
project(fcdlib)
|
||||
|
||||
set(fcdlib_SOURCES
|
||||
fcdtraits.cpp
|
||||
)
|
||||
|
||||
set(fcdlib_HEADERS
|
||||
fcdtraits.h
|
||||
)
|
||||
|
||||
include_directories(
|
||||
.
|
||||
${CMAKE_CURRENT_BINARY_DIR}
|
||||
${CMAKE_SOURCE_DIR}/include
|
||||
${CMAKE_SOURCE_DIR}/include-gpl
|
||||
)
|
||||
|
||||
#add_definitions(-DQT_PLUGIN)
|
||||
add_definitions(-DQT_SHARED)
|
||||
|
||||
add_library(fcdlib SHARED
|
||||
${fcdlib_SOURCES}
|
||||
)
|
||||
|
||||
target_link_libraries(fcdlib)
|
23
fcdlib/fcdtraits.cpp
Normal file
23
fcdlib/fcdtraits.cpp
Normal file
@ -0,0 +1,23 @@
|
||||
/*
|
||||
* fcdtraits.cpp
|
||||
*
|
||||
* Created on: Sep 5, 2015
|
||||
* Author: f4exb
|
||||
*/
|
||||
|
||||
#include "fcdtraits.h"
|
||||
|
||||
const char *fcd_traits<Pro>::alsaDeviceName = "hw:CARD=V10";
|
||||
const char *fcd_traits<ProPlus>::alsaDeviceName = "hw:CARD=V20";
|
||||
|
||||
const char *fcd_traits<Pro>::interfaceIID = "org.osmocom.sdr.samplesource.fcdpro";
|
||||
const char *fcd_traits<ProPlus>::interfaceIID = "org.osmocom.sdr.samplesource.fcdproplus";
|
||||
|
||||
const char *fcd_traits<Pro>::displayedName = "FunCube Dongle Pro";
|
||||
const char *fcd_traits<ProPlus>::displayedName = "FunCube Dongle Pro+";
|
||||
|
||||
const char *fcd_traits<Pro>::pluginDisplayedName = "FunCube Pro Input";
|
||||
const char *fcd_traits<ProPlus>::pluginDisplayedName = "FunCube Pro+ Input";
|
||||
|
||||
const char *fcd_traits<Pro>::pluginVersion = "---";
|
||||
const char *fcd_traits<ProPlus>::pluginVersion = "---";
|
67
fcdlib/fcdtraits.h
Normal file
67
fcdlib/fcdtraits.h
Normal file
@ -0,0 +1,67 @@
|
||||
/*
|
||||
* fcdtraits.h
|
||||
*
|
||||
* Created on: 3 Sep 2015
|
||||
* Author: egriffiths
|
||||
*/
|
||||
|
||||
#ifndef FCDLIB_FCDTRAITS_H_
|
||||
#define FCDLIB_FCDTRAITS_H_
|
||||
|
||||
#include <inttypes.h>
|
||||
|
||||
typedef enum
|
||||
{
|
||||
Pro,
|
||||
ProPlus
|
||||
} fcd_type;
|
||||
|
||||
template <fcd_type FCDType>
|
||||
struct fcd_traits
|
||||
{
|
||||
static const uint16_t vendorId = 0x0;
|
||||
static const uint16_t productId = 0x0;
|
||||
static const int sampleRate = 48000;
|
||||
static const int convBufSize = (1<<11);
|
||||
static const char *alsaDeviceName;
|
||||
static const char *interfaceIID;
|
||||
static const char *displayedName;
|
||||
static const char *pluginDisplayedName;
|
||||
static const char *pluginVersion;
|
||||
};
|
||||
|
||||
template<>
|
||||
struct fcd_traits<Pro>
|
||||
{
|
||||
static const uint16_t vendorId = 0x04D8;
|
||||
static const uint16_t productId = 0xFB56;
|
||||
static const int sampleRate = 96000;
|
||||
static const int convBufSize = (1<<11);
|
||||
static const char *alsaDeviceName;
|
||||
static const char *interfaceIID;
|
||||
static const char *displayedName;
|
||||
static const char *pluginDisplayedName;
|
||||
static const char *pluginVersion;
|
||||
};
|
||||
|
||||
template<>
|
||||
struct fcd_traits<ProPlus>
|
||||
{
|
||||
static const uint16_t vendorId = 0x04D8;
|
||||
static const uint16_t productId = 0xFB31;
|
||||
static const int sampleRate = 192000;
|
||||
static const int convBufSize = (1<<13);
|
||||
static const char *alsaDeviceName;
|
||||
static const char *interfaceIID;
|
||||
static const char *displayedName;
|
||||
static const char *pluginDisplayedName;
|
||||
static const char *pluginVersion;
|
||||
};
|
||||
|
||||
template <fcd_type FCDType> const char *fcd_traits<FCDType>::alsaDeviceName = "";
|
||||
template <fcd_type FCDType> const char *fcd_traits<FCDType>::interfaceIID = "";
|
||||
template <fcd_type FCDType> const char *fcd_traits<FCDType>::displayedName = "";
|
||||
template <fcd_type FCDType> const char *fcd_traits<FCDType>::pluginDisplayedName = "";
|
||||
template <fcd_type FCDType> const char *fcd_traits<FCDType>::pluginVersion = "---";
|
||||
|
||||
#endif /* FCDLIB_FCDTRAITS_H_ */
|
@ -26,6 +26,7 @@ include_directories(
|
||||
${CMAKE_SOURCE_DIR}/include
|
||||
${CMAKE_SOURCE_DIR}/include-gpl
|
||||
${CMAKE_SOURCE_DIR}/fcdhid
|
||||
${CMAKE_SOURCE_DIR}/fcdlib
|
||||
)
|
||||
|
||||
#include(${QT_USE_FILE})
|
||||
@ -47,6 +48,7 @@ target_link_libraries(inputfcdpro
|
||||
${LIBUSB_LIBRARIES}
|
||||
asound
|
||||
fcdhid
|
||||
fcdlib
|
||||
sdrbase
|
||||
)
|
||||
|
||||
|
@ -26,6 +26,7 @@
|
||||
#include "fcdprogui.h"
|
||||
#include "fcdproserializer.h"
|
||||
#include "fcdprothread.h"
|
||||
#include "fcdtraits.h"
|
||||
|
||||
MESSAGE_CLASS_DEFINITION(FCDProInput::MsgConfigureFCD, Message)
|
||||
|
||||
@ -113,7 +114,7 @@ FCDProInput::FCDProInput() :
|
||||
m_dev(0),
|
||||
m_settings(),
|
||||
m_FCDThread(0),
|
||||
m_deviceDescription("Funcube Dongle Pro")
|
||||
m_deviceDescription(fcd_traits<Pro>::displayedName)
|
||||
{
|
||||
}
|
||||
|
||||
@ -138,7 +139,7 @@ bool FCDProInput::start(int device)
|
||||
return false;
|
||||
}
|
||||
|
||||
m_dev = fcdOpen(0x04D8, 0xFB56, device);
|
||||
m_dev = fcdOpen(fcd_traits<Pro>::vendorId, fcd_traits<Pro>::productId, device);
|
||||
|
||||
if (m_dev == 0)
|
||||
{
|
||||
@ -197,7 +198,7 @@ const QString& FCDProInput::getDeviceDescription() const
|
||||
|
||||
int FCDProInput::getSampleRate() const
|
||||
{
|
||||
return 96000;
|
||||
return fcd_traits<Pro>::sampleRate;
|
||||
}
|
||||
|
||||
quint64 FCDProInput::getCenterFrequency() const
|
||||
@ -259,7 +260,7 @@ void FCDProInput::applySettings(const Settings& settings, bool force)
|
||||
|
||||
if (signalChange)
|
||||
{
|
||||
DSPSignalNotification *notif = new DSPSignalNotification(96000, m_settings.centerFrequency);
|
||||
DSPSignalNotification *notif = new DSPSignalNotification(fcd_traits<Pro>::sampleRate, m_settings.centerFrequency);
|
||||
getOutputMessageQueue()->push(notif);
|
||||
}
|
||||
}
|
||||
|
@ -20,10 +20,11 @@
|
||||
#include "util/simpleserializer.h"
|
||||
#include "fcdproplugin.h"
|
||||
#include "fcdprogui.h"
|
||||
#include "fcdtraits.h"
|
||||
|
||||
const PluginDescriptor FCDProPlugin::m_pluginDescriptor = {
|
||||
QString("FunCube Pro Input"),
|
||||
QString("---"),
|
||||
QString(fcd_traits<Pro>::pluginDisplayedName),
|
||||
QString(fcd_traits<Pro>::pluginVersion),
|
||||
QString("(c) Edouard Griffiths, F4EXB"),
|
||||
QString("https://github.com/f4exb/sdrangel"),
|
||||
true,
|
||||
@ -44,7 +45,7 @@ void FCDProPlugin::initPlugin(PluginAPI* pluginAPI)
|
||||
{
|
||||
m_pluginAPI = pluginAPI;
|
||||
|
||||
m_pluginAPI->registerSampleSource("org.osmocom.sdr.samplesource.fcdpro", this);
|
||||
m_pluginAPI->registerSampleSource(fcd_traits<Pro>::interfaceIID, this);
|
||||
}
|
||||
|
||||
PluginInterface::SampleSourceDevices FCDProPlugin::enumSampleSources()
|
||||
@ -52,15 +53,15 @@ PluginInterface::SampleSourceDevices FCDProPlugin::enumSampleSources()
|
||||
SampleSourceDevices result;
|
||||
|
||||
int i = 1;
|
||||
struct hid_device_info *device_info = hid_enumerate(0x04D8, 0xFB56);
|
||||
struct hid_device_info *device_info = hid_enumerate(fcd_traits<Pro>::vendorId, fcd_traits<Pro>::productId);
|
||||
|
||||
while (device_info != 0)
|
||||
{
|
||||
QString serialNumber = QString::fromWCharArray(device_info->serial_number);
|
||||
QString displayedName(QString("FunCube Dongle Pro #%1 ").arg(i) + serialNumber);
|
||||
QString displayedName(QString("%1 #%2 %3").arg(fcd_traits<Pro>::displayedName).arg(i).arg(serialNumber));
|
||||
SimpleSerializer s(1);
|
||||
s.writeS32(1, 0);
|
||||
result.append(SampleSourceDevice(displayedName, "org.osmocom.sdr.samplesource.fcdpro", s.final()));
|
||||
result.append(SampleSourceDevice(displayedName, fcd_traits<Pro>::interfaceIID, s.final()));
|
||||
|
||||
device_info = device_info->next;
|
||||
i++;
|
||||
@ -71,7 +72,7 @@ PluginInterface::SampleSourceDevices FCDProPlugin::enumSampleSources()
|
||||
|
||||
PluginGUI* FCDProPlugin::createSampleSourcePluginGUI(const QString& sourceName, const QByteArray& address)
|
||||
{
|
||||
if(sourceName == "org.osmocom.sdr.samplesource.fcdpro")
|
||||
if(sourceName == fcd_traits<Pro>::interfaceIID)
|
||||
{
|
||||
FCDProGui* gui = new FCDProGui(m_pluginAPI);
|
||||
m_pluginAPI->setInputGUI(gui);
|
||||
|
@ -20,13 +20,13 @@
|
||||
#include <errno.h>
|
||||
#include "dsp/samplefifo.h"
|
||||
#include "fcdprothread.h"
|
||||
#include "fcdproinput.h"
|
||||
#include "fcdtraits.h"
|
||||
|
||||
FCDProThread::FCDProThread(SampleFifo* sampleFifo, QObject* parent) :
|
||||
QThread(parent),
|
||||
fcd_handle(NULL),
|
||||
m_running(false),
|
||||
m_convertBuffer(FCD_BLOCKSIZE),
|
||||
m_convertBuffer(fcd_traits<Pro>::convBufSize),
|
||||
m_sampleFifo(sampleFifo)
|
||||
{
|
||||
start();
|
||||
@ -58,7 +58,7 @@ void FCDProThread::stopWork()
|
||||
|
||||
void FCDProThread::run()
|
||||
{
|
||||
if ( !OpenSource("hw:CARD=V10") )
|
||||
if ( !OpenSource(fcd_traits<Pro>::alsaDeviceName) )
|
||||
{
|
||||
qCritical() << "FCDThread::run: cannot open FCD sound card";
|
||||
return;
|
||||
@ -69,7 +69,7 @@ void FCDProThread::run()
|
||||
|
||||
while(m_running)
|
||||
{
|
||||
if (work(FCD_BLOCKSIZE) < 0)
|
||||
if (work(fcd_traits<Pro>::convBufSize) < 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
@ -24,8 +24,6 @@
|
||||
#include "dsp/inthalfbandfilter.h"
|
||||
#include <alsa/asoundlib.h>
|
||||
|
||||
#define FCD_BLOCKSIZE (1<<11)
|
||||
|
||||
class FCDProThread : public QThread {
|
||||
Q_OBJECT
|
||||
|
||||
|
@ -26,6 +26,7 @@ include_directories(
|
||||
${CMAKE_SOURCE_DIR}/include
|
||||
${CMAKE_SOURCE_DIR}/include-gpl
|
||||
${CMAKE_SOURCE_DIR}/fcdhid
|
||||
${CMAKE_SOURCE_DIR}/fcdlib
|
||||
)
|
||||
|
||||
#include(${QT_USE_FILE})
|
||||
@ -47,6 +48,7 @@ target_link_libraries(inputfcdproplus
|
||||
${LIBUSB_LIBRARIES}
|
||||
asound
|
||||
fcdhid
|
||||
fcdlib
|
||||
sdrbase
|
||||
)
|
||||
|
||||
|
@ -26,6 +26,7 @@
|
||||
#include "fcdproplusgui.h"
|
||||
#include "fcdproplusserializer.h"
|
||||
#include "fcdproplusthread.h"
|
||||
#include "fcdtraits.h"
|
||||
|
||||
MESSAGE_CLASS_DEFINITION(FCDProPlusInput::MsgConfigureFCD, Message)
|
||||
//MESSAGE_CLASS_DEFINITION(FCDInput::MsgReportFCD, Message)
|
||||
@ -114,7 +115,7 @@ FCDProPlusInput::FCDProPlusInput() :
|
||||
m_dev(0),
|
||||
m_settings(),
|
||||
m_FCDThread(0),
|
||||
m_deviceDescription("Funcube Dongle Pro+")
|
||||
m_deviceDescription(fcd_traits<ProPlus>::displayedName)
|
||||
{
|
||||
}
|
||||
|
||||
@ -139,7 +140,7 @@ bool FCDProPlusInput::start(int device)
|
||||
return false;
|
||||
}
|
||||
|
||||
m_dev = fcdOpen(0x04D8, 0xFB31, device);
|
||||
m_dev = fcdOpen(fcd_traits<ProPlus>::vendorId, fcd_traits<ProPlus>::productId, device);
|
||||
|
||||
if (m_dev == 0)
|
||||
{
|
||||
@ -198,7 +199,7 @@ const QString& FCDProPlusInput::getDeviceDescription() const
|
||||
|
||||
int FCDProPlusInput::getSampleRate() const
|
||||
{
|
||||
return 192000;
|
||||
return fcd_traits<ProPlus>::sampleRate;
|
||||
}
|
||||
|
||||
quint64 FCDProPlusInput::getCenterFrequency() const
|
||||
@ -260,7 +261,7 @@ void FCDProPlusInput::applySettings(const Settings& settings, bool force)
|
||||
|
||||
if (signalChange)
|
||||
{
|
||||
DSPSignalNotification *notif = new DSPSignalNotification(192000, m_settings.centerFrequency);
|
||||
DSPSignalNotification *notif = new DSPSignalNotification(fcd_traits<ProPlus>::sampleRate, m_settings.centerFrequency);
|
||||
getOutputMessageQueue()->push(notif);
|
||||
}
|
||||
}
|
||||
|
@ -20,10 +20,11 @@
|
||||
#include "util/simpleserializer.h"
|
||||
#include "fcdproplusplugin.h"
|
||||
#include "fcdproplusgui.h"
|
||||
#include "fcdtraits.h"
|
||||
|
||||
const PluginDescriptor FCDProPlusPlugin::m_pluginDescriptor = {
|
||||
QString("FunCube Pro+ Input"),
|
||||
QString("---"),
|
||||
QString(fcd_traits<ProPlus>::pluginDisplayedName),
|
||||
QString(fcd_traits<ProPlus>::pluginVersion),
|
||||
QString("(c) Edouard Griffiths, F4EXB"),
|
||||
QString("https://github.com/f4exb/sdrangel"),
|
||||
true,
|
||||
@ -44,7 +45,7 @@ void FCDProPlusPlugin::initPlugin(PluginAPI* pluginAPI)
|
||||
{
|
||||
m_pluginAPI = pluginAPI;
|
||||
|
||||
m_pluginAPI->registerSampleSource("org.osmocom.sdr.samplesource.fcdproplus", this);
|
||||
m_pluginAPI->registerSampleSource(fcd_traits<ProPlus>::interfaceIID, this);
|
||||
}
|
||||
|
||||
PluginInterface::SampleSourceDevices FCDProPlusPlugin::enumSampleSources()
|
||||
@ -52,15 +53,15 @@ PluginInterface::SampleSourceDevices FCDProPlusPlugin::enumSampleSources()
|
||||
SampleSourceDevices result;
|
||||
|
||||
int i = 1;
|
||||
struct hid_device_info *device_info = hid_enumerate(0x04D8, 0xFB31);
|
||||
struct hid_device_info *device_info = hid_enumerate(fcd_traits<ProPlus>::vendorId, fcd_traits<ProPlus>::productId);
|
||||
|
||||
while (device_info != 0)
|
||||
{
|
||||
QString serialNumber = QString::fromWCharArray(device_info->serial_number);
|
||||
QString displayedName(QString("FunCube Dongle Pro+ #%1 ").arg(i) + serialNumber);
|
||||
QString displayedName(QString("%1 #%2 %3").arg(fcd_traits<ProPlus>::displayedName).arg(i).arg(serialNumber));
|
||||
SimpleSerializer s(1);
|
||||
s.writeS32(1, 0);
|
||||
result.append(SampleSourceDevice(displayedName, "org.osmocom.sdr.samplesource.fcdproplus", s.final()));
|
||||
result.append(SampleSourceDevice(displayedName, fcd_traits<ProPlus>::interfaceIID, s.final()));
|
||||
|
||||
device_info = device_info->next;
|
||||
i++;
|
||||
@ -71,7 +72,7 @@ PluginInterface::SampleSourceDevices FCDProPlusPlugin::enumSampleSources()
|
||||
|
||||
PluginGUI* FCDProPlusPlugin::createSampleSourcePluginGUI(const QString& sourceName, const QByteArray& address)
|
||||
{
|
||||
if(sourceName == "org.osmocom.sdr.samplesource.fcdproplus")
|
||||
if(sourceName == fcd_traits<ProPlus>::interfaceIID)
|
||||
{
|
||||
FCDProPlusGui* gui = new FCDProPlusGui(m_pluginAPI);
|
||||
m_pluginAPI->setInputGUI(gui);
|
||||
|
@ -20,13 +20,13 @@
|
||||
#include <errno.h>
|
||||
#include "dsp/samplefifo.h"
|
||||
#include "fcdproplusthread.h"
|
||||
#include "fcdproplusinput.h"
|
||||
#include "fcdtraits.h"
|
||||
|
||||
FCDProPlusThread::FCDProPlusThread(SampleFifo* sampleFifo, QObject* parent) :
|
||||
QThread(parent),
|
||||
fcd_handle(NULL),
|
||||
m_running(false),
|
||||
m_convertBuffer(FCD_BLOCKSIZE),
|
||||
m_convertBuffer(fcd_traits<ProPlus>::convBufSize),
|
||||
m_sampleFifo(sampleFifo)
|
||||
{
|
||||
start();
|
||||
@ -58,7 +58,7 @@ void FCDProPlusThread::stopWork()
|
||||
|
||||
void FCDProPlusThread::run()
|
||||
{
|
||||
if ( !OpenSource("hw:CARD=V20") )
|
||||
if ( !OpenSource(fcd_traits<ProPlus>::alsaDeviceName) )
|
||||
{
|
||||
qCritical() << "FCDThread::run: cannot open FCD sound card";
|
||||
return;
|
||||
@ -69,7 +69,7 @@ void FCDProPlusThread::run()
|
||||
|
||||
while(m_running)
|
||||
{
|
||||
if (work(FCD_BLOCKSIZE) < 0)
|
||||
if (work(fcd_traits<ProPlus>::convBufSize) < 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
@ -25,8 +25,6 @@
|
||||
#include "dsp/inthalfbandfilter.h"
|
||||
#include <alsa/asoundlib.h>
|
||||
|
||||
#define FCD_BLOCKSIZE (1<<13)
|
||||
|
||||
class FCDProPlusThread : public QThread {
|
||||
Q_OBJECT
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user