diff --git a/components/CameraManager/CameraManager/CameraManager.hpp b/components/CameraManager/CameraManager/CameraManager.hpp index 53ab4bc..3a6a441 100644 --- a/components/CameraManager/CameraManager/CameraManager.hpp +++ b/components/CameraManager/CameraManager/CameraManager.hpp @@ -1,6 +1,6 @@ #pragma once -#ifndef _CAMERAMANAGER_HPP_ -#define _CAMERAMANAGER_HPP_ +#ifndef CAMERAMANAGER_HPP +#define CAMERAMANAGER_HPP #include "esp_log.h" #include "esp_camera.h" @@ -31,12 +31,11 @@ private: public: CameraManager(std::shared_ptr projectConfig, QueueHandle_t eventQueue); int setCameraResolution(framesize_t frameSize); - bool setupCamera(); // todo, once we have observers, make it private - + bool setupCamera(); int setVFlip(int direction); int setHFlip(int direction); int setVieWindow(int offsetX, int offsetY, int outputX, int outputY); - void resetCamera(bool type = 0); + void resetCamera(bool type); private: void loadConfigData(); @@ -45,4 +44,4 @@ private: void setupBasicResolution(); }; -#endif // _CAMERAMANAGER_HPP_ \ No newline at end of file +#endif // CAMERAMANAGER_HPP \ No newline at end of file diff --git a/components/CommandManager/CommandManager/CommandManager.cpp b/components/CommandManager/CommandManager/CommandManager.cpp index 9a7f1f6..9d981f1 100644 --- a/components/CommandManager/CommandManager/CommandManager.cpp +++ b/components/CommandManager/CommandManager/CommandManager.cpp @@ -5,10 +5,9 @@ std::unordered_map commandTypeMap = { {"set_wifi", CommandType::SET_WIFI}, {"update_wifi", CommandType::UPDATE_WIFI}, {"set_streaming_mode", CommandType::SET_STREAMING_MODE}, - {"update_device", CommandType::UPDATE_DEVICE}, + {"update_ota_credentials", CommandType::UPDATE_OTA_CREDENTIALS}, {"delete_network", CommandType::DELETE_NETWORK}, {"update_ap_wifi", CommandType::UPDATE_AP_WIFI}, - {"update_mdns", CommandType::UPDATE_MDNS}, {"set_mdns", CommandType::SET_MDNS}, {"update_camera", CommandType::UPDATE_CAMERA}, {"restart_camera", CommandType::RESTART_CAMERA}, @@ -18,13 +17,15 @@ std::unordered_map commandTypeMap = { {"restart_device", CommandType::RESTART_DEVICE}, }; -std::function CommandManager::createCommand(CommandType type, std::string_view json) const { +std::function CommandManager::createCommand(const CommandType type, std::string_view json) const { switch (type) { case CommandType::PING: return { PingCommand }; - case CommandType::SET_STREAMING_MODE: + case CommandType::SET_STREAMING_MODE: return [this, json] {return setDeviceModeCommand(this->registry, json); }; + case CommandType::UPDATE_OTA_CREDENTIALS: + return [this, json] { return updateOTACredentialsCommand(this->registry, json); }; case CommandType::SET_WIFI: return [this, json] { return setWiFiCommand(this->registry, json); }; case CommandType::UPDATE_WIFI: @@ -35,9 +36,6 @@ std::function CommandManager::createCommand(CommandType type, s return [this, json] { return deleteWiFiCommand(this->registry, json); }; case CommandType::SET_MDNS: return [this, json] { return setMDNSCommand(this->registry, json); }; - // updating the mnds name is essentially the same operation - case CommandType::UPDATE_MDNS: - return [this, json] { return setMDNSCommand(this->registry, json); }; case CommandType::UPDATE_CAMERA: return [this, json] { return updateCameraCommand(this->registry, json); }; case CommandType::RESTART_CAMERA: diff --git a/components/CommandManager/CommandManager/CommandManager.hpp b/components/CommandManager/CommandManager/CommandManager.hpp index 7042db9..eea0477 100644 --- a/components/CommandManager/CommandManager/CommandManager.hpp +++ b/components/CommandManager/CommandManager/CommandManager.hpp @@ -24,12 +24,11 @@ enum class CommandType None, PING, SET_WIFI, - UPDATE_DEVICE, + UPDATE_OTA_CREDENTIALS, SET_STREAMING_MODE, UPDATE_WIFI, DELETE_NETWORK, UPDATE_AP_WIFI, - UPDATE_MDNS, SET_MDNS, UPDATE_CAMERA, RESTART_CAMERA, diff --git a/components/CommandManager/CommandManager/commands/device_commands.cpp b/components/CommandManager/CommandManager/commands/device_commands.cpp index f3f2a31..0a3fe92 100644 --- a/components/CommandManager/CommandManager/commands/device_commands.cpp +++ b/components/CommandManager/CommandManager/commands/device_commands.cpp @@ -27,6 +27,39 @@ CommandResult setDeviceModeCommand(std::shared_ptr registry, return CommandResult::getSuccessResult("Device mode set"); } +CommandResult updateOTACredentialsCommand(std::shared_ptr registry, std::string_view jsonPayload) { + const auto parsedJson = cJSON_Parse(jsonPayload.data()); + + if (parsedJson == nullptr) { + return CommandResult::getErrorResult("Invalid payload"); + } + + const auto projectConfig = registry->resolve(DependencyType::project_config); + const auto oldDeviceConfig = projectConfig->getDeviceConfig(); + auto OTALogin = oldDeviceConfig.OTALogin; + auto OTAPassword = oldDeviceConfig.OTAPassword; + auto OTAPort = oldDeviceConfig.OTAPort; + + if (const auto OTALoginObject = cJSON_GetObjectItem(parsedJson, "login"); OTALoginObject != nullptr) { + if (const auto newLogin = OTALoginObject->valuestring; strcmp(newLogin, "") != 0) { + OTALogin = newLogin; + } + } + + if (const auto OTAPasswordObject = cJSON_GetObjectItem(parsedJson, s"password"); OTAPasswordObject != nullptr) { + OTAPassword = OTAPasswordObject->valuestring; + } + + if (const auto OTAPortObject = cJSON_GetObjectItem(parsedJson, "port"); OTAPortObject != nullptr) { + if (const auto newPort = OTAPortObject->valueint; newPort >= 82) { + OTAPort = newPort; + } + } + + projectConfig->setDeviceConfig(OTALogin, OTAPassword, OTAPort); + return CommandResult::getSuccessResult("OTA Config set"); +} + CommandResult restartDeviceCommand() { OpenIrisTasks::ScheduleRestart(2000); return CommandResult::getSuccessResult("Device restarted"); diff --git a/components/CommandManager/CommandManager/commands/device_commands.hpp b/components/CommandManager/CommandManager/commands/device_commands.hpp index 4efa65a..2532624 100644 --- a/components/CommandManager/CommandManager/commands/device_commands.hpp +++ b/components/CommandManager/CommandManager/commands/device_commands.hpp @@ -4,4 +4,6 @@ CommandResult setDeviceModeCommand(std::shared_ptr registry, std::string_view jsonPayload); +CommandResult updateOTACredentialsCommand(std::shared_ptr registry, std::string_view jsonPayload); + CommandResult restartDeviceCommand(); \ No newline at end of file diff --git a/components/RestAPI/RestAPI/RestAPI.cpp b/components/RestAPI/RestAPI/RestAPI.cpp index a646bb3..a0c9bb8 100644 --- a/components/RestAPI/RestAPI/RestAPI.cpp +++ b/components/RestAPI/RestAPI/RestAPI.cpp @@ -103,7 +103,7 @@ void RestAPI::handle_update_device(RequestContext *context) { return; } - auto const result = command_manager->executeFromType(CommandType::UPDATE_DEVICE, context->body); + auto const result = command_manager->executeFromType(CommandType::UPDATE_OTA_CREDENTIALS, context->body); auto const code = result.isSuccess() ? 200 : 500; mg_http_reply(context->connection, code, JSON_RESPONSE, result.getResult().c_str()); } diff --git a/components/UVCStream/UVCStream/UVCStream.hpp b/components/UVCStream/UVCStream/UVCStream.hpp index 1208754..34a4d92 100644 --- a/components/UVCStream/UVCStream/UVCStream.hpp +++ b/components/UVCStream/UVCStream/UVCStream.hpp @@ -31,15 +31,13 @@ namespace UVCStreamHelpers static esp_err_t camera_start_cb(uvc_format_t format, int width, int height, int rate, void *cb_ctx); static void camera_stop_cb(void *cb_ctx); - static esp_err_t camera_start_cb(uvc_format_t format, int width, int height, int rate, void *cb_ctx); static uvc_fb_t *camera_fb_get_cb(void *cb_ctx); static void camera_fb_return_cb(uvc_fb_t *fb, void *cb_ctx); } class UVCStreamManager { -private: - uint8_t *uvc_buffer; + uint8_t *uvc_buffer = nullptr; public: esp_err_t setup();