|
| 1 | +/* |
| 2 | + * |
| 3 | + * Copyright (c) 2023-2026 Project CHIP Authors |
| 4 | + * All rights reserved. |
| 5 | + * |
| 6 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | + * you may not use this file except in compliance with the License. |
| 8 | + * You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, software |
| 13 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | + * See the License for the specific language governing permissions and |
| 16 | + * limitations under the License. |
| 17 | + */ |
| 18 | + |
| 19 | +#pragma once |
| 20 | + |
| 21 | +#include <app-common/zap-generated/cluster-objects.h> |
| 22 | +#include <app/AttributeAccessInterface.h> |
| 23 | +#include <app/CommandHandlerInterface.h> |
| 24 | +#include <app/clusters/microwave-oven-control-server/Delegate.h> |
| 25 | +#include <app/clusters/mode-base-server/mode-base-server.h> |
| 26 | +#include <app/clusters/operational-state-server/operational-state-server.h> |
| 27 | + |
| 28 | +namespace chip { |
| 29 | +namespace app { |
| 30 | +namespace Clusters { |
| 31 | +namespace MicrowaveOvenControl { |
| 32 | + |
| 33 | +constexpr uint32_t kDefaultCookTimeSec = 30u; |
| 34 | +constexpr uint32_t kMinCookTimeSec = 1u; |
| 35 | +constexpr uint8_t kDefaultMinPowerNum = 10u; |
| 36 | +constexpr uint8_t kDefaultMaxPowerNum = 100u; |
| 37 | +constexpr uint8_t kDefaultPowerStepNum = 10u; |
| 38 | + |
| 39 | +class Delegate; |
| 40 | + |
| 41 | +class Instance : public CommandHandlerInterface, public AttributeAccessInterface |
| 42 | +{ |
| 43 | +public: |
| 44 | + /** |
| 45 | + * @brief Creates a Microwave Oven Control cluster instance. The Init() function needs to be called for this instance |
| 46 | + * to be registered and called by the interaction model at the appropriate times. |
| 47 | + * @param aDelegate A pointer to the delegate to be used by this server. |
| 48 | + * Note: the caller must ensure that the delegate lives throughout the instance's lifetime. |
| 49 | + * @param aEndpointId The endpoint on which this cluster exists. This must match the zap configuration. |
| 50 | + * @param aClusterId The ID of the Microwave Oven Control cluster to be instantiated. |
| 51 | + * @param aFeature The bitmask value that identifies which features are supported by this instance. |
| 52 | + * @param aOpStateInstance The reference of Operational State Instance. |
| 53 | + * @param aMicrowaveOvenModeInstance The reference of Microwave Oven Mode Instance. |
| 54 | + * Note: a MicrowaveOvenControl instance must relies on an Operational State instance and a Microwave Oven Mode instance. |
| 55 | + * Caller must ensure those 2 instances are live and initialized before initializing MicorwaveOvenControl instance. |
| 56 | + */ |
| 57 | + Instance(Delegate * aDelegate, EndpointId aEndpointId, ClusterId aClusterId, BitMask<MicrowaveOvenControl::Feature> aFeature, |
| 58 | + Clusters::OperationalState::Instance & aOpStateInstance, Clusters::ModeBase::Instance & aMicrowaveOvenModeInstance); |
| 59 | + |
| 60 | + ~Instance() override; |
| 61 | + |
| 62 | + /** |
| 63 | + * @brief Initialise the Microwave Oven Control server instance. |
| 64 | + * This function must be called after defining an Instance class object. |
| 65 | + * @return Returns an error if the given endpoint and cluster ID have not been enabled in zap or if the |
| 66 | + * CommandHandler or AttributeHandler registration fails, else returns CHIP_NO_ERROR. |
| 67 | + * This method also checks if the feature setting is valid, if invalid it will returns CHIP_ERROR_INVALID_ARGUMENT. |
| 68 | + */ |
| 69 | + CHIP_ERROR Init(); |
| 70 | + |
| 71 | + bool HasFeature(MicrowaveOvenControl::Feature feature) const; |
| 72 | + |
| 73 | + uint8_t GetCountOfSupportedWattLevels() const; |
| 74 | + |
| 75 | + uint32_t GetCookTimeSec() const; |
| 76 | + |
| 77 | + void SetCookTimeSec(uint32_t cookTimeSec); |
| 78 | + |
| 79 | +private: |
| 80 | + Delegate * mDelegate; |
| 81 | + EndpointId mEndpointId; |
| 82 | + ClusterId mClusterId; |
| 83 | + BitMask<MicrowaveOvenControl::Feature> mFeature; |
| 84 | + Clusters::OperationalState::Instance & mOpStateInstance; |
| 85 | + Clusters::ModeBase::Instance & mMicrowaveOvenModeInstance; |
| 86 | + |
| 87 | + uint32_t mCookTimeSec = kDefaultCookTimeSec; |
| 88 | + uint8_t mSupportedWattLevels = 0; |
| 89 | + |
| 90 | + /** |
| 91 | + * IM-level implementation of read |
| 92 | + * @return appropriately mapped CHIP_ERROR if applicable |
| 93 | + */ |
| 94 | + CHIP_ERROR Read(const ConcreteReadAttributePath & aPath, AttributeValueEncoder & aEncoder) override; |
| 95 | + |
| 96 | + /** |
| 97 | + * @brief Inherited from CommandHandlerInterface |
| 98 | + */ |
| 99 | + void InvokeCommand(HandlerContext & ctx) override; |
| 100 | + |
| 101 | + /** |
| 102 | + * @brief Handle Command: SetCookingParameters. |
| 103 | + * @param ctx Returns the Interaction Model status code which was user determined in the business logic. |
| 104 | + * If the input value is invalid, returns the Interaction Model status code of INVALID_COMMAND. |
| 105 | + * If the operational state is not in 'Stopped', returns the Interaction Model status code of INVALID_IN_STATE. |
| 106 | + */ |
| 107 | + void HandleSetCookingParameters(HandlerContext & ctx, const Commands::SetCookingParameters::DecodableType & req); |
| 108 | + |
| 109 | + /** |
| 110 | + * @brief Handle Command: AddMoreTime. |
| 111 | + * @param ctx Returns the Interaction Model status code which was user determined in the business logic. |
| 112 | + * If the cook time value is out of range, returns the Interaction Model status code of CONSTRAINT_ERROR. |
| 113 | + * If the operational state is in 'Error', returns the Interaction Model status code of INVALID_IN_STATE. |
| 114 | + */ |
| 115 | + void HandleAddMoreTime(HandlerContext & ctx, const Commands::AddMoreTime::DecodableType & req); |
| 116 | +}; |
| 117 | + |
| 118 | +/** |
| 119 | + * @brief Check if the given cook time is in range. |
| 120 | + */ |
| 121 | +bool IsCookTimeSecondsInRange(uint32_t cookTimeSec, uint32_t maxCookTimeSec); |
| 122 | + |
| 123 | +/** |
| 124 | + * @brief Check if the given cooking power is in range. |
| 125 | + */ |
| 126 | +bool IsPowerSettingNumberInRange(uint8_t powerSettingNum, uint8_t minCookPowerNum, uint8_t maxCookPowerNum); |
| 127 | + |
| 128 | +} // namespace MicrowaveOvenControl |
| 129 | +} // namespace Clusters |
| 130 | +} // namespace app |
| 131 | +} // namespace chip |
0 commit comments