diff --git a/CMakeLists.txt b/CMakeLists.txt index 23d4d8d25..1df2582d1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -330,3 +330,4 @@ qt5_use_modules(sdrangel Widgets Multimedia) add_subdirectory(plugins) add_subdirectory(fcdhid) +add_subdirectory(fcdlib) diff --git a/fcdlib/CMakeLists.txt b/fcdlib/CMakeLists.txt new file mode 100644 index 000000000..819972110 --- /dev/null +++ b/fcdlib/CMakeLists.txt @@ -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) diff --git a/fcdlib/fcdtraits.cpp b/fcdlib/fcdtraits.cpp new file mode 100644 index 000000000..7027c8db0 --- /dev/null +++ b/fcdlib/fcdtraits.cpp @@ -0,0 +1,23 @@ +/* + * fcdtraits.cpp + * + * Created on: Sep 5, 2015 + * Author: f4exb + */ + +#include "fcdtraits.h" + +const char *fcd_traits::alsaDeviceName = "hw:CARD=V10"; +const char *fcd_traits::alsaDeviceName = "hw:CARD=V20"; + +const char *fcd_traits::interfaceIID = "org.osmocom.sdr.samplesource.fcdpro"; +const char *fcd_traits::interfaceIID = "org.osmocom.sdr.samplesource.fcdproplus"; + +const char *fcd_traits::displayedName = "FunCube Dongle Pro"; +const char *fcd_traits::displayedName = "FunCube Dongle Pro+"; + +const char *fcd_traits::pluginDisplayedName = "FunCube Pro Input"; +const char *fcd_traits::pluginDisplayedName = "FunCube Pro+ Input"; + +const char *fcd_traits::pluginVersion = "---"; +const char *fcd_traits::pluginVersion = "---"; diff --git a/fcdlib/fcdtraits.h b/fcdlib/fcdtraits.h new file mode 100644 index 000000000..a7f3aafb0 --- /dev/null +++ b/fcdlib/fcdtraits.h @@ -0,0 +1,67 @@ +/* + * fcdtraits.h + * + * Created on: 3 Sep 2015 + * Author: egriffiths + */ + +#ifndef FCDLIB_FCDTRAITS_H_ +#define FCDLIB_FCDTRAITS_H_ + +#include + +typedef enum +{ + Pro, + ProPlus +} fcd_type; + +template +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 +{ + 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 +{ + 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 const char *fcd_traits::alsaDeviceName = ""; +template const char *fcd_traits::interfaceIID = ""; +template const char *fcd_traits::displayedName = ""; +template const char *fcd_traits::pluginDisplayedName = ""; +template const char *fcd_traits::pluginVersion = "---"; + +#endif /* FCDLIB_FCDTRAITS_H_ */ diff --git a/plugins/samplesource/fcdpro/CMakeLists.txt b/plugins/samplesource/fcdpro/CMakeLists.txt index 5ca0ccdeb..39f9efe03 100644 --- a/plugins/samplesource/fcdpro/CMakeLists.txt +++ b/plugins/samplesource/fcdpro/CMakeLists.txt @@ -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 ) diff --git a/plugins/samplesource/fcdpro/fcdproinput.cpp b/plugins/samplesource/fcdpro/fcdproinput.cpp index a87db3abb..d2781433b 100644 --- a/plugins/samplesource/fcdpro/fcdproinput.cpp +++ b/plugins/samplesource/fcdpro/fcdproinput.cpp @@ -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::displayedName) { } @@ -138,7 +139,7 @@ bool FCDProInput::start(int device) return false; } - m_dev = fcdOpen(0x04D8, 0xFB56, device); + m_dev = fcdOpen(fcd_traits::vendorId, fcd_traits::productId, device); if (m_dev == 0) { @@ -197,7 +198,7 @@ const QString& FCDProInput::getDeviceDescription() const int FCDProInput::getSampleRate() const { - return 96000; + return fcd_traits::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::sampleRate, m_settings.centerFrequency); getOutputMessageQueue()->push(notif); } } diff --git a/plugins/samplesource/fcdpro/fcdproplugin.cpp b/plugins/samplesource/fcdpro/fcdproplugin.cpp index 2c5754703..0e4c8d9c4 100644 --- a/plugins/samplesource/fcdpro/fcdproplugin.cpp +++ b/plugins/samplesource/fcdpro/fcdproplugin.cpp @@ -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::pluginDisplayedName), + QString(fcd_traits::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::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::vendorId, fcd_traits::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::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::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::interfaceIID) { FCDProGui* gui = new FCDProGui(m_pluginAPI); m_pluginAPI->setInputGUI(gui); diff --git a/plugins/samplesource/fcdpro/fcdprothread.cpp b/plugins/samplesource/fcdpro/fcdprothread.cpp index cefc5ebec..6ad7430a2 100644 --- a/plugins/samplesource/fcdpro/fcdprothread.cpp +++ b/plugins/samplesource/fcdpro/fcdprothread.cpp @@ -20,13 +20,13 @@ #include #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::convBufSize), m_sampleFifo(sampleFifo) { start(); @@ -58,7 +58,7 @@ void FCDProThread::stopWork() void FCDProThread::run() { - if ( !OpenSource("hw:CARD=V10") ) + if ( !OpenSource(fcd_traits::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::convBufSize) < 0) { break; } diff --git a/plugins/samplesource/fcdpro/fcdprothread.h b/plugins/samplesource/fcdpro/fcdprothread.h index 48d061e39..e4b8b496d 100644 --- a/plugins/samplesource/fcdpro/fcdprothread.h +++ b/plugins/samplesource/fcdpro/fcdprothread.h @@ -24,8 +24,6 @@ #include "dsp/inthalfbandfilter.h" #include -#define FCD_BLOCKSIZE (1<<11) - class FCDProThread : public QThread { Q_OBJECT diff --git a/plugins/samplesource/fcdproplus/CMakeLists.txt b/plugins/samplesource/fcdproplus/CMakeLists.txt index 1bd5d9a12..87c077d4d 100644 --- a/plugins/samplesource/fcdproplus/CMakeLists.txt +++ b/plugins/samplesource/fcdproplus/CMakeLists.txt @@ -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 ) diff --git a/plugins/samplesource/fcdproplus/fcdproplusinput.cpp b/plugins/samplesource/fcdproplus/fcdproplusinput.cpp index 976d2943e..ebf0998a4 100644 --- a/plugins/samplesource/fcdproplus/fcdproplusinput.cpp +++ b/plugins/samplesource/fcdproplus/fcdproplusinput.cpp @@ -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::displayedName) { } @@ -139,7 +140,7 @@ bool FCDProPlusInput::start(int device) return false; } - m_dev = fcdOpen(0x04D8, 0xFB31, device); + m_dev = fcdOpen(fcd_traits::vendorId, fcd_traits::productId, device); if (m_dev == 0) { @@ -198,7 +199,7 @@ const QString& FCDProPlusInput::getDeviceDescription() const int FCDProPlusInput::getSampleRate() const { - return 192000; + return fcd_traits::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::sampleRate, m_settings.centerFrequency); getOutputMessageQueue()->push(notif); } } diff --git a/plugins/samplesource/fcdproplus/fcdproplusplugin.cpp b/plugins/samplesource/fcdproplus/fcdproplusplugin.cpp index 69c066dfe..07e4cc5f0 100644 --- a/plugins/samplesource/fcdproplus/fcdproplusplugin.cpp +++ b/plugins/samplesource/fcdproplus/fcdproplusplugin.cpp @@ -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::pluginDisplayedName), + QString(fcd_traits::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::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::vendorId, fcd_traits::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::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::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::interfaceIID) { FCDProPlusGui* gui = new FCDProPlusGui(m_pluginAPI); m_pluginAPI->setInputGUI(gui); diff --git a/plugins/samplesource/fcdproplus/fcdproplusthread.cpp b/plugins/samplesource/fcdproplus/fcdproplusthread.cpp index e57ed41a6..82ce94495 100644 --- a/plugins/samplesource/fcdproplus/fcdproplusthread.cpp +++ b/plugins/samplesource/fcdproplus/fcdproplusthread.cpp @@ -20,13 +20,13 @@ #include #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::convBufSize), m_sampleFifo(sampleFifo) { start(); @@ -58,7 +58,7 @@ void FCDProPlusThread::stopWork() void FCDProPlusThread::run() { - if ( !OpenSource("hw:CARD=V20") ) + if ( !OpenSource(fcd_traits::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::convBufSize) < 0) { break; } diff --git a/plugins/samplesource/fcdproplus/fcdproplusthread.h b/plugins/samplesource/fcdproplus/fcdproplusthread.h index 07c558d90..0c2f72dc5 100644 --- a/plugins/samplesource/fcdproplus/fcdproplusthread.h +++ b/plugins/samplesource/fcdproplus/fcdproplusthread.h @@ -25,8 +25,6 @@ #include "dsp/inthalfbandfilter.h" #include -#define FCD_BLOCKSIZE (1<<13) - class FCDProPlusThread : public QThread { Q_OBJECT