refactor(custom_robot): Simplify SwitchSet command processing
- Removed redundant state retrieval for the SwitchSet command. - Added error handling for missing 'enable' parameter in the command message. - Streamlined the logic for setting the switch state based on the provided parameter.
This commit is contained in:
@@ -525,25 +525,12 @@ bool CustomRobot::processOacCmd(const std::string& cmd, const nlohmann::json& me
|
||||
|
||||
try {
|
||||
if (cmd == "SwitchSet") {
|
||||
// get current state
|
||||
bool currentEnable = false;
|
||||
if (!controller_->SwitchGet(currentEnable)) {
|
||||
LOG_ERROR("Failed to get current switch state");
|
||||
if (message.find("param") == message.end() || message["param"].find("enable") == message["param"].end()) {
|
||||
LOG_ERROR("Missing 'enable' parameter for Switch command");
|
||||
return false;
|
||||
}
|
||||
LOG_INFO("Current switch state: " + std::string(currentEnable ? "true" : "false"));
|
||||
// switch to opposite state
|
||||
bool enable = !currentEnable;
|
||||
bool enable = message["param"]["enable"];
|
||||
return controller_->SwitchSet(enable);
|
||||
|
||||
} else if (cmd == "SwitchGet") {
|
||||
bool enable = false;
|
||||
bool result = controller_->SwitchGet(enable);
|
||||
if (result) {
|
||||
LOG_INFO("SwitchGet result: enable=" + std::string(enable ? "true" : "false"));
|
||||
}
|
||||
return result;
|
||||
|
||||
} else if (cmd == "Move") {
|
||||
if (!message.contains("param")) {
|
||||
LOG_ERROR("Move cmd missing 'param'");
|
||||
|
||||
Reference in New Issue
Block a user