From 21c5bc2573a91f8053349a0415a880234bb3d1b5 Mon Sep 17 00:00:00 2001 From: Sucan126 <632190820@qq.com> Date: Tue, 9 Sep 2025 11:46:27 +0800 Subject: [PATCH] Enhance logging in Controller class methods. Added checks for uninitialized ObstaclesAvoidClient and included informational logs for SwitchSet and SwitchGet API responses, improving error handling and visibility into state changes. --- src/controller.cpp | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/controller.cpp b/src/controller.cpp index af52c6a..c686d5f 100644 --- a/src/controller.cpp +++ b/src/controller.cpp @@ -175,7 +175,14 @@ bool Controller::Hello() { bool Controller::SwitchSet(bool enable) { try { - return oac_ && oac_->SwitchSet(enable) == 0; + if (!oac_) { + LOG_ERROR("ObstaclesAvoidClient not initialized"); + return false; + } + + int32_t result = oac_->SwitchSet(enable); + LOG_INFO("SwitchSet API returned: " + std::to_string(result)); + return result == 0; } catch (const std::exception& e) { LOG_ERROR("Switch set failed: " + std::string(e.what())); return false; @@ -184,7 +191,15 @@ bool Controller::SwitchSet(bool enable) { bool Controller::SwitchGet(bool& enable) { try { - return oac_ && oac_->SwitchGet(enable) == 0; + if (!oac_) { + LOG_ERROR("ObstaclesAvoidClient not initialized"); + return false; + } + + int32_t result = oac_->SwitchGet(enable); + LOG_INFO("SwitchGet API returned: " + std::to_string(result) + + ", enable: " + std::string(enable ? "true" : "false")); + return result == 0; } catch (const std::exception& e) { LOG_ERROR("Switch get failed: " + std::string(e.what())); return false;