#include "app.hpp" #include #include #include #include #include #include namespace { std::atomic g_running{true}; void signalHandler(int) { g_running = false; } } int main(int argc, char* argv[]) { std::filesystem::path configPath = "config/microbit.json"; for (int i = 1; i < argc; ++i) { std::string arg = argv[i]; if ((arg == "--config" || arg == "-c") && i + 1 < argc) { configPath = argv[++i]; } else if (arg == "--help" || arg == "-h") { std::cout << "Usage: smartbotic-microbit [options]\n" << " --config, -c Configuration file path (default: config/microbit.json)\n" << " --help, -h Show this help\n"; return 0; } } try { auto config = smartbotic::microbit::ConfigLoader::loadFromFile(configPath); auto logLevel = spdlog::level::from_str( smartbotic::microbit::ConfigLoader::get(config, "log_level", "info")); smartbotic::microbit::logging::init("microbit", logLevel); std::signal(SIGINT, signalHandler); std::signal(SIGTERM, signalHandler); std::signal(SIGPIPE, SIG_IGN); smartbotic::microbit::App app(config); app.start(); while (g_running && app.isRunning()) { std::this_thread::sleep_for(std::chrono::milliseconds(100)); } app.stop(); } catch (const std::exception& e) { spdlog::error("Fatal error: {}", e.what()); return 1; } return 0; }