Skip to content

Commit

Permalink
Convert all OTA related enums to enum class (#13312)
Browse files Browse the repository at this point in the history
  • Loading branch information
carol-apple authored and pull[bot] committed Oct 3, 2023
1 parent 4cec5d9 commit 1134172
Show file tree
Hide file tree
Showing 17 changed files with 211 additions and 297 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,8 @@ EmberAfStatus OTAProviderExample::HandleApplyUpdateRequest(chip::app::CommandHan
{
// TODO: handle multiple transfers by tracking updateTokens

EmberAfOTAApplyUpdateAction updateAction = EMBER_ZCL_OTA_APPLY_UPDATE_ACTION_PROCEED; // For now, just allow any update request
char tokenBuf[kUpdateTokenStrLen] = { 0 };
OTAApplyUpdateAction updateAction = OTAApplyUpdateAction::kProceed; // For now, just allow any update request
char tokenBuf[kUpdateTokenStrLen] = { 0 };

GetUpdateTokenString(commandData.updateToken, tokenBuf, kUpdateTokenStrLen);
ChipLogDetail(SoftwareUpdate, "%s: token: %s, version: %" PRIu32, __FUNCTION__, tokenBuf, commandData.newVersion);
Expand Down
2 changes: 1 addition & 1 deletion src/app/clusters/ota-provider/ota-provider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ bool emberAfOtaSoftwareUpdateProviderClusterQueryImageCallback(app::CommandHandl
auto protocolIter = protocolsSupported.begin();
while (protocolIter.Next())
{
ChipLogDetail(Zcl, " %" PRIu8, protocolIter.GetValue());
ChipLogDetail(Zcl, " %" PRIu8, to_underlying(protocolIter.GetValue()));
}
ChipLogDetail(Zcl, " ]");
if (hardwareVersion.HasValue())
Expand Down
39 changes: 20 additions & 19 deletions src/app/clusters/ota-requestor/OTARequestor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ namespace chip {
using namespace app::Clusters;
using namespace app::Clusters::OtaSoftwareUpdateProvider;
using namespace app::Clusters::OtaSoftwareUpdateProvider::Commands;
using namespace app::Clusters::OtaSoftwareUpdateRequestor;
using namespace app::Clusters::OtaSoftwareUpdateRequestor::Commands;
using bdx::TransferSession;

Expand Down Expand Up @@ -118,7 +119,7 @@ void OTARequestor::OnQueryImageResponse(void * context, const QueryImageResponse

if (err != CHIP_NO_ERROR)
{
requestorCore->mOtaRequestorDriver->HandleError(UpdateStateEnum::Querying, err);
requestorCore->mOtaRequestorDriver->HandleError(OTAUpdateStateEnum::kQuerying, err);
return;
}

Expand All @@ -140,7 +141,7 @@ void OTARequestor::OnQueryImageResponse(void * context, const QueryImageResponse
System::Clock::Seconds32(response.delayedActionTime.ValueOr(0)));
break;
default:
requestorCore->mOtaRequestorDriver->HandleError(UpdateStateEnum::Querying, CHIP_ERROR_BAD_REQUEST);
requestorCore->mOtaRequestorDriver->HandleError(OTAUpdateStateEnum::kQuerying, CHIP_ERROR_BAD_REQUEST);
break;
}
}
Expand All @@ -151,7 +152,7 @@ void OTARequestor::OnQueryImageFailure(void * context, EmberAfStatus status)
VerifyOrDie(requestorCore != nullptr);

ChipLogDetail(SoftwareUpdate, "QueryImage failure response %" PRIu8, status);
requestorCore->mOtaRequestorDriver->HandleError(UpdateStateEnum::Querying, CHIP_ERROR_BAD_REQUEST);
requestorCore->mOtaRequestorDriver->HandleError(OTAUpdateStateEnum::kQuerying, CHIP_ERROR_BAD_REQUEST);
}

void OTARequestor::OnApplyUpdateResponse(void * context, const ApplyUpdateResponse::DecodableType & response)
Expand All @@ -163,13 +164,13 @@ void OTARequestor::OnApplyUpdateResponse(void * context, const ApplyUpdateRespon

switch (response.action)
{
case EMBER_ZCL_OTA_APPLY_UPDATE_ACTION_PROCEED:
case OTAApplyUpdateAction::kProceed:
requestorCore->mOtaRequestorDriver->UpdateConfirmed(System::Clock::Seconds32(response.delayedActionTime));
break;
case EMBER_ZCL_OTA_APPLY_UPDATE_ACTION_AWAIT_NEXT_ACTION:
case OTAApplyUpdateAction::kAwaitNextAction:
requestorCore->mOtaRequestorDriver->UpdateSuspended(System::Clock::Seconds32(response.delayedActionTime));
break;
case EMBER_ZCL_OTA_APPLY_UPDATE_ACTION_DISCONTINUE:
case OTAApplyUpdateAction::kDiscontinue:
requestorCore->mOtaRequestorDriver->UpdateDiscontinued();
break;
}
Expand All @@ -181,7 +182,7 @@ void OTARequestor::OnApplyUpdateFailure(void * context, EmberAfStatus status)
VerifyOrDie(requestorCore != nullptr);

ChipLogDetail(SoftwareUpdate, "ApplyUpdate failure response %" PRIu8, status);
requestorCore->mOtaRequestorDriver->HandleError(UpdateStateEnum::Applying, CHIP_ERROR_BAD_REQUEST);
requestorCore->mOtaRequestorDriver->HandleError(OTAUpdateStateEnum::kApplying, CHIP_ERROR_BAD_REQUEST);
}

EmberAfStatus OTARequestor::HandleAnnounceOTAProvider(app::CommandHandler * commandObj,
Expand All @@ -206,7 +207,7 @@ EmberAfStatus OTARequestor::HandleAnnounceOTAProvider(app::CommandHandler * comm
ChipLogDetail(SoftwareUpdate, " FabricIndex: %" PRIu8, mProviderFabricIndex);
ChipLogDetail(SoftwareUpdate, " ProviderNodeID: 0x" ChipLogFormatX64, ChipLogValueX64(mProviderNodeId));
ChipLogDetail(SoftwareUpdate, " VendorID: 0x%" PRIx16, commandData.vendorId);
ChipLogDetail(SoftwareUpdate, " AnnouncementReason: %" PRIu8, announcementReason);
ChipLogDetail(SoftwareUpdate, " AnnouncementReason: %" PRIu8, to_underlying(announcementReason));
if (commandData.metadataForNode.HasValue())
{
ChipLogDetail(SoftwareUpdate, " MetadataForNode: %zu", commandData.metadataForNode.Value().size());
Expand All @@ -218,11 +219,11 @@ EmberAfStatus OTARequestor::HandleAnnounceOTAProvider(app::CommandHandler * comm
uint32_t msToStart = 0;
switch (announcementReason)
{
case static_cast<uint8_t>(EMBER_ZCL_OTA_ANNOUNCEMENT_REASON_SIMPLE_ANNOUNCEMENT):
case static_cast<uint8_t>(EMBER_ZCL_OTA_ANNOUNCEMENT_REASON_UPDATE_AVAILABLE):
case OTAAnnouncementReason::kSimpleAnnouncement:
case OTAAnnouncementReason::kUpdateAvailable:
msToStart = mOtaStartDelayMs;
break;
case static_cast<uint8_t>(EMBER_ZCL_OTA_ANNOUNCEMENT_REASON_URGENT_UPDATE_AVAILABLE):
case OTAAnnouncementReason::kUrgentUpdateAvailable:
msToStart = kImmediateStartDelayMs;
break;
default:
Expand Down Expand Up @@ -269,7 +270,7 @@ void OTARequestor::OnConnected(void * context, OperationalDeviceProxy * devicePr
if (err != CHIP_NO_ERROR)
{
ChipLogError(SoftwareUpdate, "Failed to send QueryImage command: %" CHIP_ERROR_FORMAT, err.Format());
requestorCore->mOtaRequestorDriver->HandleError(UpdateStateEnum::Querying, err);
requestorCore->mOtaRequestorDriver->HandleError(OTAUpdateStateEnum::kQuerying, err);
}

break;
Expand All @@ -280,7 +281,7 @@ void OTARequestor::OnConnected(void * context, OperationalDeviceProxy * devicePr
if (err != CHIP_NO_ERROR)
{
ChipLogError(SoftwareUpdate, "Failed to start download: %" CHIP_ERROR_FORMAT, err.Format());
requestorCore->mOtaRequestorDriver->HandleError(UpdateStateEnum::Downloading, err);
requestorCore->mOtaRequestorDriver->HandleError(OTAUpdateStateEnum::kDownloading, err);
}

break;
Expand All @@ -291,7 +292,7 @@ void OTARequestor::OnConnected(void * context, OperationalDeviceProxy * devicePr
if (err != CHIP_NO_ERROR)
{
ChipLogError(SoftwareUpdate, "Failed to send ApplyUpdate command: %" CHIP_ERROR_FORMAT, err.Format());
requestorCore->mOtaRequestorDriver->HandleError(UpdateStateEnum::Applying, err);
requestorCore->mOtaRequestorDriver->HandleError(OTAUpdateStateEnum::kApplying, err);
}

break;
Expand Down Expand Up @@ -328,13 +329,13 @@ void OTARequestor::OnConnectionFailure(void * context, PeerId peerId, CHIP_ERROR
switch (requestorCore->mOnConnectedAction)
{
case kQueryImage:
requestorCore->mOtaRequestorDriver->HandleError(UpdateStateEnum::Querying, error);
requestorCore->mOtaRequestorDriver->HandleError(OTAUpdateStateEnum::kQuerying, error);
break;
case kStartBDX:
requestorCore->mOtaRequestorDriver->HandleError(UpdateStateEnum::Downloading, error);
requestorCore->mOtaRequestorDriver->HandleError(OTAUpdateStateEnum::kDownloading, error);
break;
case kApplyUpdate:
requestorCore->mOtaRequestorDriver->HandleError(UpdateStateEnum::Applying, error);
requestorCore->mOtaRequestorDriver->HandleError(OTAUpdateStateEnum::kApplying, error);
break;
default:
break;
Expand All @@ -361,7 +362,7 @@ void OTARequestor::OnDownloadStateChanged(OTADownloader::State state)
mOtaRequestorDriver->UpdateDownloaded();
break;
case OTADownloader::State::kIdle:
mOtaRequestorDriver->HandleError(UpdateStateEnum::Downloading, CHIP_ERROR_CONNECTION_ABORTED);
mOtaRequestorDriver->HandleError(OTAUpdateStateEnum::kDownloading, CHIP_ERROR_CONNECTION_ABORTED);
break;
default:
break;
Expand All @@ -370,7 +371,7 @@ void OTARequestor::OnDownloadStateChanged(OTADownloader::State state)

CHIP_ERROR OTARequestor::SendQueryImageRequest(OperationalDeviceProxy & deviceProxy)
{
constexpr EmberAfOTADownloadProtocol kProtocolsSupported[] = { EMBER_ZCL_OTA_DOWNLOAD_PROTOCOL_BDX_SYNCHRONOUS };
constexpr OTADownloadProtocol kProtocolsSupported[] = { OTADownloadProtocol::kBDXSynchronous };
QueryImage::Type args;

uint16_t vendorId;
Expand Down
5 changes: 0 additions & 5 deletions src/app/zap-templates/templates/app/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -615,7 +615,6 @@ function isWeaklyTypedEnum(label)
"BarrierControlBarrierPosition",
"BarrierControlMovingState",
"BootReasonType",
"ChangeReasonEnum",
"ColorControlOptions",
"ColorLoopAction",
"ColorLoopDirection",
Expand Down Expand Up @@ -648,9 +647,6 @@ function isWeaklyTypedEnum(label)
"MoveMode",
"NetworkFaultType",
"NodeOperationalCertStatus",
"OTAAnnouncementReason",
"OTAApplyUpdateAction",
"OTADownloadProtocol",
"OnOffDelayedAllOffEffectVariant",
"OnOffDyingLightEffectVariant",
"OnOffEffectIdentifier",
Expand All @@ -669,7 +665,6 @@ function isWeaklyTypedEnum(label)
"ThermostatControlSequence",
"ThermostatRunningMode",
"ThermostatSystemMode",
"UpdateStateEnum",
"WcEndProductType",
"WcType",
"WiFiVersionType",
Expand Down
12 changes: 6 additions & 6 deletions src/app/zap-templates/zcl/data-model/chip/chip-ota.xml
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ limitations under the License.
<item name="UpdateAvailable" value="0x1"/>
<item name="UrgentUpdateAvailable" value="0x2"/>
</enum>
<enum name="UpdateStateEnum" type="ENUM8">
<enum name="OTAUpdateStateEnum" type="ENUM8">
<cluster code="0x002a"/>
<item name="Unknown" value="0x0"/>
<item name="Idle" value="0x1"/>
Expand All @@ -100,7 +100,7 @@ limitations under the License.
<item name="RollingBack" value="0x7"/>
<item name="DelayedOnUserConsent" value="0x8"/>
</enum>
<enum name="ChangeReasonEnum" type="ENUM8">
<enum name="OTAChangeReasonEnum" type="ENUM8">
<cluster code="0x002a"/>
<item name="Unknown" value="0x0"/>
<item name="Success" value="0x1"/>
Expand All @@ -124,7 +124,7 @@ limitations under the License.
<server tick="false" init="false">true</server>
<attribute side="server" code="0x0000" define="DEFAULT_OTA_PROVIDERS" type="ARRAY" entryType="ProviderLocation" writable="true" optional="false">DefaultOtaProviders</attribute>
<attribute side="server" code="0x0001" define="UPDATE_POSSIBLE" type="BOOLEAN" default="true" writable="false" optional="false">UpdatePossible</attribute>
<attribute side="server" code="0x0002" define="UPDATE_STATE" type="UpdateStateEnum" default="Unknown" writable="false" optional="false">UpdateState</attribute>
<attribute side="server" code="0x0002" define="UPDATE_STATE" type="OTAUpdateStateEnum" default="Unknown" writable="false" optional="false">UpdateState</attribute>
<attribute side="server" code="0x0003" define="UPDATE_STATE_PROGRESS" type="INT8U" min="0" max="100" writable="false" isNullable="true" optional="false">UpdateStateProgress</attribute>
<command source="client" code="0x00" name="AnnounceOtaProvider" optional="true" cli="chip ota announceotaprovider">
<description>Announce the presence of an OTA Provider</description>
Expand All @@ -136,9 +136,9 @@ limitations under the License.
</command>
<event side="server" code="0x00" name="StateTransition" priority="info" optional="false">
<description>This event SHALL be generated when a change of the UpdateState attribute occurs due to an OTA Requestor moving through the states necessary to query for updates.</description>
<field id="0" name="PreviousState" type="UpdateStateEnum" isNullable="true"/>
<field id="1" name="NewState" type="UpdateStateEnum"/>
<field id="2" name="Reason" type="ChangeReasonEnum"/>
<field id="0" name="PreviousState" type="OTAUpdateStateEnum" isNullable="true"/>
<field id="1" name="NewState" type="OTAUpdateStateEnum"/>
<field id="2" name="Reason" type="OTAChangeReasonEnum"/>
<field id="3" name="TargetSoftwareVersion" type="INT32U" isNullable="true"/>
</event>
<event side="server" code="0x01" name="VersionApplied" priority="critical" optional="false">
Expand Down
34 changes: 17 additions & 17 deletions src/controller/python/chip/clusters/Objects.py

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

0 comments on commit 1134172

Please sign in to comment.