From 3c15be157ca6bb82a3e31f27d4ea44e23daeb257 Mon Sep 17 00:00:00 2001 From: Rohit Jadhav Date: Fri, 22 Apr 2022 14:08:59 +0530 Subject: [PATCH] Some minor changes --- .../esp32/main/CMakeLists.txt | 2 +- .../esp32/main/DeviceCallbacks.cpp | 20 +++++++++----- .../lighting-app/esp32/main/CMakeLists.txt | 2 +- .../esp32/main/DeviceCallbacks.cpp | 21 ++++++++++----- .../esp32/main/CMakeLists.txt | 2 +- .../esp32/main/DeviceCallbacks.cpp | 20 +++++++++----- .../esp32/ota/{InitOTAR.h => OTAHelper.cpp} | 26 ++++++++++--------- .../esp32/ota/{InitOTAR.cpp => OTAHelper.h} | 24 +++++++---------- 8 files changed, 67 insertions(+), 50 deletions(-) rename examples/platform/esp32/ota/{InitOTAR.h => OTAHelper.cpp} (69%) rename examples/platform/esp32/ota/{InitOTAR.cpp => OTAHelper.h} (53%) diff --git a/examples/all-clusters-app/esp32/main/CMakeLists.txt b/examples/all-clusters-app/esp32/main/CMakeLists.txt index 99600c5d19fb60..94c5bd15476d60 100644 --- a/examples/all-clusters-app/esp32/main/CMakeLists.txt +++ b/examples/all-clusters-app/esp32/main/CMakeLists.txt @@ -21,7 +21,7 @@ set(PRIV_INCLUDE_DIRS_LIST "${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/zzz_generated/all-clusters-app" "${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/examples/all-clusters-app/all-clusters-common/include" "${CMAKE_CURRENT_LIST_DIR}/include" - "${CMAKE_SOURCE_DIR}/third_party/connectedhomeip" + "${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/examples/platform/esp32" ) set(SRC_DIRS_LIST "${CMAKE_CURRENT_LIST_DIR}" diff --git a/examples/all-clusters-app/esp32/main/DeviceCallbacks.cpp b/examples/all-clusters-app/esp32/main/DeviceCallbacks.cpp index 499be4c2f0c6a7..2fe0c6f10edca6 100644 --- a/examples/all-clusters-app/esp32/main/DeviceCallbacks.cpp +++ b/examples/all-clusters-app/esp32/main/DeviceCallbacks.cpp @@ -44,9 +44,9 @@ #include #include #include -#include #include #include +#include static const char * TAG = "app-devicecallbacks"; @@ -57,7 +57,7 @@ using namespace ::chip::DeviceLayer; using namespace chip::app; constexpr uint32_t kIdentifyTimerDelayMS = 250; -constexpr uint32_t mInitOTARequestorDelaySec = 3; +constexpr uint32_t kInitOTARequestorDelaySec = 3; void OnIdentifyTriggerEffect(Identify * identify) { @@ -204,23 +204,23 @@ void DeviceCallbacks::PostAttributeChangeCallback(EndpointId endpointId, Cluster void InitOTARequestorHandler(System::Layer * systemLayer, void * appState) { - InitOTA::Instance().InitOTARequestor(); + OTAHelpers::Instance().InitOTARequestor(); } void DeviceCallbacks::OnInternetConnectivityChange(const ChipDeviceEvent * event) { - static bool IsOTAInitialized = false; + static bool isOTAInitialized = false; if (event->InternetConnectivityChange.IPv4 == kConnectivity_Established) { ESP_LOGI(TAG, "Server ready at: %s:%d", event->InternetConnectivityChange.address, CHIP_PORT); wifiLED.Set(true); chip::app::DnssdServer::Instance().StartServer(); - if (!IsOTAInitialized) + if (!isOTAInitialized) { - chip::DeviceLayer::SystemLayer().StartTimer(chip::System::Clock::Seconds32(mInitOTARequestorDelaySec), + chip::DeviceLayer::SystemLayer().StartTimer(chip::System::Clock::Seconds32(kInitOTARequestorDelaySec), InitOTARequestorHandler, nullptr); - IsOTAInitialized = true; + isOTAInitialized = true; } } else if (event->InternetConnectivityChange.IPv4 == kConnectivity_Lost) @@ -232,6 +232,12 @@ void DeviceCallbacks::OnInternetConnectivityChange(const ChipDeviceEvent * event { ESP_LOGI(TAG, "IPv6 Server ready..."); chip::app::DnssdServer::Instance().StartServer(); + if (!isOTAInitialized) + { + chip::DeviceLayer::SystemLayer().StartTimer(chip::System::Clock::Seconds32(kInitOTARequestorDelaySec), + InitOTARequestorHandler, nullptr); + isOTAInitialized = true; + } } else if (event->InternetConnectivityChange.IPv6 == kConnectivity_Lost) { diff --git a/examples/lighting-app/esp32/main/CMakeLists.txt b/examples/lighting-app/esp32/main/CMakeLists.txt index ff6715bd8e8b29..efbabfd9b5f678 100644 --- a/examples/lighting-app/esp32/main/CMakeLists.txt +++ b/examples/lighting-app/esp32/main/CMakeLists.txt @@ -20,7 +20,7 @@ idf_component_register(PRIV_INCLUDE_DIRS "${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/zzz_generated/lighting-app" "${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/examples/lighting-app/lighting-common/color_format" "${CMAKE_CURRENT_LIST_DIR}/include" - "${CMAKE_SOURCE_DIR}/third_party/connectedhomeip" + "${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/examples/platform/esp32" SRC_DIRS "${CMAKE_CURRENT_LIST_DIR}" "${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/zzz_generated/app-common/app-common/zap-generated/attributes" diff --git a/examples/lighting-app/esp32/main/DeviceCallbacks.cpp b/examples/lighting-app/esp32/main/DeviceCallbacks.cpp index 75e04bf1a44c54..fdcb2e11dc7230 100644 --- a/examples/lighting-app/esp32/main/DeviceCallbacks.cpp +++ b/examples/lighting-app/esp32/main/DeviceCallbacks.cpp @@ -37,11 +37,11 @@ #include #include #include -#include #include +#include static const char * TAG = "light-app-callbacks"; -constexpr uint32_t mInitOTARequestorDelaySec = 3; +constexpr uint32_t kInitOTARequestorDelaySec = 3; extern LEDWidget AppLED; @@ -153,22 +153,22 @@ void DeviceCallbacks::PostAttributeChangeCallback(EndpointId endpointId, Cluster void InitOTARequestorHandler(System::Layer * systemLayer, void * appState) { - InitOTA::Instance().InitOTARequestor(); + OTAHelpers::Instance().InitOTARequestor(); } void DeviceCallbacks::OnInternetConnectivityChange(const ChipDeviceEvent * event) { - static bool IsOTAInitialized = false; + static bool isOTAInitialized = false; if (event->InternetConnectivityChange.IPv4 == kConnectivity_Established) { ESP_LOGI(TAG, "Server ready at: %s:%d", event->InternetConnectivityChange.address, CHIP_PORT); chip::app::DnssdServer::Instance().StartServer(); - if (!IsOTAInitialized) + if (!isOTAInitialized) { - chip::DeviceLayer::SystemLayer().StartTimer(chip::System::Clock::Seconds32(mInitOTARequestorDelaySec), + chip::DeviceLayer::SystemLayer().StartTimer(chip::System::Clock::Seconds32(kInitOTARequestorDelaySec), InitOTARequestorHandler, nullptr); - IsOTAInitialized = true; + isOTAInitialized = true; } } else if (event->InternetConnectivityChange.IPv4 == kConnectivity_Lost) @@ -179,6 +179,13 @@ void DeviceCallbacks::OnInternetConnectivityChange(const ChipDeviceEvent * event { ESP_LOGI(TAG, "IPv6 Server ready..."); chip::app::DnssdServer::Instance().StartServer(); + + if (!isOTAInitialized) + { + chip::DeviceLayer::SystemLayer().StartTimer(chip::System::Clock::Seconds32(kInitOTARequestorDelaySec), + InitOTARequestorHandler, nullptr); + isOTAInitialized = true; + } } else if (event->InternetConnectivityChange.IPv6 == kConnectivity_Lost) { diff --git a/examples/ota-requestor-app/esp32/main/CMakeLists.txt b/examples/ota-requestor-app/esp32/main/CMakeLists.txt index e9623612bb6a58..f89b111d538656 100644 --- a/examples/ota-requestor-app/esp32/main/CMakeLists.txt +++ b/examples/ota-requestor-app/esp32/main/CMakeLists.txt @@ -20,7 +20,7 @@ idf_component_register(PRIV_INCLUDE_DIRS "${CMAKE_CURRENT_LIST_DIR}/include" "${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src" "${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/zzz_generated/ota-requestor-app/" - "${CMAKE_SOURCE_DIR}/third_party/connectedhomeip" + "${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/examples/platform/esp32" SRC_DIRS "${CMAKE_CURRENT_LIST_DIR}" "${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/zzz_generated/ota-requestor-app/zap-generated" diff --git a/examples/ota-requestor-app/esp32/main/DeviceCallbacks.cpp b/examples/ota-requestor-app/esp32/main/DeviceCallbacks.cpp index c7fdb12b64b26f..6807e16cde0bb9 100644 --- a/examples/ota-requestor-app/esp32/main/DeviceCallbacks.cpp +++ b/examples/ota-requestor-app/esp32/main/DeviceCallbacks.cpp @@ -29,11 +29,11 @@ #include #include #include -#include #include +#include static const char * TAG = "echo-devicecallbacks"; -constexpr uint32_t mInitOTARequestorDelaySec = 3; +constexpr uint32_t kInitOTARequestorDelaySec = 3; using namespace ::chip; using namespace ::chip::Inet; @@ -82,21 +82,21 @@ void DeviceCallbacks::PostAttributeChangeCallback(EndpointId endpointId, Cluster void InitOTARequestorHandler(System::Layer * systemLayer, void * appState) { - InitOTA::Instance().InitOTARequestor(); + OTAHelpers::Instance().InitOTARequestor(); } void DeviceCallbacks::OnInternetConnectivityChange(const ChipDeviceEvent * event) { - static bool IsOTAInitialized = false; + static bool isOTAInitialized = false; if (event->InternetConnectivityChange.IPv4 == kConnectivity_Established) { ESP_LOGI(TAG, "Server ready at: %s:%d", event->InternetConnectivityChange.address, CHIP_PORT); chip::app::DnssdServer::Instance().StartServer(); - if (!IsOTAInitialized) + if (!isOTAInitialized) { - chip::DeviceLayer::SystemLayer().StartTimer(chip::System::Clock::Seconds32(mInitOTARequestorDelaySec), + chip::DeviceLayer::SystemLayer().StartTimer(chip::System::Clock::Seconds32(kInitOTARequestorDelaySec), InitOTARequestorHandler, nullptr); - IsOTAInitialized = true; + isOTAInitialized = true; } } else if (event->InternetConnectivityChange.IPv4 == kConnectivity_Lost) @@ -107,6 +107,12 @@ void DeviceCallbacks::OnInternetConnectivityChange(const ChipDeviceEvent * event { ESP_LOGI(TAG, "IPv6 Server ready..."); chip::app::DnssdServer::Instance().StartServer(); + if (!isOTAInitialized) + { + chip::DeviceLayer::SystemLayer().StartTimer(chip::System::Clock::Seconds32(kInitOTARequestorDelaySec), + InitOTARequestorHandler, nullptr); + isOTAInitialized = true; + } } else if (event->InternetConnectivityChange.IPv6 == kConnectivity_Lost) { diff --git a/examples/platform/esp32/ota/InitOTAR.h b/examples/platform/esp32/ota/OTAHelper.cpp similarity index 69% rename from examples/platform/esp32/ota/InitOTAR.h rename to examples/platform/esp32/ota/OTAHelper.cpp index 682d526a6c641f..d561a09ad815e6 100644 --- a/examples/platform/esp32/ota/InitOTAR.h +++ b/examples/platform/esp32/ota/OTAHelper.cpp @@ -1,6 +1,6 @@ /* * - * Copyright (c) 2021 Project CHIP Authors + * Copyright (c) 2022 Project CHIP Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,7 +14,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#pragma once + +#include "OTAHelper.h" #include #include @@ -35,14 +36,15 @@ BDXDownloader gDownloader; OTAImageProcessorImpl gImageProcessor; #endif } // namespace - -class InitOTA +void OTAHelpers::InitOTARequestor() { -public: - static InitOTA & Instance(void) - { - static InitOTA sInitOTA; - return sInitOTA; - } - void InitOTARequestor(void); -}; + +#if CONFIG_ENABLE_OTA_REQUESTOR + SetRequestorInstance(&gRequestorCore); + gRequestorStorage.Init(Server::GetInstance().GetPersistentStorage()); + gRequestorCore.Init(Server::GetInstance(), gRequestorStorage, gRequestorUser, gDownloader); + gImageProcessor.SetOTADownloader(&gDownloader); + gDownloader.SetImageProcessorDelegate(&gImageProcessor); + gRequestorUser.Init(&gRequestorCore, &gImageProcessor); +#endif +} diff --git a/examples/platform/esp32/ota/InitOTAR.cpp b/examples/platform/esp32/ota/OTAHelper.h similarity index 53% rename from examples/platform/esp32/ota/InitOTAR.cpp rename to examples/platform/esp32/ota/OTAHelper.h index abc759a6b87fa8..521c5b39532b6d 100644 --- a/examples/platform/esp32/ota/InitOTAR.cpp +++ b/examples/platform/esp32/ota/OTAHelper.h @@ -1,6 +1,6 @@ /* * - * Copyright (c) 2021 Project CHIP Authors + * Copyright (c) 2022 Project CHIP Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,17 +15,13 @@ * limitations under the License. */ -#include "InitOTAR.h" - -void InitOTA::InitOTARequestor() +class OTAHelpers { - -#if CONFIG_ENABLE_OTA_REQUESTOR - SetRequestorInstance(&gRequestorCore); - gRequestorStorage.Init(Server::GetInstance().GetPersistentStorage()); - gRequestorCore.Init(Server::GetInstance(), gRequestorStorage, gRequestorUser, gDownloader); - gImageProcessor.SetOTADownloader(&gDownloader); - gDownloader.SetImageProcessorDelegate(&gImageProcessor); - gRequestorUser.Init(&gRequestorCore, &gImageProcessor); -#endif -} +public: + static OTAHelpers & Instance(void) + { + static OTAHelpers sInitOTA; + return sInitOTA; + } + void InitOTARequestor(void); +};