mirror of
https://github.com/AlexandreRouma/SDRPlusPlus.git
synced 2025-06-26 12:27:51 +02:00
new stuff idk
This commit is contained in:
31
sdrplay_source/CMakeLists.txt
Normal file
31
sdrplay_source/CMakeLists.txt
Normal file
@ -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)
|
190
sdrplay_source/src/main.cpp
Normal file
190
sdrplay_source/src/main.cpp
Normal file
@ -0,0 +1,190 @@
|
||||
#include <imgui.h>
|
||||
#include <spdlog/spdlog.h>
|
||||
#include <module.h>
|
||||
#include <gui/gui.h>
|
||||
#include <signal_path/signal_path.h>
|
||||
#include <core.h>
|
||||
#include <gui/style.h>
|
||||
#include <config.h>
|
||||
#include <options.h>
|
||||
#include <libairspy/airspy.h>
|
||||
|
||||
|
||||
#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<dsp::complex_t> stream;
|
||||
double sampleRate;
|
||||
SourceManager::SourceHandler handler;
|
||||
bool running = false;
|
||||
double freq;
|
||||
|
||||
int devId = 0;
|
||||
int srId = 0;
|
||||
|
||||
std::vector<uint64_t> devList;
|
||||
std::string devListTxt;
|
||||
std::vector<uint32_t> 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();
|
||||
}
|
Reference in New Issue
Block a user