mirror of
https://github.com/MrUnknownDE/OpenIris-ESPIDF.git
synced 2026-04-19 06:23:44 +02:00
Fix multiple commands not being executed correctly
This commit is contained in:
@@ -57,6 +57,8 @@ std::function<CommandResult()> CommandManager::createCommand(CommandType type, s
|
|||||||
|
|
||||||
CommandResult CommandManager::executeFromJson(std::string_view json)
|
CommandResult CommandManager::executeFromJson(std::string_view json)
|
||||||
{
|
{
|
||||||
|
std::string results = "";
|
||||||
|
|
||||||
cJSON *parsedJson = cJSON_Parse(json.data());
|
cJSON *parsedJson = cJSON_Parse(json.data());
|
||||||
if (parsedJson == nullptr)
|
if (parsedJson == nullptr)
|
||||||
return CommandResult::getErrorResult("Initial JSON Parse: Invalid JSON");
|
return CommandResult::getErrorResult("Initial JSON Parse: Invalid JSON");
|
||||||
@@ -64,8 +66,12 @@ CommandResult CommandManager::executeFromJson(std::string_view json)
|
|||||||
const cJSON *commandData = nullptr;
|
const cJSON *commandData = nullptr;
|
||||||
const cJSON *commands = cJSON_GetObjectItem(parsedJson, "commands");
|
const cJSON *commands = cJSON_GetObjectItem(parsedJson, "commands");
|
||||||
|
|
||||||
// I wrote it in a way that only the first command will be executed
|
if (cJSON_GetArraySize(commands) == 0)
|
||||||
// merge the results of all commands and then return, god damn it
|
{
|
||||||
|
cJSON_Delete(parsedJson);
|
||||||
|
return CommandResult::getErrorResult("Commands missing");
|
||||||
|
}
|
||||||
|
|
||||||
cJSON_ArrayForEach(commandData, commands)
|
cJSON_ArrayForEach(commandData, commands)
|
||||||
{
|
{
|
||||||
const cJSON *commandTypeString = cJSON_GetObjectItem(commandData, "command");
|
const cJSON *commandTypeString = cJSON_GetObjectItem(commandData, "command");
|
||||||
@@ -88,12 +94,12 @@ CommandResult CommandManager::executeFromJson(std::string_view json)
|
|||||||
return CommandResult::getErrorResult("Unknown command");
|
return CommandResult::getErrorResult("Unknown command");
|
||||||
}
|
}
|
||||||
|
|
||||||
cJSON_Delete(parsedJson);
|
// todo, make it a proper json later
|
||||||
return command();
|
results += command().getResult() + ", \n";
|
||||||
}
|
}
|
||||||
|
|
||||||
cJSON_Delete(parsedJson);
|
cJSON_Delete(parsedJson);
|
||||||
return CommandResult::getErrorResult("Commands missing");
|
return CommandResult::getSuccessResult(results);
|
||||||
}
|
}
|
||||||
|
|
||||||
CommandResult CommandManager::executeFromType(CommandType type, std::string_view json)
|
CommandResult CommandManager::executeFromType(CommandType type, std::string_view json)
|
||||||
|
|||||||
Reference in New Issue
Block a user