Skip to content

Commit

Permalink
[Ameba] Additional Ameba Implementation (project-chip#29720)
Browse files Browse the repository at this point in the history
* [Ameba] added implementation for manual operation of several clusters (dishwasher alarm, refrigerator alarm, operational state, rvc operational state, rvc runmode, and rvc cleanmode), test event trigger for smoke alarm, shutdown function of CHIPDeviceManager, and init laundrywashercontrolserver

* [Ameba] Run restyle-diff.sh, and modified cmake configuration to add additional implementation

* [Ameba] Added CONFIG_ENABLE_AMEBA_TEST_EVENT_TRIGGER macro

* [Ameba] added CONFIG_ENABLE_AMEBA_TEST_EVENT_TRIGGER define flag at cmake

* [Ameba] Updated switch case at ManualOperationalStateCommand.h and updated raise and lower alarm function at ManualDishWasherAlarmCommand.h

* [Ameba] Updated RvcOperationalState::ErrorStateEnum::kUnknownEnumValue to OperationalState::ErrorStateEnum::kUnknownEnumValue because it was removed, and added minor comments.
  • Loading branch information
pankore authored and shripad621git committed Oct 31, 2023
1 parent 8cf19c6 commit 898870e
Show file tree
Hide file tree
Showing 16 changed files with 1,538 additions and 2 deletions.
12 changes: 10 additions & 2 deletions examples/all-clusters-app/ameba/chip_main.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
)

Expand Down Expand Up @@ -263,6 +270,7 @@ list(
-DMBEDTLS_CONFIG_FILE=<mbedtls_config.h>
-DCHIP_SHELL_MAX_TOKENS=11
-DCONFIG_ENABLE_AMEBA_FACTORY_DATA=0
-DCONFIG_ENABLE_AMEBA_TEST_EVENT_TRIGGER=0
)

if (matter_enable_persistentstorage_audit)
Expand Down
6 changes: 6 additions & 0 deletions examples/all-clusters-app/ameba/main/CHIPDeviceManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,12 @@ CHIP_ERROR CHIPDeviceManager::Init(CHIPDeviceManagerCallbacks * cb)
exit:
return err;
}

void CHIPDeviceManager::Shutdown()
{
PlatformMgr().Shutdown();
}

} // namespace DeviceManager
} // namespace chip

Expand Down
159 changes: 159 additions & 0 deletions examples/all-clusters-app/ameba/main/ManualOperationCommand.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
/*
*
* Copyright (c) 2022 Project CHIP Authors
* All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include "ManualOperationCommand.h"
#include "ManualDishWasherAlarmCommand.h"
#include "ManualOperationalStateCommand.h"
#include "ManualRVCModesCommand.h"
#include "ManualRefrigeratorAlarmCommand.h"

#include "app/server/Server.h"
#include "platform/CHIPDeviceLayer.h"
#include <lib/support/CodeUtils.h>

#if CONFIG_ENABLE_CHIP_SHELL
#include "lib/shell/Engine.h"
#include "lib/shell/commands/Help.h"
#endif // ENABLE_CHIP_SHELL

using namespace chip;
using namespace chip::app;

#if CONFIG_ENABLE_CHIP_SHELL
using Shell::Engine;
using Shell::shell_command_t;
using Shell::streamer_get;
using Shell::streamer_printf;

Engine sShellManualOperationSubCommands;
#endif // defined(ENABLE_CHIP_SHELL)

namespace {
#if CONFIG_ENABLE_CHIP_SHELL

/********************************************************
* Manual Operation shell functions
*********************************************************/

CHIP_ERROR ManualOperationHelpHandler(int argc, char ** argv)
{
sShellManualOperationSubCommands.ForEachCommand(Shell::PrintCommandHelp, nullptr);
return CHIP_NO_ERROR;
}

CHIP_ERROR ManualOperationCommandHandler(int argc, char ** argv)
{
if (argc == 0)
{
return ManualOperationHelpHandler(argc, argv);
}

return sShellManualOperationSubCommands.ExecCommand(argc, argv);
}

