Skip to content

Commit

Permalink
Some minor changes
Browse files Browse the repository at this point in the history
  • Loading branch information
jadhavrohit924 committed Apr 22, 2022
1 parent 6aaaeee commit 7ebb1f2
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 51 deletions.
2 changes: 1 addition & 1 deletion examples/all-clusters-app/esp32/main/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down
20 changes: 13 additions & 7 deletions examples/all-clusters-app/esp32/main/DeviceCallbacks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@
#include <app/server/Dnssd.h>
#include <app/util/basic-types.h>
#include <app/util/util.h>
#include <examples/platform/esp32/ota/InitOTAR.h>
#include <lib/dnssd/Advertiser.h>
#include <lib/support/CodeUtils.h>
#include <ota/OTAHelper.h>

static const char * TAG = "app-devicecallbacks";

Expand All @@ -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)
{
Expand Down Expand Up @@ -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)
Expand All @@ -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)
{
Expand Down
2 changes: 1 addition & 1 deletion examples/lighting-app/esp32/main/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
21 changes: 14 additions & 7 deletions examples/lighting-app/esp32/main/DeviceCallbacks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@
#include <app-common/zap-generated/cluster-id.h>
#include <app/server/Dnssd.h>
#include <app/util/util.h>
#include <examples/platform/esp32/ota/InitOTAR.h>
#include <lib/support/CodeUtils.h>
#include <ota/OTAHelper.h>

static const char * TAG = "light-app-callbacks";
constexpr uint32_t mInitOTARequestorDelaySec = 3;
constexpr uint32_t kInitOTARequestorDelaySec = 3;

extern LEDWidget AppLED;

Expand Down Expand Up @@ -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)
Expand All @@ -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)
{
Expand Down
2 changes: 1 addition & 1 deletion examples/ota-requestor-app/esp32/main/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
20 changes: 13 additions & 7 deletions examples/ota-requestor-app/esp32/main/DeviceCallbacks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@
#include <app-common/zap-generated/attribute-id.h>
#include <app-common/zap-generated/cluster-id.h>
#include <app/server/Dnssd.h>
#include <examples/platform/esp32/ota/InitOTAR.h>
#include <lib/support/CodeUtils.h>
#include <ota/OTAHelper.h>

static const char * TAG = "echo-devicecallbacks";
constexpr uint32_t mInitOTARequestorDelaySec = 3;
constexpr uint32_t kInitOTARequestorDelaySec = 3;

using namespace ::chip;
using namespace ::chip::Inet;
Expand Down Expand Up @@ -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)
Expand All @@ -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)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -14,7 +14,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#pragma once

#include "OTAHelper.h"

#include <app/clusters/ota-requestor/BDXDownloader.h>
#include <app/clusters/ota-requestor/DefaultOTARequestor.h>
Expand All @@ -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
}
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -14,18 +14,13 @@
* See the License for the specific language governing permissions and
* 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);
};

0 comments on commit 7ebb1f2

Please sign in to comment.