diff --git a/examples/microwave-oven-app/microwave-oven-common/include/microwave-oven-device.h b/examples/microwave-oven-app/microwave-oven-common/include/microwave-oven-device.h index 9b563e886a1d19..9e053283f69719 100644 --- a/examples/microwave-oven-app/microwave-oven-common/include/microwave-oven-device.h +++ b/examples/microwave-oven-app/microwave-oven-common/include/microwave-oven-device.h @@ -102,13 +102,13 @@ class ExampleMicrowaveOvenDevice : public MicrowaveOvenControl::Delegate, public /** * handle command for microwave oven control: set cooking parameters */ - Protocols::InteractionModel::Status HandleSetCookingParametersCallback(uint8_t cookMode, uint32_t cookTime, + Protocols::InteractionModel::Status HandleSetCookingParametersCallback(Optional cookMode, uint32_t cookTime, uint8_t powerSetting) override; /** * handle command for microwave oven control: add more time */ - Protocols::InteractionModel::Status HandleSetCookTimeCallback(uint32_t finalCookTime) override; + Protocols::InteractionModel::Status HandleModifyCookTimeCallback(uint32_t finalCookTime) override; /** * Get the value of MinPower. diff --git a/examples/microwave-oven-app/microwave-oven-common/src/microwave-oven-device.cpp b/examples/microwave-oven-app/microwave-oven-common/src/microwave-oven-device.cpp index cacd0b5d1fa0a5..3521dd1843b056 100644 --- a/examples/microwave-oven-app/microwave-oven-common/src/microwave-oven-device.cpp +++ b/examples/microwave-oven-app/microwave-oven-common/src/microwave-oven-device.cpp @@ -42,11 +42,21 @@ void ExampleMicrowaveOvenDevice::MicrowaveOvenInit(EndpointId aEndpoint) * MicrowaveOvenControl cluster */ Protocols::InteractionModel::Status -ExampleMicrowaveOvenDevice::HandleSetCookingParametersCallback(uint8_t cookMode, uint32_t cookTime, uint8_t powerSetting) +ExampleMicrowaveOvenDevice::HandleSetCookingParametersCallback(Optional cookMode, uint32_t cookTime, uint8_t powerSetting) { // placeholder implementation Status status; - if((status = mMicrowaveOvenModeInstance.UpdateCurrentMode(cookMode)) != Status::Success) + uint8_t reqCookMode; + if(cookMode.HasValue()){ + reqCookMode = cookMode.Value(); + } + else + { + // set Microwave Oven cooking mode to normal mode(default). + reqCookMode = ModeNormal; + } + + if((status = mMicrowaveOvenModeInstance.UpdateCurrentMode(reqCookMode)) != Status::Success) { return status; } @@ -55,7 +65,7 @@ ExampleMicrowaveOvenDevice::HandleSetCookingParametersCallback(uint8_t cookMode, return Status::Success; } -Protocols::InteractionModel::Status ExampleMicrowaveOvenDevice::HandleSetCookTimeCallback(uint32_t finalCookTime) +Protocols::InteractionModel::Status ExampleMicrowaveOvenDevice::HandleModifyCookTimeCallback(uint32_t finalCookTime) { // placeholder implementation mMicrowaveOvenControlInstance.SetCookTime(finalCookTime); diff --git a/src/app/clusters/microwave-oven-control-server/microwave-oven-control-server.cpp b/src/app/clusters/microwave-oven-control-server/microwave-oven-control-server.cpp index deaf66f191999d..ca8d7eae2aa8cb 100644 --- a/src/app/clusters/microwave-oven-control-server/microwave-oven-control-server.cpp +++ b/src/app/clusters/microwave-oven-control-server/microwave-oven-control-server.cpp @@ -61,7 +61,16 @@ CHIP_ERROR Instance::Init() ChipLogError(Zcl, "Microwave Oven Control: The cluster with ID %lu was not enabled in zap.", long(mClusterId)); return CHIP_ERROR_INVALID_ARGUMENT; } - + if(!mOpStateInstance) + { + ChipLogError(Zcl, "Microwave Oven Control: Operational State instance is NULL"); + return CHIP_ERROR_INVALID_ARGUMENT; + } + if(!mMicrowaveOvenModeInstance) + { + ChipLogError(Zcl, "Microwave Oven Control: Microwave Oven Mode instance is NULL"); + return CHIP_ERROR_INVALID_ARGUMENT; + } ReturnErrorOnFailure(InteractionModelEngine::GetInstance()->RegisterCommandHandler(this)); VerifyOrReturnError(registerAttributeAccessOverride(this), CHIP_ERROR_INCORRECT_STATE); @@ -183,23 +192,18 @@ void Instance::HandleSetCookingParameters(HandlerContext & ctx, const Commands:: ChipLogError(Zcl, "Failed to set cookPower, cookPower value is out of range"); goto exit; } - + //get current operational state opState = mOpStateInstance->GetCurrentOperationalState(); - if (opState == to_underlying(OperationalStateEnum::kStopped)) + if(opState != to_underlying(OperationalStateEnum::kStopped)) + { + status = Status::InvalidInState; + goto exit; + } + else { - uint8_t reqCookMode = 0; uint32_t reqCookTime = 0; uint8_t reqPowerSetting = 0; - if (cookMode.HasValue()) - { - reqCookMode = cookMode.Value(); - } - else - { - // set Microwave Oven cooking mode to normal mode(default). - reqCookMode = Clusters::ModeNormal; - } if (cookTime.HasValue()) { @@ -220,13 +224,7 @@ void Instance::HandleSetCookingParameters(HandlerContext & ctx, const Commands:: // set Microwave Oven cooking power to max power(default). reqPowerSetting = mDelegate->GetMaxPower(); } - status = mDelegate->HandleSetCookingParametersCallback(reqCookMode, reqCookTime, reqPowerSetting); - goto exit; - } - else - { - status = Status::InvalidInState; - goto exit; + status = mDelegate->HandleSetCookingParametersCallback(cookMode, reqCookTime, reqPowerSetting); } exit: @@ -250,7 +248,7 @@ void Instance::HandleAddMoreTime(HandlerContext & ctx, const Commands::AddMoreTi // if the added cooking time is greater than the max cooking time, the cooking time stay unchanged. if (finalCookTime < kMaxCookTime) { - status = mDelegate->HandleSetCookTimeCallback(finalCookTime); + status = mDelegate->HandleModifyCookTimeCallback(finalCookTime); goto exit; } else @@ -260,7 +258,7 @@ void Instance::HandleAddMoreTime(HandlerContext & ctx, const Commands::AddMoreTi goto exit; } } - else // operational state is in error + else // operational state is 'Error' { status = Status::InvalidInState; goto exit; diff --git a/src/app/clusters/microwave-oven-control-server/microwave-oven-control-server.h b/src/app/clusters/microwave-oven-control-server/microwave-oven-control-server.h index f0920cd9ecea7f..a440c72b6a5902 100644 --- a/src/app/clusters/microwave-oven-control-server/microwave-oven-control-server.h +++ b/src/app/clusters/microwave-oven-control-server/microwave-oven-control-server.h @@ -81,11 +81,11 @@ class Instance : public CommandHandlerInterface, public AttributeAccessInterface /** * Operational State instance */ - Clusters::OperationalState::Instance * mOpStateInstance; + Clusters::OperationalState::Instance * mOpStateInstance = nullptr; /** * Microwave Oven Mode instance */ - Clusters::ModeBase::Instance * mMicrowaveOvenModeInstance; + Clusters::ModeBase::Instance * mMicrowaveOvenModeInstance = nullptr; /** * set default values @@ -130,15 +130,19 @@ class Delegate /** * @brief Handle Command Callback in application: SetCookingParameters * @return Returns the Interaction Model status code which was user determined in the business logic + * @param cookMode: the user defined modes which from the Microwave Oven Mode application level + * @param cookTime: the input cook time value + * @param powerSetting: the input power setting value */ - virtual Protocols::InteractionModel::Status HandleSetCookingParametersCallback(uint8_t cookMode, uint32_t cookTime, + virtual Protocols::InteractionModel::Status HandleSetCookingParametersCallback(Optional cookMode, uint32_t cookTime, uint8_t powerSetting) = 0; /** * @brief Handle Command Callback in application: AddMoreTime * @return Returns the Interaction Model status code which was user determined in the business logic + * @param finalCookTime: the cook time value after adding input time */ - virtual Protocols::InteractionModel::Status HandleSetCookTimeCallback(uint32_t finalCookTime) = 0; + virtual Protocols::InteractionModel::Status HandleModifyCookTimeCallback(uint32_t finalCookTime) = 0; /** * @brief get the MinPower