Skip to content

Commit

Permalink
Convert OTAQueryStatus to an enum class (#12918)
Browse files Browse the repository at this point in the history
  • Loading branch information
carol-apple authored Dec 11, 2021
1 parent 03c6902 commit fce9c87
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ using chip::Optional;
using chip::Server;
using chip::Span;
using chip::app::Clusters::OTAProviderDelegate;
using namespace chip::app::Clusters::OtaSoftwareUpdateProvider;
using namespace chip::app::Clusters::OtaSoftwareUpdateProvider::Commands;

constexpr uint8_t kUpdateTokenLen = 32; // must be between 8 and 32
Expand Down Expand Up @@ -89,7 +90,7 @@ EmberAfStatus OTAProviderExample::HandleQueryImage(chip::app::CommandHandler * c
{
// TODO: add confiuration for returning BUSY status

EmberAfOTAQueryStatus queryStatus = EMBER_ZCL_OTA_QUERY_STATUS_NOT_AVAILABLE;
OTAQueryStatus queryStatus = OTAQueryStatus::kNotAvailable;
uint32_t newSoftwareVersion = commandData.softwareVersion + 1; // This implementation will always indicate that an update is
// available (if the user provides a file).
constexpr char kExampleSoftwareString[] = "Example-Image-V0.1";
Expand Down Expand Up @@ -122,25 +123,25 @@ EmberAfStatus OTAProviderExample::HandleQueryImage(chip::app::CommandHandler * c
case kRespondWithUpdateAvailable: {
if (strlen(mOTAFilePath) != 0)
{
queryStatus = EMBER_ZCL_OTA_QUERY_STATUS_UPDATE_AVAILABLE;
queryStatus = OTAQueryStatus::kUpdateAvailable;
}
else
{
queryStatus = EMBER_ZCL_OTA_QUERY_STATUS_NOT_AVAILABLE;
queryStatus = OTAQueryStatus::kNotAvailable;
ChipLogError(SoftwareUpdate, "No OTA file configured on the Provider");
}
break;
}
case kRespondWithBusy: {
queryStatus = EMBER_ZCL_OTA_QUERY_STATUS_BUSY;
queryStatus = OTAQueryStatus::kBusy;
break;
}
case kRespondWithNotAvailable: {
queryStatus = EMBER_ZCL_OTA_QUERY_STATUS_NOT_AVAILABLE;
queryStatus = OTAQueryStatus::kNotAvailable;
break;
}
default:
queryStatus = EMBER_ZCL_OTA_QUERY_STATUS_NOT_AVAILABLE;
queryStatus = OTAQueryStatus::kNotAvailable;
}

QueryImageResponse::Type response;
Expand Down
11 changes: 6 additions & 5 deletions src/app/clusters/ota-requestor/OTARequestor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
namespace chip {

using namespace app::Clusters;
using namespace app::Clusters::OtaSoftwareUpdateProvider;
using namespace app::Clusters::OtaSoftwareUpdateProvider::Commands;
using namespace app::Clusters::OtaSoftwareUpdateRequestor::Commands;
using bdx::TransferSession;
Expand All @@ -45,7 +46,7 @@ constexpr uint32_t kImmediateStartDelayMs = 1; // Start the timer with this valu
static void LogQueryImageResponse(const QueryImageResponse::DecodableType & response)
{
ChipLogDetail(SoftwareUpdate, "QueryImageResponse:");
ChipLogDetail(SoftwareUpdate, " status: %" PRIu8 "", response.status);
ChipLogDetail(SoftwareUpdate, " status: %" PRIu8 "", to_underlying(response.status));
if (response.delayedActionTime.HasValue())
{
ChipLogDetail(SoftwareUpdate, " delayedActionTime: %" PRIu32 " seconds", response.delayedActionTime.Value());
Expand Down Expand Up @@ -114,7 +115,7 @@ void OTARequestor::OnQueryImageResponse(void * context, const QueryImageResponse

switch (response.status)
{
case EMBER_ZCL_OTA_QUERY_STATUS_UPDATE_AVAILABLE: {
case OTAQueryStatus::kUpdateAvailable: {
// Parse out the provider node ID and file designator from the image URI
NodeId nodeId = kUndefinedNodeId;
CharSpan fileDesignator;
Expand All @@ -135,9 +136,9 @@ void OTARequestor::OnQueryImageResponse(void * context, const QueryImageResponse
requestorCore->ConnectToProvider(kStartBDX);
break;
}
case EMBER_ZCL_OTA_QUERY_STATUS_BUSY:
case OTAQueryStatus::kBusy:
break;
case EMBER_ZCL_OTA_QUERY_STATUS_NOT_AVAILABLE:
case OTAQueryStatus::kNotAvailable:
break;
// TODO: Add download protocol not supported
// Issue #9524 should handle all response status appropriately
Expand Down Expand Up @@ -437,7 +438,7 @@ CHIP_ERROR OTARequestor::BuildQueryImageRequest(QueryImageRequest & request)

bool OTARequestor::ValidateQueryImageResponse(const QueryImageResponse::DecodableType & response) const
{
if (response.status == EMBER_ZCL_OTA_QUERY_STATUS_UPDATE_AVAILABLE)
if (response.status == OTAQueryStatus::kUpdateAvailable)
{
VerifyOrReturnError(response.imageURI.HasValue(), false);
VerifyOrReturnError(response.softwareVersion.HasValue() && response.softwareVersionString.HasValue(), false);
Expand Down
1 change: 0 additions & 1 deletion src/app/zap-templates/templates/app/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -658,7 +658,6 @@ function isWeaklyTypedEnum(label)
"OTAAnnouncementReason",
"OTAApplyUpdateAction",
"OTADownloadProtocol",
"OTAQueryStatus",
"OnOffDelayedAllOffEffectVariant",
"OnOffDyingLightEffectVariant",
"OnOffEffectIdentifier",
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 0 additions & 8 deletions zzz_generated/app-common/app-common/zap-generated/enums.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit fce9c87

Please sign in to comment.