mirror of
				https://github.com/AlexandreRouma/SDRPlusPlus.git
				synced 2025-11-04 02:39:11 +01:00 
			
		
		
		
	added module system
This commit is contained in:
		
							
								
								
									
										55
									
								
								modules/demo/CMakeLists.txt
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										55
									
								
								modules/demo/CMakeLists.txt
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,55 @@
 | 
			
		||||
cmake_minimum_required(VERSION 3.9)
 | 
			
		||||
project(demo)
 | 
			
		||||
 | 
			
		||||
if (MSVC)
 | 
			
		||||
    set(CMAKE_CXX_FLAGS "-O2 /std:c++17")
 | 
			
		||||
    link_directories(demo "C:/Program Files/PothosSDR/lib/")
 | 
			
		||||
    include_directories(demo "C:/Program Files/PothosSDR/include/volk/")
 | 
			
		||||
    include_directories(demo "C:/Program Files/PothosSDR/include/")
 | 
			
		||||
else()
 | 
			
		||||
    set(CMAKE_CXX_FLAGS "-O3 -std=c++17 -fsanitize=address -g")
 | 
			
		||||
    include_directories(demo "/usr/include/volk")
 | 
			
		||||
    link_libraries(pthread)
 | 
			
		||||
    link_libraries(GL)
 | 
			
		||||
    link_libraries(GLEW)
 | 
			
		||||
    link_libraries(glfw)
 | 
			
		||||
    link_libraries(fftw3)
 | 
			
		||||
    link_libraries(fftw3f)
 | 
			
		||||
    link_libraries(portaudio)
 | 
			
		||||
    link_libraries(X11)
 | 
			
		||||
    link_libraries(Xxf86vm)
 | 
			
		||||
endif (MSVC)
 | 
			
		||||
 | 
			
		||||
link_libraries(volk)
 | 
			
		||||
link_libraries(SoapySDR)
 | 
			
		||||
 | 
			
		||||
# Main code
 | 
			
		||||
include_directories(demo "src/")
 | 
			
		||||
include_directories(demo "../../src/")
 | 
			
		||||
include_directories(demo "../../src/imgui")
 | 
			
		||||
file(GLOB SRC "src/*.cpp")
 | 
			
		||||
file(GLOB IMGUI "../../src/imgui/*.cpp")
 | 
			
		||||
add_library(demo SHARED ${SRC} ${IMGUI})
 | 
			
		||||
set_target_properties(demo PROPERTIES OUTPUT_NAME demo)
 | 
			
		||||
 | 
			
		||||
if (MSVC)
 | 
			
		||||
    # Glew
 | 
			
		||||
    find_package(GLEW REQUIRED)
 | 
			
		||||
    target_link_libraries(demo PRIVATE GLEW::GLEW)
 | 
			
		||||
 | 
			
		||||
    # GLFW3
 | 
			
		||||
    find_package(glfw3 CONFIG REQUIRED)
 | 
			
		||||
    target_link_libraries(demo PRIVATE glfw)
 | 
			
		||||
 | 
			
		||||
    # FFTW3
 | 
			
		||||
    find_package(FFTW3 CONFIG REQUIRED)
 | 
			
		||||
    target_link_libraries(demo PRIVATE FFTW3::fftw3)
 | 
			
		||||
    find_package(FFTW3f CONFIG REQUIRED)
 | 
			
		||||
    target_link_libraries(demo PRIVATE FFTW3::fftw3f)
 | 
			
		||||
 | 
			
		||||
    # PortAudio
 | 
			
		||||
    find_package(portaudio CONFIG REQUIRED)
 | 
			
		||||
    target_link_libraries(demo PRIVATE portaudio portaudio_static)
 | 
			
		||||
endif (MSVC)
 | 
			
		||||
 | 
			
		||||
# cmake .. "-DCMAKE_TOOLCHAIN_FILE=C:/Users/Alex/vcpkg/scripts/buildsystems/vcpkg.cmake" -G "Visual Studio 15 2017 Win64"
 | 
			
		||||
							
								
								
									
										26
									
								
								modules/demo/src/main.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										26
									
								
								modules/demo/src/main.cpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,26 @@
 | 
			
		||||
