From 9f2648ac3f68976931be808a5d1135eca129e4f1 Mon Sep 17 00:00:00 2001 From: pankore <86098180+pankore@users.noreply.github.com> Date: Fri, 6 Oct 2023 14:16:12 +0800 Subject: [PATCH 1/6] [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/main/CHIPDeviceManager.cpp | 6 + .../ameba/main/ManualOperationCommand.cpp | 155 +++++++++++++ .../ameba/main/OperationalStateManager.cpp | 173 ++++++++++++++ .../ameba/main/SmokeCOAlarmManager.cpp | 171 ++++++++++++++ .../ameba/main/chipinterface.cpp | 26 +++ .../ameba/main/include/CHIPDeviceManager.h | 2 + .../include/ManualDishWasherAlarmCommand.h | 121 ++++++++++ .../main/include/ManualOperationCommand.h | 26 +++ .../include/ManualOperationalStateCommand.h | 211 ++++++++++++++++++ .../main/include/ManualRVCModesCommand.h | 135 +++++++++++ .../include/ManualRefrigeratorAlarmCommand.h | 149 +++++++++++++ .../main/include/OperationalStateManager.h | 162 ++++++++++++++ .../ameba/main/include/SmokeCOAlarmManager.h | 47 ++++ .../AmebaTestEventTriggerDelegate.cpp | 37 +++ .../AmebaTestEventTriggerDelegate.h | 61 +++++ 15 files changed, 1482 insertions(+) create mode 100644 examples/all-clusters-app/ameba/main/ManualOperationCommand.cpp create mode 100644 examples/all-clusters-app/ameba/main/OperationalStateManager.cpp create mode 100644 examples/all-clusters-app/ameba/main/SmokeCOAlarmManager.cpp create mode 100644 examples/all-clusters-app/ameba/main/include/ManualDishWasherAlarmCommand.h create mode 100644 examples/all-clusters-app/ameba/main/include/ManualOperationCommand.h create mode 100644 examples/all-clusters-app/ameba/main/include/ManualOperationalStateCommand.h create mode 100644 examples/all-clusters-app/ameba/main/include/ManualRVCModesCommand.h create mode 100644 examples/all-clusters-app/ameba/main/include/ManualRefrigeratorAlarmCommand.h create mode 100644 examples/all-clusters-app/ameba/main/include/OperationalStateManager.h create mode 100644 examples/all-clusters-app/ameba/main/include/SmokeCOAlarmManager.h create mode 100644 examples/platform/ameba/test_event_trigger/AmebaTestEventTriggerDelegate.cpp create mode 100644 examples/platform/ameba/test_event_trigger/AmebaTestEventTriggerDelegate.h diff --git a/examples/all-clusters-app/ameba/main/CHIPDeviceManager.cpp b/examples/all-clusters-app/ameba/main/CHIPDeviceManager.cpp index 50e6d11db53c25..7b178060a6fff2 100644 --- a/examples/all-clusters-app/ameba/main/CHIPDeviceManager.cpp +++ b/examples/all-clusters-app/ameba/main/CHIPDeviceManager.cpp @@ -93,6 +93,12 @@ CHIP_ERROR CHIPDeviceManager::Init(CHIPDeviceManagerCallbacks * cb) exit: return err; } + +void CHIPDeviceManager::Shutdown() +{ + PlatformMgr().Shutdown(); +} + } // namespace DeviceManager } // namespace chip diff --git a/examples/all-clusters-app/ameba/main/ManualOperationCommand.cpp b/examples/all-clusters-app/ameba/main/ManualOperationCommand.cpp new file mode 100644 index 00000000000000..51411d39329d29 --- /dev/null +++ b/examples/all-clusters-app/ameba/main/ManualOperationCommand.cpp @@ -0,0 +1,155 @@ +/* + * + * 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 "ManualOperationalStateCommand.h" +#include "ManualRVCModesCommand.h" +#include "ManualRefrigeratorAlarmCommand.h" +#include "ManualDishWasherAlarmCommand.h" + +#include "app/server/Server.h" +#include "platform/CHIPDeviceLayer.h" +#include + +#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 " }, + { &ManualOperationalStateCommandHandler, "opstate", " Usage: manual opstate " }, + { &ManualRVCCommandHandler, "rvc", " Usage: manual rvc " }, + { &ManualRefrigeratorAlarmCommandHandler, "refalm", " Usage: manual refalm " }, + { &ManualDishWasherAlarmCommandHandler, "dishalm", " Usage: manual dishalm " }, + }; + + static const shell_command_t sManualOperationalStateSubCommands[] = { + { &ManualOperationalStateCommandHelpHandler, "help", "Usage: manual opstate " }, + { &ManualOperationalStateSetStateCommandHandler, "set-state", "set-state Usage: manual opstate set-state " }, + { &ManualOperationalStateSetErrorCommandHandler, "set-error", "set-error Usage: manual opstate set-error " }, + }; + + static const shell_command_t sManualRVCSubCommands[] = { + { &ManualRVCCommandHelpHandler, "help", "Usage: manual rvc " }, + { &ManualRVCOperationalStateCommandHandler, "opstate", "Usage: manual rvc opstate " }, + { &ManualRVCRunModeCommandHandler, "runmode", "Usage: manual rvc runmode " }, + { &ManualRVCCleanModeCommandHandler, "cleanmode", "Usage: manual rvc cleanmode " }, + }; + + static const shell_command_t sManualRVCOperationalStateSubCommands[] = { + { &ManualRVCOperationalStateCommandHelpHandler, "help", "Usage: manual rvc opstate " }, + { &ManualRVCOperationalStateSetStateCommandHandler, "set-state", "set-state Usage: manual rvc opstate set-state " }, + { &ManualRVCOperationalStateSetErrorCommandHandler, "set-error", "set-error Usage: manual rvc opstate set-error " }, + }; + + static const shell_command_t sManualRVCRunModeSubCommands[] = { + { &ManualRVCRunModeCommandHelpHandler, "help", "Usage: manual rvc runmode " }, + { &ManualRVCRunModeSetModeCommandHandler, "set-mode", "set-mode Usage: manual rvc runmode set-mode " }, + }; + + static const shell_command_t sManualRVCCleanModeSubCommands[] = { + { &ManualRVCCleanModeCommandHelpHandler, "help", "Usage: manual rvc cleanmode " }, + { &ManualRVCCleanModeSetModeCommandHandler, "set-mode", "set-mode Usage: manual rvc cleanmode set-mode " }, + }; + + static const shell_command_t sManualRefrigeratorAlarmStateSubCommands[] = { + { &ManualRefrigeratorAlarmCommandHelpHandler, "help", "Usage: manual refalm " }, + { &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 " }, + { &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 " }; + + // 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; +} diff --git a/examples/all-clusters-app/ameba/main/OperationalStateManager.cpp b/examples/all-clusters-app/ameba/main/OperationalStateManager.cpp new file mode 100644 index 00000000000000..0a8d508694f731 --- /dev/null +++ b/examples/all-clusters-app/ameba/main/OperationalStateManager.cpp @@ -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 + +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(); +} diff --git a/examples/all-clusters-app/ameba/main/SmokeCOAlarmManager.cpp b/examples/all-clusters-app/ameba/main/SmokeCOAlarmManager.cpp new file mode 100644 index 00000000000000..371c2665573170 --- /dev/null +++ b/examples/all-clusters-app/ameba/main/SmokeCOAlarmManager.cpp @@ -0,0 +1,171 @@ +/* + * + * Copyright (c) 2023 Project CHIP Authors + * + * 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 "SmokeCOAlarmManager.h" +#include +#include + +using namespace chip; +using namespace chip::app::Clusters::SmokeCoAlarm; +using namespace chip::DeviceLayer; + +static std::array sPriorityOrder = { + ExpressedStateEnum::kSmokeAlarm, ExpressedStateEnum::kInterconnectSmoke, ExpressedStateEnum::kCOAlarm, + ExpressedStateEnum::kInterconnectCO, ExpressedStateEnum::kHardwareFault, ExpressedStateEnum::kTesting, + ExpressedStateEnum::kEndOfService, ExpressedStateEnum::kBatteryAlert +}; + +CHIP_ERROR SmokeCoAlarmManager::Init() +{ + return CHIP_NO_ERROR; +} + +void SmokeCoAlarmManager::StartSelfTesting() +{ + //Currently selftest is not implemented +} + +bool emberAfHandleEventTrigger(uint64_t eventTrigger) +{ + SmokeCOTrigger trigger = static_cast(eventTrigger); + + switch (trigger) + { + case SmokeCOTrigger::kForceSmokeCritical: + ChipLogProgress(Support, "[Smoke-CO-Alarm-Test-Event] => Force smoke (critical)"); + VerifyOrReturnValue(SmokeCoAlarmServer::Instance().SetSmokeState(1, AlarmStateEnum::kCritical), true); + SmokeCoAlarmServer::Instance().SetExpressedStateByPriority(1, sPriorityOrder); + break; + case SmokeCOTrigger::kForceSmokeWarning: + ChipLogProgress(Support, "[Smoke-CO-Alarm-Test-Event] => Force smoke (warning)"); + VerifyOrReturnValue(SmokeCoAlarmServer::Instance().SetSmokeState(1, AlarmStateEnum::kWarning), true); + SmokeCoAlarmServer::Instance().SetExpressedStateByPriority(1, sPriorityOrder); + break; + case SmokeCOTrigger::kForceSmokeInterconnect: + ChipLogProgress(Support, "[Smoke-CO-Alarm-Test-Event] => Force smoke interconnect (warning)"); + VerifyOrReturnValue(SmokeCoAlarmServer::Instance().SetInterconnectSmokeAlarm(1, AlarmStateEnum::kWarning), true); + SmokeCoAlarmServer::Instance().SetExpressedStateByPriority(1, sPriorityOrder); + break; + case SmokeCOTrigger::kForceCOCritical: + ChipLogProgress(Support, "[Smoke-CO-Alarm-Test-Event] => Force CO (critical)"); + VerifyOrReturnValue(SmokeCoAlarmServer::Instance().SetCOState(1, AlarmStateEnum::kCritical), true); + SmokeCoAlarmServer::Instance().SetExpressedStateByPriority(1, sPriorityOrder); + break; + case SmokeCOTrigger::kForceCOWarning: + ChipLogProgress(Support, "[Smoke-CO-Alarm-Test-Event] => Force CO (warning)"); + VerifyOrReturnValue(SmokeCoAlarmServer::Instance().SetCOState(1, AlarmStateEnum::kWarning), true); + SmokeCoAlarmServer::Instance().SetExpressedStateByPriority(1, sPriorityOrder); + break; + case SmokeCOTrigger::kForceCOInterconnect: + ChipLogProgress(Support, "[Smoke-CO-Alarm-Test-Event] => Force CO (warning)"); + VerifyOrReturnValue(SmokeCoAlarmServer::Instance().SetInterconnectCOAlarm(1, AlarmStateEnum::kWarning), true); + SmokeCoAlarmServer::Instance().SetExpressedStateByPriority(1, sPriorityOrder); + break; + case SmokeCOTrigger::kForceSmokeContaminationHigh: + ChipLogProgress(Support, "[Smoke-CO-Alarm-Test-Event] => Force smoke contamination (critical)"); + SmokeCoAlarmServer::Instance().SetContaminationState(1, ContaminationStateEnum::kCritical); + break; + case SmokeCOTrigger::kForceSmokeContaminationLow: + ChipLogProgress(Support, "[Smoke-CO-Alarm-Test-Event] => Force smoke contamination (warning)"); + SmokeCoAlarmServer::Instance().SetContaminationState(1, ContaminationStateEnum::kLow); + break; + case SmokeCOTrigger::kForceSmokeSensitivityHigh: + ChipLogProgress(Support, "[Smoke-CO-Alarm-Test-Event] => Force smoke sensistivity (high)"); + SmokeCoAlarmServer::Instance().SetSmokeSensitivityLevel(1, SensitivityEnum::kHigh); + break; + case SmokeCOTrigger::kForceSmokeSensitivityLow: + ChipLogProgress(Support, "[Smoke-CO-Alarm-Test-Event] => Force smoke sensitivity (low)"); + SmokeCoAlarmServer::Instance().SetSmokeSensitivityLevel(1, SensitivityEnum::kLow); + break; + case SmokeCOTrigger::kForceMalfunction: + ChipLogProgress(Support, "[Smoke-CO-Alarm-Test-Event] => Force malfunction"); + VerifyOrReturnValue(SmokeCoAlarmServer::Instance().SetHardwareFaultAlert(1, true), true); + SmokeCoAlarmServer::Instance().SetExpressedStateByPriority(1, sPriorityOrder); + break; + case SmokeCOTrigger::kForceLowBatteryWarning: + ChipLogProgress(Support, "[Smoke-CO-Alarm-Test-Event] => Force low battery (warning)"); + VerifyOrReturnValue(SmokeCoAlarmServer::Instance().SetBatteryAlert(1, AlarmStateEnum::kWarning), true); + SmokeCoAlarmServer::Instance().SetExpressedStateByPriority(1, sPriorityOrder); + break; + case SmokeCOTrigger::kForceLowBatteryCritical: + ChipLogProgress(Support, "[Smoke-CO-Alarm-Test-Event] => Force low battery (critical)"); + VerifyOrReturnValue(SmokeCoAlarmServer::Instance().SetBatteryAlert(1, AlarmStateEnum::kCritical), true); + SmokeCoAlarmServer::Instance().SetExpressedStateByPriority(1, sPriorityOrder); + break; + case SmokeCOTrigger::kForceEndOfLife: + ChipLogProgress(Support, "[Smoke-CO-Alarm-Test-Event] => Force end-of-life"); + VerifyOrReturnValue(SmokeCoAlarmServer::Instance().SetEndOfServiceAlert(1, EndOfServiceEnum::kExpired), true); + SmokeCoAlarmServer::Instance().SetExpressedStateByPriority(1, sPriorityOrder); + break; + case SmokeCOTrigger::kForceSilence: + ChipLogProgress(Support, "[Smoke-CO-Alarm-Test-Event] => Force silence"); + SmokeCoAlarmServer::Instance().SetDeviceMuted(1, MuteStateEnum::kMuted); + break; + case SmokeCOTrigger::kClearSmoke: + ChipLogProgress(Support, "[Smoke-CO-Alarm-Test-Event] => Clear smoke"); + VerifyOrReturnValue(SmokeCoAlarmServer::Instance().SetSmokeState(1, AlarmStateEnum::kNormal), true); + SmokeCoAlarmServer::Instance().SetExpressedStateByPriority(1, sPriorityOrder); + break; + case SmokeCOTrigger::kClearCO: + ChipLogProgress(Support, "[Smoke-CO-Alarm-Test-Event] => Clear CO"); + VerifyOrReturnValue(SmokeCoAlarmServer::Instance().SetCOState(1, AlarmStateEnum::kNormal), true); + SmokeCoAlarmServer::Instance().SetExpressedStateByPriority(1, sPriorityOrder); + break; + case SmokeCOTrigger::kClearSmokeInterconnect: + ChipLogProgress(Support, "[Smoke-CO-Alarm-Test-Event] => Clear smoke interconnect"); + VerifyOrReturnValue(SmokeCoAlarmServer::Instance().SetInterconnectSmokeAlarm(1, AlarmStateEnum::kNormal), true); + SmokeCoAlarmServer::Instance().SetExpressedStateByPriority(1, sPriorityOrder); + break; + case SmokeCOTrigger::kClearCOInterconnect: + ChipLogProgress(Support, "[Smoke-CO-Alarm-Test-Event] => Clear CO interconnect"); + VerifyOrReturnValue(SmokeCoAlarmServer::Instance().SetInterconnectCOAlarm(1, AlarmStateEnum::kNormal), true); + SmokeCoAlarmServer::Instance().SetExpressedStateByPriority(1, sPriorityOrder); + break; + case SmokeCOTrigger::kClearMalfunction: + ChipLogProgress(Support, "[Smoke-CO-Alarm-Test-Event] => Clear malfunction"); + VerifyOrReturnValue(SmokeCoAlarmServer::Instance().SetHardwareFaultAlert(1, false), true); + SmokeCoAlarmServer::Instance().SetExpressedStateByPriority(1, sPriorityOrder); + break; + case SmokeCOTrigger::kClearEndOfLife: + ChipLogProgress(Support, "[Smoke-CO-Alarm-Test-Event] => Clear end-of-life"); + VerifyOrReturnValue(SmokeCoAlarmServer::Instance().SetEndOfServiceAlert(1, EndOfServiceEnum::kNormal), true); + SmokeCoAlarmServer::Instance().SetExpressedStateByPriority(1, sPriorityOrder); + break; + case SmokeCOTrigger::kClearSilence: + ChipLogProgress(Support, "[Smoke-CO-Alarm-Test-Event] => Clear silence"); + SmokeCoAlarmServer::Instance().SetDeviceMuted(1, MuteStateEnum::kNotMuted); + break; + case SmokeCOTrigger::kClearBatteryLevelLow: + ChipLogProgress(Support, "[Smoke-CO-Alarm-Test-Event] => Clear low battery"); + VerifyOrReturnValue(SmokeCoAlarmServer::Instance().SetBatteryAlert(1, AlarmStateEnum::kNormal), true); + SmokeCoAlarmServer::Instance().SetExpressedStateByPriority(1, sPriorityOrder); + break; + case SmokeCOTrigger::kClearContamination: + ChipLogProgress(Support, "[Smoke-CO-Alarm-Test-Event] => Force SmokeContamination (warning)"); + SmokeCoAlarmServer::Instance().SetContaminationState(1, ContaminationStateEnum::kNormal); + break; + case SmokeCOTrigger::kClearSensitivity: + ChipLogProgress(Support, "[Smoke-CO-Alarm-Test-Event] => Clear Smoke Sensitivity"); + SmokeCoAlarmServer::Instance().SetSmokeSensitivityLevel(1, SensitivityEnum::kStandard); + break; + default: + + return false; + } + + return true; +} diff --git a/examples/all-clusters-app/ameba/main/chipinterface.cpp b/examples/all-clusters-app/ameba/main/chipinterface.cpp index ac3426f4b438cc..5413467de6cf65 100644 --- a/examples/all-clusters-app/ameba/main/chipinterface.cpp +++ b/examples/all-clusters-app/ameba/main/chipinterface.cpp @@ -22,15 +22,18 @@ #include "DeviceCallbacks.h" #include "Globals.h" #include "LEDWidget.h" +#include "ManualOperationCommand.h" #include "chip_porting.h" #include #include #include +#include #include #include #include #include +#include #include #include #include @@ -39,6 +42,7 @@ #include #include #include +#include #if CONFIG_ENABLE_PW_RPC #include @@ -123,11 +127,19 @@ Identify gIdentify1 = { static DeviceCallbacks EchoCallbacks; chip::DeviceLayer::DeviceInfoProviderImpl gExampleDeviceInfoProvider; +uint8_t sTestEventTriggerEnableKey[TestEventTriggerDelegate::kEnableKeyLength] = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, + 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff }; + static void InitServer(intptr_t context) { // Init ZCL Data Model and CHIP App Server static chip::CommonCaseDeviceServerInitParams initParams; initParams.InitializeStaticResourcesBeforeServerInit(); + + static AmebaTestEventTriggerDelegate testEventTriggerDelegate{ ByteSpan(sTestEventTriggerEnableKey) }; + (void) initParams.InitializeStaticResourcesBeforeServerInit(); + initParams.testEventTriggerDelegate = &testEventTriggerDelegate; + chip::Server::GetInstance().Init(initParams); gExampleDeviceInfoProvider.SetStorageDelegate(&Server::GetInstance().GetPersistentStorage()); // TODO: Use our own DeviceInfoProvider @@ -143,6 +155,7 @@ static void InitServer(intptr_t context) #if CONFIG_ENABLE_CHIP_SHELL InitBindingHandler(); + InitManualOperation(); #endif app::Clusters::TemperatureControl::SetInstance(&sAppSupportedTemperatureLevelsDelegate); } @@ -175,7 +188,20 @@ extern "C" void ChipTest(void) #endif } +extern "C" void ChipTestShutdown(void) +{ + ChipLogProgress(DeviceLayer, "All Clusters Demo! Shutdown Now!"); + CHIPDeviceManager & deviceMgr = CHIPDeviceManager::GetInstance(); + deviceMgr.Shutdown(); +} + bool lowPowerClusterSleep() { return true; } + +using namespace chip::app::Clusters::LaundryWasherControls; +void emberAfLaundryWasherControlsClusterInitCallback(EndpointId endpoint) +{ + LaundryWasherControlsServer::SetDefaultDelegate(endpoint, &LaundryWasherControlDelegate::getLaundryWasherControlDelegate()); +} diff --git a/examples/all-clusters-app/ameba/main/include/CHIPDeviceManager.h b/examples/all-clusters-app/ameba/main/include/CHIPDeviceManager.h index 4ceddc65e7085e..03588bee0d02c6 100644 --- a/examples/all-clusters-app/ameba/main/include/CHIPDeviceManager.h +++ b/examples/all-clusters-app/ameba/main/include/CHIPDeviceManager.h @@ -103,6 +103,8 @@ class DLL_EXPORT CHIPDeviceManager */ CHIP_ERROR Init(CHIPDeviceManagerCallbacks * cb); + void Shutdown(); + /** * @brief * Fetch a pointer to the registered CHIPDeviceManagerCallbacks object. diff --git a/examples/all-clusters-app/ameba/main/include/ManualDishWasherAlarmCommand.h b/examples/all-clusters-app/ameba/main/include/ManualDishWasherAlarmCommand.h new file mode 100644 index 00000000000000..cb75e6cf07b9f8 --- /dev/null +++ b/examples/all-clusters-app/ameba/main/include/ManualDishWasherAlarmCommand.h @@ -0,0 +1,121 @@ +/* + * + * 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 "controller/InvokeInteraction.h" +#include "controller/ReadInteraction.h" +#include + +#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; +using namespace chip::app::Clusters; +using namespace chip::app::Clusters::DishwasherAlarm; + +#if CONFIG_ENABLE_CHIP_SHELL +using Shell::Engine; +using Shell::shell_command_t; +using Shell::streamer_get; +using Shell::streamer_printf; + +Engine sShellManualDishWasherAlarmStateSubCommands; +#endif // defined(ENABLE_CHIP_SHELL) + +#if CONFIG_ENABLE_CHIP_SHELL + +CHIP_ERROR ManualDishWasherAlarmCommandHelpHandler(int argc, char ** argv) +{ + sShellManualDishWasherAlarmStateSubCommands.ForEachCommand(Shell::PrintCommandHelp, nullptr); + return CHIP_NO_ERROR; +} + +CHIP_ERROR ManualDishWasherAlarmCommandHandler(int argc, char ** argv) +{ + if (argc == 0) + { + return ManualDishWasherAlarmCommandHelpHandler(argc, argv); + } + + return sShellManualDishWasherAlarmStateSubCommands.ExecCommand(argc, argv); +} + +CHIP_ERROR ManualDishWasherAlarmSetRaiseCommandHandler(int argc, char ** argv) +{ + CHIP_ERROR err = CHIP_NO_ERROR; + EmberAfStatus status; + DishwasherAlarmServer& serverInstance = DishwasherAlarmServer::Instance(); + + status = serverInstance.SetSupportedValue(1,47); + if (status != EMBER_ZCL_STATUS_SUCCESS) { + err = CHIP_ERROR_INTERNAL; + goto exit; + } + + status = serverInstance.SetMaskValue(1, 47); + if (status != EMBER_ZCL_STATUS_SUCCESS) { + err = CHIP_ERROR_INTERNAL; + goto exit; + } + + status = serverInstance.SetStateValue(1, 14, 0); + if (status != EMBER_ZCL_STATUS_SUCCESS) { + err = CHIP_ERROR_INTERNAL; + goto exit; + } +exit: + if (err != CHIP_NO_ERROR) { + ChipLogError(DeviceLayer, "ManualDishWasherAlarmSetRaiseCommandHandler Failed!\r\n"); + } + + return err; +} + +CHIP_ERROR ManualDishWasherAlarmSetLowerCommandHandler(int argc, char ** argv) +{ + CHIP_ERROR err = CHIP_NO_ERROR; + EmberAfStatus status; + DishwasherAlarmServer& serverInstance = DishwasherAlarmServer::Instance(); + + status = serverInstance.SetSupportedValue(1,47); + if (status != EMBER_ZCL_STATUS_SUCCESS) { + err = CHIP_ERROR_INTERNAL; + goto exit; + } + + status = serverInstance.SetMaskValue(1, 47); + if (status != EMBER_ZCL_STATUS_SUCCESS) { + err = CHIP_ERROR_INTERNAL; + goto exit; + } + + status = serverInstance.SetStateValue(1, 14, 0); + if (status != EMBER_ZCL_STATUS_SUCCESS) { + err = CHIP_ERROR_INTERNAL; + goto exit; + } +exit: + if (err != CHIP_NO_ERROR) { + ChipLogError(DeviceLayer, "ManualDishWasherAlarmSetLowerCommandHandler Failed!\r\n"); + } + + return err; +} +#endif // CONFIG_ENABLE_CHIP_SHELL diff --git a/examples/all-clusters-app/ameba/main/include/ManualOperationCommand.h b/examples/all-clusters-app/ameba/main/include/ManualOperationCommand.h new file mode 100644 index 00000000000000..418d0aea6f498e --- /dev/null +++ b/examples/all-clusters-app/ameba/main/include/ManualOperationCommand.h @@ -0,0 +1,26 @@ +/* + * + * 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. + */ + +#pragma once + +#include "app-common/zap-generated/ids/Attributes.h" +#include "app-common/zap-generated/ids/Clusters.h" +#include "app-common/zap-generated/ids/Commands.h" +#include "lib/core/CHIPError.h" + +CHIP_ERROR InitManualOperation(); diff --git a/examples/all-clusters-app/ameba/main/include/ManualOperationalStateCommand.h b/examples/all-clusters-app/ameba/main/include/ManualOperationalStateCommand.h new file mode 100644 index 00000000000000..61c33373c9d457 --- /dev/null +++ b/examples/all-clusters-app/ameba/main/include/ManualOperationalStateCommand.h @@ -0,0 +1,211 @@ +/* + * + * 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 "controller/InvokeInteraction.h" +#include "controller/ReadInteraction.h" +#include + +#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; +using namespace chip::app::Clusters; +using namespace chip::app::Clusters::OperationalState; + +#if CONFIG_ENABLE_CHIP_SHELL +using Shell::Engine; +using Shell::shell_command_t; +using Shell::streamer_get; +using Shell::streamer_printf; + +Engine sShellManualOperationalStateSubCommands; +Engine sShellManualRVCOperationalStateSubCommands; +#endif // defined(ENABLE_CHIP_SHELL) + +#if CONFIG_ENABLE_CHIP_SHELL +/******************************************************** + * Operational State Functions + *********************************************************/ + +CHIP_ERROR ManualOperationalStateCommandHelpHandler(int argc, char ** argv) +{ + sShellManualOperationalStateSubCommands.ForEachCommand(Shell::PrintCommandHelp, nullptr); + return CHIP_NO_ERROR; +} + +CHIP_ERROR ManualOperationalStateCommandHandler(int argc, char ** argv) +{ + if (argc == 0) + { + return ManualOperationalStateCommandHelpHandler(argc, argv); + } + + return sShellManualOperationalStateSubCommands.ExecCommand(argc, argv); +} + +CHIP_ERROR ManualOperationalStateSetStateCommandHandler(int argc, char ** argv) +{ + if (argc != 1) + { + return ManualOperationalStateCommandHelpHandler(argc, argv); + } + uint32_t state = atoi(argv[0]); + + CHIP_ERROR err; + err = GetOperationalStateInstance()->SetOperationalState(state); + + if (err != CHIP_NO_ERROR) { + ChipLogError(DeviceLayer, "ManualOperationalStateSetStateCommandHandler Failed!\r\n"); + } + + return err; +} + +CHIP_ERROR ManualOperationalStateSetErrorCommandHandler(int argc, char ** argv) +{ + if (argc != 1) + { + return ManualOperationalStateCommandHelpHandler(argc, argv); + } + + GenericOperationalError err(to_underlying(ErrorStateEnum::kNoError)); + uint32_t error = atoi(argv[0]); + + switch(error) + { + case to_underlying(OperationalState::ErrorStateEnum::kNoError): + err.errorStateID = to_underlying(OperationalState::ErrorStateEnum::kNoError); + break; + case to_underlying(OperationalState::ErrorStateEnum::kUnableToStartOrResume): + err.errorStateID = to_underlying(OperationalState::ErrorStateEnum::kUnableToStartOrResume); + break; + case to_underlying(OperationalState::ErrorStateEnum::kUnableToCompleteOperation): + err.errorStateID = to_underlying(OperationalState::ErrorStateEnum::kUnableToCompleteOperation); + break; + case to_underlying(OperationalState::ErrorStateEnum::kCommandInvalidInState): + err.errorStateID = to_underlying(OperationalState::ErrorStateEnum::kCommandInvalidInState); + break; + default: + err.errorStateID = to_underlying(OperationalState::ErrorStateEnum::kUnknownEnumValue); + break; + } + + GetOperationalStateInstance()->OnOperationalErrorDetected(err); + + return CHIP_NO_ERROR; +} + +/******************************************************** + * RVC Operational State Functions + *********************************************************/ + +CHIP_ERROR ManualRVCOperationalStateCommandHelpHandler(int argc, char ** argv) +{ + sShellManualRVCOperationalStateSubCommands.ForEachCommand(Shell::PrintCommandHelp, nullptr); + return CHIP_NO_ERROR; +} + +CHIP_ERROR ManualRVCOperationalStateCommandHandler(int argc, char ** argv) +{ + if (argc == 0) + { + return ManualRVCOperationalStateCommandHelpHandler(argc, argv); + } + + return sShellManualRVCOperationalStateSubCommands.ExecCommand(argc, argv); +} + +CHIP_ERROR ManualRVCOperationalStateSetStateCommandHandler(int argc, char ** argv) +{ + if (argc != 1) + { + return ManualRVCOperationalStateCommandHelpHandler(argc, argv); + } + uint32_t state = atoi(argv[0]); + + CHIP_ERROR err; + err = GetRVCOperationalStateInstance()->SetOperationalState(state); + + if (err != CHIP_NO_ERROR) { + ChipLogError(DeviceLayer, "ManualRVCOperationalStateSetStateCommandHandler Failed!\r\n"); + } + + return err; +} + +CHIP_ERROR ManualRVCOperationalStateSetErrorCommandHandler(int argc, char ** argv) +{ + if (argc != 1) + { + return ManualRVCOperationalStateCommandHelpHandler(argc, argv); + } + + GenericOperationalError err(to_underlying(ErrorStateEnum::kNoError)); + uint32_t error = atoi(argv[0]); + + switch(error) + { + case to_underlying(OperationalState::ErrorStateEnum::kNoError): //0x00, 0 + err.errorStateID = to_underlying(OperationalState::ErrorStateEnum::kNoError); + break; + case to_underlying(OperationalState::ErrorStateEnum::kUnableToStartOrResume): //0x01, 1 + err.errorStateID = to_underlying(OperationalState::ErrorStateEnum::kUnableToStartOrResume); + break; + case to_underlying(OperationalState::ErrorStateEnum::kUnableToCompleteOperation): //0x02, 2 + err.errorStateID = to_underlying(OperationalState::ErrorStateEnum::kUnableToCompleteOperation); + break; + case to_underlying(OperationalState::ErrorStateEnum::kCommandInvalidInState): //0x03, 3 + err.errorStateID = to_underlying(OperationalState::ErrorStateEnum::kCommandInvalidInState); + break; + case to_underlying(RvcOperationalState::ErrorStateEnum::kFailedToFindChargingDock): //0x40, 64 + err.errorStateID = to_underlying(RvcOperationalState::ErrorStateEnum::kFailedToFindChargingDock); + break; + case to_underlying(RvcOperationalState::ErrorStateEnum::kStuck): //0x41, 65 + err.errorStateID = to_underlying(RvcOperationalState::ErrorStateEnum::kStuck); + break; + case to_underlying(RvcOperationalState::ErrorStateEnum::kDustBinMissing): //0x42, 66 + err.errorStateID = to_underlying(RvcOperationalState::ErrorStateEnum::kDustBinMissing); + break; + case to_underlying(RvcOperationalState::ErrorStateEnum::kDustBinFull): //0x43, 67 + err.errorStateID = to_underlying(RvcOperationalState::ErrorStateEnum::kDustBinFull); + break; + case to_underlying(RvcOperationalState::ErrorStateEnum::kWaterTankEmpty): //0x44, 68 + err.errorStateID = to_underlying(RvcOperationalState::ErrorStateEnum::kWaterTankEmpty); + break; + case to_underlying(RvcOperationalState::ErrorStateEnum::kWaterTankMissing): //0x45, 69 + err.errorStateID = to_underlying(RvcOperationalState::ErrorStateEnum::kWaterTankMissing); + break; + case to_underlying(RvcOperationalState::ErrorStateEnum::kWaterTankLidOpen): //0x46, 70 + err.errorStateID = to_underlying(RvcOperationalState::ErrorStateEnum::kWaterTankLidOpen); + break; + case to_underlying(RvcOperationalState::ErrorStateEnum::kMopCleaningPadMissing): //0x47, 71 + err.errorStateID = to_underlying(RvcOperationalState::ErrorStateEnum::kMopCleaningPadMissing); + break; + default: + err.errorStateID = to_underlying(RvcOperationalState::ErrorStateEnum::kUnknownEnumValue); + break; + } + + GetRVCOperationalStateInstance()->OnOperationalErrorDetected(err); + + return CHIP_NO_ERROR; +} +#endif // CONFIG_ENABLE_CHIP_SHELL diff --git a/examples/all-clusters-app/ameba/main/include/ManualRVCModesCommand.h b/examples/all-clusters-app/ameba/main/include/ManualRVCModesCommand.h new file mode 100644 index 00000000000000..b020141c5df7a9 --- /dev/null +++ b/examples/all-clusters-app/ameba/main/include/ManualRVCModesCommand.h @@ -0,0 +1,135 @@ +/* + * + * 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 "controller/InvokeInteraction.h" +#include "controller/ReadInteraction.h" +#include + +#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; +using namespace chip::app::Clusters; + +#if CONFIG_ENABLE_CHIP_SHELL +using Shell::Engine; +using Shell::shell_command_t; +using Shell::streamer_get; +using Shell::streamer_printf; + +Engine sShellManualRVCSubCommands; +Engine sShellManualRVCRunModeSubCommands; +Engine sShellManualRVCCleanModeSubCommands; +#endif // defined(ENABLE_CHIP_SHELL) + +#if CONFIG_ENABLE_CHIP_SHELL +/******************************************************** + * RVC + *********************************************************/ + +CHIP_ERROR ManualRVCCommandHelpHandler(int argc, char ** argv) +{ + sShellManualRVCSubCommands.ForEachCommand(Shell::PrintCommandHelp, nullptr); + return CHIP_NO_ERROR; +} + +CHIP_ERROR ManualRVCCommandHandler(int argc, char ** argv) +{ + if (argc == 0) + { + return ManualRVCCommandHelpHandler(argc, argv); + } + return sShellManualRVCSubCommands.ExecCommand(argc, argv); +} + +/******************************************************** + * RVC Run Mode + *********************************************************/ + +CHIP_ERROR ManualRVCRunModeCommandHelpHandler(int argc, char ** argv) +{ + sShellManualRVCRunModeSubCommands.ForEachCommand(Shell::PrintCommandHelp, nullptr); + return CHIP_NO_ERROR; +} + +CHIP_ERROR ManualRVCRunModeCommandHandler(int argc, char ** argv) +{ + if (argc == 0) + { + return ManualRVCRunModeCommandHelpHandler(argc, argv); + } + + return sShellManualRVCRunModeSubCommands.ExecCommand(argc, argv); +} + +CHIP_ERROR ManualRVCRunModeSetModeCommandHandler(int argc, char ** argv) +{ + if (argc != 1) + { + return ManualRVCRunModeCommandHelpHandler(argc, argv); + } + Protocols::InteractionModel::Status status; + status = RvcRunMode::Instance()->UpdateCurrentMode((uint8_t) atoi(argv[0])); + if (status != Protocols::InteractionModel::Status::Success) + { + ChipLogError(DeviceLayer, "ManualRVCRunModeSetModeCommandHandler Error!"); + return CHIP_ERROR_INTERNAL; + } + return CHIP_NO_ERROR; +} + +/******************************************************** + * RVC Clean Mode + *********************************************************/ + +CHIP_ERROR ManualRVCCleanModeCommandHelpHandler(int argc, char ** argv) +{ + sShellManualRVCCleanModeSubCommands.ForEachCommand(Shell::PrintCommandHelp, nullptr); + return CHIP_NO_ERROR; +} + +CHIP_ERROR ManualRVCCleanModeCommandHandler(int argc, char ** argv) +{ + if (argc == 0) + { + return ManualRVCCleanModeCommandHelpHandler(argc, argv); + } + + return sShellManualRVCCleanModeSubCommands.ExecCommand(argc, argv); +} + +CHIP_ERROR ManualRVCCleanModeSetModeCommandHandler(int argc, char ** argv) +{ + if (argc != 1) + { + return ManualRVCCleanModeCommandHelpHandler(argc, argv); + } + Protocols::InteractionModel::Status status; + status = RvcCleanMode::Instance()->UpdateCurrentMode((uint8_t) atoi(argv[0])); + if (status != Protocols::InteractionModel::Status::Success) + { + ChipLogError(DeviceLayer, "ManualRVCCleanModeSetModeCommandHandler Error!"); + return CHIP_ERROR_INTERNAL; + } + return CHIP_NO_ERROR; +} + +#endif // CONFIG_ENABLE_CHIP_SHELL diff --git a/examples/all-clusters-app/ameba/main/include/ManualRefrigeratorAlarmCommand.h b/examples/all-clusters-app/ameba/main/include/ManualRefrigeratorAlarmCommand.h new file mode 100644 index 00000000000000..30b50528cbc8ee --- /dev/null +++ b/examples/all-clusters-app/ameba/main/include/ManualRefrigeratorAlarmCommand.h @@ -0,0 +1,149 @@ +/* + * + * 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 "controller/InvokeInteraction.h" +#include "controller/ReadInteraction.h" +#include + +#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; +using namespace chip::app::Clusters; +using namespace chip::app::Clusters::RefrigeratorAlarm; + +#if CONFIG_ENABLE_CHIP_SHELL +using Shell::Engine; +using Shell::shell_command_t; +using Shell::streamer_get; +using Shell::streamer_printf; + +Engine sShellManualRefrigeratorAlarmStateSubCommands; +#endif // defined(ENABLE_CHIP_SHELL) + +#if CONFIG_ENABLE_CHIP_SHELL + +CHIP_ERROR ManualRefrigeratorAlarmCommandHelpHandler(int argc, char ** argv) +{ + sShellManualRefrigeratorAlarmStateSubCommands.ForEachCommand(Shell::PrintCommandHelp, nullptr); + return CHIP_NO_ERROR; +} + +CHIP_ERROR ManualRefrigeratorAlarmCommandHandler(int argc, char ** argv) +{ + if (argc == 0) + { + return ManualRefrigeratorAlarmCommandHelpHandler(argc, argv); + } + + return sShellManualRefrigeratorAlarmStateSubCommands.ExecCommand(argc, argv); +} + +CHIP_ERROR ManualRefrigeratorAlarmDoorOpenCommandHandler(int argc, char ** argv) +{ + CHIP_ERROR err = CHIP_NO_ERROR; + EmberAfStatus status; + RefrigeratorAlarmServer& serverInstance = RefrigeratorAlarmServer::Instance(); + + status = serverInstance.SetMaskValue(1, 0); + if (status != EMBER_ZCL_STATUS_SUCCESS) { + err = CHIP_ERROR_INTERNAL; + goto exit; + } + + status = serverInstance.SetStateValue(1, 1); + if (status != EMBER_ZCL_STATUS_SUCCESS) { + err = CHIP_ERROR_INTERNAL; + goto exit; + } + + status = serverInstance.SetSupportedValue(1, 0); + if (status != EMBER_ZCL_STATUS_SUCCESS) { + err = CHIP_ERROR_INTERNAL; + goto exit; + } + +exit: + if (err != CHIP_NO_ERROR) { + ChipLogError(DeviceLayer, "ManualRefrigeratorAlarmDoorOpenCommandHandler Failed!\r\n"); + } + + return err; +} + +CHIP_ERROR ManualRefrigeratorAlarmDoorCloseCommandHandler(int argc, char ** argv) +{ + CHIP_ERROR err = CHIP_NO_ERROR; + EmberAfStatus status; + RefrigeratorAlarmServer& serverInstance = RefrigeratorAlarmServer::Instance(); + + status = serverInstance.SetMaskValue(1, 1); + if (status != EMBER_ZCL_STATUS_SUCCESS) { + err = CHIP_ERROR_INTERNAL; + goto exit; + } + + status = serverInstance.SetStateValue(1, 0); + if (status != EMBER_ZCL_STATUS_SUCCESS) { + err = CHIP_ERROR_INTERNAL; + goto exit; + } + + status = serverInstance.SetSupportedValue(1, 1); + if (status != EMBER_ZCL_STATUS_SUCCESS) { + err = CHIP_ERROR_INTERNAL; + goto exit; + } + +exit: + if (err != CHIP_NO_ERROR) { + ChipLogError(DeviceLayer, "ManualRefrigeratorAlarmDoorCloseCommandHandler Failed!\r\n"); + } + + return err; +} + +CHIP_ERROR ManualRefrigeratorAlarmSuppressCommandHandler(int argc, char ** argv) +{ + CHIP_ERROR err = CHIP_NO_ERROR; + EmberAfStatus status; + RefrigeratorAlarmServer& serverInstance = RefrigeratorAlarmServer::Instance(); + + status = serverInstance.SetSupportedValue(1, 1); + if (status != EMBER_ZCL_STATUS_SUCCESS) { + err = CHIP_ERROR_INTERNAL; + goto exit; + } + + status = serverInstance.SetStateValue(1, 0); + if (status != EMBER_ZCL_STATUS_SUCCESS) { + err = CHIP_ERROR_INTERNAL; + goto exit; + } + +exit: + if (err != CHIP_NO_ERROR) { + ChipLogError(DeviceLayer, "ManualRefrigeratorAlarmDoorCloseCommandHandler Failed!\r\n"); + } + + return err; +} +#endif // CONFIG_ENABLE_CHIP_SHELL diff --git a/examples/all-clusters-app/ameba/main/include/OperationalStateManager.h b/examples/all-clusters-app/ameba/main/include/OperationalStateManager.h new file mode 100644 index 00000000000000..e1b182bcb9f1c0 --- /dev/null +++ b/examples/all-clusters-app/ameba/main/include/OperationalStateManager.h @@ -0,0 +1,162 @@ +/* + * + * 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 +#include +#include +#include + +void getOperationalStateSet(u8 state); + +namespace chip { +namespace app { +namespace Clusters { + +namespace OperationalState { + + Instance *GetOperationalStateInstance(); + Instance *GetRVCOperationalStateInstance(); + +// This is an application level delegate to handle operational state commands according to the specific business logic. +class GenericOperationalStateDelegateImpl : public Delegate +{ +public: + /** + * Get the countdown time. This attribute is not used in this application. + * @return The current countdown time. + */ + app::DataModel::Nullable GetCountdownTime() override { return {}; }; + + /** + * 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, GenericOperationalState &operationalState) override; + + /** + * Fills in the provided GenericOperationalPhase 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 GenericOperationalPhase is filled. + */ + CHIP_ERROR GetOperationalPhaseAtIndex(size_t index, GenericOperationalPhase &operationalPhase) override; + + // command callback + /** + * Handle Command Callback in application: Pause + * @param[out] get operational error after callback. + */ + void HandlePauseStateCallback(GenericOperationalError &err) override; + + /** + * Handle Command Callback in application: Resume + * @param[out] get operational error after callback. + */ + void HandleResumeStateCallback(GenericOperationalError &err) override; + + /** + * Handle Command Callback in application: Start + * @param[out] get operational error after callback. + */ + void HandleStartStateCallback(GenericOperationalError &err) override; + + /** + * Handle Command Callback in application: Stop + * @param[out] get operational error after callback. + */ + void HandleStopStateCallback(GenericOperationalError &err) override; + +protected: + Span mOperationalStateList; + Span mOperationalPhaseList; +}; + +// This is an application level delegate to handle operational state commands according to the specific business logic. +class OperationalStateDelegate : public GenericOperationalStateDelegateImpl +{ +private: + const GenericOperationalState opStateList[4] = { + GenericOperationalState(to_underlying(OperationalStateEnum::kStopped)), + GenericOperationalState(to_underlying(OperationalStateEnum::kRunning)), + GenericOperationalState(to_underlying(OperationalStateEnum::kPaused)), + GenericOperationalState(to_underlying(OperationalStateEnum::kError)), + }; + + const GenericOperationalPhase opPhaseList[1] = { + // Phase List is null + GenericOperationalPhase(DataModel::Nullable()), + }; + +public: + OperationalStateDelegate() + { + GenericOperationalStateDelegateImpl::mOperationalStateList = Span(opStateList); + GenericOperationalStateDelegateImpl::mOperationalPhaseList = Span(opPhaseList); + } +}; + +void Shutdown(); + +} // namespace OperationalState + +namespace RvcOperationalState { + +// This is an application level delegate to handle operational state commands according to the specific business logic. +class RvcOperationalStateDelegate : public OperationalState::GenericOperationalStateDelegateImpl +{ +private: + const OperationalState::GenericOperationalState rvcOpStateList[7] = { + 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)), + OperationalState::GenericOperationalState( + to_underlying(Clusters::RvcOperationalState::OperationalStateEnum::kSeekingCharger)), + OperationalState::GenericOperationalState(to_underlying(Clusters::RvcOperationalState::OperationalStateEnum::kCharging)), + OperationalState::GenericOperationalState(to_underlying(Clusters::RvcOperationalState::OperationalStateEnum::kDocked)), + }; + + const OperationalState::GenericOperationalPhase rvcOpPhaseList[1] = { + // Phase List is null + OperationalState::GenericOperationalPhase(DataModel::Nullable()), + }; + +public: + RvcOperationalStateDelegate() + { + GenericOperationalStateDelegateImpl::mOperationalStateList = + Span(rvcOpStateList); + GenericOperationalStateDelegateImpl::mOperationalPhaseList = + Span(rvcOpPhaseList); + } +}; + +void Shutdown(); + +} // namespace RvcOperationalState +} // namespace Clusters +} // namespace app +} // namespace chip diff --git a/examples/all-clusters-app/ameba/main/include/SmokeCOAlarmManager.h b/examples/all-clusters-app/ameba/main/include/SmokeCOAlarmManager.h new file mode 100644 index 00000000000000..0fc82a6f61a3b3 --- /dev/null +++ b/examples/all-clusters-app/ameba/main/include/SmokeCOAlarmManager.h @@ -0,0 +1,47 @@ +/* + * + * Copyright (c) 2023 Project CHIP Authors + * + * 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 +#include +#include +#include + +bool emberAfHandleEventTrigger(uint64_t eventTrigger); + +class SmokeCoAlarmManager +{ +public: + CHIP_ERROR Init(); + + /** + * @brief Execute the self-test process + * + */ + void StartSelfTesting(); + +private: + friend SmokeCoAlarmManager & AlarmMgr(void); + + static SmokeCoAlarmManager sAlarm; +}; + +inline SmokeCoAlarmManager & AlarmMgr(void) +{ + return SmokeCoAlarmManager::sAlarm; +} diff --git a/examples/platform/ameba/test_event_trigger/AmebaTestEventTriggerDelegate.cpp b/examples/platform/ameba/test_event_trigger/AmebaTestEventTriggerDelegate.cpp new file mode 100644 index 00000000000000..dbf7c70f6a3c83 --- /dev/null +++ b/examples/platform/ameba/test_event_trigger/AmebaTestEventTriggerDelegate.cpp @@ -0,0 +1,37 @@ +/* + * + * 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 "SmokeCOAlarmManager.h" +#include "AmebaTestEventTriggerDelegate.h" + +using namespace ::chip::DeviceLayer; + +namespace chip { + +bool AmebaTestEventTriggerDelegate::DoesEnableKeyMatch(const ByteSpan & enableKey) const +{ + return !mEnableKey.empty() && mEnableKey.data_equal(enableKey); +} + +CHIP_ERROR AmebaTestEventTriggerDelegate::HandleEventTrigger(uint64_t eventTrigger) +{ + bool success = emberAfHandleEventTrigger(eventTrigger); + return success ? CHIP_NO_ERROR : CHIP_ERROR_INVALID_ARGUMENT; +} + +} // namespace chip diff --git a/examples/platform/ameba/test_event_trigger/AmebaTestEventTriggerDelegate.h b/examples/platform/ameba/test_event_trigger/AmebaTestEventTriggerDelegate.h new file mode 100644 index 00000000000000..d461194de9b642 --- /dev/null +++ b/examples/platform/ameba/test_event_trigger/AmebaTestEventTriggerDelegate.h @@ -0,0 +1,61 @@ +/* + * + * 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 "SmokeCOAlarmManager.h" +#include + +namespace chip { + +class AmebaTestEventTriggerDelegate : public TestEventTriggerDelegate +{ +public: + explicit AmebaTestEventTriggerDelegate(const ByteSpan & enableKey) : mEnableKey(enableKey) {} + + /** + * @brief Checks to see if `enableKey` provided matches value chosen by the manufacturer. + * @param enableKey Buffer of the key to verify. + * @return True or False. + */ + bool DoesEnableKeyMatch(const ByteSpan & enableKey) const override; + + /** + * @brief User handler for handling the test event trigger based on `eventTrigger` provided. + * @param eventTrigger Event trigger to handle. + * @return CHIP_NO_ERROR on success or CHIP_ERROR_INVALID_ARGUMENT on failure. + */ + CHIP_ERROR HandleEventTrigger(uint64_t eventTrigger) override; + +private: + ByteSpan mEnableKey; +}; + +} // namespace chip + +/** + * @brief User handler for handling the test event trigger + * + * @note If TestEventTrigger is enabled, it needs to be implemented in the app + * + * @param eventTrigger Event trigger to handle + * + * @retval true on success + * @retval false if error happened + */ +bool emberAfHandleEventTrigger(uint64_t eventTrigger); From 76f6ed44ec9803fbd3e7024f9bc5c99461b50c95 Mon Sep 17 00:00:00 2001 From: pankore <86098180+pankore@users.noreply.github.com> Date: Mon, 9 Oct 2023 10:29:21 +0800 Subject: [PATCH 2/6] [Ameba] Run restyle-diff.sh, and modified cmake configuration to add additional implementation --- .../all-clusters-app/ameba/chip_main.cmake | 11 +- .../ameba/main/ManualOperationCommand.cpp | 40 +++--- .../ameba/main/OperationalStateManager.cpp | 24 ++-- .../ameba/main/SmokeCOAlarmManager.cpp | 2 +- .../include/ManualDishWasherAlarmCommand.h | 96 +++++++------ .../include/ManualOperationalStateCommand.h | 60 +++++---- .../include/ManualRefrigeratorAlarmCommand.h | 127 ++++++++++-------- .../main/include/OperationalStateManager.h | 16 +-- .../ameba/main/include/SmokeCOAlarmManager.h | 4 +- .../AmebaTestEventTriggerDelegate.cpp | 2 +- 10 files changed, 207 insertions(+), 175 deletions(-) diff --git a/examples/all-clusters-app/ameba/chip_main.cmake b/examples/all-clusters-app/ameba/chip_main.cmake index f105d3efe41a44..32b13fcc7b375b 100755 --- a/examples/all-clusters-app/ameba/chip_main.cmake +++ b/examples/all-clusters-app/ameba/chip_main.cmake @@ -154,10 +154,12 @@ list( APPEND ${list_chip_main_sources} ${chip_dir}/examples/all-clusters-app/all-clusters-common/src/bridged-actions-stub.cpp - ${chip_dir}/examples/all-clusters-app/all-clusters-common/src/air-quality-instance.cpp - ${chip_dir}/examples/all-clusters-app/all-clusters-common/src/concentration-measurement-instances.cpp + ${chip_dir}/examples/all-clusters-app/all-clusters-common/src/air-quality-instance.cpp + ${chip_dir}/examples/all-clusters-app/all-clusters-common/src/concentration-measurement-instances.cpp ${chip_dir}/examples/all-clusters-app/all-clusters-common/src/fan-stub.cpp + ${chip_dir}/examples/all-clusters-app/all-clusters-common/src/laundry-washer-controls-delegate-impl.cpp ${chip_dir}/examples/all-clusters-app/all-clusters-common/src/resource-monitoring-delegates.cpp + ${chip_dir}/examples/all-clusters-app/all-clusters-common/src/rvc-modes.cpp ${chip_dir}/examples/all-clusters-app/all-clusters-common/src/smco-stub.cpp ${chip_dir}/examples/all-clusters-app/all-clusters-common/src/static-supported-modes-manager.cpp ${chip_dir}/examples/all-clusters-app/all-clusters-common/src/static-supported-temperature-levels.cpp @@ -167,10 +169,15 @@ list( ${chip_dir}/examples/all-clusters-app/ameba/main/CHIPDeviceManager.cpp ${chip_dir}/examples/all-clusters-app/ameba/main/Globals.cpp ${chip_dir}/examples/all-clusters-app/ameba/main/LEDWidget.cpp + ${chip_dir}/examples/all-clusters-app/ameba/main/OperationalStateManager.cpp + ${chip_dir}/examples/all-clusters-app/ameba/main/ManualOperationCommand.cpp + ${chip_dir}/examples/all-clusters-app/ameba/main/SmokeCOAlarmManager.cpp ${chip_dir}/examples/platform/ameba/route_hook/ameba_route_hook.c ${chip_dir}/examples/platform/ameba/route_hook/ameba_route_table.c + ${chip_dir}/examples/platform/ameba/test_event_trigger/AmebaTestEventTriggerDelegate.cpp + ${chip_dir}/examples/providers/DeviceInfoProviderImpl.cpp ) diff --git a/examples/all-clusters-app/ameba/main/ManualOperationCommand.cpp b/examples/all-clusters-app/ameba/main/ManualOperationCommand.cpp index 51411d39329d29..feb346b892f6bb 100644 --- a/examples/all-clusters-app/ameba/main/ManualOperationCommand.cpp +++ b/examples/all-clusters-app/ameba/main/ManualOperationCommand.cpp @@ -17,10 +17,10 @@ */ #include "ManualOperationCommand.h" +#include "ManualDishWasherAlarmCommand.h" #include "ManualOperationalStateCommand.h" #include "ManualRVCModesCommand.h" #include "ManualRefrigeratorAlarmCommand.h" -#include "ManualDishWasherAlarmCommand.h" #include "app/server/Server.h" #include "platform/CHIPDeviceLayer.h" @@ -109,32 +109,36 @@ static void RegisterManualOperationCommands() { &ManualRVCCleanModeCommandHelpHandler, "help", "Usage: manual rvc cleanmode " }, { &ManualRVCCleanModeSetModeCommandHandler, "set-mode", "set-mode Usage: manual rvc cleanmode set-mode " }, }; - - static const shell_command_t sManualRefrigeratorAlarmStateSubCommands[] = { - { &ManualRefrigeratorAlarmCommandHelpHandler, "help", "Usage: manual refalm " }, - { &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 " }, - { &ManualDishWasherAlarmSetRaiseCommandHandler, "raise", "raise Usage: manual dishalm raise"}, - { &ManualDishWasherAlarmSetLowerCommandHandler, "lower", "lower Usage: manual dishalm lower" }, - }; + + static const shell_command_t sManualRefrigeratorAlarmStateSubCommands[] = { + { &ManualRefrigeratorAlarmCommandHelpHandler, "help", "Usage: manual refalm " }, + { &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 " }, + { &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 " }; // Register commands sShellManualOperationSubCommands.RegisterCommands(sManualOperationSubCommands, ArraySize(sManualOperationSubCommands)); - sShellManualOperationalStateSubCommands.RegisterCommands(sManualOperationalStateSubCommands, ArraySize(sManualOperationalStateSubCommands)); + sShellManualOperationalStateSubCommands.RegisterCommands(sManualOperationalStateSubCommands, + ArraySize(sManualOperationalStateSubCommands)); sShellManualRVCSubCommands.RegisterCommands(sManualRVCSubCommands, ArraySize(sManualRVCSubCommands)); - sShellManualRVCOperationalStateSubCommands.RegisterCommands(sManualRVCOperationalStateSubCommands, ArraySize(sManualRVCOperationalStateSubCommands)); + 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)); + sShellManualRefrigeratorAlarmStateSubCommands.RegisterCommands(sManualRefrigeratorAlarmStateSubCommands, + ArraySize(sManualRefrigeratorAlarmStateSubCommands)); + sShellManualDishWasherAlarmStateSubCommands.RegisterCommands(sManualDishWasherAlarmSubCommands, + ArraySize(sManualDishWasherAlarmSubCommands)); Engine::Root().RegisterCommands(&sManualOperationCommand, 1); } diff --git a/examples/all-clusters-app/ameba/main/OperationalStateManager.cpp b/examples/all-clusters-app/ameba/main/OperationalStateManager.cpp index 0a8d508694f731..9e4001e7d24e2d 100644 --- a/examples/all-clusters-app/ameba/main/OperationalStateManager.cpp +++ b/examples/all-clusters-app/ameba/main/OperationalStateManager.cpp @@ -23,7 +23,7 @@ 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) +CHIP_ERROR GenericOperationalStateDelegateImpl::GetOperationalStateAtIndex(size_t index, GenericOperationalState & operationalState) { if (index >= mOperationalStateList.size()) { @@ -33,7 +33,7 @@ CHIP_ERROR GenericOperationalStateDelegateImpl::GetOperationalStateAtIndex(size_ return CHIP_NO_ERROR; } -CHIP_ERROR GenericOperationalStateDelegateImpl::GetOperationalPhaseAtIndex(size_t index, GenericOperationalPhase &operationalPhase) +CHIP_ERROR GenericOperationalStateDelegateImpl::GetOperationalPhaseAtIndex(size_t index, GenericOperationalPhase & operationalPhase) { if (index >= mOperationalPhaseList.size()) { @@ -43,7 +43,7 @@ CHIP_ERROR GenericOperationalStateDelegateImpl::GetOperationalPhaseAtIndex(size_ return CHIP_NO_ERROR; } -void GenericOperationalStateDelegateImpl::HandlePauseStateCallback(GenericOperationalError &err) +void GenericOperationalStateDelegateImpl::HandlePauseStateCallback(GenericOperationalError & err) { auto error = GetInstance()->SetOperationalState(to_underlying(OperationalState::OperationalStateEnum::kPaused)); if (error == CHIP_NO_ERROR) @@ -56,7 +56,7 @@ void GenericOperationalStateDelegateImpl::HandlePauseStateCallback(GenericOperat } } -void GenericOperationalStateDelegateImpl::HandleResumeStateCallback(GenericOperationalError &err) +void GenericOperationalStateDelegateImpl::HandleResumeStateCallback(GenericOperationalError & err) { auto error = GetInstance()->SetOperationalState(to_underlying(OperationalStateEnum::kRunning)); if (error == CHIP_NO_ERROR) @@ -69,7 +69,7 @@ void GenericOperationalStateDelegateImpl::HandleResumeStateCallback(GenericOpera } } -void GenericOperationalStateDelegateImpl::HandleStartStateCallback(GenericOperationalError &err) +void GenericOperationalStateDelegateImpl::HandleStartStateCallback(GenericOperationalError & err) { auto error = GetInstance()->SetOperationalState(to_underlying(OperationalStateEnum::kRunning)); if (error == CHIP_NO_ERROR) @@ -82,7 +82,7 @@ void GenericOperationalStateDelegateImpl::HandleStartStateCallback(GenericOperat } } -void GenericOperationalStateDelegateImpl::HandleStopStateCallback(GenericOperationalError &err) +void GenericOperationalStateDelegateImpl::HandleStopStateCallback(GenericOperationalError & err) { auto error = GetInstance()->SetOperationalState(to_underlying(OperationalStateEnum::kStopped)); if (error == CHIP_NO_ERROR) @@ -97,8 +97,8 @@ void GenericOperationalStateDelegateImpl::HandleStopStateCallback(GenericOperati // Init Operational State cluster -static OperationalState::Instance *gOperationalStateInstance = nullptr; -static OperationalStateDelegate *gOperationalStateDelegate = nullptr; +static OperationalState::Instance * gOperationalStateInstance = nullptr; +static OperationalStateDelegate * gOperationalStateDelegate = nullptr; void OperationalState::Shutdown() { @@ -114,7 +114,7 @@ void OperationalState::Shutdown() } } -OperationalState::Instance *OperationalState::GetOperationalStateInstance() +OperationalState::Instance * OperationalState::GetOperationalStateInstance() { return gOperationalStateInstance; } @@ -135,10 +135,10 @@ void emberAfOperationalStateClusterInitCallback(chip::EndpointId endpointId) // Init RVC Operational State cluster -static OperationalState::Instance *gRvcOperationalStateInstance = nullptr; -static RvcOperationalStateDelegate *gRvcOperationalStateDelegate = nullptr; +static OperationalState::Instance * gRvcOperationalStateInstance = nullptr; +static RvcOperationalStateDelegate * gRvcOperationalStateDelegate = nullptr; -OperationalState::Instance *OperationalState::GetRVCOperationalStateInstance() +OperationalState::Instance * OperationalState::GetRVCOperationalStateInstance() { return gRvcOperationalStateInstance; } diff --git a/examples/all-clusters-app/ameba/main/SmokeCOAlarmManager.cpp b/examples/all-clusters-app/ameba/main/SmokeCOAlarmManager.cpp index 371c2665573170..bede2bcf537a76 100644 --- a/examples/all-clusters-app/ameba/main/SmokeCOAlarmManager.cpp +++ b/examples/all-clusters-app/ameba/main/SmokeCOAlarmManager.cpp @@ -36,7 +36,7 @@ CHIP_ERROR SmokeCoAlarmManager::Init() void SmokeCoAlarmManager::StartSelfTesting() { - //Currently selftest is not implemented + // Currently selftest is not implemented } bool emberAfHandleEventTrigger(uint64_t eventTrigger) diff --git a/examples/all-clusters-app/ameba/main/include/ManualDishWasherAlarmCommand.h b/examples/all-clusters-app/ameba/main/include/ManualDishWasherAlarmCommand.h index cb75e6cf07b9f8..8a29e7f3e68f93 100644 --- a/examples/all-clusters-app/ameba/main/include/ManualDishWasherAlarmCommand.h +++ b/examples/all-clusters-app/ameba/main/include/ManualDishWasherAlarmCommand.h @@ -61,29 +61,33 @@ CHIP_ERROR ManualDishWasherAlarmSetRaiseCommandHandler(int argc, char ** argv) { CHIP_ERROR err = CHIP_NO_ERROR; EmberAfStatus status; - DishwasherAlarmServer& serverInstance = DishwasherAlarmServer::Instance(); - - status = serverInstance.SetSupportedValue(1,47); - if (status != EMBER_ZCL_STATUS_SUCCESS) { - err = CHIP_ERROR_INTERNAL; - goto exit; - } - - status = serverInstance.SetMaskValue(1, 47); - if (status != EMBER_ZCL_STATUS_SUCCESS) { - err = CHIP_ERROR_INTERNAL; - goto exit; - } - - status = serverInstance.SetStateValue(1, 14, 0); - if (status != EMBER_ZCL_STATUS_SUCCESS) { - err = CHIP_ERROR_INTERNAL; - goto exit; - } + DishwasherAlarmServer & serverInstance = DishwasherAlarmServer::Instance(); + + status = serverInstance.SetSupportedValue(1, 47); + if (status != EMBER_ZCL_STATUS_SUCCESS) + { + err = CHIP_ERROR_INTERNAL; + goto exit; + } + + status = serverInstance.SetMaskValue(1, 47); + if (status != EMBER_ZCL_STATUS_SUCCESS) + { + err = CHIP_ERROR_INTERNAL; + goto exit; + } + + status = serverInstance.SetStateValue(1, 14, 0); + if (status != EMBER_ZCL_STATUS_SUCCESS) + { + err = CHIP_ERROR_INTERNAL; + goto exit; + } exit: - if (err != CHIP_NO_ERROR) { - ChipLogError(DeviceLayer, "ManualDishWasherAlarmSetRaiseCommandHandler Failed!\r\n"); - } + if (err != CHIP_NO_ERROR) + { + ChipLogError(DeviceLayer, "ManualDishWasherAlarmSetRaiseCommandHandler Failed!\r\n"); + } return err; } @@ -92,29 +96,33 @@ CHIP_ERROR ManualDishWasherAlarmSetLowerCommandHandler(int argc, char ** argv) { CHIP_ERROR err = CHIP_NO_ERROR; EmberAfStatus status; - DishwasherAlarmServer& serverInstance = DishwasherAlarmServer::Instance(); - - status = serverInstance.SetSupportedValue(1,47); - if (status != EMBER_ZCL_STATUS_SUCCESS) { - err = CHIP_ERROR_INTERNAL; - goto exit; - } - - status = serverInstance.SetMaskValue(1, 47); - if (status != EMBER_ZCL_STATUS_SUCCESS) { - err = CHIP_ERROR_INTERNAL; - goto exit; - } - - status = serverInstance.SetStateValue(1, 14, 0); - if (status != EMBER_ZCL_STATUS_SUCCESS) { - err = CHIP_ERROR_INTERNAL; - goto exit; - } + DishwasherAlarmServer & serverInstance = DishwasherAlarmServer::Instance(); + + status = serverInstance.SetSupportedValue(1, 47); + if (status != EMBER_ZCL_STATUS_SUCCESS) + { + err = CHIP_ERROR_INTERNAL; + goto exit; + } + + status = serverInstance.SetMaskValue(1, 47); + if (status != EMBER_ZCL_STATUS_SUCCESS) + { + err = CHIP_ERROR_INTERNAL; + goto exit; + } + + status = serverInstance.SetStateValue(1, 14, 0); + if (status != EMBER_ZCL_STATUS_SUCCESS) + { + err = CHIP_ERROR_INTERNAL; + goto exit; + } exit: - if (err != CHIP_NO_ERROR) { - ChipLogError(DeviceLayer, "ManualDishWasherAlarmSetLowerCommandHandler Failed!\r\n"); - } + if (err != CHIP_NO_ERROR) + { + ChipLogError(DeviceLayer, "ManualDishWasherAlarmSetLowerCommandHandler Failed!\r\n"); + } return err; } diff --git a/examples/all-clusters-app/ameba/main/include/ManualOperationalStateCommand.h b/examples/all-clusters-app/ameba/main/include/ManualOperationalStateCommand.h index 61c33373c9d457..f2b9281cd8317f 100644 --- a/examples/all-clusters-app/ameba/main/include/ManualOperationalStateCommand.h +++ b/examples/all-clusters-app/ameba/main/include/ManualOperationalStateCommand.h @@ -67,14 +67,15 @@ CHIP_ERROR ManualOperationalStateSetStateCommandHandler(int argc, char ** argv) { return ManualOperationalStateCommandHelpHandler(argc, argv); } - uint32_t state = atoi(argv[0]); + uint32_t state = atoi(argv[0]); CHIP_ERROR err; - err = GetOperationalStateInstance()->SetOperationalState(state); + err = GetOperationalStateInstance()->SetOperationalState(state); - if (err != CHIP_NO_ERROR) { - ChipLogError(DeviceLayer, "ManualOperationalStateSetStateCommandHandler Failed!\r\n"); - } + if (err != CHIP_NO_ERROR) + { + ChipLogError(DeviceLayer, "ManualOperationalStateSetStateCommandHandler Failed!\r\n"); + } return err; } @@ -86,11 +87,11 @@ CHIP_ERROR ManualOperationalStateSetErrorCommandHandler(int argc, char ** argv) return ManualOperationalStateCommandHelpHandler(argc, argv); } - GenericOperationalError err(to_underlying(ErrorStateEnum::kNoError)); + GenericOperationalError err(to_underlying(ErrorStateEnum::kNoError)); uint32_t error = atoi(argv[0]); - - switch(error) - { + + switch (error) + { case to_underlying(OperationalState::ErrorStateEnum::kNoError): err.errorStateID = to_underlying(OperationalState::ErrorStateEnum::kNoError); break; @@ -139,14 +140,15 @@ CHIP_ERROR ManualRVCOperationalStateSetStateCommandHandler(int argc, char ** arg { return ManualRVCOperationalStateCommandHelpHandler(argc, argv); } - uint32_t state = atoi(argv[0]); + uint32_t state = atoi(argv[0]); CHIP_ERROR err; err = GetRVCOperationalStateInstance()->SetOperationalState(state); - if (err != CHIP_NO_ERROR) { - ChipLogError(DeviceLayer, "ManualRVCOperationalStateSetStateCommandHandler Failed!\r\n"); - } + if (err != CHIP_NO_ERROR) + { + ChipLogError(DeviceLayer, "ManualRVCOperationalStateSetStateCommandHandler Failed!\r\n"); + } return err; } @@ -158,45 +160,45 @@ CHIP_ERROR ManualRVCOperationalStateSetErrorCommandHandler(int argc, char ** arg return ManualRVCOperationalStateCommandHelpHandler(argc, argv); } - GenericOperationalError err(to_underlying(ErrorStateEnum::kNoError)); + GenericOperationalError err(to_underlying(ErrorStateEnum::kNoError)); uint32_t error = atoi(argv[0]); - - switch(error) - { - case to_underlying(OperationalState::ErrorStateEnum::kNoError): //0x00, 0 + + switch (error) + { + case to_underlying(OperationalState::ErrorStateEnum::kNoError): // 0x00, 0 err.errorStateID = to_underlying(OperationalState::ErrorStateEnum::kNoError); break; - case to_underlying(OperationalState::ErrorStateEnum::kUnableToStartOrResume): //0x01, 1 + case to_underlying(OperationalState::ErrorStateEnum::kUnableToStartOrResume): // 0x01, 1 err.errorStateID = to_underlying(OperationalState::ErrorStateEnum::kUnableToStartOrResume); break; - case to_underlying(OperationalState::ErrorStateEnum::kUnableToCompleteOperation): //0x02, 2 + case to_underlying(OperationalState::ErrorStateEnum::kUnableToCompleteOperation): // 0x02, 2 err.errorStateID = to_underlying(OperationalState::ErrorStateEnum::kUnableToCompleteOperation); break; - case to_underlying(OperationalState::ErrorStateEnum::kCommandInvalidInState): //0x03, 3 + case to_underlying(OperationalState::ErrorStateEnum::kCommandInvalidInState): // 0x03, 3 err.errorStateID = to_underlying(OperationalState::ErrorStateEnum::kCommandInvalidInState); break; - case to_underlying(RvcOperationalState::ErrorStateEnum::kFailedToFindChargingDock): //0x40, 64 + case to_underlying(RvcOperationalState::ErrorStateEnum::kFailedToFindChargingDock): // 0x40, 64 err.errorStateID = to_underlying(RvcOperationalState::ErrorStateEnum::kFailedToFindChargingDock); break; - case to_underlying(RvcOperationalState::ErrorStateEnum::kStuck): //0x41, 65 + case to_underlying(RvcOperationalState::ErrorStateEnum::kStuck): // 0x41, 65 err.errorStateID = to_underlying(RvcOperationalState::ErrorStateEnum::kStuck); break; - case to_underlying(RvcOperationalState::ErrorStateEnum::kDustBinMissing): //0x42, 66 + case to_underlying(RvcOperationalState::ErrorStateEnum::kDustBinMissing): // 0x42, 66 err.errorStateID = to_underlying(RvcOperationalState::ErrorStateEnum::kDustBinMissing); break; - case to_underlying(RvcOperationalState::ErrorStateEnum::kDustBinFull): //0x43, 67 + case to_underlying(RvcOperationalState::ErrorStateEnum::kDustBinFull): // 0x43, 67 err.errorStateID = to_underlying(RvcOperationalState::ErrorStateEnum::kDustBinFull); break; - case to_underlying(RvcOperationalState::ErrorStateEnum::kWaterTankEmpty): //0x44, 68 + case to_underlying(RvcOperationalState::ErrorStateEnum::kWaterTankEmpty): // 0x44, 68 err.errorStateID = to_underlying(RvcOperationalState::ErrorStateEnum::kWaterTankEmpty); break; - case to_underlying(RvcOperationalState::ErrorStateEnum::kWaterTankMissing): //0x45, 69 + case to_underlying(RvcOperationalState::ErrorStateEnum::kWaterTankMissing): // 0x45, 69 err.errorStateID = to_underlying(RvcOperationalState::ErrorStateEnum::kWaterTankMissing); break; - case to_underlying(RvcOperationalState::ErrorStateEnum::kWaterTankLidOpen): //0x46, 70 + case to_underlying(RvcOperationalState::ErrorStateEnum::kWaterTankLidOpen): // 0x46, 70 err.errorStateID = to_underlying(RvcOperationalState::ErrorStateEnum::kWaterTankLidOpen); break; - case to_underlying(RvcOperationalState::ErrorStateEnum::kMopCleaningPadMissing): //0x47, 71 + case to_underlying(RvcOperationalState::ErrorStateEnum::kMopCleaningPadMissing): // 0x47, 71 err.errorStateID = to_underlying(RvcOperationalState::ErrorStateEnum::kMopCleaningPadMissing); break; default: diff --git a/examples/all-clusters-app/ameba/main/include/ManualRefrigeratorAlarmCommand.h b/examples/all-clusters-app/ameba/main/include/ManualRefrigeratorAlarmCommand.h index 30b50528cbc8ee..d2ec4224a5332f 100644 --- a/examples/all-clusters-app/ameba/main/include/ManualRefrigeratorAlarmCommand.h +++ b/examples/all-clusters-app/ameba/main/include/ManualRefrigeratorAlarmCommand.h @@ -61,30 +61,34 @@ CHIP_ERROR ManualRefrigeratorAlarmDoorOpenCommandHandler(int argc, char ** argv) { CHIP_ERROR err = CHIP_NO_ERROR; EmberAfStatus status; - RefrigeratorAlarmServer& serverInstance = RefrigeratorAlarmServer::Instance(); - - status = serverInstance.SetMaskValue(1, 0); - if (status != EMBER_ZCL_STATUS_SUCCESS) { - err = CHIP_ERROR_INTERNAL; - goto exit; - } - - status = serverInstance.SetStateValue(1, 1); - if (status != EMBER_ZCL_STATUS_SUCCESS) { - err = CHIP_ERROR_INTERNAL; - goto exit; - } - - status = serverInstance.SetSupportedValue(1, 0); - if (status != EMBER_ZCL_STATUS_SUCCESS) { - err = CHIP_ERROR_INTERNAL; - goto exit; - } + RefrigeratorAlarmServer & serverInstance = RefrigeratorAlarmServer::Instance(); + + status = serverInstance.SetMaskValue(1, 0); + if (status != EMBER_ZCL_STATUS_SUCCESS) + { + err = CHIP_ERROR_INTERNAL; + goto exit; + } + + status = serverInstance.SetStateValue(1, 1); + if (status != EMBER_ZCL_STATUS_SUCCESS) + { + err = CHIP_ERROR_INTERNAL; + goto exit; + } + + status = serverInstance.SetSupportedValue(1, 0); + if (status != EMBER_ZCL_STATUS_SUCCESS) + { + err = CHIP_ERROR_INTERNAL; + goto exit; + } exit: - if (err != CHIP_NO_ERROR) { - ChipLogError(DeviceLayer, "ManualRefrigeratorAlarmDoorOpenCommandHandler Failed!\r\n"); - } + if (err != CHIP_NO_ERROR) + { + ChipLogError(DeviceLayer, "ManualRefrigeratorAlarmDoorOpenCommandHandler Failed!\r\n"); + } return err; } @@ -93,30 +97,34 @@ CHIP_ERROR ManualRefrigeratorAlarmDoorCloseCommandHandler(int argc, char ** argv { CHIP_ERROR err = CHIP_NO_ERROR; EmberAfStatus status; - RefrigeratorAlarmServer& serverInstance = RefrigeratorAlarmServer::Instance(); - - status = serverInstance.SetMaskValue(1, 1); - if (status != EMBER_ZCL_STATUS_SUCCESS) { - err = CHIP_ERROR_INTERNAL; - goto exit; - } - - status = serverInstance.SetStateValue(1, 0); - if (status != EMBER_ZCL_STATUS_SUCCESS) { - err = CHIP_ERROR_INTERNAL; - goto exit; - } - - status = serverInstance.SetSupportedValue(1, 1); - if (status != EMBER_ZCL_STATUS_SUCCESS) { - err = CHIP_ERROR_INTERNAL; - goto exit; - } + RefrigeratorAlarmServer & serverInstance = RefrigeratorAlarmServer::Instance(); + + status = serverInstance.SetMaskValue(1, 1); + if (status != EMBER_ZCL_STATUS_SUCCESS) + { + err = CHIP_ERROR_INTERNAL; + goto exit; + } + + status = serverInstance.SetStateValue(1, 0); + if (status != EMBER_ZCL_STATUS_SUCCESS) + { + err = CHIP_ERROR_INTERNAL; + goto exit; + } + + status = serverInstance.SetSupportedValue(1, 1); + if (status != EMBER_ZCL_STATUS_SUCCESS) + { + err = CHIP_ERROR_INTERNAL; + goto exit; + } exit: - if (err != CHIP_NO_ERROR) { - ChipLogError(DeviceLayer, "ManualRefrigeratorAlarmDoorCloseCommandHandler Failed!\r\n"); - } + if (err != CHIP_NO_ERROR) + { + ChipLogError(DeviceLayer, "ManualRefrigeratorAlarmDoorCloseCommandHandler Failed!\r\n"); + } return err; } @@ -125,24 +133,27 @@ CHIP_ERROR ManualRefrigeratorAlarmSuppressCommandHandler(int argc, char ** argv) { CHIP_ERROR err = CHIP_NO_ERROR; EmberAfStatus status; - RefrigeratorAlarmServer& serverInstance = RefrigeratorAlarmServer::Instance(); + RefrigeratorAlarmServer & serverInstance = RefrigeratorAlarmServer::Instance(); - status = serverInstance.SetSupportedValue(1, 1); - if (status != EMBER_ZCL_STATUS_SUCCESS) { - err = CHIP_ERROR_INTERNAL; - goto exit; - } + status = serverInstance.SetSupportedValue(1, 1); + if (status != EMBER_ZCL_STATUS_SUCCESS) + { + err = CHIP_ERROR_INTERNAL; + goto exit; + } - status = serverInstance.SetStateValue(1, 0); - if (status != EMBER_ZCL_STATUS_SUCCESS) { - err = CHIP_ERROR_INTERNAL; - goto exit; - } + status = serverInstance.SetStateValue(1, 0); + if (status != EMBER_ZCL_STATUS_SUCCESS) + { + err = CHIP_ERROR_INTERNAL; + goto exit; + } exit: - if (err != CHIP_NO_ERROR) { - ChipLogError(DeviceLayer, "ManualRefrigeratorAlarmDoorCloseCommandHandler Failed!\r\n"); - } + if (err != CHIP_NO_ERROR) + { + ChipLogError(DeviceLayer, "ManualRefrigeratorAlarmDoorCloseCommandHandler Failed!\r\n"); + } return err; } diff --git a/examples/all-clusters-app/ameba/main/include/OperationalStateManager.h b/examples/all-clusters-app/ameba/main/include/OperationalStateManager.h index e1b182bcb9f1c0..e98d32171328ac 100644 --- a/examples/all-clusters-app/ameba/main/include/OperationalStateManager.h +++ b/examples/all-clusters-app/ameba/main/include/OperationalStateManager.h @@ -31,8 +31,8 @@ namespace Clusters { namespace OperationalState { - Instance *GetOperationalStateInstance(); - Instance *GetRVCOperationalStateInstance(); +Instance * GetOperationalStateInstance(); +Instance * GetRVCOperationalStateInstance(); // This is an application level delegate to handle operational state commands according to the specific business logic. class GenericOperationalStateDelegateImpl : public Delegate @@ -52,7 +52,7 @@ class GenericOperationalStateDelegateImpl : public Delegate * @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, GenericOperationalState &operationalState) override; + CHIP_ERROR GetOperationalStateAtIndex(size_t index, GenericOperationalState & operationalState) override; /** * Fills in the provided GenericOperationalPhase with the phase at index `index` if there is one, @@ -62,32 +62,32 @@ class GenericOperationalStateDelegateImpl : public Delegate * @param index The index of the phase, with 0 representing the first phase. * @param operationalPhase The GenericOperationalPhase is filled. */ - CHIP_ERROR GetOperationalPhaseAtIndex(size_t index, GenericOperationalPhase &operationalPhase) override; + CHIP_ERROR GetOperationalPhaseAtIndex(size_t index, GenericOperationalPhase & operationalPhase) override; // command callback /** * Handle Command Callback in application: Pause * @param[out] get operational error after callback. */ - void HandlePauseStateCallback(GenericOperationalError &err) override; + void HandlePauseStateCallback(GenericOperationalError & err) override; /** * Handle Command Callback in application: Resume * @param[out] get operational error after callback. */ - void HandleResumeStateCallback(GenericOperationalError &err) override; + void HandleResumeStateCallback(GenericOperationalError & err) override; /** * Handle Command Callback in application: Start * @param[out] get operational error after callback. */ - void HandleStartStateCallback(GenericOperationalError &err) override; + void HandleStartStateCallback(GenericOperationalError & err) override; /** * Handle Command Callback in application: Stop * @param[out] get operational error after callback. */ - void HandleStopStateCallback(GenericOperationalError &err) override; + void HandleStopStateCallback(GenericOperationalError & err) override; protected: Span mOperationalStateList; diff --git a/examples/all-clusters-app/ameba/main/include/SmokeCOAlarmManager.h b/examples/all-clusters-app/ameba/main/include/SmokeCOAlarmManager.h index 0fc82a6f61a3b3..390ee679d0d255 100644 --- a/examples/all-clusters-app/ameba/main/include/SmokeCOAlarmManager.h +++ b/examples/all-clusters-app/ameba/main/include/SmokeCOAlarmManager.h @@ -17,10 +17,10 @@ #pragma once -#include -#include #include #include +#include +#include bool emberAfHandleEventTrigger(uint64_t eventTrigger); diff --git a/examples/platform/ameba/test_event_trigger/AmebaTestEventTriggerDelegate.cpp b/examples/platform/ameba/test_event_trigger/AmebaTestEventTriggerDelegate.cpp index dbf7c70f6a3c83..9cfddd6f3de9fa 100644 --- a/examples/platform/ameba/test_event_trigger/AmebaTestEventTriggerDelegate.cpp +++ b/examples/platform/ameba/test_event_trigger/AmebaTestEventTriggerDelegate.cpp @@ -16,8 +16,8 @@ * limitations under the License. */ -#include "SmokeCOAlarmManager.h" #include "AmebaTestEventTriggerDelegate.h" +#include "SmokeCOAlarmManager.h" using namespace ::chip::DeviceLayer; From 66a87a4efc07f93edb791ea1843f2a8368b6d945 Mon Sep 17 00:00:00 2001 From: pankore <86098180+pankore@users.noreply.github.com> Date: Tue, 10 Oct 2023 10:53:22 +0800 Subject: [PATCH 3/6] [Ameba] Added CONFIG_ENABLE_AMEBA_TEST_EVENT_TRIGGER macro --- examples/all-clusters-app/ameba/main/chipinterface.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/examples/all-clusters-app/ameba/main/chipinterface.cpp b/examples/all-clusters-app/ameba/main/chipinterface.cpp index 5413467de6cf65..21280c676154be 100644 --- a/examples/all-clusters-app/ameba/main/chipinterface.cpp +++ b/examples/all-clusters-app/ameba/main/chipinterface.cpp @@ -42,7 +42,9 @@ #include #include #include +#if CONFIG_ENABLE_AMEBA_TEST_EVENT_TRIGGER #include +#endif #if CONFIG_ENABLE_PW_RPC #include @@ -127,18 +129,22 @@ Identify gIdentify1 = { static DeviceCallbacks EchoCallbacks; chip::DeviceLayer::DeviceInfoProviderImpl gExampleDeviceInfoProvider; +#if CONFIG_ENABLE_AMEBA_TEST_EVENT_TRIGGER uint8_t sTestEventTriggerEnableKey[TestEventTriggerDelegate::kEnableKeyLength] = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff }; +#endif static void InitServer(intptr_t context) { // Init ZCL Data Model and CHIP App Server static chip::CommonCaseDeviceServerInitParams initParams; - initParams.InitializeStaticResourcesBeforeServerInit(); +#if CONFIG_ENABLE_AMEBA_TEST_EVENT_TRIGGER static AmebaTestEventTriggerDelegate testEventTriggerDelegate{ ByteSpan(sTestEventTriggerEnableKey) }; - (void) initParams.InitializeStaticResourcesBeforeServerInit(); initParams.testEventTriggerDelegate = &testEventTriggerDelegate; +#endif + + initParams.InitializeStaticResourcesBeforeServerInit(); chip::Server::GetInstance().Init(initParams); gExampleDeviceInfoProvider.SetStorageDelegate(&Server::GetInstance().GetPersistentStorage()); From 7245b90bb77291909f1977377ba2558caf18f3a4 Mon Sep 17 00:00:00 2001 From: pankore <86098180+pankore@users.noreply.github.com> Date: Tue, 10 Oct 2023 15:07:37 +0800 Subject: [PATCH 4/6] [Ameba] added CONFIG_ENABLE_AMEBA_TEST_EVENT_TRIGGER define flag at cmake --- examples/all-clusters-app/ameba/chip_main.cmake | 1 + 1 file changed, 1 insertion(+) diff --git a/examples/all-clusters-app/ameba/chip_main.cmake b/examples/all-clusters-app/ameba/chip_main.cmake index 32b13fcc7b375b..07052e123757cd 100755 --- a/examples/all-clusters-app/ameba/chip_main.cmake +++ b/examples/all-clusters-app/ameba/chip_main.cmake @@ -270,6 +270,7 @@ list( -DMBEDTLS_CONFIG_FILE= -DCHIP_SHELL_MAX_TOKENS=11 -DCONFIG_ENABLE_AMEBA_FACTORY_DATA=0 + -DCONFIG_ENABLE_AMEBA_TEST_EVENT_TRIGGER=0 ) if (matter_enable_persistentstorage_audit) From b9de5a56c96944237ffc22576f0c2462552730a0 Mon Sep 17 00:00:00 2001 From: pankore <86098180+pankore@users.noreply.github.com> Date: Fri, 13 Oct 2023 14:02:44 +0800 Subject: [PATCH 5/6] [Ameba] Updated switch case at ManualOperationalStateCommand.h and updated raise and lower alarm function at ManualDishWasherAlarmCommand.h --- .../include/ManualDishWasherAlarmCommand.h | 55 +++++++++++++++++-- .../include/ManualOperationalStateCommand.h | 54 +++++------------- 2 files changed, 62 insertions(+), 47 deletions(-) diff --git a/examples/all-clusters-app/ameba/main/include/ManualDishWasherAlarmCommand.h b/examples/all-clusters-app/ameba/main/include/ManualDishWasherAlarmCommand.h index 8a29e7f3e68f93..c1a37be41d385a 100644 --- a/examples/all-clusters-app/ameba/main/include/ManualDishWasherAlarmCommand.h +++ b/examples/all-clusters-app/ameba/main/include/ManualDishWasherAlarmCommand.h @@ -59,25 +59,49 @@ CHIP_ERROR ManualDishWasherAlarmCommandHandler(int argc, char ** argv) CHIP_ERROR ManualDishWasherAlarmSetRaiseCommandHandler(int argc, char ** argv) { + if (argc != 0) + { + return ManualDishWasherAlarmCommandHelpHandler(argc, argv); + } + CHIP_ERROR err = CHIP_NO_ERROR; EmberAfStatus status; DishwasherAlarmServer & serverInstance = DishwasherAlarmServer::Instance(); - status = serverInstance.SetSupportedValue(1, 47); + BitMask supported; // Set dishwasher alarm supported value + supported.SetField(AlarmMap::kInflowError, 1); // 0x01, 1 + supported.SetField(AlarmMap::kDrainError, 1); // 0x02, 2 + supported.SetField(AlarmMap::kDoorError, 1); // 0x04, 4 + supported.SetField(AlarmMap::kTempTooLow, 1); // 0x08, 8 + supported.SetField(AlarmMap::kWaterLevelError, 1); // 0x20, 32 + + BitMask mask; // Set dishwasher alarm mask value + mask.SetField(AlarmMap::kInflowError, 1); // 0x01, 1 + mask.SetField(AlarmMap::kDrainError, 1); // 0x02, 2 + mask.SetField(AlarmMap::kDoorError, 1); // 0x04, 4 + mask.SetField(AlarmMap::kTempTooLow, 1); // 0x08, 8 + mask.SetField(AlarmMap::kWaterLevelError, 1); // 0x20, 32 + + BitMask state; // Set dishwasher alarm state value + state.SetField(AlarmMap::kDrainError, 1); // 0x02, 2 + state.SetField(AlarmMap::kDoorError, 1); // 0x04, 4 + state.SetField(AlarmMap::kTempTooLow, 1); // 0x08, 8 + + status = serverInstance.SetSupportedValue(1, supported); // 0x2F, 47 if (status != EMBER_ZCL_STATUS_SUCCESS) { err = CHIP_ERROR_INTERNAL; goto exit; } - status = serverInstance.SetMaskValue(1, 47); + status = serverInstance.SetMaskValue(1, mask); // 0x2F, 47 if (status != EMBER_ZCL_STATUS_SUCCESS) { err = CHIP_ERROR_INTERNAL; goto exit; } - status = serverInstance.SetStateValue(1, 14, 0); + status = serverInstance.SetStateValue(1, state); // 0x0E, 14 if (status != EMBER_ZCL_STATUS_SUCCESS) { err = CHIP_ERROR_INTERNAL; @@ -94,25 +118,44 @@ CHIP_ERROR ManualDishWasherAlarmSetRaiseCommandHandler(int argc, char ** argv) CHIP_ERROR ManualDishWasherAlarmSetLowerCommandHandler(int argc, char ** argv) { + if (argc != 0) + { + return ManualDishWasherAlarmCommandHelpHandler(argc, argv); + } + CHIP_ERROR err = CHIP_NO_ERROR; EmberAfStatus status; DishwasherAlarmServer & serverInstance = DishwasherAlarmServer::Instance(); - status = serverInstance.SetSupportedValue(1, 47); + BitMask supported; // Set dishwasher alarm supported value + supported.SetField(AlarmMap::kInflowError, 1); // 0x01, 1 + supported.SetField(AlarmMap::kDrainError, 1); // 0x02, 2 + supported.SetField(AlarmMap::kDoorError, 1); // 0x04, 4 + supported.SetField(AlarmMap::kTempTooLow, 1); // 0x08, 8 + supported.SetField(AlarmMap::kWaterLevelError, 1); // 0x20, 32 + + BitMask mask; // Set dishwasher alarm mask value + mask.SetField(AlarmMap::kInflowError, 1); // 0x01, 1 + mask.SetField(AlarmMap::kDrainError, 1); // 0x02, 2 + mask.SetField(AlarmMap::kDoorError, 1); // 0x04, 4 + mask.SetField(AlarmMap::kTempTooLow, 1); // 0x08, 8 + mask.SetField(AlarmMap::kWaterLevelError, 1); // 0x20, 32 + + status = serverInstance.SetSupportedValue(1, supported); // 0x2F, 47 if (status != EMBER_ZCL_STATUS_SUCCESS) { err = CHIP_ERROR_INTERNAL; goto exit; } - status = serverInstance.SetMaskValue(1, 47); + status = serverInstance.SetMaskValue(1, mask); // 0x2F, 47 if (status != EMBER_ZCL_STATUS_SUCCESS) { err = CHIP_ERROR_INTERNAL; goto exit; } - status = serverInstance.SetStateValue(1, 14, 0); + status = serverInstance.SetStateValue(1, 0); // Set dishwasher alarm state value 0x00, 0 if (status != EMBER_ZCL_STATUS_SUCCESS) { err = CHIP_ERROR_INTERNAL; diff --git a/examples/all-clusters-app/ameba/main/include/ManualOperationalStateCommand.h b/examples/all-clusters-app/ameba/main/include/ManualOperationalStateCommand.h index f2b9281cd8317f..dbe07ade006f9f 100644 --- a/examples/all-clusters-app/ameba/main/include/ManualOperationalStateCommand.h +++ b/examples/all-clusters-app/ameba/main/include/ManualOperationalStateCommand.h @@ -93,16 +93,10 @@ CHIP_ERROR ManualOperationalStateSetErrorCommandHandler(int argc, char ** argv) switch (error) { case to_underlying(OperationalState::ErrorStateEnum::kNoError): - err.errorStateID = to_underlying(OperationalState::ErrorStateEnum::kNoError); - break; case to_underlying(OperationalState::ErrorStateEnum::kUnableToStartOrResume): - err.errorStateID = to_underlying(OperationalState::ErrorStateEnum::kUnableToStartOrResume); - break; case to_underlying(OperationalState::ErrorStateEnum::kUnableToCompleteOperation): - err.errorStateID = to_underlying(OperationalState::ErrorStateEnum::kUnableToCompleteOperation); - break; case to_underlying(OperationalState::ErrorStateEnum::kCommandInvalidInState): - err.errorStateID = to_underlying(OperationalState::ErrorStateEnum::kCommandInvalidInState); + err.errorStateID = error; break; default: err.errorStateID = to_underlying(OperationalState::ErrorStateEnum::kUnknownEnumValue); @@ -165,41 +159,19 @@ CHIP_ERROR ManualRVCOperationalStateSetErrorCommandHandler(int argc, char ** arg switch (error) { - case to_underlying(OperationalState::ErrorStateEnum::kNoError): // 0x00, 0 - err.errorStateID = to_underlying(OperationalState::ErrorStateEnum::kNoError); - break; - case to_underlying(OperationalState::ErrorStateEnum::kUnableToStartOrResume): // 0x01, 1 - err.errorStateID = to_underlying(OperationalState::ErrorStateEnum::kUnableToStartOrResume); - break; - case to_underlying(OperationalState::ErrorStateEnum::kUnableToCompleteOperation): // 0x02, 2 - err.errorStateID = to_underlying(OperationalState::ErrorStateEnum::kUnableToCompleteOperation); - break; - case to_underlying(OperationalState::ErrorStateEnum::kCommandInvalidInState): // 0x03, 3 - err.errorStateID = to_underlying(OperationalState::ErrorStateEnum::kCommandInvalidInState); - break; + case to_underlying(OperationalState::ErrorStateEnum::kNoError): // 0x00, 0 + case to_underlying(OperationalState::ErrorStateEnum::kUnableToStartOrResume): // 0x01, 1 + case to_underlying(OperationalState::ErrorStateEnum::kUnableToCompleteOperation): // 0x02, 2 + case to_underlying(OperationalState::ErrorStateEnum::kCommandInvalidInState): // 0x03, 3 case to_underlying(RvcOperationalState::ErrorStateEnum::kFailedToFindChargingDock): // 0x40, 64 - err.errorStateID = to_underlying(RvcOperationalState::ErrorStateEnum::kFailedToFindChargingDock); - break; - case to_underlying(RvcOperationalState::ErrorStateEnum::kStuck): // 0x41, 65 - err.errorStateID = to_underlying(RvcOperationalState::ErrorStateEnum::kStuck); - break; - case to_underlying(RvcOperationalState::ErrorStateEnum::kDustBinMissing): // 0x42, 66 - err.errorStateID = to_underlying(RvcOperationalState::ErrorStateEnum::kDustBinMissing); - break; - case to_underlying(RvcOperationalState::ErrorStateEnum::kDustBinFull): // 0x43, 67 - err.errorStateID = to_underlying(RvcOperationalState::ErrorStateEnum::kDustBinFull); - break; - case to_underlying(RvcOperationalState::ErrorStateEnum::kWaterTankEmpty): // 0x44, 68 - err.errorStateID = to_underlying(RvcOperationalState::ErrorStateEnum::kWaterTankEmpty); - break; - case to_underlying(RvcOperationalState::ErrorStateEnum::kWaterTankMissing): // 0x45, 69 - err.errorStateID = to_underlying(RvcOperationalState::ErrorStateEnum::kWaterTankMissing); - break; - case to_underlying(RvcOperationalState::ErrorStateEnum::kWaterTankLidOpen): // 0x46, 70 - err.errorStateID = to_underlying(RvcOperationalState::ErrorStateEnum::kWaterTankLidOpen); - break; - case to_underlying(RvcOperationalState::ErrorStateEnum::kMopCleaningPadMissing): // 0x47, 71 - err.errorStateID = to_underlying(RvcOperationalState::ErrorStateEnum::kMopCleaningPadMissing); + case to_underlying(RvcOperationalState::ErrorStateEnum::kStuck): // 0x41, 65 + case to_underlying(RvcOperationalState::ErrorStateEnum::kDustBinMissing): // 0x42, 66 + case to_underlying(RvcOperationalState::ErrorStateEnum::kDustBinFull): // 0x43, 67 + case to_underlying(RvcOperationalState::ErrorStateEnum::kWaterTankEmpty): // 0x44, 68 + case to_underlying(RvcOperationalState::ErrorStateEnum::kWaterTankMissing): // 0x45, 69 + case to_underlying(RvcOperationalState::ErrorStateEnum::kWaterTankLidOpen): // 0x46, 70 + case to_underlying(RvcOperationalState::ErrorStateEnum::kMopCleaningPadMissing): // 0x47, 71 + err.errorStateID = error; break; default: err.errorStateID = to_underlying(RvcOperationalState::ErrorStateEnum::kUnknownEnumValue); From bdc8b88411fc323a25d3c0ecb3b80732fbd5362b Mon Sep 17 00:00:00 2001 From: pankore <86098180+pankore@users.noreply.github.com> Date: Fri, 20 Oct 2023 16:54:38 +0800 Subject: [PATCH 6/6] [Ameba] Updated RvcOperationalState::ErrorStateEnum::kUnknownEnumValue to OperationalState::ErrorStateEnum::kUnknownEnumValue because it was removed, and added minor comments. --- .../main/include/ManualOperationalStateCommand.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/examples/all-clusters-app/ameba/main/include/ManualOperationalStateCommand.h b/examples/all-clusters-app/ameba/main/include/ManualOperationalStateCommand.h index dbe07ade006f9f..1f6d899b59e828 100644 --- a/examples/all-clusters-app/ameba/main/include/ManualOperationalStateCommand.h +++ b/examples/all-clusters-app/ameba/main/include/ManualOperationalStateCommand.h @@ -92,14 +92,14 @@ CHIP_ERROR ManualOperationalStateSetErrorCommandHandler(int argc, char ** argv) switch (error) { - case to_underlying(OperationalState::ErrorStateEnum::kNoError): - case to_underlying(OperationalState::ErrorStateEnum::kUnableToStartOrResume): - case to_underlying(OperationalState::ErrorStateEnum::kUnableToCompleteOperation): - case to_underlying(OperationalState::ErrorStateEnum::kCommandInvalidInState): + case to_underlying(OperationalState::ErrorStateEnum::kNoError): // 0x00, 0 + case to_underlying(OperationalState::ErrorStateEnum::kUnableToStartOrResume): // 0x01, 1 + case to_underlying(OperationalState::ErrorStateEnum::kUnableToCompleteOperation): // 0x02, 2 + case to_underlying(OperationalState::ErrorStateEnum::kCommandInvalidInState): // 0x03, 3 err.errorStateID = error; break; default: - err.errorStateID = to_underlying(OperationalState::ErrorStateEnum::kUnknownEnumValue); + err.errorStateID = to_underlying(OperationalState::ErrorStateEnum::kUnknownEnumValue); // 0x04, 4 break; } @@ -174,7 +174,7 @@ CHIP_ERROR ManualRVCOperationalStateSetErrorCommandHandler(int argc, char ** arg err.errorStateID = error; break; default: - err.errorStateID = to_underlying(RvcOperationalState::ErrorStateEnum::kUnknownEnumValue); + err.errorStateID = to_underlying(OperationalState::ErrorStateEnum::kUnknownEnumValue); // 0x04, 4 break; }