forked from project-chip/connectedhomeip
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Ameba] Additional Ameba Implementation (project-chip#29720)
* [Ameba] added implementation for manual operation of several clusters (dishwasher alarm, refrigerator alarm, operational state, rvc operational state, rvc runmode, and rvc cleanmode), test event trigger for smoke alarm, shutdown function of CHIPDeviceManager, and init laundrywashercontrolserver * [Ameba] Run restyle-diff.sh, and modified cmake configuration to add additional implementation * [Ameba] Added CONFIG_ENABLE_AMEBA_TEST_EVENT_TRIGGER macro * [Ameba] added CONFIG_ENABLE_AMEBA_TEST_EVENT_TRIGGER define flag at cmake * [Ameba] Updated switch case at ManualOperationalStateCommand.h and updated raise and lower alarm function at ManualDishWasherAlarmCommand.h * [Ameba] Updated RvcOperationalState::ErrorStateEnum::kUnknownEnumValue to OperationalState::ErrorStateEnum::kUnknownEnumValue because it was removed, and added minor comments.
- Loading branch information
1 parent
8cf19c6
commit 898870e
Showing
16 changed files
with
1,538 additions
and
2 deletions.
There are no files selected for viewing
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
159 changes: 159 additions & 0 deletions
159
examples/all-clusters-app/ameba/main/ManualOperationCommand.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,159 @@ | ||
/* | ||
* | ||
* Copyright (c) 2022 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 "ManualOperationCommand.h" | ||
#include "ManualDishWasherAlarmCommand.h" | ||
#include "ManualOperationalStateCommand.h" | ||
#include "ManualRVCModesCommand.h" | ||
#include "ManualRefrigeratorAlarmCommand.h" | ||
|
||
#include "app/server/Server.h" | ||
#include "platform/CHIPDeviceLayer.h" | ||
#include <lib/support/CodeUtils.h> | ||
|
||
#if CONFIG_ENABLE_CHIP_SHELL | ||
#include "lib/shell/Engine.h" | ||
#include "lib/shell/commands/Help.h" | ||
#endif // ENABLE_CHIP_SHELL | ||
|
||
using namespace chip; | ||
using namespace chip::app; | ||
|
||
#if CONFIG_ENABLE_CHIP_SHELL | ||
using Shell::Engine; | ||
using Shell::shell_command_t; | ||
using Shell::streamer_get; | ||
using Shell::streamer_printf; | ||
|
||
Engine sShellManualOperationSubCommands; | ||
#endif // defined(ENABLE_CHIP_SHELL) | ||
|
||
namespace { | ||
#if CONFIG_ENABLE_CHIP_SHELL | ||
|
||
/******************************************************** | ||
* Manual Operation shell functions | ||
*********************************************************/ | ||
|
||
CHIP_ERROR ManualOperationHelpHandler(int argc, char ** argv) | ||
{ | ||
sShellManualOperationSubCommands.ForEachCommand(Shell::PrintCommandHelp, nullptr); | ||
return CHIP_NO_ERROR; | ||
} | ||
|
||
CHIP_ERROR ManualOperationCommandHandler(int argc, char ** argv) | ||
{ | ||
if (argc == 0) | ||
{ | ||
return ManualOperationHelpHandler(argc, argv); | ||
} | ||
|
||
return sShellManualOperationSubCommands.ExecCommand(argc, argv); | ||
} | ||
|
||
/** | ||
* @brief configures switch matter shell | ||
* | ||
*/ | ||
static void RegisterManualOperationCommands() | ||
{ | ||
|
||
static const shell_command_t sManualOperationSubCommands[] = { | ||
{ &ManualOperationHelpHandler, "help", "Usage: manual <subcommand>" }, | ||
{ &ManualOperationalStateCommandHandler, "opstate", " Usage: manual opstate <subcommand>" }, | ||
{ &ManualRVCCommandHandler, "rvc", " Usage: manual rvc <subcommand>" }, | ||
{ &ManualRefrigeratorAlarmCommandHandler, "refalm", " Usage: manual refalm <subcommand>" }, | ||
{ &ManualDishWasherAlarmCommandHandler, "dishalm", " Usage: manual dishalm <subcommand>" }, | ||
}; | ||
|
||
static const shell_command_t sManualOperationalStateSubCommands[] = { | ||
{ &ManualOperationalStateCommandHelpHandler, "help", "Usage: manual opstate <subcommand>" }, | ||
{ &ManualOperationalStateSetStateCommandHandler, "set-state", "set-state Usage: manual opstate set-state <state>" }, | ||
{ &ManualOperationalStateSetErrorCommandHandler, "set-error", "set-error Usage: manual opstate set-error <error>" }, | ||
}; | ||
|
||
static const shell_command_t sManualRVCSubCommands[] = { | ||
{ &ManualRVCCommandHelpHandler, "help", "Usage: manual rvc <subcommand>" }, | ||
{ &ManualRVCOperationalStateCommandHandler, "opstate", "Usage: manual rvc opstate <subcommand>" }, | ||
{ &ManualRVCRunModeCommandHandler, "runmode", "Usage: manual rvc runmode <subcommand>" }, | ||
{ &ManualRVCCleanModeCommandHandler, "cleanmode", "Usage: manual rvc cleanmode <subcommand>" }, | ||
}; | ||
|
||
static const shell_command_t sManualRVCOperationalStateSubCommands[] = { | ||
{ &ManualRVCOperationalStateCommandHelpHandler, "help", "Usage: manual rvc opstate <subcommand>" }, | ||
{ &ManualRVCOperationalStateSetStateCommandHandler, "set-state", "set-state Usage: manual rvc opstate set-state <state>" }, | ||
{ &ManualRVCOperationalStateSetErrorCommandHandler, "set-error", "set-error Usage: manual rvc opstate set-error <error>" }, | ||
}; | ||
|
||
static const shell_command_t sManualRVCRunModeSubCommands[] = { | ||
{ &ManualRVCRunModeCommandHelpHandler, "help", "Usage: manual rvc runmode <subcommand>" }, | ||
{ &ManualRVCRunModeSetModeCommandHandler, "set-mode", "set-mode Usage: manual rvc runmode set-mode <mode>" }, | ||
}; | ||
|
||
static const shell_command_t sManualRVCCleanModeSubCommands[] = { | ||
{ &ManualRVCCleanModeCommandHelpHandler, "help", "Usage: manual rvc cleanmode <subcommand>" }, | ||
{ &ManualRVCCleanModeSetModeCommandHandler, "set-mode", "set-mode Usage: manual rvc cleanmode set-mode <mode>" }, | ||
}; | ||
|
||
static const shell_command_t sManualRefrigeratorAlarmStateSubCommands[] = { | ||
{ &ManualRefrigeratorAlarmCommandHelpHandler, "help", "Usage: manual refalm <subcommand>" }, | ||
{ &ManualRefrigeratorAlarmDoorOpenCommandHandler, "door-open", "door-open Usage: manual refalm door-open" }, | ||
{ &ManualRefrigeratorAlarmDoorCloseCommandHandler, "door-close", "door-close Usage: manual refalm door-close" }, | ||
{ &ManualRefrigeratorAlarmSuppressCommandHandler, "suppress-alarm", "suppress-alarm Usage: manual refalm suppress-alarm" }, | ||
}; | ||
|
||
static const shell_command_t sManualDishWasherAlarmSubCommands[] = { | ||
{ &ManualDishWasherAlarmCommandHelpHandler, "help", "Usage: manual dishalm <subcommand>" }, | ||
{ &ManualDishWasherAlarmSetRaiseCommandHandler, "raise", "raise Usage: manual dishalm raise" }, | ||
{ &ManualDishWasherAlarmSetLowerCommandHandler, "lower", "lower Usage: manual dishalm lower" }, | ||
}; | ||
|
||
static const shell_command_t sManualOperationCommand = { &ManualOperationCommandHandler, "manual", | ||
"Manual Operation commands. Usage: manual <subcommand>" }; | ||
|
||
// Register commands | ||
sShellManualOperationSubCommands.RegisterCommands(sManualOperationSubCommands, ArraySize(sManualOperationSubCommands)); | ||
sShellManualOperationalStateSubCommands.RegisterCommands(sManualOperationalStateSubCommands, | ||
ArraySize(sManualOperationalStateSubCommands)); | ||
sShellManualRVCSubCommands.RegisterCommands(sManualRVCSubCommands, ArraySize(sManualRVCSubCommands)); | ||
sShellManualRVCOperationalStateSubCommands.RegisterCommands(sManualRVCOperationalStateSubCommands, | ||
ArraySize(sManualRVCOperationalStateSubCommands)); | ||
sShellManualRVCRunModeSubCommands.RegisterCommands(sManualRVCRunModeSubCommands, ArraySize(sManualRVCRunModeSubCommands)); | ||
sShellManualRVCCleanModeSubCommands.RegisterCommands(sManualRVCCleanModeSubCommands, ArraySize(sManualRVCCleanModeSubCommands)); | ||
sShellManualRefrigeratorAlarmStateSubCommands.RegisterCommands(sManualRefrigeratorAlarmStateSubCommands, | ||
ArraySize(sManualRefrigeratorAlarmStateSubCommands)); | ||
sShellManualDishWasherAlarmStateSubCommands.RegisterCommands(sManualDishWasherAlarmSubCommands, | ||
ArraySize(sManualDishWasherAlarmSubCommands)); | ||
|
||
Engine::Root().RegisterCommands(&sManualOperationCommand, 1); | ||
} | ||
#endif // ENABLE_CHIP_SHELL | ||
|
||
} // namespace | ||
|
||
/******************************************************** | ||
* Switch functions | ||
*********************************************************/ | ||
|
||
CHIP_ERROR InitManualOperation() | ||
{ | ||
#if CONFIG_ENABLE_CHIP_SHELL | ||
RegisterManualOperationCommands(); | ||
#endif | ||
return CHIP_NO_ERROR; | ||
} |
173 changes: 173 additions & 0 deletions
173
examples/all-clusters-app/ameba/main/OperationalStateManager.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,173 @@ | ||
/* | ||
* | ||
* 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 <OperationalStateManager.h> | ||
|
||
using namespace chip; | ||
using namespace chip::app; | ||
using namespace chip::app::Clusters; | ||
using namespace chip::app::Clusters::OperationalState; | ||
using namespace chip::app::Clusters::RvcOperationalState; | ||
|
||
CHIP_ERROR GenericOperationalStateDelegateImpl::GetOperationalStateAtIndex(size_t index, GenericOperationalState & operationalState) | ||
{ | ||
if (index >= mOperationalStateList.size()) | ||
{ | ||
return CHIP_ERROR_NOT_FOUND; | ||
} | ||
operationalState = mOperationalStateList[index]; | ||
return CHIP_NO_ERROR; | ||
} | ||
|
||
CHIP_ERROR GenericOperationalStateDelegateImpl::GetOperationalPhaseAtIndex(size_t index, GenericOperationalPhase & operationalPhase) | ||
{ | ||
if (index >= mOperationalPhaseList.size()) | ||
{ | ||
return CHIP_ERROR_NOT_FOUND; | ||
} | ||
operationalPhase = mOperationalPhaseList[index]; | ||
return CHIP_NO_ERROR; | ||
} | ||
|
||
void GenericOperationalStateDelegateImpl::HandlePauseStateCallback(GenericOperationalError & err) | ||
{ | ||
auto error = GetInstance()->SetOperationalState(to_underlying(OperationalState::OperationalStateEnum::kPaused)); | ||
if (error == CHIP_NO_ERROR) | ||
{ | ||
err.Set(to_underlying(ErrorStateEnum::kNoError)); | ||
} | ||
else | ||
{ | ||
err.Set(to_underlying(ErrorStateEnum::kUnableToCompleteOperation)); | ||
} | ||
} | ||
|
||
void GenericOperationalStateDelegateImpl::HandleResumeStateCallback(GenericOperationalError & err) | ||
{ | ||
auto error = GetInstance()->SetOperationalState(to_underlying(OperationalStateEnum::kRunning)); | ||
if (error == CHIP_NO_ERROR) | ||
{ | ||
err.Set(to_underlying(ErrorStateEnum::kNoError)); | ||
} | ||
else | ||
{ | ||
err.Set(to_underlying(ErrorStateEnum::kUnableToCompleteOperation)); | ||
} | ||
} | ||
|
||
void GenericOperationalStateDelegateImpl::HandleStartStateCallback(GenericOperationalError & err) | ||
{ | ||
auto error = GetInstance()->SetOperationalState(to_underlying(OperationalStateEnum::kRunning)); | ||
if (error == CHIP_NO_ERROR) | ||
{ | ||
err.Set(to_underlying(ErrorStateEnum::kNoError)); | ||
} | ||
else | ||
{ | ||
err.Set(to_underlying(ErrorStateEnum::kUnableToCompleteOperation)); | ||
} | ||
} | ||
|
||
void GenericOperationalStateDelegateImpl::HandleStopStateCallback(GenericOperationalError & err) | ||
{ | ||
auto error = GetInstance()->SetOperationalState(to_underlying(OperationalStateEnum::kStopped)); | ||
if (error == CHIP_NO_ERROR) | ||
{ | ||
err.Set(to_underlying(ErrorStateEnum::kNoError)); | ||
} | ||
else | ||
{ | ||
err.Set(to_underlying(ErrorStateEnum::kUnableToCompleteOperation)); | ||
} | ||
} | ||
|
||
// Init Operational State cluster | ||
|
||
static OperationalState::Instance * gOperationalStateInstance = nullptr; | ||
static OperationalStateDelegate * gOperationalStateDelegate = nullptr; | ||
|
||
void OperationalState::Shutdown() | ||
{ | ||
if (gOperationalStateInstance != nullptr) | ||
{ | ||
delete gOperationalStateInstance; | ||
gOperationalStateInstance = nullptr; | ||
} | ||
if (gOperationalStateDelegate != nullptr) | ||
{ | ||
delete gOperationalStateDelegate; | ||
gOperationalStateDelegate = nullptr; | ||
} | ||
} | ||
|
||
OperationalState::Instance * OperationalState::GetOperationalStateInstance() | ||
{ | ||
return gOperationalStateInstance; | ||
} | ||
|
||
void emberAfOperationalStateClusterInitCallback(chip::EndpointId endpointId) | ||
{ | ||
VerifyOrDie(endpointId == 1); // this cluster is only enabled for endpoint 1. | ||
VerifyOrDie(gOperationalStateInstance == nullptr && gOperationalStateDelegate == nullptr); | ||
|
||
gOperationalStateDelegate = new OperationalStateDelegate; | ||
EndpointId operationalStateEndpoint = 0x01; | ||
gOperationalStateInstance = new Instance(gOperationalStateDelegate, operationalStateEndpoint, Clusters::OperationalState::Id); | ||
|
||
gOperationalStateInstance->SetOperationalState(to_underlying(OperationalState::OperationalStateEnum::kStopped)); | ||
|
||
gOperationalStateInstance->Init(); | ||
} | ||
|
||
// Init RVC Operational State cluster | ||
|
||
static OperationalState::Instance * gRvcOperationalStateInstance = nullptr; | ||
static RvcOperationalStateDelegate * gRvcOperationalStateDelegate = nullptr; | ||
|
||
OperationalState::Instance * OperationalState::GetRVCOperationalStateInstance() | ||
{ | ||
return gRvcOperationalStateInstance; | ||
} | ||
|
||
void RvcOperationalState::Shutdown() | ||
{ | ||
if (gRvcOperationalStateInstance != nullptr) | ||
{ | ||
delete gRvcOperationalStateInstance; | ||
gRvcOperationalStateInstance = nullptr; | ||
} | ||
if (gRvcOperationalStateDelegate != nullptr) | ||
{ | ||
delete gRvcOperationalStateDelegate; | ||
gRvcOperationalStateDelegate = nullptr; | ||
} | ||
} | ||
|
||
void emberAfRvcOperationalStateClusterInitCallback(chip::EndpointId endpointId) | ||
{ | ||
VerifyOrDie(endpointId == 1); // this cluster is only enabled for endpoint 1. | ||
VerifyOrDie(gRvcOperationalStateInstance == nullptr && gRvcOperationalStateDelegate == nullptr); | ||
|
||
gRvcOperationalStateDelegate = new RvcOperationalStateDelegate; | ||
EndpointId operationalStateEndpoint = 0x01; | ||
gRvcOperationalStateInstance = | ||
new Instance(gRvcOperationalStateDelegate, operationalStateEndpoint, Clusters::RvcOperationalState::Id); | ||
|
||
gRvcOperationalStateInstance->SetOperationalState(to_underlying(OperationalState::OperationalStateEnum::kStopped)); | ||
|
||
gRvcOperationalStateInstance->Init(); | ||
} |
Oops, something went wrong.