mirror of
https://github.com/MrUnknownDE/OpenIris-ESPIDF.git
synced 2026-04-20 15:03: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);
|
return std::make_unique<setMDNSCommand>(projectConfig);
|
||||||
case CommandType::UPDATE_CAMERA:
|
case CommandType::UPDATE_CAMERA:
|
||||||
return std::make_unique<updateCameraCommand>(projectConfig);
|
return std::make_unique<updateCameraCommand>(projectConfig);
|
||||||
|
case CommandType::GET_CONFIG:
|
||||||
|
return std::make_unique<getConfigCommand>(projectConfig);
|
||||||
case CommandType::SAVE_CONFIG:
|
case CommandType::SAVE_CONFIG:
|
||||||
return std::make_unique<saveConfigCommand>(projectConfig);
|
return std::make_unique<saveConfigCommand>(projectConfig);
|
||||||
default:
|
default:
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ enum CommandType
|
|||||||
SET_MDNS,
|
SET_MDNS,
|
||||||
UPDATE_CAMERA,
|
UPDATE_CAMERA,
|
||||||
SAVE_CONFIG,
|
SAVE_CONFIG,
|
||||||
|
GET_CONFIG,
|
||||||
RESET_CONFIG,
|
RESET_CONFIG,
|
||||||
RESTART_DEVICE,
|
RESTART_DEVICE,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -9,3 +9,5 @@ public:
|
|||||||
CommandResult execute(std::string_view jsonPayload) override;
|
CommandResult execute(std::string_view jsonPayload) override;
|
||||||
std::optional<UpdateCameraConfigPayload> parsePayload(std::string_view jsonPayload);
|
std::optional<UpdateCameraConfigPayload> parsePayload(std::string_view jsonPayload);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// add cropping command
|
||||||
@@ -5,3 +5,9 @@ CommandResult saveConfigCommand::execute(std::string_view jsonPayload)
|
|||||||
projectConfig->save();
|
projectConfig->save();
|
||||||
return CommandResult::getSuccessResult("Config saved");
|
return CommandResult::getSuccessResult("Config saved");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CommandResult getConfigCommand::execute(std::string_view jsonPayload)
|
||||||
|
{
|
||||||
|
auto configRepresentation = projectConfig->getTrackerConfig().toRepresentation();
|
||||||
|
return CommandResult::getSuccessResult(configRepresentation);
|
||||||
|
}
|
||||||
@@ -7,3 +7,11 @@ public:
|
|||||||
saveConfigCommand(std::shared_ptr<ProjectConfig> projectConfig) : projectConfig(projectConfig) {};
|
saveConfigCommand(std::shared_ptr<ProjectConfig> projectConfig) : projectConfig(projectConfig) {};
|
||||||
CommandResult execute(std::string_view jsonPayload) override;
|
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;
|
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
|
//! Get Methods
|
||||||
@@ -497,3 +517,7 @@ ProjectConfig::WiFiTxPower_t &ProjectConfig::getWiFiTxPowerConfig()
|
|||||||
{
|
{
|
||||||
return this->config.txpower;
|
return this->config.txpower;
|
||||||
}
|
}
|
||||||
|
ProjectConfig::TrackerConfig_t &ProjectConfig::getTrackerConfig()
|
||||||
|
{
|
||||||
|
return this->config;
|
||||||
|
}
|
||||||
@@ -99,6 +99,7 @@ public:
|
|||||||
AP_WiFiConfig_t ap_network;
|
AP_WiFiConfig_t ap_network;
|
||||||
MDNSConfig_t mdns;
|
MDNSConfig_t mdns;
|
||||||
WiFiTxPower_t txpower;
|
WiFiTxPower_t txpower;
|
||||||
|
std::string toRepresentation();
|
||||||
};
|
};
|
||||||
|
|
||||||
DeviceConfig_t &getDeviceConfig();
|
DeviceConfig_t &getDeviceConfig();
|
||||||
@@ -107,6 +108,7 @@ public:
|
|||||||
AP_WiFiConfig_t &getAPWifiConfig();
|
AP_WiFiConfig_t &getAPWifiConfig();
|
||||||
MDNSConfig_t &getMDNSConfig();
|
MDNSConfig_t &getMDNSConfig();
|
||||||
WiFiTxPower_t &getWiFiTxPowerConfig();
|
WiFiTxPower_t &getWiFiTxPowerConfig();
|
||||||
|
TrackerConfig_t &getTrackerConfig();
|
||||||
|
|
||||||
void setDeviceConfig(const std::string &OTALogin,
|
void setDeviceConfig(const std::string &OTALogin,
|
||||||
const std::string &OTAPassword,
|
const std::string &OTAPassword,
|
||||||
|
|||||||
@@ -121,7 +121,8 @@ void RestAPI::handle_update_camera(RequestContext *context)
|
|||||||
|
|
||||||
void RestAPI::handle_get_config(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
|
// resets
|
||||||
|
|||||||
Reference in New Issue
Block a user