mirror of
https://github.com/MrUnknownDE/OpenIris-ESPIDF.git
synced 2026-04-10 18:33:44 +02:00
Implement get config command and api endpoint for testing purposes
This commit is contained in:
@@ -29,6 +29,8 @@ std::unique_ptr<Command> CommandManager::createCommand(CommandType type)
|
||||
return std::make_unique<setMDNSCommand>(projectConfig);
|
||||
case CommandType::UPDATE_CAMERA:
|
||||
return std::make_unique<updateCameraCommand>(projectConfig);
|
||||
case CommandType::GET_CONFIG:
|
||||
return std::make_unique<getConfigCommand>(projectConfig);
|
||||
case CommandType::SAVE_CONFIG:
|
||||
return std::make_unique<saveConfigCommand>(projectConfig);
|
||||
default:
|
||||
|
||||
@@ -32,6 +32,7 @@ enum CommandType
|
||||
SET_MDNS,
|
||||
UPDATE_CAMERA,
|
||||
SAVE_CONFIG,
|
||||
GET_CONFIG,
|
||||
RESET_CONFIG,
|
||||
RESTART_DEVICE,
|
||||
};
|
||||
|
||||
@@ -9,3 +9,5 @@ public:
|
||||
CommandResult execute(std::string_view jsonPayload) override;
|
||||
std::optional<UpdateCameraConfigPayload> parsePayload(std::string_view jsonPayload);
|
||||
};
|
||||
|
||||
// add cropping command
|
||||
@@ -4,4 +4,10 @@ CommandResult saveConfigCommand::execute(std::string_view jsonPayload)
|
||||
{
|
||||
projectConfig->save();
|
||||
return CommandResult::getSuccessResult("Config saved");
|
||||
}
|
||||
|
||||
CommandResult getConfigCommand::execute(std::string_view jsonPayload)
|
||||
{
|
||||
auto configRepresentation = projectConfig->getTrackerConfig().toRepresentation();
|
||||
return CommandResult::getSuccessResult(configRepresentation);
|
||||
}
|
||||
@@ -6,4 +6,12 @@ public:
|
||||
std::shared_ptr<ProjectConfig> projectConfig;
|
||||
saveConfigCommand(std::shared_ptr<ProjectConfig> projectConfig) : projectConfig(projectConfig) {};
|
||||
CommandResult execute(std::string_view jsonPayload) override;
|
||||
};
|
||||
};
|
||||
|
||||
class getConfigCommand : public Command
|
||||
{
|
||||
public:
|
||||
std::shared_ptr<ProjectConfig> projectConfig;
|
||||
getConfigCommand(std::shared_ptr<ProjectConfig> projectConfig) : projectConfig(projectConfig) {};
|
||||
CommandResult execute(std::string_view jsonPayload) override;
|
||||
};
|
||||
|
||||
@@ -467,6 +467,26 @@ std::string ProjectConfig::WiFiTxPower_t::toRepresentation()
|
||||
return json;
|
||||
}
|
||||
|
||||
std::string ProjectConfig::TrackerConfig_t::toRepresentation()
|
||||
{
|
||||
std::string WifiConfigRepresentation = "";
|
||||
|
||||
for (auto &network : this->networks)
|
||||
{
|
||||
WifiConfigRepresentation += Helpers::format_string(", %s", network.toRepresentation());
|
||||
}
|
||||
|
||||
std::string json = Helpers::format_string(
|
||||
"%s, %s, %s, %s, %s, %s",
|
||||
this->device.toRepresentation().c_str(),
|
||||
this->mdns.toRepresentation().c_str(),
|
||||
this->camera.toRepresentation().c_str(),
|
||||
WifiConfigRepresentation.c_str(),
|
||||
this->mdns.toRepresentation().c_str(),
|
||||
this->txpower.toRepresentation().c_str());
|
||||
return json;
|
||||
}
|
||||
|
||||
//**********************************************************************************************************************
|
||||
//*
|
||||
//! Get Methods
|
||||
@@ -497,3 +517,7 @@ ProjectConfig::WiFiTxPower_t &ProjectConfig::getWiFiTxPowerConfig()
|
||||
{
|
||||
return this->config.txpower;
|
||||
}
|
||||
ProjectConfig::TrackerConfig_t &ProjectConfig::getTrackerConfig()
|
||||
{
|
||||
return this->config;
|
||||
}
|
||||
@@ -99,6 +99,7 @@ public:
|
||||
AP_WiFiConfig_t ap_network;
|
||||
MDNSConfig_t mdns;
|
||||
WiFiTxPower_t txpower;
|
||||
std::string toRepresentation();
|
||||
};
|
||||
|
||||
DeviceConfig_t &getDeviceConfig();
|
||||
@@ -107,6 +108,7 @@ public:
|
||||
AP_WiFiConfig_t &getAPWifiConfig();
|
||||
MDNSConfig_t &getMDNSConfig();
|
||||
WiFiTxPower_t &getWiFiTxPowerConfig();
|
||||
TrackerConfig_t &getTrackerConfig();
|
||||
|
||||
void setDeviceConfig(const std::string &OTALogin,
|
||||
const std::string &OTAPassword,
|
||||
|
||||
@@ -121,7 +121,8 @@ void RestAPI::handle_update_camera(RequestContext *context)
|
||||
|
||||
void RestAPI::handle_get_config(RequestContext *context)
|
||||
{
|
||||
mg_http_reply(context->connection, 200, JSON_RESPONSE, "{%m:%m}", MG_ESC("result"), "Device config updated");
|
||||
auto result = this->command_manager->executeFromType(CommandType::GET_CONFIG, "");
|
||||
mg_http_reply(context->connection, 200, JSON_RESPONSE, "{%m:%m}", MG_ESC("result"), result.getResult());
|
||||
}
|
||||
|
||||
// resets
|
||||
|
||||
Reference in New Issue
Block a user