Skip to content

Commit

Permalink
Pass config file via argv.
Browse files Browse the repository at this point in the history
  • Loading branch information
shajen committed Nov 22, 2024
1 parent 74dcc1a commit 182da49
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
1 change: 0 additions & 1 deletion sources/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#include <string>

// INTERNAL SETTINGS
constexpr auto CONFIG_FILE = "config.json"; // user config file
constexpr auto DEBUG_SAVE_FULL_RAW_IQ = false; // save orgignal sdr data as raw iq
constexpr auto DEBUG_SAVE_FULL_POWER = false; // save orgignal sdr data as raw iq
constexpr auto DEBUG_SAVE_RECORDING_RAW_IQ = false; // save recordings as raw iq
Expand Down
13 changes: 9 additions & 4 deletions sources/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ void handler(int) {
isRunning = false;
}

int main(int, char**) {
int main(int argc, char** argv) {
dup2(fileno(fopen("/dev/null", "w")), fileno(stderr));
SoapySDR_setLogLevel(SoapySDRLogLevel::SOAPY_SDR_WARNING);
signal(SIGINT, handler);
Expand All @@ -27,19 +27,24 @@ int main(int, char**) {
try {
Logger::configure(spdlog::level::info, spdlog::level::info, LOG_FILE_NAME, LOG_FILE_SIZE, LOG_FILES_COUNT, true);
Logger::info(LABEL, "{}", colored(GREEN, "{}", "starting"));
const std::string configFile = 2 <= argc ? argv[1] : "";
if (configFile.empty()) {
Logger::error(LABEL, "no config file argument provided");
return 1;
}

const auto id = generateRandomHash();
while (isRunning) {
bool reload = false;
const Config config = Config::loadFromFile(CONFIG_FILE);
const Config config = Config::loadFromFile(configFile);
Logger::configure(config.consoleLogLevel(), config.fileLogLevel(), LOG_FILE_NAME, LOG_FILE_SIZE, LOG_FILES_COUNT, config.isColorLogEnabled());
Logger::info(LABEL, "config: {}", colored(GREEN, "{}", config.json().dump()));
Logger::info(LABEL, "mqtt: {}", colored(GREEN, "{}", config.mqtt()));

Mqtt mqtt(config);
RemoteController remoteController(config, id, mqtt, [&reload](const nlohmann::json& json) {
RemoteController remoteController(config, id, mqtt, [&reload, &configFile](const nlohmann::json& json) {
Logger::info(LABEL, "reload config: {}", colored(GREEN, "{}", json.dump()));
Config::saveToFile(CONFIG_FILE, json);
Config::saveToFile(configFile, json);
reload = true;
});
std::vector<std::unique_ptr<Scanner>> scanners;
Expand Down

0 comments on commit 182da49

Please sign in to comment.