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.
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user