Skip to content

Commit

Permalink
[OTA] Set the current state on every attempt for CASE session establi…
Browse files Browse the repository at this point in the history
…shment (#15846)
  • Loading branch information
carol-apple authored and pull[bot] committed Jul 7, 2023
1 parent 71dc5fe commit 1065020
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 20 deletions.
23 changes: 8 additions & 15 deletions src/app/clusters/ota-requestor/OTARequestor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -385,11 +385,9 @@ void OTARequestor::OnConnected(void * context, OperationalDeviceProxy * devicePr
requestorCore->RecordErrorUpdateState(UpdateFailureState::kQuerying, err);
return;
}

// The kQuerying state is set in TriggerImmediateQueryInternal(), do not set it here
break;
}
case kStartBDX: {
case kDownload: {
CHIP_ERROR err = requestorCore->StartDownload(*deviceProxy);

if (err != CHIP_NO_ERROR)
Expand All @@ -398,8 +396,6 @@ void OTARequestor::OnConnected(void * context, OperationalDeviceProxy * devicePr
requestorCore->RecordErrorUpdateState(UpdateFailureState::kDownloading, err);
return;
}

requestorCore->RecordNewUpdateState(OTAUpdateStateEnum::kDownloading, OTAChangeReasonEnum::kSuccess);
break;
}
case kApplyUpdate: {
Expand All @@ -411,8 +407,6 @@ void OTARequestor::OnConnected(void * context, OperationalDeviceProxy * devicePr
requestorCore->RecordErrorUpdateState(UpdateFailureState::kApplying, err);
return;
}

requestorCore->RecordNewUpdateState(OTAUpdateStateEnum::kApplying, OTAChangeReasonEnum::kSuccess);
break;
}
case kNotifyUpdateApplied: {
Expand All @@ -424,8 +418,6 @@ void OTARequestor::OnConnected(void * context, OperationalDeviceProxy * devicePr
requestorCore->RecordErrorUpdateState(UpdateFailureState::kNotifying, err);
return;
}

requestorCore->RecordNewUpdateState(OTAUpdateStateEnum::kIdle, OTAChangeReasonEnum::kSuccess);
break;
}
default:
Expand All @@ -447,7 +439,7 @@ void OTARequestor::OnConnectionFailure(void * context, PeerId peerId, CHIP_ERROR
case kQueryImage:
requestorCore->RecordErrorUpdateState(UpdateFailureState::kQuerying, error);
break;
case kStartBDX:
case kDownload:
requestorCore->RecordErrorUpdateState(UpdateFailureState::kDownloading, error);
break;
case kApplyUpdate:
Expand Down Expand Up @@ -483,10 +475,6 @@ OTARequestorInterface::OTATriggerResult OTARequestor::TriggerImmediateQuery()

SetCurrentProviderLocation(providerLocation);

// We are now querying a provider, leave the kIdle state.
// No state matches this one fully but we can't be in kIdle.
RecordNewUpdateState(OTAUpdateStateEnum::kQuerying, OTAChangeReasonEnum::kSuccess);

// Go through the driver as it has additional logic to execute
mOtaRequestorDriver->SendQueryImage();

Expand All @@ -495,11 +483,13 @@ OTARequestorInterface::OTATriggerResult OTARequestor::TriggerImmediateQuery()

void OTARequestor::DownloadUpdate()
{
ConnectToProvider(kStartBDX);
RecordNewUpdateState(OTAUpdateStateEnum::kDownloading, OTAChangeReasonEnum::kSuccess);
ConnectToProvider(kDownload);
}

void OTARequestor::ApplyUpdate()
{
RecordNewUpdateState(OTAUpdateStateEnum::kApplying, OTAChangeReasonEnum::kSuccess);
ConnectToProvider(kApplyUpdate);
}

Expand All @@ -519,6 +509,9 @@ void OTARequestor::NotifyUpdateApplied(uint32_t version)

OtaRequestorServerOnVersionApplied(version, productId);

// There is no response for a notify so consider this OTA complete
RecordNewUpdateState(OTAUpdateStateEnum::kIdle, OTAChangeReasonEnum::kSuccess);

ConnectToProvider(kNotifyUpdateApplied);
}

Expand Down
6 changes: 3 additions & 3 deletions src/app/clusters/ota-requestor/OTARequestor.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@ class OTARequestor : public OTARequestorInterface, public BDXDownloader::StateDe
// Initiate download of the new image
void DownloadUpdate() override;

// Send ApplyImage
// Initiate the session to send ApplyUpdateRequest command
void ApplyUpdate() override;

// Send NotifyUpdateApplied, update Basic cluster SoftwareVersion attribute, log the VersionApplied event
// Initiate the session to send NotifyUpdateApplied command
void NotifyUpdateApplied(uint32_t version) override;

// Get image update progress in percents unit
Expand Down Expand Up @@ -230,7 +230,7 @@ class OTARequestor : public OTARequestorInterface, public BDXDownloader::StateDe
enum OnConnectedAction
{
kQueryImage = 0,
kStartBDX,
kDownload,
kApplyUpdate,
kNotifyUpdateApplied,
};
Expand Down
4 changes: 2 additions & 2 deletions src/include/platform/OTARequestorInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -182,10 +182,10 @@ class OTARequestorInterface
// Download image
virtual void DownloadUpdate() = 0;

// Send ApplyImage command
// Initiate the session to send ApplyUpdateRequest command
virtual void ApplyUpdate() = 0;

// Send NotifyUpdateApplied command
// Initiate the session to send NotifyUpdateApplied command
virtual void NotifyUpdateApplied(uint32_t version) = 0;

// Get image update progress in percents unit
Expand Down

0 comments on commit 1065020

Please sign in to comment.