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.

This commit is contained in:
2025-09-08 20:11:08 +08:00
parent 99ca9456c0
commit e7bfce9dcb
3 changed files with 12 additions and 6 deletions

View File

@@ -93,10 +93,6 @@ bool CustomRobot::start() {
return false; 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)) { if (!SwitchService("sport_mode", false)) {
LOG_ERROR("Failed to stop sport_mode service"); LOG_ERROR("Failed to stop sport_mode service");
return false; return false;

View File

@@ -1,6 +1,8 @@
#include <iostream> #include <iostream>
#include <memory> #include <memory>
#include <signal.h> #include <signal.h>
#include <thread>
#include <chrono>
#include "custom_robot.hpp" #include "custom_robot.hpp"
#include "logger.hpp" #include "logger.hpp"
#include "config.hpp" #include "config.hpp"
@@ -32,6 +34,16 @@ int main(int argc, char** argv) {
LOG_INFO("Robot initialized successfully"); LOG_INFO("Robot initialized successfully");
g_robot->start(); 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) { } catch (const std::exception& e) {
LOG_ERROR("Exception: " + std::string(e.what())); LOG_ERROR("Exception: " + std::string(e.what()));
return 1; return 1;

View File

@@ -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_); int rc = MQTTClient_connect(client_, &connOpts_);
if (rc != MQTTCLIENT_SUCCESS) { if (rc != MQTTCLIENT_SUCCESS) {
LOG_ERROR("Failed to connect to MQTT broker, return code: " + std::to_string(rc)); LOG_ERROR("Failed to connect to MQTT broker, return code: " + std::to_string(rc));