/**
* @brief configures switch matter shell
*
*/
static void RegisterManualOperationCommands()
{

static const shell_command_t sManualOperationSubCommands[] = {
{ &ManualOperationHelpHandler, "help", "Usage: manual <subcommand>" },
{ &ManualOperationalStateCommandHandler, "opstate", " Usage: manual opstate <subcommand>" },
{ &ManualRVCCommandHandler, "rvc", " Usage: manual rvc <subcommand>" },
{ &ManualRefrigeratorAlarmCommandHandler, "refalm", " Usage: manual refalm <subcommand>" },
{ &ManualDishWasherAlarmCommandHandler, "dishalm", " Usage: manual dishalm <subcommand>" },
};

static const shell_command_t sManualOperationalStateSubCommands[] = {
{ &ManualOperationalStateCommandHelpHandler, "help", "Usage: manual opstate <subcommand>" },
{ &ManualOperationalStateSetStateCommandHandler, "set-state", "set-state Usage: manual opstate set-state <state>" },
{ &ManualOperationalStateSetErrorCommandHandler, "set-error", "set-error Usage: manual opstate set-error <error>" },
};

static const shell_command_t sManualRVCSubCommands[] = {
{ &ManualRVCCommandHelpHandler, "help", "Usage: manual rvc <subcommand>" },
{ &ManualRVCOperationalStateCommandHandler, "opstate", "Usage: manual rvc opstate <subcommand>" },
{ &ManualRVCRunModeCommandHandler, "runmode", "Usage: manual rvc runmode <subcommand>" },
{ &ManualRVCCleanModeCommandHandler, "cleanmode", "Usage: manual rvc cleanmode <subcommand>" },
};

static const shell_command_t sManualRVCOperationalStateSubCommands[] = {
{ &ManualRVCOperationalStateCommandHelpHandler, "help", "Usage: manual rvc opstate <subcommand>" },
{ &ManualRVCOperationalStateSetStateCommandHandler, "set-state", "set-state Usage: manual rvc opstate set-state <state>" },
{ &ManualRVCOperationalStateSetErrorCommandHandler, "set-error", "set-error Usage: manual rvc opstate set-error <error>" },
};

static const shell_command_t sManualRVCRunModeSubCommands[] = {
{ &ManualRVCRunModeCommandHelpHandler, "help", "Usage: manual rvc runmode <subcommand>" },
{ &ManualRVCRunModeSetModeCommandHandler, "set-mode", "set-mode Usage: manual rvc runmode set-mode <mode>" },
};

static const shell_command_t sManualRVCCleanModeSubCommands[] = {
{ &ManualRVCCleanModeCommandHelpHandler, "help", "Usage: manual rvc cleanmode <subcommand>" },
{ &ManualRVCCleanModeSetModeCommandHandler, "set-mode", "set-mode Usage: manual rvc cleanmode set-mode <mode>" },
};

static const shell_command_t sManualRefrigeratorAlarmStateSubCommands[] = {
{ &ManualRefrigeratorAlarmCommandHelpHandler, "help", "Usage: manual refalm <subcommand>" },
{ &ManualRefrigeratorAlarmDoorOpenCommandHandler, "door-open", "door-open Usage: manual refalm door-open" },
{ &ManualRefrigeratorAlarmDoorCloseCommandHandler, "door-close", "door-close Usage: manual refalm door-close" },
{ &ManualRefrigeratorAlarmSuppressCommandHandler, "suppress-alarm", "suppress-alarm Usage: manual refalm suppress-alarm" },
};

static const shell_command_t sManualDishWasherAlarmSubCommands[] = {
{ &ManualDishWasherAlarmCommandHelpHandler, "help", "Usage: manual dishalm <subcommand>" },
{ &ManualDishWasherAlarmSetRaiseCommandHandler, "raise", "raise Usage: manual dishalm raise" },
{ &ManualDishWasherAlarmSetLowerCommandHandler, "lower", "lower Usage: manual dishalm lower" },
};

static const shell_command_t sManualOperationCommand = { &ManualOperationCommandHandler, "manual",
"Manual Operation commands. Usage: manual <subcommand>" };

// Register commands
sShellManualOperationSubCommands.RegisterCommands(sManualOperationSubCommands, ArraySize(sManualOperationSubCommands));
sShellManualOperationalStateSubCommands.RegisterCommands(sManualOperationalStateSubCommands,
ArraySize(sManualOperationalStateSubCommands));
sShellManualRVCSubCommands.RegisterCommands(sManualRVCSubCommands, ArraySize(sManualRVCSubCommands));
sShellManualRVCOperationalStateSubCommands.RegisterCommands(sManualRVCOperationalStateSubCommands,
ArraySize(sManualRVCOperationalStateSubCommands));
sShellManualRVCRunModeSubCommands.RegisterCommands(sManualRVCRunModeSubCommands, ArraySize(sManualRVCRunModeSubCommands));
sShellManualRVCCleanModeSubCommands.RegisterCommands(sManualRVCCleanModeSubCommands, ArraySize(sManualRVCCleanModeSubCommands));
sShellManualRefrigeratorAlarmStateSubCommands.RegisterCommands(sManualRefrigeratorAlarmStateSubCommands,
ArraySize(sManualRefrigeratorAlarmStateSubCommands));
sShellManualDishWasherAlarmStateSubCommands.RegisterCommands(sManualDishWasherAlarmSubCommands,
ArraySize(sManualDishWasherAlarmSubCommands));

Engine::Root().RegisterCommands(&sManualOperationCommand, 1);
}
#endif // ENABLE_CHIP_SHELL

} // namespace

