-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add operational state cluster implement
- Loading branch information
1 parent
834663d
commit 4927843
Showing
15 changed files
with
1,753 additions
and
0 deletions.
There are no files selected for viewing
77 changes: 77 additions & 0 deletions
77
examples/all-clusters-app/all-clusters-common/include/operational-state-delegates.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/* | ||
* | ||
* 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/clusters/operational-state-server/operational-state-delegate.h> | ||
#include <app/util/af.h> | ||
#include <app/util/config.h> | ||
|
||
namespace chip { | ||
namespace app { | ||
namespace Clusters { | ||
namespace OperationalState { | ||
|
||
// This is an application level delegate to handle operational state commands according to the specific business logic. | ||
class OperationalStateDelegate : public Delegate | ||
{ | ||
|
||
private: | ||
CHIP_ERROR Init() override; | ||
|
||
public: | ||
/** | ||
* Handle Command Callback: Pause | ||
* @param state operational state. | ||
* @param error operational error. | ||
* @return CHIP_ERROR CHIP_NO_ERROR on success, or corresponding error code. | ||
*/ | ||
void HandlePauseState(OperationalStateStruct & state, OperationalErrorStateStruct & error) override; | ||
|
||
/** | ||
* Handle Command Callback: Resume | ||
* @param state operational state. | ||
* @param error operational error. | ||
* @return CHIP_ERROR CHIP_NO_ERROR on success, or corresponding error code. | ||
*/ | ||
void HandleResumeState(OperationalStateStruct & state, OperationalErrorStateStruct & error) override; | ||
|
||
/** | ||
* Handle Command Callback: Start | ||
* @param state operational state. | ||
* @param error operational error. | ||
* @return CHIP_ERROR CHIP_NO_ERROR on success, or corresponding error code. | ||
*/ | ||
void HandleStartState(OperationalStateStruct & state, OperationalErrorStateStruct & error) override; | ||
|
||
/** | ||
* Handle Command Callback: Stop | ||
* @param state operational state. | ||
* @param error operational error. | ||
* @return CHIP_ERROR CHIP_NO_ERROR on success, or corresponding error code. | ||
*/ | ||
void HandleStopState(OperationalStateStruct & state, OperationalErrorStateStruct & error) override; | ||
|
||
~OperationalStateDelegate() override = default; | ||
}; | ||
|
||
} // namespace OperationalState | ||
} // namespace Clusters | ||
} // namespace app | ||
} // namespace chip |
73 changes: 73 additions & 0 deletions
73
examples/all-clusters-app/all-clusters-common/src/operational-state-delegates.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/* | ||
* | ||
* 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. | ||
*/ | ||
#include <app-common/zap-generated/attributes/Accessors.h> | ||
#include <app/util/config.h> | ||
#include <operational-state-delegates.h> | ||
|
||
using namespace chip::app::Clusters; | ||
using namespace chip::app::Clusters::OperationalState; | ||
using chip::Protocols::InteractionModel::Status; | ||
|
||
|
||
static OperationalErrorStateStruct & setOperationalNoError(OperationalErrorStateStruct & error) | ||
{ | ||
char opNoError[64] = "No Error"; | ||
char opNoErrorDetails[64] = "No Error Details"; | ||
|
||
error.ErrorStateID = static_cast<uint8_t>(ErrorStateEnum::kNoError); | ||
memset(error.ErrorStateLabel, 0, sizeof(error.ErrorStateLabel)); | ||
memset(error.ErrorStateDetails, 0, sizeof(error.ErrorStateDetails)); | ||
memcpy(error.ErrorStateLabel, opNoError, sizeof(opNoError)); | ||
memcpy(error.ErrorStateDetails, opNoErrorDetails, sizeof(opNoErrorDetails)); | ||
|
||
return error; | ||
} | ||
//-- Operational state delegate functions | ||
|
||
CHIP_ERROR OperationalStateDelegate::Init() | ||
{ | ||
return CHIP_NO_ERROR; | ||
} | ||
|
||
void OperationalStateDelegate::HandlePauseState(OperationalStateStruct & state, OperationalErrorStateStruct & error) | ||
{ | ||
ChipLogDetail(Zcl, "Op: HandlePauseState"); | ||
state.OperationalStateID = static_cast<uint8_t>(OperationalStateEnum::kPaused); | ||
setOperationalNoError(error); | ||
} | ||
|
||
void OperationalStateDelegate::HandleResumeState(OperationalStateStruct & state, OperationalErrorStateStruct & error) | ||
{ | ||
ChipLogDetail(Zcl, "Op: HandleResumeState"); | ||
state.OperationalStateID = static_cast<uint8_t>(OperationalStateEnum::kRunning); | ||
setOperationalNoError(error); | ||
} | ||
|
||
void OperationalStateDelegate::HandleStartState(OperationalStateStruct & state, OperationalErrorStateStruct & error) | ||
{ | ||
ChipLogDetail(Zcl, "Op: HandleStartState"); | ||
state.OperationalStateID = static_cast<uint8_t>(OperationalStateEnum::kRunning); | ||
setOperationalNoError(error); | ||
} | ||
|
||
void OperationalStateDelegate::HandleStopState(OperationalStateStruct & state, OperationalErrorStateStruct & error) | ||
{ | ||
ChipLogDetail(Zcl, "Op: HandleStopState"); | ||
state.OperationalStateID = static_cast<uint8_t>(OperationalStateEnum::kStopped); | ||
setOperationalNoError(error); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.