From 4d34590cef8865b8a38eeceabba948cc72625712 Mon Sep 17 00:00:00 2001 From: chirag-silabs Date: Fri, 29 Nov 2024 11:43:09 +0530 Subject: [PATCH] Adding the dimmer switch and level control on switch app --- .../light-switch-common/light-switch-app.zap | 96 ++- .../silabs/include/BindingHandler.h | 3 +- .../silabs/src/BindingHandler.cpp | 186 ++++++ .../silabs/src/ShellCommands.cpp | 581 ++++++++++++++++++ 4 files changed, 854 insertions(+), 12 deletions(-) diff --git a/examples/light-switch-app/light-switch-common/light-switch-app.zap b/examples/light-switch-app/light-switch-common/light-switch-app.zap index 595b0d8f83..c23a5058a7 100644 --- a/examples/light-switch-app/light-switch-common/light-switch-app.zap +++ b/examples/light-switch-app/light-switch-common/light-switch-app.zap @@ -4400,29 +4400,29 @@ }, { "id": 2, - "name": "MA-onofflightswitch", + "name": "MA-dimmerswitch", "deviceTypeRef": { - "code": 259, + "code": 260, "profileId": 259, - "label": "MA-onofflightswitch", - "name": "MA-onofflightswitch" + "label": "MA-dimmerswitch", + "name": "MA-dimmerswitch" }, "deviceTypes": [ { - "code": 259, + "code": 260, "profileId": 259, - "label": "MA-onofflightswitch", - "name": "MA-onofflightswitch" + "label": "MA-dimmerswitch", + "name": "MA-dimmerswitch" } ], "deviceVersions": [ 1 ], "deviceIdentifiers": [ - 259 + 260 ], - "deviceTypeName": "MA-onofflightswitch", - "deviceTypeCode": 259, + "deviceTypeName": "MA-dimmerswitch", + "deviceTypeCode": 260, "deviceTypeProfileId": 259, "clusters": [ { @@ -4733,6 +4733,80 @@ } ] }, + { + "name": "Level Control", + "code": 8, + "mfgCode": null, + "define": "LEVEL_CONTROL_CLUSTER", + "side": "client", + "enabled": 1, + "commands": [ + { + "name": "MoveToLevel", + "code": 0, + "mfgCode": null, + "source": "client", + "isIncoming": 0, + "isEnabled": 1 + }, + { + "name": "Move", + "code": 1, + "mfgCode": null, + "source": "client", + "isIncoming": 0, + "isEnabled": 1 + }, + { + "name": "Step", + "code": 2, + "mfgCode": null, + "source": "client", + "isIncoming": 0, + "isEnabled": 1 + }, + { + "name": "Stop", + "code": 3, + "mfgCode": null, + "source": "client", + "isIncoming": 0, + "isEnabled": 1 + }, + { + "name": "MoveToLevelWithOnOff", + "code": 4, + "mfgCode": null, + "source": "client", + "isIncoming": 0, + "isEnabled": 1 + }, + { + "name": "MoveWithOnOff", + "code": 5, + "mfgCode": null, + "source": "client", + "isIncoming": 0, + "isEnabled": 1 + }, + { + "name": "StepWithOnOff", + "code": 6, + "mfgCode": null, + "source": "client", + "isIncoming": 0, + "isEnabled": 1 + }, + { + "name": "StopWithOnOff", + "code": 7, + "mfgCode": null, + "source": "client", + "isIncoming": 0, + "isEnabled": 1 + } + ] + }, { "name": "Descriptor", "code": 29, @@ -5633,7 +5707,7 @@ "parentEndpointIdentifier": null }, { - "endpointTypeName": "MA-onofflightswitch", + "endpointTypeName": "MA-dimmerswitch", "endpointTypeIndex": 1, "profileId": 259, "endpointId": 1, diff --git a/examples/light-switch-app/silabs/include/BindingHandler.h b/examples/light-switch-app/silabs/include/BindingHandler.h index aed08be25e..58a4a0a7b4 100644 --- a/examples/light-switch-app/silabs/include/BindingHandler.h +++ b/examples/light-switch-app/silabs/include/BindingHandler.h @@ -29,5 +29,6 @@ struct BindingCommandData chip::EndpointId localEndpointId = 1; chip::CommandId commandId; chip::ClusterId clusterId; - bool isGroup = false; + bool isGroup = false; + uint32_t args[7]; }; diff --git a/examples/light-switch-app/silabs/src/BindingHandler.cpp b/examples/light-switch-app/silabs/src/BindingHandler.cpp index 56f7c306f9..2ee51668b2 100644 --- a/examples/light-switch-app/silabs/src/BindingHandler.cpp +++ b/examples/light-switch-app/silabs/src/BindingHandler.cpp @@ -26,8 +26,13 @@ #include #include +#include + using namespace chip; using namespace chip::app; +using chip::app::Clusters::LevelControl::MoveModeEnum; +using chip::app::Clusters::LevelControl::OptionsBitmap; +using chip::app::Clusters::LevelControl::StepModeEnum; namespace { @@ -85,6 +90,181 @@ void ProcessOnOffGroupBindingCommand(CommandId commandId, const EmberBindingTabl } } +void ProcessLevelControlUnicastBindingCommand(BindingCommandData * data, const EmberBindingTableEntry & binding, + OperationalDeviceProxy * peer_device) +{ + auto onSuccess = [](const ConcreteCommandPath & commandPath, const StatusIB & status, const auto & dataResponse) { + ChipLogProgress(NotSpecified, "LevelControl command succeeds"); + }; + + auto onFailure = [](CHIP_ERROR error) { + ChipLogError(NotSpecified, "LevelControl command failed: %" CHIP_ERROR_FORMAT, error.Format()); + }; + + VerifyOrDie(peer_device != nullptr && peer_device->ConnectionReady()); + + Clusters::LevelControl::Commands::MoveToLevel::Type moveToLevelCommand; + Clusters::LevelControl::Commands::Move::Type moveCommand; + Clusters::LevelControl::Commands::Step::Type stepCommand; + Clusters::LevelControl::Commands::Stop::Type stopCommand; + Clusters::LevelControl::Commands::MoveToLevelWithOnOff::Type moveToLevelWithOnOffCommand; + Clusters::LevelControl::Commands::MoveWithOnOff::Type moveWithOnOffCommand; + Clusters::LevelControl::Commands::StepWithOnOff::Type stepWithOnOffCommand; + Clusters::LevelControl::Commands::StopWithOnOff::Type stopWithOnOffCommand; + + switch (data->commandId) + { + case Clusters::LevelControl::Commands::MoveToLevel::Id: + moveToLevelCommand.level = static_cast(data->args[0]); + moveToLevelCommand.transitionTime = static_cast>(data->args[1]); + moveToLevelCommand.optionsMask = static_cast>(data->args[2]); + moveToLevelCommand.optionsOverride = static_cast>(data->args[3]); + Controller::InvokeCommandRequest(peer_device->GetExchangeManager(), peer_device->GetSecureSession().Value(), binding.remote, + moveToLevelCommand, onSuccess, onFailure); + break; + + case Clusters::LevelControl::Commands::Move::Id: + moveCommand.moveMode = static_cast(data->args[0]); + moveCommand.rate = static_cast>(data->args[1]); + moveCommand.optionsMask = static_cast>(data->args[2]); + moveCommand.optionsOverride = static_cast>(data->args[3]); + Controller::InvokeCommandRequest(peer_device->GetExchangeManager(), peer_device->GetSecureSession().Value(), binding.remote, + moveCommand, onSuccess, onFailure); + break; + + case Clusters::LevelControl::Commands::Step::Id: + stepCommand.stepMode = static_cast(data->args[0]); + stepCommand.stepSize = static_cast(data->args[1]); + stepCommand.transitionTime = static_cast>(data->args[2]); + stepCommand.optionsMask = static_cast>(data->args[3]); + stepCommand.optionsOverride = static_cast>(data->args[4]); + Controller::InvokeCommandRequest(peer_device->GetExchangeManager(), peer_device->GetSecureSession().Value(), binding.remote, + stepCommand, onSuccess, onFailure); + break; + + case Clusters::LevelControl::Commands::Stop::Id: + stopCommand.optionsMask = static_cast>(data->args[0]); + stopCommand.optionsOverride = static_cast>(data->args[1]); + Controller::InvokeCommandRequest(peer_device->GetExchangeManager(), peer_device->GetSecureSession().Value(), binding.remote, + stopCommand, onSuccess, onFailure); + break; + + case Clusters::LevelControl::Commands::MoveToLevelWithOnOff::Id: + moveToLevelWithOnOffCommand.level = static_cast(data->args[0]); + moveToLevelWithOnOffCommand.transitionTime = static_cast>(data->args[1]); + moveToLevelWithOnOffCommand.optionsMask = static_cast>(data->args[2]); + moveToLevelWithOnOffCommand.optionsOverride = static_cast>(data->args[3]); + Controller::InvokeCommandRequest(peer_device->GetExchangeManager(), peer_device->GetSecureSession().Value(), binding.remote, + moveToLevelWithOnOffCommand, onSuccess, onFailure); + break; + + case Clusters::LevelControl::Commands::MoveWithOnOff::Id: + moveWithOnOffCommand.moveMode = static_cast(data->args[0]); + moveWithOnOffCommand.rate = static_cast>(data->args[1]); + moveWithOnOffCommand.optionsMask = static_cast>(data->args[2]); + moveWithOnOffCommand.optionsOverride = static_cast>(data->args[3]); + Controller::InvokeCommandRequest(peer_device->GetExchangeManager(), peer_device->GetSecureSession().Value(), binding.remote, + moveWithOnOffCommand, onSuccess, onFailure); + break; + + case Clusters::LevelControl::Commands::StepWithOnOff::Id: + stepWithOnOffCommand.stepMode = static_cast(data->args[0]); + stepWithOnOffCommand.stepSize = static_cast(data->args[1]); + stepWithOnOffCommand.transitionTime = static_cast>(data->args[2]); + stepWithOnOffCommand.optionsMask = static_cast>(data->args[3]); + stepWithOnOffCommand.optionsOverride = static_cast>(data->args[4]); + Controller::InvokeCommandRequest(peer_device->GetExchangeManager(), peer_device->GetSecureSession().Value(), binding.remote, + stepWithOnOffCommand, onSuccess, onFailure); + break; + + case Clusters::LevelControl::Commands::StopWithOnOff::Id: + stopWithOnOffCommand.optionsMask = static_cast>(data->args[0]); + stopWithOnOffCommand.optionsOverride = static_cast>(data->args[1]); + Controller::InvokeCommandRequest(peer_device->GetExchangeManager(), peer_device->GetSecureSession().Value(), binding.remote, + stopWithOnOffCommand, onSuccess, onFailure); + break; + } +} + +void ProcessLevelControlGroupBindingCommand(BindingCommandData * data, const EmberBindingTableEntry & binding) +{ + Messaging::ExchangeManager & exchangeMgr = Server::GetInstance().GetExchangeManager(); + + Clusters::LevelControl::Commands::MoveToLevel::Type moveToLevelCommand; + Clusters::LevelControl::Commands::Move::Type moveCommand; + Clusters::LevelControl::Commands::Step::Type stepCommand; + Clusters::LevelControl::Commands::Stop::Type stopCommand; + Clusters::LevelControl::Commands::MoveToLevelWithOnOff::Type moveToLevelWithOnOffCommand; + Clusters::LevelControl::Commands::MoveWithOnOff::Type moveWithOnOffCommand; + Clusters::LevelControl::Commands::StepWithOnOff::Type stepWithOnOffCommand; + Clusters::LevelControl::Commands::StopWithOnOff::Type stopWithOnOffCommand; + + switch (data->commandId) + { + case Clusters::LevelControl::Commands::MoveToLevel::Id: + moveToLevelCommand.level = static_cast(data->args[0]); + moveToLevelCommand.transitionTime = static_cast>(data->args[1]); + moveToLevelCommand.optionsMask = static_cast>(data->args[2]); + moveToLevelCommand.optionsOverride = static_cast>(data->args[3]); + Controller::InvokeGroupCommandRequest(&exchangeMgr, binding.fabricIndex, binding.groupId, moveToLevelCommand); + break; + + case Clusters::LevelControl::Commands::Move::Id: + moveCommand.moveMode = static_cast(data->args[0]); + moveCommand.rate = static_cast>(data->args[1]); + moveCommand.optionsMask = static_cast>(data->args[2]); + moveCommand.optionsOverride = static_cast>(data->args[3]); + Controller::InvokeGroupCommandRequest(&exchangeMgr, binding.fabricIndex, binding.groupId, moveCommand); + break; + + case Clusters::LevelControl::Commands::Step::Id: + stepCommand.stepMode = static_cast(data->args[0]); + stepCommand.stepSize = static_cast(data->args[1]); + stepCommand.transitionTime = static_cast>(data->args[2]); + stepCommand.optionsMask = static_cast>(data->args[3]); + stepCommand.optionsOverride = static_cast>(data->args[4]); + Controller::InvokeGroupCommandRequest(&exchangeMgr, binding.fabricIndex, binding.groupId, stepCommand); + break; + + case Clusters::LevelControl::Commands::Stop::Id: + stopCommand.optionsMask = static_cast>(data->args[0]); + stopCommand.optionsOverride = static_cast>(data->args[1]); + Controller::InvokeGroupCommandRequest(&exchangeMgr, binding.fabricIndex, binding.groupId, stopCommand); + break; + + case Clusters::LevelControl::Commands::MoveToLevelWithOnOff::Id: + moveToLevelWithOnOffCommand.level = static_cast(data->args[0]); + moveToLevelWithOnOffCommand.transitionTime = static_cast>(data->args[1]); + moveToLevelWithOnOffCommand.optionsMask = static_cast>(data->args[2]); + moveToLevelWithOnOffCommand.optionsOverride = static_cast>(data->args[3]); + Controller::InvokeGroupCommandRequest(&exchangeMgr, binding.fabricIndex, binding.groupId, moveToLevelWithOnOffCommand); + break; + + case Clusters::LevelControl::Commands::MoveWithOnOff::Id: + moveWithOnOffCommand.moveMode = static_cast(data->args[0]); + moveWithOnOffCommand.rate = static_cast>(data->args[1]); + moveWithOnOffCommand.optionsMask = static_cast>(data->args[2]); + moveWithOnOffCommand.optionsOverride = static_cast>(data->args[3]); + Controller::InvokeGroupCommandRequest(&exchangeMgr, binding.fabricIndex, binding.groupId, moveWithOnOffCommand); + break; + + case Clusters::LevelControl::Commands::StepWithOnOff::Id: + stepWithOnOffCommand.stepMode = static_cast(data->args[0]); + stepWithOnOffCommand.stepSize = static_cast(data->args[1]); + stepWithOnOffCommand.transitionTime = static_cast>(data->args[2]); + stepWithOnOffCommand.optionsMask = static_cast>(data->args[3]); + stepWithOnOffCommand.optionsOverride = static_cast>(data->args[4]); + Controller::InvokeGroupCommandRequest(&exchangeMgr, binding.fabricIndex, binding.groupId, stepWithOnOffCommand); + break; + + case Clusters::LevelControl::Commands::StopWithOnOff::Id: + stopWithOnOffCommand.optionsMask = static_cast>(data->args[0]); + stopWithOnOffCommand.optionsOverride = static_cast>(data->args[1]); + Controller::InvokeGroupCommandRequest(&exchangeMgr, binding.fabricIndex, binding.groupId, stopWithOnOffCommand); + break; + } +} + void LightSwitchChangedHandler(const EmberBindingTableEntry & binding, OperationalDeviceProxy * peer_device, void * context) { VerifyOrReturn(context != nullptr, ChipLogError(NotSpecified, "OnDeviceConnectedFn: context is null")); @@ -97,6 +277,9 @@ void LightSwitchChangedHandler(const EmberBindingTableEntry & binding, Operation case Clusters::OnOff::Id: ProcessOnOffGroupBindingCommand(data->commandId, binding); break; + case Clusters::LevelControl::Id: + ProcessLevelControlGroupBindingCommand(data, binding); + break; } } else if (binding.type == MATTER_UNICAST_BINDING && !data->isGroup) @@ -108,6 +291,9 @@ void LightSwitchChangedHandler(const EmberBindingTableEntry & binding, Operation ProcessOnOffUnicastBindingCommand(data->commandId, binding, peer_device->GetExchangeManager(), peer_device->GetSecureSession().Value()); break; + case Clusters::LevelControl::Id: + ProcessLevelControlUnicastBindingCommand(data, binding, peer_device); + break; } } } diff --git a/examples/light-switch-app/silabs/src/ShellCommands.cpp b/examples/light-switch-app/silabs/src/ShellCommands.cpp index 167453906e..68126a7add 100644 --- a/examples/light-switch-app/silabs/src/ShellCommands.cpp +++ b/examples/light-switch-app/silabs/src/ShellCommands.cpp @@ -38,9 +38,11 @@ using Shell::streamer_printf; Engine sShellSwitchSubCommands; Engine sShellSwitchOnOffSubCommands; +Engine sShellSwitchLevelControlSubCommands; Engine sShellSwitchGroupsSubCommands; Engine sShellSwitchGroupsOnOffSubCommands; +Engine sShellSwitchGroupsLevelControlSubCommands; Engine sShellSwitchBindingSubCommands; @@ -238,6 +240,542 @@ CHIP_ERROR GroupToggleSwitchCommandHandler(int argc, char ** argv) return CHIP_NO_ERROR; } +/******************************************************** + * LevelControl switch shell functions + *********************************************************/ + +CHIP_ERROR LevelControlHelpHandler(int argc, char ** argv) +{ + sShellSwitchLevelControlSubCommands.ForEachCommand(Shell::PrintCommandHelp, nullptr); + return CHIP_NO_ERROR; +} + +CHIP_ERROR LevelControlSwitchCommandHandler(int argc, char ** argv) +{ + if (argc == 0) + { + return LevelControlHelpHandler(argc, argv); + } + + return sShellSwitchLevelControlSubCommands.ExecCommand(argc, argv); +} + +CHIP_ERROR MoveToLevelSwitchCommandHandler(int argc, char ** argv) +{ + if (argc != 4) + { + return LevelControlHelpHandler(argc, argv); + } + + BindingCommandData * data = Platform::New(); + data->commandId = Clusters::LevelControl::Commands::MoveToLevel::Id; + data->clusterId = Clusters::LevelControl::Id; + data->args[0] = atoi(argv[0]); + data->args[1] = atoi(argv[1]); + data->args[2] = atoi(argv[2]); + data->args[3] = atoi(argv[3]); + + DeviceLayer::PlatformMgr().ScheduleWork(SwitchWorkerFunction, reinterpret_cast(data)); + return CHIP_NO_ERROR; +} + +CHIP_ERROR MoveSwitchCommandHandler(int argc, char ** argv) +{ + if (argc != 4) + { + return LevelControlHelpHandler(argc, argv); + } + + BindingCommandData * data = Platform::New(); + data->commandId = Clusters::LevelControl::Commands::Move::Id; + data->clusterId = Clusters::LevelControl::Id; + data->args[0] = atoi(argv[0]); + data->args[1] = atoi(argv[1]); + data->args[2] = atoi(argv[2]); + data->args[3] = atoi(argv[3]); + + DeviceLayer::PlatformMgr().ScheduleWork(SwitchWorkerFunction, reinterpret_cast(data)); + return CHIP_NO_ERROR; +} + +CHIP_ERROR StepSwitchCommandHandler(int argc, char ** argv) +{ + if (argc != 5) + { + return LevelControlHelpHandler(argc, argv); + } + + BindingCommandData * data = Platform::New(); + data->commandId = Clusters::LevelControl::Commands::Step::Id; + data->clusterId = Clusters::LevelControl::Id; + data->args[0] = atoi(argv[0]); + data->args[1] = atoi(argv[1]); + data->args[2] = atoi(argv[2]); + data->args[3] = atoi(argv[3]); + data->args[4] = atoi(argv[4]); + + DeviceLayer::PlatformMgr().ScheduleWork(SwitchWorkerFunction, reinterpret_cast(data)); + return CHIP_NO_ERROR; +} + +CHIP_ERROR StopSwitchCommandHandler(int argc, char ** argv) +{ + if (argc != 2) + { + return LevelControlHelpHandler(argc, argv); + } + + BindingCommandData * data = Platform::New(); + data->commandId = Clusters::LevelControl::Commands::Stop::Id; + data->clusterId = Clusters::LevelControl::Id; + data->args[0] = atoi(argv[0]); + data->args[1] = atoi(argv[1]); + + DeviceLayer::PlatformMgr().ScheduleWork(SwitchWorkerFunction, reinterpret_cast(data)); + return CHIP_NO_ERROR; +} + +CHIP_ERROR MoveToLevelWithOnOffSwitchCommandHandler(int argc, char ** argv) +{ + if (argc != 4) + { + return LevelControlHelpHandler(argc, argv); + } + + BindingCommandData * data = Platform::New(); + data->commandId = Clusters::LevelControl::Commands::MoveToLevelWithOnOff::Id; + data->clusterId = Clusters::LevelControl::Id; + data->args[0] = atoi(argv[0]); + data->args[1] = atoi(argv[1]); + data->args[2] = atoi(argv[2]); + data->args[3] = atoi(argv[3]); + + DeviceLayer::PlatformMgr().ScheduleWork(SwitchWorkerFunction, reinterpret_cast(data)); + return CHIP_NO_ERROR; +} + +CHIP_ERROR MoveWithOnOffSwitchCommandHandler(int argc, char ** argv) +{ + if (argc != 4) + { + return LevelControlHelpHandler(argc, argv); + } + + BindingCommandData * data = Platform::New(); + data->commandId = Clusters::LevelControl::Commands::MoveWithOnOff::Id; + data->clusterId = Clusters::LevelControl::Id; + data->args[0] = atoi(argv[0]); + data->args[1] = atoi(argv[1]); + data->args[2] = atoi(argv[2]); + data->args[3] = atoi(argv[3]); + + DeviceLayer::PlatformMgr().ScheduleWork(SwitchWorkerFunction, reinterpret_cast(data)); + return CHIP_NO_ERROR; +} + +CHIP_ERROR StepWithOnOffSwitchCommandHandler(int argc, char ** argv) +{ + if (argc != 5) + { + return LevelControlHelpHandler(argc, argv); + } + + BindingCommandData * data = Platform::New(); + data->commandId = Clusters::LevelControl::Commands::StepWithOnOff::Id; + data->clusterId = Clusters::LevelControl::Id; + data->args[0] = atoi(argv[0]); + data->args[1] = atoi(argv[1]); + data->args[2] = atoi(argv[2]); + data->args[3] = atoi(argv[3]); + data->args[4] = atoi(argv[4]); + + DeviceLayer::PlatformMgr().ScheduleWork(SwitchWorkerFunction, reinterpret_cast(data)); + return CHIP_NO_ERROR; +} + +CHIP_ERROR StopWithOnOffSwitchCommandHandler(int argc, char ** argv) +{ + if (argc != 2) + { + return LevelControlHelpHandler(argc, argv); + } + + BindingCommandData * data = Platform::New(); + data->commandId = Clusters::LevelControl::Commands::StopWithOnOff::Id; + data->clusterId = Clusters::LevelControl::Id; + data->args[0] = atoi(argv[0]); + data->args[1] = atoi(argv[1]); + + DeviceLayer::PlatformMgr().ScheduleWork(SwitchWorkerFunction, reinterpret_cast(data)); + return CHIP_NO_ERROR; +} + +#if 0 +/******************************************************** + * LevelControl Read switch shell functions + *********************************************************/ + +CHIP_ERROR LevelControlReadHelpHandler(int argc, char ** argv) +{ + sShellSwitchLevelControlReadSubCommands.ForEachCommand(Shell::PrintCommandHelp, nullptr); + return CHIP_NO_ERROR; +} + +CHIP_ERROR LevelControlRead(int argc, char ** argv) +{ + if (argc == 0) + { + return LevelControlReadHelpHandler(argc, argv); + } + + return sShellSwitchLevelControlReadSubCommands.ExecCommand(argc, argv); +} + +CHIP_ERROR LevelControlReadAttributeList(int argc, char ** argv) +{ + BindingCommandData * data = Platform::New(); + data->attributeId = Clusters::LevelControl::Attributes::AttributeList::Id; + data->clusterId = Clusters::LevelControl::Id; + data->isReadAttribute = true; + + DeviceLayer::PlatformMgr().ScheduleWork(SwitchWorkerFunction, reinterpret_cast(data)); + return CHIP_NO_ERROR; +} + +CHIP_ERROR LevelControlReadCurrentLevel(int argc, char ** argv) +{ + BindingCommandData * data = Platform::New(); + data->attributeId = Clusters::LevelControl::Attributes::CurrentLevel::Id; + data->clusterId = Clusters::LevelControl::Id; + data->isReadAttribute = true; + ChipLogProgress(NotSpecified, "Read cluster=0x%x, attribute=0x%08x", data->clusterId, data->attributeId); + DeviceLayer::PlatformMgr().ScheduleWork(SwitchWorkerFunction, reinterpret_cast(data)); + return CHIP_NO_ERROR; +} + +CHIP_ERROR LevelControlReadRemainingTime(int argc, char ** argv) +{ + BindingCommandData * data = Platform::New(); + data->attributeId = Clusters::LevelControl::Attributes::RemainingTime::Id; + data->clusterId = Clusters::LevelControl::Id; + data->isReadAttribute = true; + ChipLogProgress(NotSpecified, "Read cluster=0x%x, attribute=0x%08x", data->clusterId, data->attributeId); + DeviceLayer::PlatformMgr().ScheduleWork(SwitchWorkerFunction, reinterpret_cast(data)); + return CHIP_NO_ERROR; +} + +CHIP_ERROR LevelControlReadMinLevel(int argc, char ** argv) +{ + BindingCommandData * data = Platform::New(); + data->attributeId = Clusters::LevelControl::Attributes::MinLevel::Id; + data->clusterId = Clusters::LevelControl::Id; + data->isReadAttribute = true; + ChipLogProgress(NotSpecified, "Read cluster=0x%x, attribute=0x%08x", data->clusterId, data->attributeId); + DeviceLayer::PlatformMgr().ScheduleWork(SwitchWorkerFunction, reinterpret_cast(data)); + return CHIP_NO_ERROR; +} + +CHIP_ERROR LevelControlReadMaxLevel(int argc, char ** argv) +{ + BindingCommandData * data = Platform::New(); + data->attributeId = Clusters::LevelControl::Attributes::MaxLevel::Id; + data->clusterId = Clusters::LevelControl::Id; + data->isReadAttribute = true; + ChipLogProgress(NotSpecified, "Read cluster=0x%x, attribute=0x%08x", data->clusterId, data->attributeId); + DeviceLayer::PlatformMgr().ScheduleWork(SwitchWorkerFunction, reinterpret_cast(data)); + return CHIP_NO_ERROR; +} + +CHIP_ERROR LevelControlReadCurrentFrequency(int argc, char ** argv) +{ + BindingCommandData * data = Platform::New(); + data->attributeId = Clusters::LevelControl::Attributes::CurrentFrequency::Id; + data->clusterId = Clusters::LevelControl::Id; + data->isReadAttribute = true; + ChipLogProgress(NotSpecified, "Read cluster=0x%x, attribute=0x%08x", data->clusterId, data->attributeId); + DeviceLayer::PlatformMgr().ScheduleWork(SwitchWorkerFunction, reinterpret_cast(data)); + return CHIP_NO_ERROR; +} + +CHIP_ERROR LevelControlReadMinFrequency(int argc, char ** argv) +{ + BindingCommandData * data = Platform::New(); + data->attributeId = Clusters::LevelControl::Attributes::MinFrequency::Id; + data->clusterId = Clusters::LevelControl::Id; + data->isReadAttribute = true; + ChipLogProgress(NotSpecified, "Read cluster=0x%x, attribute=0x%08x", data->clusterId, data->attributeId); + DeviceLayer::PlatformMgr().ScheduleWork(SwitchWorkerFunction, reinterpret_cast(data)); + return CHIP_NO_ERROR; +} + +CHIP_ERROR LevelControlReadMaxFrequency(int argc, char ** argv) +{ + BindingCommandData * data = Platform::New(); + data->attributeId = Clusters::LevelControl::Attributes::MaxFrequency::Id; + data->clusterId = Clusters::LevelControl::Id; + data->isReadAttribute = true; + ChipLogProgress(NotSpecified, "Read cluster=0x%x, attribute=0x%08x", data->clusterId, data->attributeId); + DeviceLayer::PlatformMgr().ScheduleWork(SwitchWorkerFunction, reinterpret_cast(data)); + return CHIP_NO_ERROR; +} + +CHIP_ERROR LevelControlReadOptions(int argc, char ** argv) +{ + BindingCommandData * data = Platform::New(); + data->attributeId = Clusters::LevelControl::Attributes::Options::Id; + data->clusterId = Clusters::LevelControl::Id; + data->isReadAttribute = true; + ChipLogProgress(NotSpecified, "Read cluster=0x%x, attribute=0x%08x", data->clusterId, data->attributeId); + DeviceLayer::PlatformMgr().ScheduleWork(SwitchWorkerFunction, reinterpret_cast(data)); + return CHIP_NO_ERROR; +} + +CHIP_ERROR LevelControlReadOnOffTransitionTime(int argc, char ** argv) +{ + BindingCommandData * data = Platform::New(); + data->attributeId = Clusters::LevelControl::Attributes::OnOffTransitionTime::Id; + data->clusterId = Clusters::LevelControl::Id; + data->isReadAttribute = true; + ChipLogProgress(NotSpecified, "Read cluster=0x%x, attribute=0x%08x", data->clusterId, data->attributeId); + DeviceLayer::PlatformMgr().ScheduleWork(SwitchWorkerFunction, reinterpret_cast(data)); + return CHIP_NO_ERROR; +} + +CHIP_ERROR LevelControlReadOnLevel(int argc, char ** argv) +{ + BindingCommandData * data = Platform::New(); + data->attributeId = Clusters::LevelControl::Attributes::OnLevel::Id; + data->clusterId = Clusters::LevelControl::Id; + data->isReadAttribute = true; + ChipLogProgress(NotSpecified, "Read cluster=0x%x, attribute=0x%08x", data->clusterId, data->attributeId); + DeviceLayer::PlatformMgr().ScheduleWork(SwitchWorkerFunction, reinterpret_cast(data)); + return CHIP_NO_ERROR; +} + +CHIP_ERROR LevelControlReadOnTransitionTime(int argc, char ** argv) +{ + BindingCommandData * data = Platform::New(); + data->attributeId = Clusters::LevelControl::Attributes::OnTransitionTime::Id; + data->clusterId = Clusters::LevelControl::Id; + data->isReadAttribute = true; + ChipLogProgress(NotSpecified, "Read cluster=0x%x, attribute=0x%08x", data->clusterId, data->attributeId); + DeviceLayer::PlatformMgr().ScheduleWork(SwitchWorkerFunction, reinterpret_cast(data)); + return CHIP_NO_ERROR; +} + +CHIP_ERROR LevelControlReadOffTransitionTime(int argc, char ** argv) +{ + BindingCommandData * data = Platform::New(); + data->attributeId = Clusters::LevelControl::Attributes::OffTransitionTime::Id; + data->clusterId = Clusters::LevelControl::Id; + data->isReadAttribute = true; + ChipLogProgress(NotSpecified, "Read cluster=0x%x, attribute=0x%08x", data->clusterId, data->attributeId); + DeviceLayer::PlatformMgr().ScheduleWork(SwitchWorkerFunction, reinterpret_cast(data)); + return CHIP_NO_ERROR; +} + +CHIP_ERROR LevelControlReadDefaultMoveRate(int argc, char ** argv) +{ + BindingCommandData * data = Platform::New(); + data->attributeId = Clusters::LevelControl::Attributes::DefaultMoveRate::Id; + data->clusterId = Clusters::LevelControl::Id; + data->isReadAttribute = true; + ChipLogProgress(NotSpecified, "Read cluster=0x%x, attribute=0x%08x", data->clusterId, data->attributeId); + DeviceLayer::PlatformMgr().ScheduleWork(SwitchWorkerFunction, reinterpret_cast(data)); + return CHIP_NO_ERROR; +} + +CHIP_ERROR LevelControlReadStartUpCurrentLevel(int argc, char ** argv) +{ + BindingCommandData * data = Platform::New(); + data->attributeId = Clusters::LevelControl::Attributes::StartUpCurrentLevel::Id; + data->clusterId = Clusters::LevelControl::Id; + data->isReadAttribute = true; + ChipLogProgress(NotSpecified, "Read cluster=0x%x, attribute=0x%08x", data->clusterId, data->attributeId); + DeviceLayer::PlatformMgr().ScheduleWork(SwitchWorkerFunction, reinterpret_cast(data)); + return CHIP_NO_ERROR; +} + +#endif // commenting the read functions + +/******************************************************** + * Groups LevelControl switch shell functions + *********************************************************/ + +CHIP_ERROR GroupsLevelControlHelpHandler(int argc, char ** argv) +{ + sShellSwitchGroupsLevelControlSubCommands.ForEachCommand(Shell::PrintCommandHelp, nullptr); + return CHIP_NO_ERROR; +} + +CHIP_ERROR GroupsLevelControlSwitchCommandHandler(int argc, char ** argv) +{ + if (argc == 0) + { + return GroupsLevelControlHelpHandler(argc, argv); + } + + return sShellSwitchGroupsLevelControlSubCommands.ExecCommand(argc, argv); +} + +CHIP_ERROR GroupsMoveToLevelSwitchCommandHandler(int argc, char ** argv) +{ + if (argc != 4) + { + return GroupsLevelControlHelpHandler(argc, argv); + } + + BindingCommandData * data = Platform::New(); + data->commandId = Clusters::LevelControl::Commands::MoveToLevel::Id; + data->clusterId = Clusters::LevelControl::Id; + data->args[0] = atoi(argv[0]); + data->args[1] = atoi(argv[1]); + data->args[2] = atoi(argv[2]); + data->args[3] = atoi(argv[3]); + data->isGroup = true; + + DeviceLayer::PlatformMgr().ScheduleWork(SwitchWorkerFunction, reinterpret_cast(data)); + return CHIP_NO_ERROR; +} + +CHIP_ERROR GroupsMoveSwitchCommandHandler(int argc, char ** argv) +{ + if (argc != 4) + { + return GroupsLevelControlHelpHandler(argc, argv); + } + + BindingCommandData * data = Platform::New(); + data->commandId = Clusters::LevelControl::Commands::Move::Id; + data->clusterId = Clusters::LevelControl::Id; + data->args[0] = atoi(argv[0]); + data->args[1] = atoi(argv[1]); + data->args[2] = atoi(argv[2]); + data->args[3] = atoi(argv[3]); + data->isGroup = true; + + DeviceLayer::PlatformMgr().ScheduleWork(SwitchWorkerFunction, reinterpret_cast(data)); + return CHIP_NO_ERROR; +} + +CHIP_ERROR GroupsStepSwitchCommandHandler(int argc, char ** argv) +{ + if (argc != 5) + { + return GroupsLevelControlHelpHandler(argc, argv); + } + + BindingCommandData * data = Platform::New(); + data->commandId = Clusters::LevelControl::Commands::Step::Id; + data->clusterId = Clusters::LevelControl::Id; + data->args[0] = atoi(argv[0]); + data->args[1] = atoi(argv[1]); + data->args[2] = atoi(argv[2]); + data->args[3] = atoi(argv[3]); + data->args[4] = atoi(argv[4]); + data->isGroup = true; + + DeviceLayer::PlatformMgr().ScheduleWork(SwitchWorkerFunction, reinterpret_cast(data)); + return CHIP_NO_ERROR; +} + +CHIP_ERROR GroupsStopSwitchCommandHandler(int argc, char ** argv) +{ + if (argc != 2) + { + return GroupsLevelControlHelpHandler(argc, argv); + } + + BindingCommandData * data = Platform::New(); + data->commandId = Clusters::LevelControl::Commands::Stop::Id; + data->clusterId = Clusters::LevelControl::Id; + data->args[0] = atoi(argv[0]); + data->args[1] = atoi(argv[1]); + data->isGroup = true; + + DeviceLayer::PlatformMgr().ScheduleWork(SwitchWorkerFunction, reinterpret_cast(data)); + return CHIP_NO_ERROR; +} + +CHIP_ERROR GroupsMoveToLevelWithOnOffSwitchCommandHandler(int argc, char ** argv) +{ + if (argc != 4) + { + return GroupsLevelControlHelpHandler(argc, argv); + } + + BindingCommandData * data = Platform::New(); + data->commandId = Clusters::LevelControl::Commands::MoveToLevelWithOnOff::Id; + data->clusterId = Clusters::LevelControl::Id; + data->args[0] = atoi(argv[0]); + data->args[1] = atoi(argv[1]); + data->args[2] = atoi(argv[2]); + data->args[3] = atoi(argv[3]); + data->isGroup = true; + + DeviceLayer::PlatformMgr().ScheduleWork(SwitchWorkerFunction, reinterpret_cast(data)); + return CHIP_NO_ERROR; +} + +CHIP_ERROR GroupsMoveWithOnOffSwitchCommandHandler(int argc, char ** argv) +{ + if (argc != 4) + { + return GroupsLevelControlHelpHandler(argc, argv); + } + + BindingCommandData * data = Platform::New(); + data->commandId = Clusters::LevelControl::Commands::MoveWithOnOff::Id; + data->clusterId = Clusters::LevelControl::Id; + data->args[0] = atoi(argv[0]); + data->args[1] = atoi(argv[1]); + data->args[2] = atoi(argv[2]); + data->args[3] = atoi(argv[3]); + data->isGroup = true; + + DeviceLayer::PlatformMgr().ScheduleWork(SwitchWorkerFunction, reinterpret_cast(data)); + return CHIP_NO_ERROR; +} + +CHIP_ERROR GroupsStepWithOnOffSwitchCommandHandler(int argc, char ** argv) +{ + if (argc != 5) + { + return GroupsLevelControlHelpHandler(argc, argv); + } + + BindingCommandData * data = Platform::New(); + data->commandId = Clusters::LevelControl::Commands::StepWithOnOff::Id; + data->clusterId = Clusters::LevelControl::Id; + data->args[0] = atoi(argv[0]); + data->args[1] = atoi(argv[1]); + data->args[2] = atoi(argv[2]); + data->args[3] = atoi(argv[3]); + data->args[4] = atoi(argv[4]); + data->isGroup = true; + + DeviceLayer::PlatformMgr().ScheduleWork(SwitchWorkerFunction, reinterpret_cast(data)); + return CHIP_NO_ERROR; +} + +CHIP_ERROR GroupsStopWithOnOffSwitchCommandHandler(int argc, char ** argv) +{ + if (argc != 2) + { + return GroupsLevelControlHelpHandler(argc, argv); + } + + BindingCommandData * data = Platform::New(); + data->commandId = Clusters::LevelControl::Commands::StopWithOnOff::Id; + data->clusterId = Clusters::LevelControl::Id; + data->args[0] = atoi(argv[0]); + data->args[1] = atoi(argv[1]); + data->isGroup = true; + + DeviceLayer::PlatformMgr().ScheduleWork(SwitchWorkerFunction, reinterpret_cast(data)); + return CHIP_NO_ERROR; +} + /** * @brief configures switch matter shell */ @@ -246,6 +784,7 @@ void RegisterSwitchCommands() static const shell_command_t sSwitchSubCommands[] = { { &SwitchHelpHandler, "help", "Usage: switch " }, { &OnOffSwitchCommandHandler, "onoff", " Usage: switch onoff " }, + { &LevelControlSwitchCommandHandler, "levelcontrol", " Usage: switch levelcontrol " }, { &GroupsSwitchCommandHandler, "groups", "Usage: switch groups " }, { &BindingSwitchCommandHandler, "binding", "Usage: switch binding " } }; @@ -257,6 +796,26 @@ void RegisterSwitchCommands() { &ToggleSwitchCommandHandler, "toggle", "Sends toggle command to bound lighting app" } }; + static const shell_command_t sSwitchLevelControlSubCommands[] = { + { &LevelControlHelpHandler, "help", "Usage: switch levelcontrol " }, + { &MoveToLevelSwitchCommandHandler, "move-to-level", + "Usage: switch levelcontrol move-to-level " }, + { &MoveSwitchCommandHandler, "move", + "Usage: switch levelcontrol move " }, + { &StepSwitchCommandHandler, "step", + "Usage: switch levelcontrol step " }, + { &StopSwitchCommandHandler, "stop", "step Usage: switch levelcontrol stop " }, + { &MoveToLevelWithOnOffSwitchCommandHandler, "move-to-level-with-on-off", + "Usage: switch levelcontrol move-with-to-level-with-on-off " }, + { &MoveWithOnOffSwitchCommandHandler, "move-with-on-off", + "Usage: switch levelcontrol move-with-on-off " }, + { &StepWithOnOffSwitchCommandHandler, "step-with-on-off", + "Usage: switch levelcontrol step-with-on-off " + "" }, + { &StopWithOnOffSwitchCommandHandler, "stop-with-on-off", + "Usage: switch levelcontrol stop-with-on-off " }, + }; + static const shell_command_t sSwitchGroupsSubCommands[] = { { &GroupsHelpHandler, "help", "Usage: switch groups " }, { &GroupsOnOffSwitchCommandHandler, "onoff", "Usage: switch groups onoff " } }; @@ -268,6 +827,26 @@ void RegisterSwitchCommands() { &GroupToggleSwitchCommandHandler, "toggle", "Sends toggle command to group" } }; + static const shell_command_t sSwitchGroupsLevelControlSubCommands[] = { + { &GroupsLevelControlHelpHandler, "help", "Usage: switch groups levelcontrol " }, + { &GroupsMoveToLevelSwitchCommandHandler, "move-to-level", + "Usage: switch groups levelcontrol move-to-level " }, + { &GroupsMoveSwitchCommandHandler, "move", + "Usage: switch groups levelcontrol move " }, + { &GroupsStepSwitchCommandHandler, "step", + "Usage: switch groups levelcontrol step " }, + { &GroupsStopSwitchCommandHandler, "stop", "step Usage: switch groups levelcontrol stop " }, + { &GroupsMoveToLevelWithOnOffSwitchCommandHandler, "move-to-level-with-on-off", + "Usage: switch groups levelcontrol move-with-to-level-with-on-off " }, + { &GroupsMoveWithOnOffSwitchCommandHandler, "move-with-on-off", + "Usage: switch groups levelcontrol move-with-on-off " }, + { &GroupsStepWithOnOffSwitchCommandHandler, "step-with-on-off", + "Usage: switch groups levelcontrol step-with-on-off " + "" }, + { &GroupsStopWithOnOffSwitchCommandHandler, "stop-with-on-off", + "Usage: switch groups levelcontrol stop-with-on-off " }, + }; + static const shell_command_t sSwitchBindingSubCommands[] = { { &BindingHelpHandler, "help", "Usage: switch binding " }, { &BindingGroupBindCommandHandler, "group", "Usage: switch binding group " }, @@ -278,7 +857,9 @@ void RegisterSwitchCommands() "Light-switch commands. Usage: switch " }; sShellSwitchGroupsOnOffSubCommands.RegisterCommands(sSwitchGroupsOnOffSubCommands, ArraySize(sSwitchGroupsOnOffSubCommands)); + sShellSwitchGroupsLevelControlSubCommands.RegisterCommands(sSwitchGroupsLevelControlSubCommands, ArraySize(sSwitchGroupsLevelControlSubCommands)); sShellSwitchOnOffSubCommands.RegisterCommands(sSwitchOnOffSubCommands, ArraySize(sSwitchOnOffSubCommands)); + sShellSwitchLevelControlSubCommands.RegisterCommands(sSwitchLevelControlSubCommands, ArraySize(sSwitchLevelControlSubCommands)); sShellSwitchGroupsSubCommands.RegisterCommands(sSwitchGroupsSubCommands, ArraySize(sSwitchGroupsSubCommands)); sShellSwitchBindingSubCommands.RegisterCommands(sSwitchBindingSubCommands, ArraySize(sSwitchBindingSubCommands)); sShellSwitchSubCommands.RegisterCommands(sSwitchSubCommands, ArraySize(sSwitchSubCommands));