Skip to content

Commit

Permalink
Keep supporting query behaviour option and set DelayedActionTime in Busy
Browse files Browse the repository at this point in the history
and NotAvailable Case
  • Loading branch information
shubhamdp committed Feb 2, 2022
1 parent ee22f87 commit 3257434
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 41 deletions.
2 changes: 1 addition & 1 deletion examples/ota-provider-app/linux/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ constexpr uint16_t kOptionQueryImageBehavior = 'q';
constexpr uint16_t kOptionDelayedActionTimeSec = 'd';

// Global variables used for passing the CLI arguments to the OTAProviderExample object
static OTAProviderExample::QueryImageBehaviorType gQueryImageBehavior = OTAProviderExample::kRespondWithUpdateAvailable;
static OTAProviderExample::QueryImageBehaviorType gQueryImageBehavior = OTAProviderExample::kRespondWithUnknown;
static uint32_t gDelayedActionTimeSec = 0;
static const char * gOtaFilepath = nullptr;
static const char * gOtaImageListFilepath = nullptr;
Expand Down
102 changes: 62 additions & 40 deletions examples/ota-provider-app/ota-provider-common/OTAProviderExample.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,63 +138,85 @@ EmberAfStatus OTAProviderExample::HandleQueryImage(chip::app::CommandHandler * c
const chip::app::ConcreteCommandPath & commandPath,
const QueryImage::DecodableType & commandData)
{
ChipLogDetail(SoftwareUpdate, "Requestor endpoint:%" PRIu16 " node-id:0x" ChipLogFormatX64, commandPath.mEndpointId,
ChipLogValueX64(commandObj->SourceNodeId()));

OTAQueryStatus queryStatus = OTAQueryStatus::kNotAvailable;
OTAProviderExample::DeviceSoftwareVersionModel candidate;
bool otaAvailable = false;
uint32_t newSoftwareVersion = 0;
const char * newSoftwareVersionString = nullptr;
const char * otaFilePath = nullptr;
uint8_t updateToken[kUpdateTokenLen] = { 0 };
char strBuf[kUpdateTokenStrLen] = { 0 };
char uriBuf[kUriMaxLen] = { 0 };
bool userConsentNeeded = commandData.requestorCanConsent.ValueOr(false);
uint32_t delayedActionTimeSec = mDelayedActionTimeSec;
bool requestorCanConsent = commandData.requestorCanConsent.ValueOr(false);
QueryImageResponse::Type response;

// This use-case is a subset of the ota-candidates-file option.
// Can be removed once all other platforms (ESP, etc.)
// start using the ota-candidates-file method.
if (strlen(mOTAFilePath)) // If OTA file is directly provided
{
otaAvailable = true;
newSoftwareVersion = commandData.softwareVersion + 1; // This implementation will always indicate that an update is
// available (if the user provides a file).
newSoftwareVersionString = "Example-Image-V0.1";
otaFilePath = mOTAFilePath;
queryStatus = OTAQueryStatus::kUpdateAvailable;
}
else if (!mCandidates.empty()) // If list of OTA candidates is supplied instead
switch (mQueryImageBehavior)
{
otaAvailable = SelectOTACandidate(commandData.vendorId, commandData.productId, commandData.softwareVersion, candidate);
if (otaAvailable)
case kRespondWithUnknown:
// This use-case is a subset of the ota-candidates-file option.
// Can be removed once all other platforms (ESP, etc.)
// start using the ota-candidates-file method.
if (strlen(mOTAFilePath)) // If OTA file is directly provided
{
newSoftwareVersion = candidate.softwareVersion;
newSoftwareVersionString = candidate.softwareVersionString;
otaFilePath = candidate.otaURL;
newSoftwareVersion = commandData.softwareVersion + 1; // This implementation will always indicate that an update is
// available (if the user provides a file).
newSoftwareVersionString = "Example-Image-V0.1";
otaFilePath = mOTAFilePath;
queryStatus = OTAQueryStatus::kUpdateAvailable;
}
}

if (queryStatus == OTAQueryStatus::kUpdateAvailable && mUserConsentDelegate != nullptr)
{
UserConsentState state = mUserConsentDelegate->GetUserConsentState(commandObj->SourceNodeId(), commandPath.mEndpointId,
commandData.softwareVersion, newSoftwareVersion);
switch (state)
else if (!mCandidates.empty()) // If list of OTA candidates is supplied instead
{
case UserConsentState::kGranted:
queryStatus = OTAQueryStatus::kUpdateAvailable;
break;
if (SelectOTACandidate(commandData.vendorId, commandData.productId, commandData.softwareVersion, candidate))
{
newSoftwareVersion = candidate.softwareVersion;
newSoftwareVersionString = candidate.softwareVersionString;
otaFilePath = candidate.otaURL;
queryStatus = OTAQueryStatus::kUpdateAvailable;
}
}

case chip::ota::UserConsentState::kObtaining:
queryStatus = OTAQueryStatus::kBusy;
break;

case chip::ota::UserConsentState::kDenied:
queryStatus = OTAQueryStatus::kNotAvailable;
break;
if (queryStatus == OTAQueryStatus::kUpdateAvailable && mUserConsentDelegate != nullptr)
{
UserConsentState state = mUserConsentDelegate->GetUserConsentState(commandObj->SourceNodeId(), commandPath.mEndpointId,
commandData.softwareVersion, newSoftwareVersion);
switch (state)
{
case UserConsentState::kGranted:
queryStatus = OTAQueryStatus::kUpdateAvailable;
break;

case chip::ota::UserConsentState::kObtaining:
queryStatus = OTAQueryStatus::kBusy;
delayedActionTimeSec = (delayedActionTimeSec < 120) ? 120 : delayedActionTimeSec;
break;

case chip::ota::UserConsentState::kDenied:
queryStatus = OTAQueryStatus::kNotAvailable;
delayedActionTimeSec = (delayedActionTimeSec < 120) ? 120 : delayedActionTimeSec;
break;
}
}
break;

case kRespondWithUpdateAvailable:
queryStatus = OTAQueryStatus::kUpdateAvailable;
break;

case kRespondWithBusy:
queryStatus = OTAQueryStatus::kBusy;
delayedActionTimeSec = (delayedActionTimeSec < 120) ? 120 : delayedActionTimeSec;
break;

case kRespondWithNotAvailable:
queryStatus = OTAQueryStatus::kNotAvailable;
delayedActionTimeSec = (delayedActionTimeSec < 120) ? 120 : delayedActionTimeSec;
break;

default:
queryStatus = OTAQueryStatus::kNotAvailable;
delayedActionTimeSec = (delayedActionTimeSec < 120) ? 120 : delayedActionTimeSec;
break;
}

if (queryStatus == OTAQueryStatus::kUpdateAvailable)
Expand Down Expand Up @@ -233,7 +255,7 @@ EmberAfStatus OTAProviderExample::HandleQueryImage(chip::app::CommandHandler * c
}

response.status = queryStatus;
response.delayedActionTime.Emplace(mDelayedActionTimeSec);
response.delayedActionTime.Emplace(delayedActionTimeSec);
response.userConsentNeeded.Emplace(requestorCanConsent);
// Could also just not send metadataForRequestor at all.
response.metadataForRequestor.Emplace(chip::ByteSpan());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class OTAProviderExample : public chip::app::Clusters::OTAProviderDelegate

enum QueryImageBehaviorType
{
kRespondWithUnknown,
kRespondWithUpdateAvailable,
kRespondWithBusy,
kRespondWithNotAvailable
Expand Down

0 comments on commit 3257434

Please sign in to comment.