Skip to content

Commit

Permalink
[OTA] Make PreviousState of StateTransition event non-nullable (#15439)
Browse files Browse the repository at this point in the history
  • Loading branch information
carol-apple authored Feb 23, 2022
1 parent 8a9e023 commit 76fb87d
Show file tree
Hide file tree
Showing 12 changed files with 23 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2198,7 +2198,7 @@ server cluster OtaSoftwareUpdateRequestor = 42 {
}

info event StateTransition = 0 {
nullable OTAUpdateStateEnum previousState = 0;
OTAUpdateStateEnum previousState = 0;
OTAUpdateStateEnum newState = 1;
OTAChangeReasonEnum reason = 2;
nullable INT32U targetSoftwareVersion = 3;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -947,7 +947,7 @@ server cluster OtaSoftwareUpdateRequestor = 42 {
}

info event StateTransition = 0 {
nullable OTAUpdateStateEnum previousState = 0;
OTAUpdateStateEnum previousState = 0;
OTAUpdateStateEnum newState = 1;
OTAChangeReasonEnum reason = 2;
nullable INT32U targetSoftwareVersion = 3;
Expand Down
2 changes: 1 addition & 1 deletion examples/lighting-app/lighting-common/lighting-app.matter
Original file line number Diff line number Diff line change
Expand Up @@ -1104,7 +1104,7 @@ server cluster OtaSoftwareUpdateRequestor = 42 {
}

info event StateTransition = 0 {
nullable OTAUpdateStateEnum previousState = 0;
OTAUpdateStateEnum previousState = 0;
OTAUpdateStateEnum newState = 1;
OTAChangeReasonEnum reason = 2;
nullable INT32U targetSoftwareVersion = 3;
Expand Down
2 changes: 1 addition & 1 deletion examples/lock-app/lock-common/lock-app.matter
Original file line number Diff line number Diff line change
Expand Up @@ -597,7 +597,7 @@ server cluster OtaSoftwareUpdateRequestor = 42 {
}

info event StateTransition = 0 {
nullable OTAUpdateStateEnum previousState = 0;
OTAUpdateStateEnum previousState = 0;
OTAUpdateStateEnum newState = 1;
OTAChangeReasonEnum reason = 2;
nullable INT32U targetSoftwareVersion = 3;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ server cluster OtaSoftwareUpdateRequestor = 42 {
}

info event StateTransition = 0 {
nullable OTAUpdateStateEnum previousState = 0;
OTAUpdateStateEnum previousState = 0;
OTAUpdateStateEnum newState = 1;
OTAChangeReasonEnum reason = 2;
nullable INT32U targetSoftwareVersion = 3;
Expand Down
4 changes: 1 addition & 3 deletions src/app/clusters/ota-requestor/OTARequestor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -555,15 +555,13 @@ void OTARequestor::RecordNewUpdateState(OTAUpdateStateEnum newState, OTAChangeRe
}

// Log the StateTransition event
Nullable<OTAUpdateStateEnum> previousState;
previousState.SetNonNull(mCurrentUpdateState);
Nullable<uint32_t> targetSoftwareVersion;
if ((newState == OTAUpdateStateEnum::kDownloading) || (newState == OTAUpdateStateEnum::kApplying) ||
(newState == OTAUpdateStateEnum::kRollingBack))
{
targetSoftwareVersion.SetNonNull(mTargetVersion);
}
OtaRequestorServerOnStateTransition(previousState, newState, reason, targetSoftwareVersion);
OtaRequestorServerOnStateTransition(mCurrentUpdateState, newState, reason, targetSoftwareVersion);

mCurrentUpdateState = newState;

Expand Down
6 changes: 3 additions & 3 deletions src/app/clusters/ota-requestor/ota-requestor-server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,10 +195,10 @@ EmberAfStatus OtaRequestorServerGetUpdateStateProgress(chip::EndpointId endpoint
return Attributes::UpdateStateProgress::Get(endpointId, value);
}

void OtaRequestorServerOnStateTransition(DataModel::Nullable<OTAUpdateStateEnum> previousState, OTAUpdateStateEnum newState,
OTAChangeReasonEnum reason, DataModel::Nullable<uint32_t> const & targetSoftwareVersion)
void OtaRequestorServerOnStateTransition(OTAUpdateStateEnum previousState, OTAUpdateStateEnum newState, OTAChangeReasonEnum reason,
DataModel::Nullable<uint32_t> const & targetSoftwareVersion)
{
if (!previousState.IsNull() && previousState.Value() == newState)
if (previousState == newState)
{
ChipLogError(Zcl, "Previous state and new state are the same, no event to log");
return;
Expand Down
9 changes: 4 additions & 5 deletions src/app/clusters/ota-requestor/ota-requestor-server.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,10 @@ EmberAfStatus OtaRequestorServerSetUpdateStateProgress(chip::app::DataModel::Nul
EmberAfStatus OtaRequestorServerGetUpdateStateProgress(chip::EndpointId endpointId,
chip::app::DataModel::Nullable<uint8_t> & value);

void OtaRequestorServerOnStateTransition(
chip::app::DataModel::Nullable<chip::app::Clusters::OtaSoftwareUpdateRequestor::OTAUpdateStateEnum> previousState,
chip::app::Clusters::OtaSoftwareUpdateRequestor::OTAUpdateStateEnum newState,
chip::app::Clusters::OtaSoftwareUpdateRequestor::OTAChangeReasonEnum reason,
chip::app::DataModel::Nullable<uint32_t> const & targetSoftwareVersion);
void OtaRequestorServerOnStateTransition(chip::app::Clusters::OtaSoftwareUpdateRequestor::OTAUpdateStateEnum previousState,
chip::app::Clusters::OtaSoftwareUpdateRequestor::OTAUpdateStateEnum newState,
chip::app::Clusters::OtaSoftwareUpdateRequestor::OTAChangeReasonEnum reason,
chip::app::DataModel::Nullable<uint32_t> const & targetSoftwareVersion);
void OtaRequestorServerOnVersionApplied(uint32_t softwareVersion, uint16_t productId);
void OtaRequestorServerOnDownloadError(uint32_t softwareVersion, uint64_t bytesDownloaded,
chip::app::DataModel::Nullable<uint8_t> progressPercent,
Expand Down
2 changes: 1 addition & 1 deletion src/app/zap-templates/zcl/data-model/chip/chip-ota.xml
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ 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="OTAUpdateStateEnum" isNullable="true"/>
<field id="0" name="PreviousState" type="OTAUpdateStateEnum"/>
<field id="1" name="NewState" type="OTAUpdateStateEnum"/>
<field id="2" name="Reason" type="OTAChangeReasonEnum"/>
<field id="3" name="TargetSoftwareVersion" type="INT32U" isNullable="true"/>
Expand Down
2 changes: 1 addition & 1 deletion src/controller/data_model/controller-clusters.matter
Original file line number Diff line number Diff line change
Expand Up @@ -2599,7 +2599,7 @@ client cluster OtaSoftwareUpdateRequestor = 42 {
}

info event StateTransition = 0 {
nullable OTAUpdateStateEnum previousState = 0;
OTAUpdateStateEnum previousState = 0;
OTAUpdateStateEnum newState = 1;
OTAChangeReasonEnum reason = 2;
nullable INT32U targetSoftwareVersion = 3;
Expand Down
4 changes: 2 additions & 2 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.

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

0 comments on commit 76fb87d

Please sign in to comment.