#include <imgui.h>
 | 
			
		||||
#include <module.h>
 | 
			
		||||
 | 
			
		||||
mod::API_t* API;
 | 
			
		||||
 | 
			
		||||
struct DemoContext_t {
 | 
			
		||||
    std::string name;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
MOD_EXPORT void* _INIT_(mod::API_t* _API, ImGuiContext* imctx, std::string _name) {
 | 
			
		||||
    API = _API;
 | 
			
		||||
    DemoContext_t* ctx = new DemoContext_t;
 | 
			
		||||
    ctx->name = _name;
 | 
			
		||||
    ImGui::SetCurrentContext(imctx);
 | 
			
		||||
    return ctx;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
MOD_EXPORT void _DRAW_MENU_(DemoContext_t* ctx) {
 | 
			
		||||
    char buf[100];
 | 
			
		||||
    sprintf(buf, "I'm %s", ctx->name.c_str());
 | 
			
		||||
    ImGui::Button(buf);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
MOD_EXPORT void _STOP_(DemoContext_t* ctx) {
 | 
			
		||||
    delete ctx;
 | 
			
		||||
}
 | 
			
		||||
@@ -10,6 +10,7 @@
 | 
			
		||||
#include <version.h>
 | 
			
		||||
#include <spdlog/spdlog.h>
 | 
			
		||||
#include <bandplan.h>
 | 
			
		||||
#include <module.h>
 | 
			
		||||
 | 
			
		||||
#ifdef _WIN32
 | 
			
		||||
#include <Windows.h>
 | 
			
		||||
@@ -72,6 +73,11 @@ int main() {
 | 
			
		||||
    spdlog::info("Loading band plans color table");
 | 
			
		||||
    bandplan::loadColorTable("band_colors.json");
 | 
			
		||||
 | 
			
		||||
    spdlog::info("Loading test module");
 | 
			
		||||
    //mod::loadModule("../modules/demo/build/Release/demo.dll", "Demo Module 1");
 | 
			
		||||
    //mod::loadModule("../modules/demo/build/Release/demo.dll", "Demo Module 2");
 | 
			
		||||
    //mod::loadModule("../modules/demo/build/Release/demo.dll", "Demo Module 3");
 | 
			
		||||
 | 
			
		||||
    spdlog::info("Ready.");
 | 
			
		||||
 | 
			
		||||
    // Main loop
 | 
			
		||||
 
 | 
			
		||||
@@ -1,20 +1,4 @@
 | 
			
		||||
#include <main_window.h>
 | 
			
		||||
#include <imgui_plot.h>
 | 
			
		||||
#include <dsp/resampling.h>
 | 
			
		||||
#include <dsp/demodulator.h>
 | 
			
		||||
#include <dsp/filter.h>
 | 
			
		||||
#include <thread>
 | 
			
		||||
#include <complex>
 | 
			
		||||
#include <dsp/source.h>
 | 
			
		||||
#include <dsp/math.h>
 | 
			
		||||
#include <waterfall.h>
 | 
			
		||||
#include <frequency_select.h>
 | 
			
		||||
#include <fftw3.h>
 | 
			
		||||
#include <signal_path.h>
 | 
			
		||||
#include <io/soapy.h>
 | 
			
		||||
#include <icons.h>
 | 
			
		||||
#include <bandplan.h>
 | 
			
		||||
#include <watcher.h>
 | 
			
		||||
 | 
			
		||||
std::thread worker;
 | 
			
		||||
std::mutex fft_mtx;
 | 
			
		||||
@@ -304,6 +288,15 @@ void drawWindow() {
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    int modCount = mod::moduleNames.size();
 | 
			
		||||
    mod::Module_t mod;
 | 
			
		||||
    for (int i = 0; i < modCount; i++) {
 | 
			
		||||
        if (ImGui::CollapsingHeader(mod::moduleNames[i].c_str())) {
 | 
			
		||||
            mod = mod::modules[mod::moduleNames[i]];
 | 
			
		||||
            mod._DRAW_MENU_(mod.ctx);
 | 
			
		||||
        }
 | 
			
		||||
    } 
 | 
			
		||||
 | 
			
		||||
    if (ImGui::CollapsingHeader("Radio")) {
 | 
			
		||||
        ImGui::BeginGroup();
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -5,6 +5,23 @@
 | 
			
		||||
#include <stdio.h>
 | 
			
		||||
#include <GL/glew.h>
 | 
			
		||||
#include <GLFW/glfw3.h>
 | 
			
		||||
#include <imgui_plot.h>
 | 
			
		||||
#include <dsp/resampling.h>
 | 
			
		||||
#include <dsp/demodulator.h>
 | 
			
		||||
#include <dsp/filter.h>
 | 
			
		||||
#include <thread>
 | 
			
		||||
#include <complex>
 | 
			
		||||
#include <dsp/source.h>
 | 
			
		||||
#include <dsp/math.h>
 | 
			
		||||
#include <waterfall.h>
 | 
			
		||||
#include <frequency_select.h>
 | 
			
		||||
#include <fftw3.h>
 | 
			
		||||
#include <signal_path.h>
 | 
			
		||||
#include <io/soapy.h>
 | 
			
		||||
#include <icons.h>
 | 
			
		||||
#include <bandplan.h>
 | 
			
		||||
#include <watcher.h>
 | 
			
		||||
#include <module.h>
 | 
			
		||||
 | 
			
		||||
#define WINDOW_FLAGS    ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoBringToFrontOnFocus | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoBackground
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										50
									
								
								src/module.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										50
									
								
								src/module.cpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,50 @@
 | 
			
		||||
#include <module.h>
 | 
			
		||||
 | 
			
		||||
namespace mod {
 | 
			
		||||
    API_t API;
 | 
			
		||||
    std::map<std::string, Module_t> modules;
 | 
			
		||||
    std::vector<std::string> moduleNames;
 | 
			
		||||
 | 
			
		||||
    void loadModule(std::string path, std::string name) {
 | 
			
		||||
        if (!std::filesystem::exists(path)) {
 | 
			
		||||
            spdlog::error("{0} does not exist", path);
 | 
			
		||||
            return;
 | 
			
		||||
        }
 | 
			
		||||
        if (!std::filesystem::is_regular_file(path)) {
 | 
			
		||||
            spdlog::error("{0} isn't a loadable module", path);
 | 
			
		||||
            return;
 | 
			
		||||
        }
 | 
			
		||||
        Module_t mod;
 | 
			
		||||
#ifdef _WIN32
 | 
			
		||||
        mod.inst = LoadLibraryA(path.c_str());
 | 
			
		||||
        if (mod.inst == NULL) {
 | 
			
		||||
            spdlog::error("Couldn't load {0}.", name);
 | 
			
		||||
            return;
 | 
			
		||||
        }
 | 
			
		||||
        mod._INIT_ = (void*(*)(mod::API_t*,ImGuiContext*,std::string))GetProcAddress(mod.inst, "_INIT_"); 
 | 
			
		||||
        mod._DRAW_MENU_ = (void(*)(void*))GetProcAddress(mod.inst, "_DRAW_MENU_");
 | 
			
		||||
        mod._STOP_ = (void(*)(void*))GetProcAddress(mod.inst, "_STOP_");
 | 
			
		||||
#else
 | 
			
		||||
        // Linux function here
 | 
			
		||||
#endif
 | 
			
		||||
        if (mod._INIT_ == NULL) {
 | 
			
		||||
            spdlog::error("Couldn't load {0} because it's missing _INIT_.", name);
 | 
			
		||||
            return;
 | 
			
		||||
        }
 | 
			
		||||
        if (mod._DRAW_MENU_ == NULL) {
 | 
			
		||||
            spdlog::error("Couldn't load {0} because it's missing _DRAW_MENU_.", name);
 | 
			
		||||
            return;
 | 
			
		||||
        }
 | 
			
		||||
        if (mod._STOP_ == NULL) {
 | 
			
		||||
            spdlog::error("Couldn't load {0} because it's missing _STOP_.", name);
 | 
			
		||||
            return;
 | 
			
		||||
        }
 | 
			
		||||
        mod.ctx = mod._INIT_(&API, ImGui::GetCurrentContext(), name);
 | 
			
		||||
        if (mod.ctx == NULL) {
 | 
			
		||||
            spdlog::error("{0} Failed to initialize.", name);
 | 
			
		||||
        }
 | 
			
		||||
        modules[name] = mod;
 | 
			
		||||
        moduleNames.push_back(name);
 | 
			
		||||
    }
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										38
									
								
								src/module.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										38
									
								
								src/module.h
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,38 @@
 | 
			
		||||
#pragma once
 | 
			
		||||
#include <string>
 | 
			
		||||
#include <map>
 | 
			
		||||
#include <filesystem>
 | 
			
		||||
#include <stdint.h>
 | 
			
		||||
#include <imgui.h>
 | 
			
		||||
#include <spdlog/spdlog.h>
 | 
			
		||||
 | 
			
		||||
#ifdef _WIN32
 | 
			
		||||
#include <Windows.h>
 | 
			
		||||
#define MOD_EXPORT  extern "C" \
 | 
			
		||||
                    __declspec(dllexport)
 | 
			
		||||
#else
 | 
			
		||||
#define MOD_EXPORT  extern "C"
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
namespace mod {
 | 
			
		||||
    struct API_t {
 | 
			
		||||
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    struct Module_t {
 | 
			
		||||
#ifdef _WIN32
 | 
			
		||||
        HINSTANCE inst;
 | 
			
		||||
#else
 | 
			
		||||
        void* inst;
 | 
			
		||||
#endif
 | 
			
		||||
        void* (*_INIT_)(API_t*, ImGuiContext*, std::string);
 | 
			
		||||
        void (*_DRAW_MENU_)(void*);
 | 
			
		||||
        void (*_STOP_)(void*);
 | 
			
		||||
        void* ctx;
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    void loadModule(std::string path, std::string name);
 | 
			
		||||
    
 | 
			
		||||
    extern std::map<std::string, Module_t> modules;
 | 
			
		||||
    extern std::vector<std::string> moduleNames;
 | 
			
		||||
};
 | 
			
		||||
@@ -1,3 +1,3 @@
 | 
			
		||||
#pragma once
 | 
			
		||||
 | 
			
		||||
#define VERSION_STR "0.2.4_alpha"
 | 
			
		||||
#define VERSION_STR "0.2.5_alpha"
 | 
			
		||||
@@ -1,6 +1,4 @@
 | 
			
		||||
#include <waterfall.h>
 | 
			
		||||
#include <algorithm>
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
float COLOR_MAP[][3] = {
 | 
			
		||||
    {0x00, 0x00, 0x20},
 | 
			
		||||
@@ -20,7 +18,6 @@ float COLOR_MAP[][3] = {
 | 
			
		||||
 | 
			
		||||
void doZoom(int offset, int width, int outWidth, std::vector<float> data, float* out) {
 | 
			
		||||
    // NOTE: REMOVE THAT SHIT, IT'S JUST A HACKY FIX
 | 
			
		||||
    
 | 
			
		||||
    if (offset < 0) {
 | 
			
		||||
        offset = 0;
 | 
			
		||||
    }
 | 
			
		||||
 
 | 
			
		||||
@@ -6,6 +6,7 @@
 | 
			
		||||
#include <GL/glew.h>
 | 
			
		||||
#include <imutils.h>
 | 
			
		||||
#include <bandplan.h>
 | 
			
		||||
#include <algorithm>
 | 
			
		||||
 | 
			
		||||
#define WATERFALL_RESOLUTION    1000000
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user