/********************************************************
* Switch functions
*********************************************************/

CHIP_ERROR InitManualOperation()
{
#if CONFIG_ENABLE_CHIP_SHELL
RegisterManualOperationCommands();
#endif
return CHIP_NO_ERROR;
}
173 changes: 173 additions & 0 deletions examples/all-clusters-app/ameba/main/OperationalStateManager.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
/*
*
* Copyright (c) 2023 Project CHIP Authors
* All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <OperationalStateManager.h>

using namespace chip;
using namespace chip::app;
using namespace chip::app::Clusters;
using namespace chip::app::Clusters::OperationalState;
using namespace chip::app::Clusters::RvcOperationalState;

CHIP_ERROR GenericOperationalStateDelegateImpl::GetOperationalStateAtIndex(size_t index, GenericOperationalState & operationalState)
{
if (index >= mOperationalStateList.size())
{
return CHIP_ERROR_NOT_FOUND;
}
operationalState = mOperationalStateList[index];
return CHIP_NO_ERROR;
}

CHIP_ERROR GenericOperationalStateDelegateImpl::GetOperationalPhaseAtIndex(size_t index, GenericOperationalPhase & operationalPhase)
{
if (index >= mOperationalPhaseList.size())
{
return CHIP_ERROR_NOT_FOUND;
}
operationalPhase = mOperationalPhaseList[index];
return CHIP_NO_ERROR;
}

void GenericOperationalStateDelegateImpl::HandlePauseStateCallback(GenericOperationalError & err)
{
auto error = GetInstance()->SetOperationalState(to_underlying(OperationalState::OperationalStateEnum::kPaused));
if (error == CHIP_NO_ERROR)
{
err.Set(to_underlying(ErrorStateEnum::kNoError));
}
else
{
err.Set(to_underlying(ErrorStateEnum::kUnableToCompleteOperation));
}
}

void GenericOperationalStateDelegateImpl::HandleResumeStateCallback(GenericOperationalError & err)
{
auto error = GetInstance()->SetOperationalState(to_underlying(OperationalStateEnum::kRunning));
if (error == CHIP_NO_ERROR)
{
err.Set(to_underlying(ErrorStateEnum::kNoError));
}
else
{
err.Set(to_underlying(ErrorStateEnum::kUnableToCompleteOperation));
}
}

void GenericOperationalStateDelegateImpl::HandleStartStateCallback(GenericOperationalError & err)
{
auto error = GetInstance()->SetOperationalState(to_underlying(OperationalStateEnum::kRunning));
if (error == CHIP_NO_ERROR)
{
err.Set(to_underlying(ErrorStateEnum::kNoError));
}
else
{
err.Set(to_underlying(ErrorStateEnum::kUnableToCompleteOperation));
}
}

void GenericOperationalStateDelegateImpl::HandleStopStateCallback(GenericOperationalError & err)
{
auto error = GetInstance()->SetOperationalState(to_underlying(OperationalStateEnum::kStopped));
if (error == CHIP_NO_ERROR)
{
err.Set(to_underlying(ErrorStateEnum::kNoError));
}
else
{
err.Set(to_underlying(ErrorStateEnum::kUnableToCompleteOperation));
}
}

// Init Operational State cluster

static OperationalState::Instance * gOperationalStateInstance = nullptr;
static OperationalStateDelegate * gOperationalStateDelegate = nullptr;

void OperationalState::Shutdown()
{
if (gOperationalStateInstance != nullptr)
{
delete gOperationalStateInstance;
gOperationalStateInstance = nullptr;
}
if (gOperationalStateDelegate != nullptr)
{
delete gOperationalStateDelegate;
gOperationalStateDelegate = nullptr;
}
}

OperationalState::Instance * OperationalState::GetOperationalStateInstance()
{
return gOperationalStateInstance;
}

void emberAfOperationalStateClusterInitCallback(chip::EndpointId endpointId)
{
VerifyOrDie(endpointId == 1); // this cluster is only enabled for endpoint 1.
VerifyOrDie(gOperationalStateInstance == nullptr && gOperationalStateDelegate == nullptr);

gOperationalStateDelegate = new OperationalStateDelegate;
EndpointId operationalStateEndpoint = 0x01;
gOperationalStateInstance = new Instance(gOperationalStateDelegate, operationalStateEndpoint, Clusters::OperationalState::Id);

gOperationalStateInstance->SetOperationalState(to_underlying(OperationalState::OperationalStateEnum::kStopped));

gOperationalStateInstance->Init();
}

// Init RVC Operational State cluster

static OperationalState::Instance * gRvcOperationalStateInstance = nullptr;
static RvcOperationalStateDelegate * gRvcOperationalStateDelegate = nullptr;

OperationalState::Instance * OperationalState::GetRVCOperationalStateInstance()
{
return gRvcOperationalStateInstance;
}

void RvcOperationalState::Shutdown()
{
if (gRvcOperationalStateInstance != nullptr)
{
delete gRvcOperationalStateInstance;
gRvcOperationalStateInstance = nullptr;
}
if (gRvcOperationalStateDelegate != nullptr)
{
delete gRvcOperationalStateDelegate;
gRvcOperationalStateDelegate = nullptr;
}
}

void emberAfRvcOperationalStateClusterInitCallback(chip::EndpointId endpointId)
{
VerifyOrDie(endpointId == 1); // this cluster is only enabled for endpoint 1.
VerifyOrDie(gRvcOperationalStateInstance == nullptr && gRvcOperationalStateDelegate == nullptr);

gRvcOperationalStateDelegate = new RvcOperationalStateDelegate;
EndpointId operationalStateEndpoint = 0x01;
gRvcOperationalStateInstance =
new Instance(gRvcOperationalStateDelegate, operationalStateEndpoint, Clusters::RvcOperationalState::Id);

gRvcOperationalStateInstance->SetOperationalState(to_underlying(OperationalState::OperationalStateEnum::kStopped));

gRvcOperationalStateInstance->Init();
}
Loading

0 comments on commit 898870e

Please sign in to comment.