New system for band plans

This commit is contained in:
Ryzerth 2020-12-23 00:11:12 +01:00
parent a08758ea54
commit a93681a980
8 changed files with 37 additions and 25 deletions

View File

@ -17,6 +17,7 @@
#include <options.h> #include <options.h>
#include <duktape/duktape.h> #include <duktape/duktape.h>
#include <duktape/duk_console.h> #include <duktape/duk_console.h>
#include <filesystem>
#define STB_IMAGE_RESIZE_IMPLEMENTATION #define STB_IMAGE_RESIZE_IMPLEMENTATION
#include <stb_image_resize.h> #include <stb_image_resize.h>
@ -77,6 +78,20 @@ int sdrpp_main(int argc, char *argv[]) {
options::loadDefaults(); options::loadDefaults();
if (!options::parse(argc, argv)) { return -1; } if (!options::parse(argc, argv)) { return -1; }
// Check root directory
if (!std::filesystem::exists(options::opts.root)) {
spdlog::warn("Root directory {0} does not exist, creating it", options::opts.root);
if (!std::filesystem::create_directory(options::opts.root)) {
spdlog::error("Could not create root directory {0}", options::opts.root);
return -1;
}
}
if (!std::filesystem::is_directory(options::opts.root)) {
spdlog::error("{0} is not a directory", options::opts.root);
return -1;
}
// ======== DEFAULT CONFIG ======== // ======== DEFAULT CONFIG ========
json defConfig; json defConfig;
defConfig["bandColors"]["amateur"] = "#FF0000FF"; defConfig["bandColors"]["amateur"] = "#FF0000FF";
@ -103,12 +118,14 @@ int sdrpp_main(int argc, char *argv[]) {
}; };
defConfig["menuWidth"] = 300; defConfig["menuWidth"] = 300;
defConfig["min"] = -70.0; defConfig["min"] = -70.0;
defConfig["moduleInstances"]["Audio Sink"] = "audio_sink"; defConfig["moduleInstances"]["Audio Sink"] = "audio_sink";
defConfig["moduleInstances"]["PlutoSDR Source"] = "plutosdr_source"; defConfig["moduleInstances"]["PlutoSDR Source"] = "plutosdr_source";
defConfig["moduleInstances"]["RTL-TCP Source"] = "rtl_tcp_source"; defConfig["moduleInstances"]["RTL-TCP Source"] = "rtl_tcp_source";
defConfig["moduleInstances"]["Radio"] = "radio"; defConfig["moduleInstances"]["Radio"] = "radio";
defConfig["moduleInstances"]["Recorder"] = "recorder"; defConfig["moduleInstances"]["Recorder"] = "recorder";
defConfig["moduleInstances"]["SoapySDR Source"] = "soapy_source"; defConfig["moduleInstances"]["SoapySDR Source"] = "soapy_source";
defConfig["modules"] = json::array(); defConfig["modules"] = json::array();
defConfig["offset"] = 0.0; defConfig["offset"] = 0.0;
defConfig["showWaterfall"] = true; defConfig["showWaterfall"] = true;
@ -116,6 +133,12 @@ int sdrpp_main(int argc, char *argv[]) {
defConfig["streams"] = json::object(); defConfig["streams"] = json::object();
defConfig["windowSize"]["h"] = 720; defConfig["windowSize"]["h"] = 720;
defConfig["windowSize"]["w"] = 1280; defConfig["windowSize"]["w"] = 1280;
defConfig["bandColors"]["broadcast"] = "#0000FFFF";
defConfig["bandColors"]["amateur"] = "#FF0000FF";
defConfig["bandColors"]["aviation"] = "#00FF00FF";
defConfig["bandColors"]["marine"] = "#00FFFFFF";
defConfig["bandColors"]["military"] = "#FFFF00FF";
#ifdef _WIN32 #ifdef _WIN32
defConfig["modulesDirectory"] = "./modules"; defConfig["modulesDirectory"] = "./modules";
@ -147,6 +170,7 @@ int sdrpp_main(int argc, char *argv[]) {
int winHeight = core::configManager.conf["windowSize"]["h"]; int winHeight = core::configManager.conf["windowSize"]["h"];
maximized = core::configManager.conf["maximized"]; maximized = core::configManager.conf["maximized"];
std::string resDir = core::configManager.conf["resourcesDirectory"]; std::string resDir = core::configManager.conf["resourcesDirectory"];
json bandColors = core::configManager.conf["bandColors"];
core::configManager.release(); core::configManager.release();
// Create window with graphics context // Create window with graphics context
@ -217,11 +241,11 @@ int sdrpp_main(int argc, char *argv[]) {
LoadingScreen::show("Loading band plans"); LoadingScreen::show("Loading band plans");
spdlog::info("Loading band plans"); spdlog::info("Loading band plans");
bandplan::loadFromDir(options::opts.root + "/bandplans"); bandplan::loadFromDir(resDir + "/bandplans");
LoadingScreen::show("Loading band plan colors"); LoadingScreen::show("Loading band plan colors");
spdlog::info("Loading band plans color table"); spdlog::info("Loading band plans color table");
bandplan::loadColorTable(options::opts.root + "/band_colors.json"); bandplan::loadColorTable(bandColors);
windowInit(); windowInit();

View File

@ -108,20 +108,7 @@ namespace bandplan {
} }
} }
void loadColorTable(std::string path) { void loadColorTable(json table) {
if (!std::filesystem::exists(path)) { colorTable = table.get<std::map<std::string, BandPlanColor_t>>();
spdlog::error("Band Plan Color Table file does not exist");
return;
}
if (!std::filesystem::is_regular_file(path)) {
spdlog::error("Band Plan Color Table file isn't a file...");
return;
}
std::ifstream file(path.c_str());
json data;
file >> data;
file.close();
colorTable = data.get<std::map<std::string, BandPlanColor_t>>();
} }
}; };

View File

@ -38,7 +38,7 @@ namespace bandplan {
void loadBandPlan(std::string path); void loadBandPlan(std::string path);
void loadFromDir(std::string path); void loadFromDir(std::string path);
void loadColorTable(std::string path); void loadColorTable(json table);
extern std::map<std::string, BandPlan_t> bandplans; extern std::map<std::string, BandPlan_t> bandplans;
extern std::vector<std::string> bandplanNames; extern std::vector<std::string> bandplanNames;

View File

@ -310,6 +310,14 @@ MOD_EXPORT void _INIT_() {
config.setPath(options::opts.root + "/recorder_config.json"); config.setPath(options::opts.root + "/recorder_config.json");
config.load(def); config.load(def);
config.enableAutoSave(); config.enableAutoSave();
// Create default recording directory
if (!std::filesystem::exists(options::opts.root + "/recordings")) {
spdlog::warn("Recordings directory does not exist, creating it");
if (!std::filesystem::create_directory(options::opts.root + "/recordings")) {
spdlog::error("Could not create recordings directory");
}
}
} }
MOD_EXPORT ModuleManager::Instance* _CREATE_INSTANCE_(std::string name) { MOD_EXPORT ModuleManager::Instance* _CREATE_INSTANCE_(std::string name) {

View File

@ -1,7 +0,0 @@
{
"broadcast": "#0000FFFF",
"amateur": "#FF0000FF",
"aviation": "#00FF00FF",
"marine": "#00FFFFFF",
"military": "#FFFF00FF"
}