satdump/src-core/init.cpp

145 lines
5.8 KiB
C++
Raw Normal View History

2022-05-12 15:24:25 -07:00
#define SATDUMP_DLL_EXPORT 1
2021-03-22 18:53:09 +01:00
#include "init.h"
#include "logger.h"
#include "core/module.h"
#include "core/pipeline.h"
2021-05-04 12:23:22 +02:00
#include <filesystem>
// #include "tle.h"
#include "core/plugin.h"
#include "satdump_vars.h"
#include "core/config.h"
2021-08-02 23:33:10 +02:00
2022-04-21 16:10:00 +02:00
#include "common/tracking/tle.h"
2022-05-20 20:19:14 +02:00
#include "products/products.h"
2022-04-21 16:10:00 +02:00
2022-08-30 12:01:12 +02:00
#include "core/opencl.h"
#include "common/dsp/buffer.h"
2022-03-10 19:56:37 +01:00
namespace satdump
2021-03-22 18:53:09 +01:00
{
2022-05-12 15:24:25 -07:00
SATDUMP_DLL std::string user_path;
2022-09-11 19:15:24 +02:00
SATDUMP_DLL std::string tle_file_override = "";
2023-01-23 14:23:09 +01:00
SATDUMP_DLL bool tle_do_update_on_init = true;
2022-05-07 17:06:56 +02:00
2022-03-10 19:56:37 +01:00
void initSatdump()
{
logger->info(" _____ __ ____ ");
logger->info(" / ___/____ _/ /_/ __ \\__ ______ ___ ____ ");
logger->info(" \\__ \\/ __ `/ __/ / / / / / / __ `__ \\/ __ \\");
logger->info(" ___/ / /_/ / /_/ /_/ / /_/ / / / / / / /_/ /");
logger->info("/____/\\__,_/\\__/_____/\\__,_/_/ /_/ /_/ .___/ ");
logger->info(" /_/ ");
logger->info("Starting SatDump v" + (std::string)SATDUMP_VERSION);
logger->info("");
2022-03-30 15:41:23 +02:00
#ifdef _WIN32
2022-05-07 17:06:56 +02:00
user_path = ".";
2022-05-13 21:35:51 +02:00
#elif __ANDROID__
user_path = ".";
2022-03-30 15:41:23 +02:00
#else
2022-05-07 17:06:56 +02:00
user_path = std::string(getenv("HOME")) + "/.config/satdump";
2022-03-30 15:41:23 +02:00
#endif
if (std::filesystem::exists("satdump_cfg.json"))
config::loadConfig("satdump_cfg.json", user_path);
else
config::loadConfig(satdump::RESPATH + "satdump_cfg.json", user_path);
2022-03-10 19:56:37 +01:00
2022-11-26 17:50:44 +01:00
if (config::main_cfg["satdump_general"].contains("log_to_file"))
{
bool log_file = config::main_cfg["satdump_general"]["log_to_file"]["value"];
if (log_file)
initFileSink();
}
2022-11-26 17:34:22 +01:00
if (config::main_cfg["satdump_general"].contains("log_level"))
{
2022-11-27 21:30:17 +01:00
std::string log_level = config::main_cfg["satdump_general"]["log_level"]["value"];
if (log_level == "trace")
setConsoleLevel(spdlog::level::level_enum::trace);
else if (log_level == "debug")
setConsoleLevel(spdlog::level::level_enum::debug);
else if (log_level == "info")
setConsoleLevel(spdlog::level::level_enum::info);
else if (log_level == "warn")
setConsoleLevel(spdlog::level::level_enum::warn);
else if (log_level == "error")
setConsoleLevel(spdlog::level::level_enum::err);
else if (log_level == "critical")
setConsoleLevel(spdlog::level::level_enum::critical);
2022-11-26 17:34:22 +01:00
}
2022-03-10 19:56:37 +01:00
loadPlugins();
registerModules();
// Load pipelines
if (std::filesystem::exists("pipelines") && std::filesystem::is_directory("pipelines"))
loadPipelines("pipelines");
else
loadPipelines(satdump::RESPATH + "pipelines");
2022-03-10 19:56:37 +01:00
// List them
logger->debug("Registered pipelines :");
for (Pipeline &pipeline : pipelines)
logger->debug(" - " + pipeline.name);
2022-08-30 12:01:12 +02:00
#ifdef USE_OPENCL
// OpenCL
opencl::initOpenCL();
#endif
2022-03-10 19:56:37 +01:00
// TLEs
2022-09-11 19:15:24 +02:00
if (tle_file_override == "")
2022-09-08 23:03:54 +02:00
{
2023-01-23 14:23:09 +01:00
if (config::main_cfg["satdump_general"]["update_tles_startup"]["value"].get<bool>() && tle_do_update_on_init)
2022-09-11 19:15:24 +02:00
updateTLEFile(user_path + "/satdump_tles.txt");
2022-09-08 23:03:54 +02:00
loadTLEFileIntoRegistry(user_path + "/satdump_tles.txt");
2023-01-23 14:23:09 +01:00
if (general_tle_registry.size() == 0 && tle_do_update_on_init) // NO TLEs? Download now.
2022-09-11 19:15:24 +02:00
{
updateTLEFile(user_path + "/satdump_tles.txt");
loadTLEFileIntoRegistry(user_path + "/satdump_tles.txt");
}
}
else
{
if (std::filesystem::exists(tle_file_override))
loadTLEFileIntoRegistry(tle_file_override);
else
logger->error("TLE File doesn't exist : " + tle_file_override);
2022-09-08 23:03:54 +02:00
}
2022-03-10 19:56:37 +01:00
2022-05-20 20:19:14 +02:00
// Products
registerProducts();
// Set DSP buffer sizes if they have been changed
if (config::main_cfg.contains("advanced_settings"))
{
if (config::main_cfg["advanced_settings"].contains("default_buffer_size"))
{
int new_sz = config::main_cfg["advanced_settings"]["default_buffer_size"].get<int>();
dsp::STREAM_BUFFER_SIZE = new_sz;
dsp::RING_BUF_SZ = new_sz;
logger->warn("DSP Buffer size was changed to {:d}", new_sz);
}
}
2022-03-10 19:56:37 +01:00
// Let plugins know we started
eventBus->fire_event<SatDumpStartedEvent>({});
#ifdef BUILD_IS_DEBUG
// If in debug, warn the user!
logger->error("██████╗ █████╗ ███╗ ██╗ ██████╗ ███████╗██████╗ ");
logger->error("██╔══██╗██╔══██╗████╗ ██║██╔════╝ ██╔════╝██╔══██╗");
logger->error("██║ ██║███████║██╔██╗ ██║██║ ███╗█████╗ ██████╔╝");
logger->error("██║ ██║██╔══██║██║╚██╗██║██║ ██║██╔══╝ ██╔══██╗");
logger->error("██████╔╝██║ ██║██║ ╚████║╚██████╔╝███████╗██║ ██║");
logger->error("╚═════╝ ╚═╝ ╚═╝╚═╝ ╚═══╝ ╚═════╝ ╚══════╝╚═╝ ╚═╝");
logger->error("SatDump has NOT been built in Release mode.");
logger->error("If you are not a developer but intending to use the software,");
logger->error("you probably do not want this. If so, make sure to");
logger->error("specify -DCMAKE_BUILD_TYPE=Release in CMake.");
#endif
2022-03-10 19:56:37 +01:00
}
}