srs-control 0.2.2
Loading...
Searching...
No Matches
srs_fec_emulator.cpp
Go to the documentation of this file.
4#include <CLI/CLI.hpp>
5#include <cstdlib>
6#include <fmt/format.h>
7#include <fmt/ranges.h>
8#include <spdlog/common.h>
9#include <spdlog/spdlog.h>
10#include <string>
11
15
18
19auto main(int argc, char** argv) -> int
20{
21
22 auto spdlog_level = spdlog::level::info;
23 auto cli_args = CLI::App{ "SRS FEC emulators" };
24 argv = cli_args.ensure_utf8(argv);
25
26 auto is_dump_needed = false;
27
28 auto config_filepath = std::string{};
29
30 auto dump_config_callback = [&config_filepath, &is_dump_needed](const std::string& filename)
31 {
32 is_dump_needed = true;
33 config_filepath = filename;
34 };
35
36 auto config = srs::emulator::World::Config{};
37
38 cli_args
39 .add_option("-l, --log-level",
40 spdlog_level,
41 fmt::format("Set log level\nAvailable options: [{}]", fmt::join(SPDLOG_LOG_NAMES, ", ")))
42
43 ->transform(CLI::CheckedTransformer(spdlog_map, CLI::ignore_case).description(""))
44 ->default_str(get_enum_dashed_name(spdlog_level));
45 ;
46 auto dump_option = cli_args
47 .add_option_function<std::string>(
48 "--dump-config", dump_config_callback, "Dump default configuration to the file")
49 ->default_val("fec_emulator.yaml")
50 ->run_callback_for_default()
51 ->expected(0, 1);
52
53 auto config_option = cli_args.add_option("config_file", config_filepath, "Set the path of the config file")
54 ->capture_default_str()
55 ->excludes(dump_option);
56
57 CLI11_PARSE(cli_args, argc, argv);
58
59 spdlog::set_level(spdlog_level);
60
61 if (is_dump_needed)
62 {
63 auto is_not_ok = srs::config::output_config_to_file(config, config_filepath);
64 if (is_not_ok)
65 {
66 spdlog::error("{}", is_not_ok.value());
67 return EXIT_FAILURE;
68 }
69 else
70 {
71 spdlog::info("Config file {:?} is created.", config_filepath);
72 }
73 return EXIT_SUCCESS;
74 }
75
76 auto is_not_ok = srs::config::set_config_from_file(config, config_filepath);
77
78 if (is_not_ok)
79 {
80 spdlog::error("{}", is_not_ok.value());
81 return EXIT_FAILURE;
82 }
83
84 auto world = srs::emulator::World{ config };
85
86 world.init();
87
88 world.launch();
89
90 return EXIT_SUCCESS;
91}
Emulators for FECs devices.
Definition World.hpp:17
constexpr auto get_enum_dashed_names()
constexpr auto get_enum_dashed_name()
auto output_config_to_file(const auto &config, std::string_view filename, bool is_overwrite=false) -> std::optional< std::string >
auto set_config_from_file(auto &config, std::string_view filename, bool is_default_generated=true) -> std::optional< std::string >
const auto spdlog_map
constexpr auto SPDLOG_LOG_NAMES
constexpr auto get_enum_dashed_names()
constexpr auto get_enum_dashed_name()
auto main(int argc, char **argv) -> int
constexpr auto get_enum_dash_map()