From e7bfce9dcbea7392a6e9ebc1f3cb5e8d9df5e452 Mon Sep 17 00:00:00 2001 From: Sucan126 <632190820@qq.com> Date: Mon, 8 Sep 2025 20:11:08 +0800 Subject: [PATCH] Refactor logging in CustomRobot and main event loop implementation. Removed service logging from CustomRobot::start for cleaner output. Added a continuous event loop in main to keep the program running and allow for future periodic tasks. --- src/custom_robot.cpp | 4 ---- src/main.cpp | 12 ++++++++++++ src/mqtt.cpp | 2 -- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/custom_robot.cpp b/src/custom_robot.cpp index a781c7f..4b901c1 100644 --- a/src/custom_robot.cpp +++ b/src/custom_robot.cpp @@ -93,10 +93,6 @@ bool CustomRobot::start() { return false; } - for (const auto& service : serviceList) { - LOG_INFO("Service - name: " + service.name + ", protect: " + std::to_string(service.protect) + ", status: " + std::to_string(service.status)); - } - if (!SwitchService("sport_mode", false)) { LOG_ERROR("Failed to stop sport_mode service"); return false; diff --git a/src/main.cpp b/src/main.cpp index 2a502d6..cc2f2da 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,6 +1,8 @@ #include #include #include +#include +#include #include "custom_robot.hpp" #include "logger.hpp" #include "config.hpp" @@ -32,6 +34,16 @@ int main(int argc, char** argv) { LOG_INFO("Robot initialized successfully"); g_robot->start(); + + // Keep the program running + LOG_INFO("System is running. Press Ctrl+C to stop."); + + // Main event loop - wait for signals or other events + while (true) { + std::this_thread::sleep_for(std::chrono::milliseconds(100)); + // You can add periodic tasks here if needed + } + } catch (const std::exception& e) { LOG_ERROR("Exception: " + std::string(e.what())); return 1; diff --git a/src/mqtt.cpp b/src/mqtt.cpp index 95bb83c..1a0573b 100644 --- a/src/mqtt.cpp +++ b/src/mqtt.cpp @@ -88,8 +88,6 @@ bool MqttClient::connect(const std::string& username, const std::string& passwor } } - LOG_INFO("Connecting to MQTT broker: " + serverURI_); - int rc = MQTTClient_connect(client_, &connOpts_); if (rc != MQTTCLIENT_SUCCESS) { LOG_ERROR("Failed to connect to MQTT broker, return code: " + std::to_string(rc));