mirror of
https://github.com/MrUnknownDE/OpenIris-ESPIDF.git
synced 2026-04-14 12:13:45 +02:00
Make command manager output proper json
This commit is contained in:
@@ -57,14 +57,17 @@ std::function<CommandResult()> CommandManager::createCommand(CommandType type, s
|
||||
|
||||
CommandResult CommandManager::executeFromJson(std::string_view json)
|
||||
{
|
||||
std::string results = "";
|
||||
|
||||
cJSON *parsedJson = cJSON_Parse(json.data());
|
||||
if (parsedJson == nullptr)
|
||||
return CommandResult::getErrorResult("Initial JSON Parse: Invalid JSON");
|
||||
|
||||
const cJSON *commandData = nullptr;
|
||||
const cJSON *commands = cJSON_GetObjectItem(parsedJson, "commands");
|
||||
cJSON *responseDocument = cJSON_CreateObject();
|
||||
cJSON *responses = cJSON_CreateArray();
|
||||
cJSON *response = nullptr;
|
||||
|
||||
cJSON_AddItemToObject(responseDocument, "results", responses);
|
||||
|
||||
if (cJSON_GetArraySize(commands) == 0)
|
||||
{
|
||||
@@ -93,13 +96,15 @@ CommandResult CommandManager::executeFromJson(std::string_view json)
|
||||
cJSON_Delete(parsedJson);
|
||||
return CommandResult::getErrorResult("Unknown command");
|
||||
}
|
||||
|
||||
// todo, make it a proper json later
|
||||
results += command().getResult() + ", \n";
|
||||
response = cJSON_CreateString(command().getResult().c_str());
|
||||
cJSON_AddItemToArray(responses, response);
|
||||
}
|
||||
|
||||
auto jsonString = cJSON_Print(responseDocument);
|
||||
cJSON_Delete(responseDocument);
|
||||
cJSON_Delete(parsedJson);
|
||||
return CommandResult::getSuccessResult(results);
|
||||
|
||||
return CommandResult::getSuccessResult(jsonString);
|
||||
}
|
||||
|
||||
CommandResult CommandManager::executeFromType(CommandType type, std::string_view json)
|
||||
|
||||
@@ -127,7 +127,7 @@ struct CameraConfig_t : BaseConfigModel
|
||||
// save them under an indexed name and load them as such.
|
||||
struct WiFiConfig_t : BaseConfigModel
|
||||
{
|
||||
// default construcotr used for loading
|
||||
// default constructor used for loading
|
||||
WiFiConfig_t(Preferences *pref) : BaseConfigModel(pref) {}
|
||||
|
||||
WiFiConfig_t(
|
||||
@@ -284,7 +284,7 @@ public:
|
||||
}
|
||||
|
||||
return Helpers::format_string(
|
||||
"%s, %s, %s, networks: [%s], %s, %s",
|
||||
"{%s, %s, %s, \"networks\": [%s], %s, %s}",
|
||||
this->device.toRepresentation().c_str(),
|
||||
this->mdns.toRepresentation().c_str(),
|
||||
this->camera.toRepresentation().c_str(),
|
||||
|
||||
Reference in New Issue
Block a user