Skip to content

Commit

Permalink
[OTA-R] OTA watchdog timer should not expire when device is in idle s…
Browse files Browse the repository at this point in the history
…tate. (#18271)

* Fixed watchdog and peridoc timer handler.
Contains debug code.

* Debug OTA-R config

* Remove debug code.

* Revert debug config.

* - Move static functions together for style.
- scripts/helpers/restyle-diff.sh

* Code review changes.
  • Loading branch information
isiu-apple authored and pull[bot] committed Oct 5, 2023
1 parent 8d8877b commit 2871105
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 19 deletions.
33 changes: 16 additions & 17 deletions src/app/clusters/ota-requestor/DefaultOTARequestorDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -319,60 +319,59 @@ void DefaultOTARequestorDriver::PeriodicQueryTimerHandler(System::Layer * system
{
ChipLogProgress(SoftwareUpdate, "Default Provider timer handler is invoked");

DefaultOTARequestorDriver * driver = ToDriver(appState);

// Determine which provider to query next
ProviderLocationType providerLocation;
bool listExhausted = false;
if (GetNextProviderLocation(providerLocation, listExhausted) != true)
if (driver->GetNextProviderLocation(providerLocation, listExhausted) != true)
{
StartSelectedTimer(SelectedTimer::kPeriodicQueryTimer);
driver->StartSelectedTimer(SelectedTimer::kPeriodicQueryTimer);
return;
}

mRequestor->SetCurrentProviderLocation(providerLocation);
driver->mRequestor->SetCurrentProviderLocation(providerLocation);

SendQueryImage();
driver->SendQueryImage();
}

void DefaultOTARequestorDriver::StartPeriodicQueryTimer()
{
ChipLogProgress(SoftwareUpdate, "Starting the periodic query timer, timeout: %u seconds",
(unsigned int) mPeriodicQueryTimeInterval);
ScheduleDelayedAction(
System::Clock::Seconds32(mPeriodicQueryTimeInterval),
[](System::Layer *, void * context) { (ToDriver(context))->PeriodicQueryTimerHandler(nullptr, context); }, this);
ScheduleDelayedAction(System::Clock::Seconds32(mPeriodicQueryTimeInterval), PeriodicQueryTimerHandler, this);
}

void DefaultOTARequestorDriver::StopPeriodicQueryTimer()
{
ChipLogProgress(SoftwareUpdate, "Stopping the Periodic Query timer");
CancelDelayedAction([](System::Layer *, void * context) { (ToDriver(context))->PeriodicQueryTimerHandler(nullptr, context); },
this);
CancelDelayedAction(PeriodicQueryTimerHandler, this);
}

void DefaultOTARequestorDriver::WatchdogTimerHandler(System::Layer * systemLayer, void * appState)
{
DefaultOTARequestorDriver * driver = ToDriver(appState);

ChipLogError(SoftwareUpdate, "Watchdog timer detects state stuck at %u. Cancelling download and resetting state.",
to_underlying(mRequestor->GetCurrentUpdateState()));
to_underlying(driver->mRequestor->GetCurrentUpdateState()));

// Something went wrong and OTA requestor is stuck in a non-idle state for too long.
// Let's just cancel download, reset state, and re-start periodic query timer.
UpdateDiscontinued();
mRequestor->CancelImageUpdate();
StartPeriodicQueryTimer();
driver->UpdateDiscontinued();
driver->mRequestor->CancelImageUpdate();
driver->StartPeriodicQueryTimer();
}

void DefaultOTARequestorDriver::StartWatchdogTimer()
{
ChipLogProgress(SoftwareUpdate, "Starting the watchdog timer, timeout: %u seconds", (unsigned int) mWatchdogTimeInterval);
ScheduleDelayedAction(
System::Clock::Seconds32(mWatchdogTimeInterval),
[](System::Layer *, void * context) { (ToDriver(context))->WatchdogTimerHandler(nullptr, context); }, this);
ScheduleDelayedAction(System::Clock::Seconds32(mWatchdogTimeInterval), WatchdogTimerHandler, this);
}

void DefaultOTARequestorDriver::StopWatchdogTimer()
{
ChipLogProgress(SoftwareUpdate, "Stopping the watchdog timer");
CancelDelayedAction([](System::Layer *, void * context) { (ToDriver(context))->WatchdogTimerHandler(nullptr, context); }, this);
CancelDelayedAction(WatchdogTimerHandler, this);
}

void DefaultOTARequestorDriver::StartSelectedTimer(SelectedTimer timer)
Expand Down
5 changes: 3 additions & 2 deletions src/app/clusters/ota-requestor/DefaultOTARequestorDriver.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,13 @@ class DefaultOTARequestorDriver : public OTARequestorDriver
bool GetNextProviderLocation(ProviderLocationType & providerLocation, bool & listExhausted) override;

protected:
static void PeriodicQueryTimerHandler(System::Layer * systemLayer, void * appState);
static void WatchdogTimerHandler(System::Layer * systemLayer, void * appState);

void StartPeriodicQueryTimer();
void StopPeriodicQueryTimer();
void PeriodicQueryTimerHandler(System::Layer * systemLayer, void * appState);
void StartWatchdogTimer();
void StopWatchdogTimer();
void WatchdogTimerHandler(System::Layer * systemLayer, void * appState);
void StartSelectedTimer(SelectedTimer timer);
void ScheduleDelayedAction(System::Clock::Seconds32 delay, System::TimerCompleteCallback action, void * aAppState);
void CancelDelayedAction(System::TimerCompleteCallback action, void * aAppState);
Expand Down

0 comments on commit 2871105

Please sign in to comment.