diff --git a/src/custom_robot.cpp b/src/custom_robot.cpp index eba76c0..0cbff79 100644 --- a/src/custom_robot.cpp +++ b/src/custom_robot.cpp @@ -262,12 +262,15 @@ bool CustomRobot::processOacCmd(const std::string& cmd, const nlohmann::json& me try { if (cmd == "SwitchSet") { - if (!message.contains("param") || !message["param"].contains("enable")) { - LOG_ERROR("SwitchSet cmd missing 'enable' parameter"); + // get current state + bool currentEnable = false; + if (!controller_->SwitchGet(currentEnable)) { + LOG_ERROR("Failed to get current switch state"); return false; } - bool enable = message["param"]["enable"]; - return controller_->SwitchSet(enable); + + // switch to opposite state + return controller_->SwitchSet(!currentEnable); } else if (cmd == "SwitchGet") { bool enable = false;