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:
@@ -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;
|
||||
|
||||
12
src/main.cpp
12
src/main.cpp
@@ -1,6 +1,8 @@
|
||||
#include <iostream>
|
||||
#include <memory>
|
||||
#include <signal.h>
|
||||
#include <thread>
|
||||
#include <chrono>
|
||||
#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;
|
||||
|
||||
@@ -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));
|
||||
|
||||
Reference in New Issue
Block a user