satdump/src-cli/main.cpp

67 lines
2 KiB
C++
Raw Normal View History

2021-02-14 12:05:44 +01:00
#include "logger.h"
#include "core/module.h"
#include "core/pipeline.h"
2021-02-14 12:05:44 +01:00
#include <signal.h>
#include <filesystem>
2021-02-16 13:47:53 +01:00
#include "nlohmann/json.hpp"
#include <fstream>
2021-05-04 12:41:47 +02:00
#include "init.h"
2022-02-21 23:32:11 +01:00
#include "common/cli_utils.h"
2022-02-27 15:14:36 +01:00
2021-02-14 12:05:44 +01:00
int main(int argc, char *argv[])
{
2022-02-21 23:32:11 +01:00
// Init logger
2021-02-14 12:05:44 +01:00
initLogger();
2022-03-15 16:07:47 +01:00
if (argc < 5) // Check overall command
2021-10-29 15:44:15 +02:00
{
logger->error("Usage : " + std::string(argv[0]) + " [downlink] [input_level] [input_file] [output_file_or_directory] [additional options as required]");
2022-02-21 23:32:11 +01:00
logger->error("Extra options (examples. Any parameter used in modules can be used here) :");
logger->error(" --samplerate [baseband_samplerate] --baseband_format [f32/i16/i8/w8] --dc_block --iq_swap");
return 1;
2021-02-14 12:05:44 +01:00
}
2022-02-21 23:32:11 +01:00
// Init SatDump
2022-03-10 19:56:37 +01:00
satdump::initSatdump();
2021-02-14 12:05:44 +01:00
std::string downlink_pipeline = argv[1];
std::string input_level = argv[2];
std::string input_file = argv[3];
std::string output_file = argv[4];
2021-02-14 12:05:44 +01:00
2022-02-21 23:32:11 +01:00
// Parse flags
2022-03-28 11:51:13 +02:00
nlohmann::json parameters = parse_common_flags(argc - 6, &argv[5]);
2021-02-14 12:05:44 +01:00
2022-02-21 23:32:11 +01:00
// logger->warn("\n" + parameters.dump(4));
// exit(0);
2021-02-14 12:05:44 +01:00
2022-02-21 23:32:11 +01:00
// Print some useful info
2021-02-14 12:05:44 +01:00
logger->info("Starting processing pipeline " + downlink_pipeline + "...");
logger->debug("Input file (" + input_level + ") : " + input_file);
logger->debug("Output file : " + output_file);
2021-02-14 12:05:44 +01:00
2022-02-21 23:32:11 +01:00
// Create output dir
2021-02-14 12:05:44 +01:00
if (!std::filesystem::exists(output_file))
2022-02-21 23:32:11 +01:00
std::filesystem::create_directories(output_file);
2021-02-14 12:05:44 +01:00
2022-02-21 23:32:11 +01:00
// Get pipeline
2022-03-10 19:56:37 +01:00
std::optional<satdump::Pipeline> pipeline = satdump::getPipelineFromName(downlink_pipeline);
2021-02-16 13:47:53 +01:00
2022-02-21 23:32:11 +01:00
if (pipeline.has_value())
2022-03-01 15:37:58 +01:00
{
2022-04-12 20:18:44 +02:00
try
2022-03-01 15:37:58 +01:00
{
pipeline.value().run(input_file, output_file, parameters, input_level);
}
2022-04-12 20:18:44 +02:00
catch (std::exception &e)
2022-03-01 15:37:58 +01:00
{
2022-04-12 20:18:44 +02:00
logger->error("Fatal error running pipeline : " + std::string(e.what()));
return 1;
2022-03-01 15:37:58 +01:00
}
}
2021-02-16 13:47:53 +01:00
else
logger->critical("Pipeline " + downlink_pipeline + " does not exist!");
2021-02-14 12:05:44 +01:00
logger->info("Done! Goodbye");
}