diff --git a/CMakeLists.txt b/CMakeLists.txt index a3e12e55..b23f89ad 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,6 +6,7 @@ option(OPT_BUILD_SPYSERVER_SOURCE "Build SpyServer Source Module (no dependencie option(OPT_BUILD_SOAPY_SOURCE "Build SoapySDR Source Module (Depedencies: soapysdr)" ON) option(OPT_BUILD_AIRSPYHF_SOURCE "Build Airspy HF+ Source Module (Depedencies: libairspyhf)" ON) option(OPT_BUILD_AIRSPY_SOURCE "Build Airspy Source Module (Depedencies: libairspy)" ON) +option(OPT_BUILD_SDRPLAY_SOURCE "Build SDRplay Source Module (Depedencies: libsdrplay)" ON) option(OPT_BUILD_PLUTOSDR_SOURCE "Build PlutoSDR Source Module (Depedencies: libiio, libad9361)" ON) option(OPT_BUILD_HACKRF_SOURCE "Build HackRF Source Module (Depedencies: libhackrf)" ON) option(OPT_BUILD_AUDIO_SINK "Build Audio Sink Module (Depedencies: portaudio)" ON) @@ -39,6 +40,10 @@ if (OPT_BUILD_AIRSPY_SOURCE) add_subdirectory("airspy_source") endif (OPT_BUILD_AIRSPY_SOURCE) +if (OPT_BUILD_SDRPLAY_SOURCE) +add_subdirectory("sdrplay_source") +endif (OPT_BUILD_SDRPLAY_SOURCE) + if (OPT_BUILD_PLUTOSDR_SOURCE) add_subdirectory("plutosdr_source") endif (OPT_BUILD_PLUTOSDR_SOURCE) diff --git a/core/src/credits.cpp b/core/src/credits.cpp index 4f11e900..10467a3a 100644 --- a/core/src/credits.cpp +++ b/core/src/credits.cpp @@ -24,7 +24,8 @@ namespace sdrpp_credits { const char* patrons[] = { "SignalsEverywhere", - "Lee Donaghy" + "Lee Donaghy", + "Daniele D'Agnelli" }; const int contributorCount = sizeof(contributors) / sizeof(char*); diff --git a/core/src/gui/widgets/waterfall.cpp b/core/src/gui/widgets/waterfall.cpp index 236a3c32..ab8c39eb 100644 --- a/core/src/gui/widgets/waterfall.cpp +++ b/core/src/gui/widgets/waterfall.cpp @@ -186,12 +186,8 @@ namespace ImGui { if (IS_IN_AREA(mPos, wfMin, wfMax)) { for (auto const& [name, vfo] : vfos) { - ImVec2 nVfoRectMin(vfo->rectMin.x, wfMin.y); - ImVec2 nVfoRectMax(vfo->rectMax.x, wfMax.y); - ImVec2 nVfoLineMin(vfo->lineMin.x, wfMin.y); - ImVec2 nVfoLineMax(vfo->lineMin.x, wfMax.y); - window->DrawList->AddRectFilled(nVfoRectMin, nVfoRectMax, IM_COL32(255, 255, 255, 50)); - window->DrawList->AddLine(nVfoLineMin, nVfoLineMax, (name == selectedVFO) ? IM_COL32(255, 0, 0, 255) : IM_COL32(255, 255, 0, 255)); + window->DrawList->AddRectFilled(vfo->wfRectMin, vfo->wfRectMax, IM_COL32(255, 255, 255, 50)); + window->DrawList->AddLine(vfo->wfLineMin, vfo->wfLineMax, (name == selectedVFO) ? IM_COL32(255, 0, 0, 255) : IM_COL32(255, 255, 0, 255)); } } } @@ -201,6 +197,10 @@ namespace ImGui { if (vfo->redrawRequired) { vfo->redrawRequired = false; vfo->updateDrawingVars(viewBandwidth, dataWidth, viewOffset, widgetPos, fftHeight); + vfo->wfRectMin = ImVec2(vfo->rectMin.x, wfMin.y); + vfo->wfRectMax = ImVec2(vfo->rectMax.x, wfMax.y); + vfo->wfLineMin = ImVec2(vfo->lineMin.x, wfMin.y); + vfo->wfLineMax = ImVec2(vfo->lineMax.x, wfMax.y); } vfo->draw(window, name == selectedVFO); } @@ -247,9 +247,7 @@ namespace ImGui { if (name == selectedVFO) { continue; } - ImVec2 nVfoRectMin(_vfo->rectMin.x, wfMin.y); - ImVec2 nVfoRectMax(_vfo->rectMax.x, wfMax.y); - if (IS_IN_AREA(mousePos, _vfo->rectMin, _vfo->rectMax) || IS_IN_AREA(mousePos, nVfoRectMin, nVfoRectMax)) { + if (IS_IN_AREA(mousePos, _vfo->rectMin, _vfo->rectMax) || IS_IN_AREA(mousePos, _vfo->wfRectMin, _vfo->wfRectMax)) { selectedVFO = name; selectedVFOChanged = true; return; @@ -257,7 +255,7 @@ namespace ImGui { } if (vfo != NULL) { int refCenter = mousePos.x - (widgetPos.x + 50); - if (refCenter >= 0 && refCenter < dataWidth /* && ( (mousePos.y > widgetPos.y && mousePos.y < (widgetPos.y + widgetSize.y)) || (IS_IN_AREA(mousePos, nVfoRectMin, nVfoRectMax)) ) */ ) { + if (refCenter >= 0 && refCenter < dataWidth) { double off = ((((double)refCenter / ((double)dataWidth / 2.0)) - 1.0) * (viewBandwidth / 2.0)) + viewOffset; off += centerFreq; off = (round(off / vfo->snapInterval) * vfo->snapInterval) - centerFreq; @@ -766,6 +764,10 @@ namespace ImGui { void WaterFall::updateAllVFOs() { for (auto const& [name, vfo] : vfos) { vfo->updateDrawingVars(viewBandwidth, dataWidth, viewOffset, widgetPos, fftHeight); + vfo->wfRectMin = ImVec2(vfo->rectMin.x, wfMin.y); + vfo->wfRectMax = ImVec2(vfo->rectMax.x, wfMax.y); + vfo->wfLineMin = ImVec2(vfo->lineMin.x, wfMin.y); + vfo->wfLineMax = ImVec2(vfo->lineMax.x, wfMax.y); } } diff --git a/core/src/gui/widgets/waterfall.h b/core/src/gui/widgets/waterfall.h index d3d7d88d..567805ff 100644 --- a/core/src/gui/widgets/waterfall.h +++ b/core/src/gui/widgets/waterfall.h @@ -38,6 +38,10 @@ namespace ImGui { ImVec2 rectMax; ImVec2 lineMin; ImVec2 lineMax; + ImVec2 wfRectMin; + ImVec2 wfRectMax; + ImVec2 wfLineMin; + ImVec2 wfLineMax; bool centerOffsetChanged = false; bool lowerOffsetChanged = false; diff --git a/readme.md b/readme.md index 35c58ad0..7cd83b31 100644 --- a/readme.md +++ b/readme.md @@ -221,6 +221,7 @@ I will soon publish a contributing.md listing the code style to use. ## Patrons * [SignalsEverywhere](https://signalseverywhere.com/) * [Lee Donaghy](https://github.com/github) +* [Daniele D'Agnelli](https://linkedin.com/in/dagnelli) ## Contributors * [aosync](https://github.com/aosync) diff --git a/sdrplay_source/CMakeLists.txt b/sdrplay_source/CMakeLists.txt new file mode 100644 index 00000000..f9e7bf36 --- /dev/null +++ b/sdrplay_source/CMakeLists.txt @@ -0,0 +1,31 @@ +cmake_minimum_required(VERSION 3.13) +project(sdrplay_source) + +if (MSVC) + set(CMAKE_CXX_FLAGS "-O2 /std:c++17 /EHsc") +else() + set(CMAKE_CXX_FLAGS "-O3 -std=c++17 -fpermissive") +endif (MSVC) + +include_directories("src/") + +file(GLOB SRC "src/*.cpp") + +add_library(sdrplay_source SHARED ${SRC}) +target_link_libraries(sdrplay_source PRIVATE sdrpp_core) +set_target_properties(sdrplay_source PROPERTIES PREFIX "") + +if (MSVC) + # Lib path + target_link_directories(sdrpp_core PUBLIC "C:/Program Files/SDRplay/API/x64") + + target_link_libraries(sdrplay_source PUBLIC sdrplay_api) +else (MSVC) + find_package(PkgConfig) + + pkg_check_modules(LIBAIRSPYHF REQUIRED libairspy) + + target_include_directories(sdrplay_source PUBLIC ${LIBAIRSPYHF_INCLUDE_DIRS}) + target_link_directories(sdrplay_source PUBLIC ${LIBAIRSPYHF_LIBRARY_DIRS}) + target_link_libraries(sdrplay_source PUBLIC ${LIBAIRSPYHF_LIBRARIES}) +endif (MSVC) \ No newline at end of file diff --git a/sdrplay_source/src/main.cpp b/sdrplay_source/src/main.cpp new file mode 100644 index 00000000..cf1de8e2 --- /dev/null +++ b/sdrplay_source/src/main.cpp @@ -0,0 +1,190 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +#define CONCAT(a, b) ((std::string(a) + b).c_str()) + +SDRPP_MOD_INFO { + /* Name: */ "sdrplay_source", + /* Description: */ "Airspy source module for SDR++", + /* Author: */ "Ryzerth", + /* Version: */ 0, 1, 0, + /* Max instances */ 1 +}; + +ConfigManager config; + +class SDRPlaySourceModule : public ModuleManager::Instance { +public: + SDRPlaySourceModule(std::string name) { + this->name = name; + + sampleRate = 10000000.0; + + handler.ctx = this; + handler.selectHandler = menuSelected; + handler.deselectHandler = menuDeselected; + handler.menuHandler = menuHandler; + handler.startHandler = start; + handler.stopHandler = stop; + handler.tuneHandler = tune; + handler.stream = &stream; + + refresh(); + if (sampleRateList.size() > 0) { + sampleRate = sampleRateList[0]; + } + + // Select device from config + // config.aquire(); + // std::string devSerial = config.conf["device"]; + // config.release(); + // selectByString(devSerial); + // core::setInputSampleRate(sampleRate); + + sigpath::sourceManager.registerSource("SDRplay", &handler); + } + + ~SDRPlaySourceModule() { + + } + + void enable() { + enabled = true; + } + + void disable() { + enabled = false; + } + + bool isEnabled() { + return enabled; + } + + void refresh() { + devList.clear(); + devListTxt = ""; + + // Fill in list here + } + +private: + std::string getBandwdithScaled(double bw) { + char buf[1024]; + if (bw >= 1000000.0) { + sprintf(buf, "%.1lfMHz", bw / 1000000.0); + } + else if (bw >= 1000.0) { + sprintf(buf, "%.1lfKHz", bw / 1000.0); + } + else { + sprintf(buf, "%.1lfHz", bw); + } + return std::string(buf); + } + + static void menuSelected(void* ctx) { + SDRPlaySourceModule* _this = (SDRPlaySourceModule*)ctx; + core::setInputSampleRate(_this->sampleRate); + spdlog::info("SDRPlaySourceModule '{0}': Menu Select!", _this->name); + } + + static void menuDeselected(void* ctx) { + SDRPlaySourceModule* _this = (SDRPlaySourceModule*)ctx; + spdlog::info("SDRPlaySourceModule '{0}': Menu Deselect!", _this->name); + } + + static void start(void* ctx) { + SDRPlaySourceModule* _this = (SDRPlaySourceModule*)ctx; + if (_this->running) { + return; + } + + // Do start procedure here + + _this->running = true; + spdlog::info("SDRPlaySourceModule '{0}': Start!", _this->name); + } + + static void stop(void* ctx) { + SDRPlaySourceModule* _this = (SDRPlaySourceModule*)ctx; + if (!_this->running) { + return; + } + _this->running = false; + _this->stream.stopWriter(); + + // Stop procedure here + + _this->stream.clearWriteStop(); + spdlog::info("SDRPlaySourceModule '{0}': Stop!", _this->name); + } + + static void tune(double freq, void* ctx) { + SDRPlaySourceModule* _this = (SDRPlaySourceModule*)ctx; + if (_this->running) { + // Tune here + } + _this->freq = freq; + spdlog::info("SDRPlaySourceModule '{0}': Tune: {1}!", _this->name, freq); + } + + static void menuHandler(void* ctx) { + SDRPlaySourceModule* _this = (SDRPlaySourceModule*)ctx; + float menuWidth = ImGui::GetContentRegionAvailWidth(); + + if (_this->running) { style::beginDisabled(); } + + ImGui::SetNextItemWidth(menuWidth); + + // Menu here + + + } + + std::string name; + bool enabled = true; + dsp::stream stream; + double sampleRate; + SourceManager::SourceHandler handler; + bool running = false; + double freq; + + int devId = 0; + int srId = 0; + + std::vector devList; + std::string devListTxt; + std::vector sampleRateList; + std::string sampleRateListTxt; +}; + +MOD_EXPORT void _INIT_() { + json def = json({}); + def["devices"] = json({}); + def["device"] = ""; + config.setPath(options::opts.root + "/sdrplay_config.json"); + config.load(def); + config.enableAutoSave(); +} + +MOD_EXPORT ModuleManager::Instance* _CREATE_INSTANCE_(std::string name) { + return new SDRPlaySourceModule(name); +} + +MOD_EXPORT void _DELETE_INSTANCE_(ModuleManager::Instance* instance) { + delete (SDRPlaySourceModule*)instance; +} + +MOD_EXPORT void _END_() { + config.disableAutoSave(); + config.save(); +} \ No newline at end of file