Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Oven: adding OvenCavityOperationalState example #30898

Merged
merged 26 commits into from
Jan 18, 2024
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2592,60 +2592,70 @@ cluster BooleanState = 69 {
readonly attribute int16u clusterRevision = 65533;
}

/** Attributes and commands for selecting a mode from a list of supported options. */
provisional cluster OvenMode = 73 {
/** This cluster supports remotely monitoring and, where supported, changing the operational state of an Oven. */
provisional cluster OvenCavityOperationalState = 72 {
revision 1;

enum ModeTag : enum16 {
kBake = 16384;
kConvection = 16385;
kGrill = 16386;
kRoast = 16387;
kClean = 16388;
kConvectionBake = 16389;
kConvectionRoast = 16390;
kWarming = 16391;
kProofing = 16392;
enum ErrorStateEnum : enum8 {
kNoError = 0;
kUnableToStartOrResume = 1;
kUnableToCompleteOperation = 2;
kCommandInvalidInState = 3;
}

bitmap Feature : bitmap32 {
kOnOff = 0x1;
enum OperationalStateEnum : enum8 {
kStopped = 0;
kRunning = 1;
kPaused = 2;
kError = 3;
}

struct ModeTagStruct {
optional vendor_id mfgCode = 0;
enum16 value = 1;
struct ErrorStateStruct {
enum8 errorStateID = 0;
optional char_string<64> errorStateLabel = 1;
optional char_string<64> errorStateDetails = 2;
}

struct ModeOptionStruct {
char_string<64> label = 0;
int8u mode = 1;
ModeTagStruct modeTags[] = 2;
struct OperationalStateStruct {
enum8 operationalStateID = 0;
optional char_string<64> operationalStateLabel = 1;
}

readonly attribute ModeOptionStruct supportedModes[] = 0;
readonly attribute int8u currentMode = 1;
attribute optional nullable int8u startUpMode = 2;
attribute optional nullable int8u onMode = 3;
critical event OperationalError = 0 {
ErrorStateStruct errorState = 0;
}

info event OperationCompletion = 1 {
enum8 completionErrorCode = 0;
optional nullable elapsed_s totalOperationalTime = 1;
optional nullable elapsed_s pausedTime = 2;
}

readonly attribute nullable char_string phaseList[] = 0;
readonly attribute nullable int8u currentPhase = 1;
readonly attribute optional nullable elapsed_s countdownTime = 2;
readonly attribute OperationalStateStruct operationalStateList[] = 3;
readonly attribute OperationalStateEnum operationalState = 4;
readonly attribute ErrorStateStruct operationalError = 5;
readonly attribute command_id generatedCommandList[] = 65528;
readonly attribute command_id acceptedCommandList[] = 65529;
readonly attribute event_id eventList[] = 65530;
readonly attribute attrib_id attributeList[] = 65531;
readonly attribute bitmap32 featureMap = 65532;
readonly attribute int16u clusterRevision = 65533;

request struct ChangeToModeRequest {
int8u newMode = 0;
}

response struct ChangeToModeResponse = 1 {
enum8 status = 0;
optional char_string statusText = 1;
response struct OperationalCommandResponse = 4 {
ErrorStateStruct commandResponseState = 0;
}

/** This command is used to change device modes.
On receipt of this command the device SHALL respond with a ChangeToModeResponse command. */
command ChangeToMode(ChangeToModeRequest): ChangeToModeResponse = 0;
/** Upon receipt, the device SHALL pause its operation if it is possible based on the current function of the server. */
command Pause(): OperationalCommandResponse = 0;
/** Upon receipt, the device SHALL stop its operation if it is at a position where it is safe to do so and/or permitted. */
command Stop(): OperationalCommandResponse = 1;
/** Upon receipt, the device SHALL start its operation if it is safe to do so and the device is in an operational state from which it can be started. */
command Start(): OperationalCommandResponse = 2;
/** Upon receipt, the device SHALL resume its operation from the point it was at when it received the Pause command, or from the point when it was paused by means outside of this cluster (for example by manual button press). */
command Resume(): OperationalCommandResponse = 3;
}

/** This cluster supports remotely monitoring and controling the different typs of
Expand Down Expand Up @@ -7530,9 +7540,12 @@ endpoint 1 {
ram attribute clusterRevision default = 1;
}

server cluster OvenMode {
callback attribute supportedModes;
ram attribute currentMode;
server cluster OvenCavityOperationalState {
callback attribute phaseList;
callback attribute currentPhase;
callback attribute operationalStateList;
callback attribute operationalState;
callback attribute operationalError;
callback attribute generatedCommandList;
callback attribute acceptedCommandList;
callback attribute eventList;
Expand Down
70 changes: 59 additions & 11 deletions examples/all-clusters-app/all-clusters-common/all-clusters-app.zap
Original file line number Diff line number Diff line change
Expand Up @@ -8457,16 +8457,16 @@
]
},
{
"name": "Oven Mode",
"code": 73,
"name": "Oven Cavity Operational State",
"code": 72,
"mfgCode": null,
"define": "OVEN_MODE_CLUSTER",
"define": "OPERATIONAL_STATE_OVEN_CLUSTER",
"side": "server",
"enabled": 1,
"apiMaturity": "provisional",
"attributes": [
{
"name": "SupportedModes",
"name": "PhaseList",
"code": 0,
"mfgCode": null,
"side": "server",
Expand All @@ -8482,13 +8482,61 @@
"reportableChange": 0
},
{
"name": "CurrentMode",
"name": "CurrentPhase",
"code": 1,
"mfgCode": null,
"side": "server",
"type": "int8u",
"included": 1,
"storageOption": "RAM",
"storageOption": "External",
"singleton": 0,
"bounded": 0,
"defaultValue": "",
"reportable": 1,
"minInterval": 1,
"maxInterval": 65534,
"reportableChange": 0
},
{
"name": "OperationalStateList",
"code": 3,
"mfgCode": null,
"side": "server",
"type": "array",
"included": 1,
"storageOption": "External",
"singleton": 0,
"bounded": 0,
"defaultValue": "",
"reportable": 1,
"minInterval": 1,
"maxInterval": 65534,
"reportableChange": 0
},
{
"name": "OperationalState",
"code": 4,
"mfgCode": null,
"side": "server",
"type": "OperationalStateEnum",
"included": 1,
"storageOption": "External",
"singleton": 0,
"bounded": 0,
"defaultValue": "",
"reportable": 1,
"minInterval": 1,
"maxInterval": 65534,
"reportableChange": 0
},
{
"name": "OperationalError",
"code": 5,
"mfgCode": null,
"side": "server",
"type": "ErrorStateStruct",
"included": 1,
"storageOption": "External",
"singleton": 0,
"bounded": 0,
"defaultValue": "",
Expand Down Expand Up @@ -8613,7 +8661,7 @@
"storageOption": "External",
"singleton": 0,
"bounded": 0,
"defaultValue": null,
"defaultValue": "",
"reportable": 1,
"minInterval": 1,
"maxInterval": 65534,
Expand Down Expand Up @@ -8645,7 +8693,7 @@
"storageOption": "External",
"singleton": 0,
"bounded": 0,
"defaultValue": null,
"defaultValue": "",
"reportable": 1,
"minInterval": 1,
"maxInterval": 65534,
Expand All @@ -8661,7 +8709,7 @@
"storageOption": "External",
"singleton": 0,
"bounded": 0,
"defaultValue": null,
"defaultValue": "",
"reportable": 1,
"minInterval": 1,
"maxInterval": 65534,
Expand All @@ -8677,7 +8725,7 @@
"storageOption": "External",
"singleton": 0,
"bounded": 0,
"defaultValue": null,
"defaultValue": "",
"reportable": 1,
"minInterval": 1,
"maxInterval": 65534,
Expand All @@ -8693,7 +8741,7 @@
"storageOption": "External",
"singleton": 0,
"bounded": 0,
"defaultValue": null,
"defaultValue": "",
"reportable": 1,
"minInterval": 1,
"maxInterval": 65534,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
/*
*
* Copyright (c) 2023 Project CHIP Authors
* All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#pragma once

#include <app-common/zap-generated/cluster-objects.h>
#include <app/clusters/operational-state-server/operational-state-server.h>
#include <app/util/af-enums.h>
#include <protocols/interaction_model/StatusCode.h>

namespace chip {
namespace app {
namespace Clusters {

namespace OvenCavityOperationalState {

// This is an application level delegate to handle operational state commands according to the specific business logic.
class OvenCavityOperationalStateDelegate : public OperationalState::Delegate
{
private:
const Clusters::OperationalState::GenericOperationalState mOperationalStateList[8] = {
eahove marked this conversation as resolved.
Show resolved Hide resolved
OperationalState::GenericOperationalState(to_underlying(OperationalState::OperationalStateEnum::kStopped)),
OperationalState::GenericOperationalState(to_underlying(OperationalState::OperationalStateEnum::kRunning)),
OperationalState::GenericOperationalState(to_underlying(OperationalState::OperationalStateEnum::kPaused)),
OperationalState::GenericOperationalState(to_underlying(OperationalState::OperationalStateEnum::kError)),
};

public:
/**
* Get the countdown time. This attribute is not supported in our example app.
* @return Null.
*/
DataModel::Nullable<uint32_t> GetCountdownTime() override { return DataModel::NullNullable; };

/**
* Fills in the provided GenericOperationalState with the state at index `index` if there is one,
* or returns CHIP_ERROR_NOT_FOUND if the index is out of range for the list of states.
* Note: This is used by the SDK to populate the operational state list attribute. If the contents of this list changes,
* the device SHALL call the Instance's ReportOperationalStateListChange method to report that this attribute has changed.
* @param index The index of the state, with 0 representing the first state.
* @param operationalState The GenericOperationalState is filled.
*/
CHIP_ERROR GetOperationalStateAtIndex(size_t index,
Clusters::OperationalState::GenericOperationalState & operationalState) override;

/**
* Fills in the provided MutableCharSpan with the phase at index `index` if there is one,
* or returns CHIP_ERROR_NOT_FOUND if the index is out of range for the list of phases.
* Note: This is used by the SDK to populate the phase list attribute. If the contents of this list changes, the
* device SHALL call the Instance's ReportPhaseListChange method to report that this attribute has changed.
* @param index The index of the phase, with 0 representing the first phase.
* @param operationalPhase The MutableCharSpan is filled.
*/
CHIP_ERROR GetOperationalPhaseAtIndex(size_t index, MutableCharSpan & operationalPhase) override;

// command callback
/**
* Handle Command Callback in application: Pause
* @param[out] get operational error after callback.
*/
void HandlePauseStateCallback(Clusters::OperationalState::GenericOperationalError & err) override
{
// This command in not supported.
bzbarsky-apple marked this conversation as resolved.
Show resolved Hide resolved
err.Set(to_underlying(ErrorStateEnum::kCommandInvalidInState));
};

/**
* Handle Command Callback in application: Resume
* @param[out] get operational error after callback.
*/
void HandleResumeStateCallback(Clusters::OperationalState::GenericOperationalError & err) override
{
// This command in not supported.
err.Set(to_underlying(ErrorStateEnum::kCommandInvalidInState));
};

/**
* Handle Command Callback in application: Start
* @param[out] get operational error after callback.
*/
void HandleStartStateCallback(Clusters::OperationalState::GenericOperationalError & err) override
{
// This command in not supported.
err.Set(to_underlying(ErrorStateEnum::kCommandInvalidInState));
};

/**
* Handle Command Callback in application: Stop
* @param[out] get operational error after callback.
*/
void HandleStopStateCallback(Clusters::OperationalState::GenericOperationalError & err) override
{
// This command in not supported.
err.Set(to_underlying(ErrorStateEnum::kCommandInvalidInState));
};
};

void Shutdown();

} // namespace OvenCavityOperationalState
} // namespace Clusters
} // namespace app
} // namespace chip
Loading
Loading