Skip to content

Commit

Permalink
Addressed review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
jadhavrohit924 committed Apr 20, 2022
1 parent b785984 commit 4158c45
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 23 deletions.
4 changes: 3 additions & 1 deletion examples/all-clusters-app/esp32/main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ using namespace ::chip::DeviceLayer;
// Used to indicate that an IP address has been added to the QRCode
#define EXAMPLE_VENDOR_TAG_IP 1

const char * TAG = "all-clusters-app";
const char * TAG = "all-clusters-app";
const uint32_t delayNotifySeconds = 10;

static DeviceCallbacks EchoCallbacks;

Expand Down Expand Up @@ -114,6 +115,7 @@ static void InitOTARequestor(void)
gRequestorCore.Init(Server::GetInstance(), gRequestorStorage, gRequestorUser, gDownloader);
gImageProcessor.SetOTADownloader(&gDownloader);
gDownloader.SetImageProcessorDelegate(&gImageProcessor);
gRequestorUser.DelayNotifyUpdateAppliedAction(delayNotifySeconds);
gRequestorUser.Init(&gRequestorCore, &gImageProcessor);
#endif
}
Expand Down
4 changes: 3 additions & 1 deletion examples/lighting-app/esp32/main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ OTAImageProcessorImpl gImageProcessor;

LEDWidget AppLED;

static const char * TAG = "light-app";
static const char * TAG = "light-app";
const uint32_t delayNotifySeconds = 10;

static DeviceCallbacks EchoCallbacks;
namespace {
Expand All @@ -80,6 +81,7 @@ static void InitOTARequestor(void)
gRequestorCore.Init(Server::GetInstance(), gRequestorStorage, gRequestorUser, gDownloader);
gImageProcessor.SetOTADownloader(&gDownloader);
gDownloader.SetImageProcessorDelegate(&gImageProcessor);
gRequestorUser.DelayNotifyUpdateAppliedAction(delayNotifySeconds);
gRequestorUser.Init(&gRequestorCore, &gImageProcessor);
#endif
}
Expand Down
4 changes: 3 additions & 1 deletion examples/ota-requestor-app/esp32/main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ using namespace ::chip::DeviceManager;
using namespace ::chip::DeviceLayer;

namespace {
const char * TAG = "ota-requester-app";
const char * TAG = "ota-requester-app";
const uint32_t delayNotifySeconds = 10;
static DeviceCallbacks EchoCallbacks;

DefaultOTARequestor gRequestorCore;
Expand Down Expand Up @@ -78,6 +79,7 @@ static void InitServer(intptr_t context)
gRequestorCore.Init(Server::GetInstance(), gRequestorStorage, gRequestorUser, gDownloader);
gImageProcessor.SetOTADownloader(&gDownloader);
gDownloader.SetImageProcessorDelegate(&gImageProcessor);
gRequestorUser.DelayNotifyUpdateAppliedAction(delayNotifySeconds);
gRequestorUser.Init(&gRequestorCore, &gImageProcessor);
}

Expand Down
38 changes: 18 additions & 20 deletions src/app/clusters/ota-requestor/DefaultOTARequestorDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ using namespace app::Clusters::OtaSoftwareUpdateRequestor::Structs;
constexpr uint32_t kDelayQueryUponCommissioningSec = 30; // Delay before sending the initial image query after commissioning
constexpr uint32_t kImmediateStartDelaySec = 1; // Delay before sending a query in response to UrgentUpdateAvailable
constexpr System::Clock::Seconds32 kDefaultDelayedActionTime = System::Clock::Seconds32(120);
constexpr uint32_t kDelayNotifyUpdateApplied = 10; // Delay before sending notify update applied command
System::Clock::Seconds32 mDelayNotifyUpdateAppliedSeconds =
System::Clock::Seconds32(0); // Delay before sending notify update applied command

DefaultOTARequestorDriver * ToDriver(void * context)
{
Expand All @@ -57,13 +58,9 @@ DefaultOTARequestorDriver * ToDriver(void * context)

} // namespace

void ScheduleNotifyUpdateApplied(chip::System::Layer * systemLayer, void * appState)
void GenericOTARequestorDriver::DelayNotifyUpdateAppliedAction(uint32_t seconds)
{
OTARequestorInterface * requestor = static_cast<OTARequestorInterface *>(appState);
if (requestor != nullptr)
{
requestor->NotifyUpdateApplied();
}
mDelayNotifyUpdateAppliedSeconds = System::Clock::Seconds32(seconds);
}

void GenericOTARequestorDriver::Init(OTARequestorInterface * requestor, OTAImageProcessorInterface * processor)
Expand All @@ -74,19 +71,20 @@ void GenericOTARequestorDriver::Init(OTARequestorInterface * requestor, OTAImage

if (mImageProcessor->IsFirstImageRun())
{
SystemLayer().ScheduleLambda([this] {
CHIP_ERROR error = mImageProcessor->ConfirmCurrentImage();

if (error != CHIP_NO_ERROR)
{
ChipLogError(SoftwareUpdate, "Failed to confirm image: %" CHIP_ERROR_FORMAT, error.Format());
mRequestor->Reset();
return;
}

chip::DeviceLayer::SystemLayer().StartTimer(chip::System::Clock::Seconds32(kDelayNotifyUpdateApplied),
ScheduleNotifyUpdateApplied, mRequestor);
});
ScheduleDelayedAction(
mDelayNotifyUpdateAppliedSeconds,
[](System::Layer *, void * context) {
CHIP_ERROR error = ToDriver(context)->mImageProcessor->ConfirmCurrentImage();
if (error != CHIP_NO_ERROR)
{
ChipLogError(SoftwareUpdate, "Failed to confirm image: %" CHIP_ERROR_FORMAT, error.Format());
ToDriver(context)->mRequestor->Reset();
return;
}

ToDriver(context)->mRequestor->NotifyUpdateApplied();
},
this);
}
else if ((mRequestor->GetCurrentUpdateState() != OTAUpdateStateEnum::kIdle))
{
Expand Down
1 change: 1 addition & 0 deletions src/app/clusters/ota-requestor/DefaultOTARequestorDriver.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ class DefaultOTARequestorDriver : public OTARequestorDriver
app::Clusters::OtaSoftwareUpdateRequestor::OTAAnnouncementReason announcementReason) override;
void SendQueryImage() override;
bool GetNextProviderLocation(ProviderLocationType & providerLocation, bool & listExhausted) override;
void DelayNotifyUpdateAppliedAction(uint32_t seconds);

protected:
void StartPeriodicQueryTimer();
Expand Down

0 comments on commit 4158c45

Please sign in to comment.