diff --git a/components/CommandManager/CommandManager/CommandManager.cpp b/components/CommandManager/CommandManager/CommandManager.cpp index 5a50273..c3e2f13 100644 --- a/components/CommandManager/CommandManager/CommandManager.cpp +++ b/components/CommandManager/CommandManager/CommandManager.cpp @@ -29,6 +29,8 @@ std::unique_ptr CommandManager::createCommand(CommandType type) return std::make_unique(projectConfig); case CommandType::UPDATE_CAMERA: return std::make_unique(projectConfig); + case CommandType::GET_CONFIG: + return std::make_unique(projectConfig); case CommandType::SAVE_CONFIG: return std::make_unique(projectConfig); default: diff --git a/components/CommandManager/CommandManager/CommandManager.hpp b/components/CommandManager/CommandManager/CommandManager.hpp index 78dafc6..552e285 100644 --- a/components/CommandManager/CommandManager/CommandManager.hpp +++ b/components/CommandManager/CommandManager/CommandManager.hpp @@ -32,6 +32,7 @@ enum CommandType SET_MDNS, UPDATE_CAMERA, SAVE_CONFIG, + GET_CONFIG, RESET_CONFIG, RESTART_DEVICE, }; diff --git a/components/CommandManager/CommandManager/commands/camera_commands.hpp b/components/CommandManager/CommandManager/commands/camera_commands.hpp index 35fddaa..f0139c0 100644 --- a/components/CommandManager/CommandManager/commands/camera_commands.hpp +++ b/components/CommandManager/CommandManager/commands/camera_commands.hpp @@ -9,3 +9,5 @@ public: CommandResult execute(std::string_view jsonPayload) override; std::optional parsePayload(std::string_view jsonPayload); }; + +// add cropping command \ No newline at end of file diff --git a/components/CommandManager/CommandManager/commands/config_commands.cpp b/components/CommandManager/CommandManager/commands/config_commands.cpp index de0fde3..e1ad844 100644 --- a/components/CommandManager/CommandManager/commands/config_commands.cpp +++ b/components/CommandManager/CommandManager/commands/config_commands.cpp @@ -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); } \ No newline at end of file diff --git a/components/CommandManager/CommandManager/commands/config_commands.hpp b/components/CommandManager/CommandManager/commands/config_commands.hpp index c0345a7..e615661 100644 --- a/components/CommandManager/CommandManager/commands/config_commands.hpp +++ b/components/CommandManager/CommandManager/commands/config_commands.hpp @@ -6,4 +6,12 @@ public: std::shared_ptr projectConfig; saveConfigCommand(std::shared_ptr projectConfig) : projectConfig(projectConfig) {}; CommandResult execute(std::string_view jsonPayload) override; -}; \ No newline at end of file +}; + +class getConfigCommand : public Command +{ +public: + std::shared_ptr projectConfig; + getConfigCommand(std::shared_ptr projectConfig) : projectConfig(projectConfig) {}; + CommandResult execute(std::string_view jsonPayload) override; +}; diff --git a/components/ProjectConfig/ProjectConfig/ProjectConfig.cpp b/components/ProjectConfig/ProjectConfig/ProjectConfig.cpp index f23c05d..e8ba863 100644 --- a/components/ProjectConfig/ProjectConfig/ProjectConfig.cpp +++ b/components/ProjectConfig/ProjectConfig/ProjectConfig.cpp @@ -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; +} \ No newline at end of file diff --git a/components/ProjectConfig/ProjectConfig/ProjectConfig.hpp b/components/ProjectConfig/ProjectConfig/ProjectConfig.hpp index f0b7779..529bd88 100644 --- a/components/ProjectConfig/ProjectConfig/ProjectConfig.hpp +++ b/components/ProjectConfig/ProjectConfig/ProjectConfig.hpp @@ -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, diff --git a/components/RestAPI/RestAPI/RestAPI.cpp b/components/RestAPI/RestAPI/RestAPI.cpp index c0a56ce..082be24 100644 --- a/components/RestAPI/RestAPI/RestAPI.cpp +++ b/components/RestAPI/RestAPI/RestAPI.cpp @@ -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