Skip to content

Commit

Permalink
Move Level Control Cluster to match the spec (#30417)
Browse files Browse the repository at this point in the history
* Rename: MoveMode == MoveModeEnum, LevelControlOptions == OptionsBitmap

* Zap regen

* Drop StepMode enum as it is not a separate enum in the spec

* Ran zap_convert_all.py

* Add backwards compat items

* Zap regen for removing stepmode

* make level control compile

* Remove weak enums from removed enums

* Make sure we use non-compat names in official code

* More non-backwards compat usage

* Minor change to kick CI

* Restyle

* Add context for backward compat data

* Move back to StepModeEnum being a thing as spec adds it back

* Zap regen

* Fix types back

* Make ameba compile

* Restyle

* Fix Darwin availability annotations

* fix casting app compile/types

* Undo submodule update ... again

* Fix backwards compat naming back to StepModeEnum

* Another compile fix

---------

Co-authored-by: Andrei Litvin <[email protected]>
Co-authored-by: Boris Zbarsky <[email protected]>
  • Loading branch information
3 people authored and pull[bot] committed Nov 18, 2023
1 parent 2400999 commit 5336110
Show file tree
Hide file tree
Showing 78 changed files with 1,000 additions and 1,001 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -436,12 +436,12 @@ server cluster OnOffSwitchConfiguration = 7 {

/** Attributes and commands for controlling devices that can be set to a level between fully 'On' and fully 'Off.' */
server cluster LevelControl = 8 {
enum MoveMode : enum8 {
enum MoveModeEnum : enum8 {
kUp = 0;
kDown = 1;
}

enum StepMode : enum8 {
enum StepModeEnum : enum8 {
kUp = 0;
kDown = 1;
}
Expand All @@ -452,7 +452,7 @@ server cluster LevelControl = 8 {
kFrequency = 0x4;
}

bitmap LevelControlOptions : bitmap8 {
bitmap OptionsBitmap : bitmap8 {
kExecuteIfOff = 0x1;
kCoupleColorTempToLevel = 0x2;
}
Expand All @@ -464,7 +464,7 @@ server cluster LevelControl = 8 {
readonly attribute int16u currentFrequency = 4;
readonly attribute int16u minFrequency = 5;
readonly attribute int16u maxFrequency = 6;
attribute LevelControlOptions options = 15;
attribute OptionsBitmap options = 15;
attribute int16u onOffTransitionTime = 16;
attribute nullable int8u onLevel = 17;
attribute nullable int16u onTransitionTime = 18;
Expand All @@ -481,55 +481,55 @@ server cluster LevelControl = 8 {
request struct MoveToLevelRequest {
int8u level = 0;
nullable int16u transitionTime = 1;
LevelControlOptions optionsMask = 2;
LevelControlOptions optionsOverride = 3;
OptionsBitmap optionsMask = 2;
OptionsBitmap optionsOverride = 3;
}

request struct MoveRequest {
MoveMode moveMode = 0;
MoveModeEnum moveMode = 0;
nullable int8u rate = 1;
LevelControlOptions optionsMask = 2;
LevelControlOptions optionsOverride = 3;
OptionsBitmap optionsMask = 2;
OptionsBitmap optionsOverride = 3;
}

request struct StepRequest {
StepMode stepMode = 0;
StepModeEnum stepMode = 0;
int8u stepSize = 1;
nullable int16u transitionTime = 2;
LevelControlOptions optionsMask = 3;
LevelControlOptions optionsOverride = 4;
OptionsBitmap optionsMask = 3;
OptionsBitmap optionsOverride = 4;
}

request struct StopRequest {
LevelControlOptions optionsMask = 0;
LevelControlOptions optionsOverride = 1;
OptionsBitmap optionsMask = 0;
OptionsBitmap optionsOverride = 1;
}

request struct MoveToLevelWithOnOffRequest {
int8u level = 0;
nullable int16u transitionTime = 1;
LevelControlOptions optionsMask = 2;
LevelControlOptions optionsOverride = 3;
OptionsBitmap optionsMask = 2;
OptionsBitmap optionsOverride = 3;
}

request struct MoveWithOnOffRequest {
MoveMode moveMode = 0;
MoveModeEnum moveMode = 0;
nullable int8u rate = 1;
LevelControlOptions optionsMask = 2;
LevelControlOptions optionsOverride = 3;
OptionsBitmap optionsMask = 2;
OptionsBitmap optionsOverride = 3;
}

request struct StepWithOnOffRequest {
StepMode stepMode = 0;
StepModeEnum stepMode = 0;
int8u stepSize = 1;
nullable int16u transitionTime = 2;
LevelControlOptions optionsMask = 3;
LevelControlOptions optionsOverride = 4;
OptionsBitmap optionsMask = 3;
OptionsBitmap optionsOverride = 4;
}

request struct StopWithOnOffRequest {
LevelControlOptions optionsMask = 0;
LevelControlOptions optionsOverride = 1;
OptionsBitmap optionsMask = 0;
OptionsBitmap optionsOverride = 1;
}

command MoveToLevel(MoveToLevelRequest): DefaultSuccess = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7389,7 +7389,7 @@
"code": 15,
"mfgCode": null,
"side": "server",
"type": "LevelControlOptions",
"type": "OptionsBitmap",
"included": 1,
"storageOption": "RAM",
"singleton": 0,
Expand Down
96 changes: 55 additions & 41 deletions examples/all-clusters-app/ameba/main/include/LevelControlCommands.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,18 @@
#include "controller/ReadInteraction.h"
#include <app/clusters/bindings/bindings.h>

#include <type_traits>

#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 chip::app::Clusters::LevelControl::LevelControlOptions;
using chip::app::Clusters::LevelControl::MoveModeEnum;
using chip::app::Clusters::LevelControl::OptionsBitmap;
using chip::app::Clusters::LevelControl::StepModeEnum;

#if CONFIG_ENABLE_CHIP_SHELL
using Shell::Engine;
Expand All @@ -40,6 +44,16 @@ Engine sShellSwitchLevelControlReadSubCommands;
Engine sShellSwitchGroupsLevelControlSubCommands;
#endif // defined(ENABLE_CHIP_SHELL)

namespace {

template <class T>
T from_underlying(std::underlying_type_t<T> value)
{
return static_cast<T>(value);
}

} // namespace

void ProcessLevelControlUnicastBindingRead(BindingCommandData * data, const EmberBindingTableEntry & binding,
OperationalDeviceProxy * peer_device)
{
Expand Down Expand Up @@ -159,69 +173,69 @@ void ProcessLevelControlUnicastBindingCommand(BindingCommandData * data, const E
case Clusters::LevelControl::Commands::MoveToLevel::Id:
moveToLevelCommand.level = static_cast<uint8_t>(data->args[0]);
moveToLevelCommand.transitionTime = static_cast<DataModel::Nullable<uint16_t>>(data->args[1]);
moveToLevelCommand.optionsMask = static_cast<chip::BitMask<LevelControlOptions>>(data->args[2]);
moveToLevelCommand.optionsOverride = static_cast<chip::BitMask<LevelControlOptions>>(data->args[3]);
moveToLevelCommand.optionsMask = static_cast<chip::BitMask<OptionsBitmap>>(data->args[2]);
moveToLevelCommand.optionsOverride = static_cast<chip::BitMask<OptionsBitmap>>(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<EmberAfMoveMode>(data->args[0]);
moveCommand.moveMode = from_underlying<MoveModeEnum>(data->args[0]);
moveCommand.rate = static_cast<DataModel::Nullable<uint8_t>>(data->args[1]);
moveCommand.optionsMask = static_cast<chip::BitMask<LevelControlOptions>>(data->args[2]);
moveCommand.optionsOverride = static_cast<chip::BitMask<LevelControlOptions>>(data->args[3]);
moveCommand.optionsMask = static_cast<chip::BitMask<OptionsBitmap>>(data->args[2]);
moveCommand.optionsOverride = static_cast<chip::BitMask<OptionsBitmap>>(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<EmberAfStepMode>(data->args[0]);
stepCommand.stepMode = from_underlying<StepModeEnum>(data->args[0]);
stepCommand.stepSize = static_cast<uint8_t>(data->args[1]);
stepCommand.transitionTime = static_cast<DataModel::Nullable<uint16_t>>(data->args[2]);
stepCommand.optionsMask = static_cast<chip::BitMask<LevelControlOptions>>(data->args[3]);
stepCommand.optionsOverride = static_cast<chip::BitMask<LevelControlOptions>>(data->args[4]);
stepCommand.optionsMask = static_cast<chip::BitMask<OptionsBitmap>>(data->args[3]);
stepCommand.optionsOverride = static_cast<chip::BitMask<OptionsBitmap>>(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<chip::BitMask<LevelControlOptions>>(data->args[0]);
stopCommand.optionsOverride = static_cast<chip::BitMask<LevelControlOptions>>(data->args[1]);
stopCommand.optionsMask = static_cast<chip::BitMask<OptionsBitmap>>(data->args[0]);
stopCommand.optionsOverride = static_cast<chip::BitMask<OptionsBitmap>>(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<uint8_t>(data->args[0]);
moveToLevelWithOnOffCommand.transitionTime = static_cast<DataModel::Nullable<uint16_t>>(data->args[1]);
moveToLevelWithOnOffCommand.optionsMask = static_cast<chip::BitMask<LevelControlOptions>>(data->args[2]);
moveToLevelWithOnOffCommand.optionsOverride = static_cast<chip::BitMask<LevelControlOptions>>(data->args[3]);
moveToLevelWithOnOffCommand.optionsMask = static_cast<chip::BitMask<OptionsBitmap>>(data->args[2]);
moveToLevelWithOnOffCommand.optionsOverride = static_cast<chip::BitMask<OptionsBitmap>>(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<EmberAfMoveMode>(data->args[0]);
moveWithOnOffCommand.moveMode = from_underlying<MoveModeEnum>(data->args[0]);
moveWithOnOffCommand.rate = static_cast<DataModel::Nullable<uint8_t>>(data->args[1]);
moveWithOnOffCommand.optionsMask = static_cast<chip::BitMask<LevelControlOptions>>(data->args[2]);
moveWithOnOffCommand.optionsOverride = static_cast<chip::BitMask<LevelControlOptions>>(data->args[3]);
moveWithOnOffCommand.optionsMask = static_cast<chip::BitMask<OptionsBitmap>>(data->args[2]);
moveWithOnOffCommand.optionsOverride = static_cast<chip::BitMask<OptionsBitmap>>(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<EmberAfStepMode>(data->args[0]);
stepWithOnOffCommand.stepMode = from_underlying<StepModeEnum>(data->args[0]);
stepWithOnOffCommand.stepSize = static_cast<uint8_t>(data->args[1]);
stepWithOnOffCommand.transitionTime = static_cast<DataModel::Nullable<uint16_t>>(data->args[2]);
stepWithOnOffCommand.optionsMask = static_cast<chip::BitMask<LevelControlOptions>>(data->args[3]);
stepWithOnOffCommand.optionsOverride = static_cast<chip::BitMask<LevelControlOptions>>(data->args[4]);
stepWithOnOffCommand.optionsMask = static_cast<chip::BitMask<OptionsBitmap>>(data->args[3]);
stepWithOnOffCommand.optionsOverride = static_cast<chip::BitMask<OptionsBitmap>>(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<chip::BitMask<LevelControlOptions>>(data->args[0]);
stopWithOnOffCommand.optionsOverride = static_cast<chip::BitMask<LevelControlOptions>>(data->args[1]);
stopWithOnOffCommand.optionsMask = static_cast<chip::BitMask<OptionsBitmap>>(data->args[0]);
stopWithOnOffCommand.optionsOverride = static_cast<chip::BitMask<OptionsBitmap>>(data->args[1]);
Controller::InvokeCommandRequest(peer_device->GetExchangeManager(), peer_device->GetSecureSession().Value(), binding.remote,
stopWithOnOffCommand, onSuccess, onFailure);
break;
Expand All @@ -246,62 +260,62 @@ void ProcessLevelControlGroupBindingCommand(BindingCommandData * data, const Emb
case Clusters::LevelControl::Commands::MoveToLevel::Id:
moveToLevelCommand.level = static_cast<uint8_t>(data->args[0]);
moveToLevelCommand.transitionTime = static_cast<DataModel::Nullable<uint16_t>>(data->args[1]);
moveToLevelCommand.optionsMask = static_cast<chip::BitMask<LevelControlOptions>>(data->args[2]);
moveToLevelCommand.optionsOverride = static_cast<chip::BitMask<LevelControlOptions>>(data->args[3]);
moveToLevelCommand.optionsMask = static_cast<chip::BitMask<OptionsBitmap>>(data->args[2]);
moveToLevelCommand.optionsOverride = static_cast<chip::BitMask<OptionsBitmap>>(data->args[3]);
Controller::InvokeGroupCommandRequest(&exchangeMgr, binding.fabricIndex, binding.groupId, moveToLevelCommand);
break;

case Clusters::LevelControl::Commands::Move::Id:
moveCommand.moveMode = static_cast<EmberAfMoveMode>(data->args[0]);
moveCommand.moveMode = from_underlying<MoveModeEnum>(data->args[0]);
moveCommand.rate = static_cast<DataModel::Nullable<uint8_t>>(data->args[1]);
moveCommand.optionsMask = static_cast<chip::BitMask<LevelControlOptions>>(data->args[2]);
moveCommand.optionsOverride = static_cast<chip::BitMask<LevelControlOptions>>(data->args[3]);
moveCommand.optionsMask = static_cast<chip::BitMask<OptionsBitmap>>(data->args[2]);
moveCommand.optionsOverride = static_cast<chip::BitMask<OptionsBitmap>>(data->args[3]);
Controller::InvokeGroupCommandRequest(&exchangeMgr, binding.fabricIndex, binding.groupId, moveCommand);
break;

case Clusters::LevelControl::Commands::Step::Id:
stepCommand.stepMode = static_cast<EmberAfStepMode>(data->args[0]);
stepCommand.stepMode = from_underlying<StepModeEnum>(data->args[0]);
stepCommand.stepSize = static_cast<uint8_t>(data->args[1]);
stepCommand.transitionTime = static_cast<DataModel::Nullable<uint16_t>>(data->args[2]);
stepCommand.optionsMask = static_cast<chip::BitMask<LevelControlOptions>>(data->args[3]);
stepCommand.optionsOverride = static_cast<chip::BitMask<LevelControlOptions>>(data->args[4]);
stepCommand.optionsMask = static_cast<chip::BitMask<OptionsBitmap>>(data->args[3]);
stepCommand.optionsOverride = static_cast<chip::BitMask<OptionsBitmap>>(data->args[4]);
Controller::InvokeGroupCommandRequest(&exchangeMgr, binding.fabricIndex, binding.groupId, stepCommand);
break;

case Clusters::LevelControl::Commands::Stop::Id:
stopCommand.optionsMask = static_cast<chip::BitMask<LevelControlOptions>>(data->args[0]);
stopCommand.optionsOverride = static_cast<chip::BitMask<LevelControlOptions>>(data->args[1]);
stopCommand.optionsMask = static_cast<chip::BitMask<OptionsBitmap>>(data->args[0]);
stopCommand.optionsOverride = static_cast<chip::BitMask<OptionsBitmap>>(data->args[1]);
Controller::InvokeGroupCommandRequest(&exchangeMgr, binding.fabricIndex, binding.groupId, stopCommand);
break;

case Clusters::LevelControl::Commands::MoveToLevelWithOnOff::Id:
moveToLevelWithOnOffCommand.level = static_cast<uint8_t>(data->args[0]);
moveToLevelWithOnOffCommand.transitionTime = static_cast<DataModel::Nullable<uint16_t>>(data->args[1]);
moveToLevelWithOnOffCommand.optionsMask = static_cast<chip::BitMask<LevelControlOptions>>(data->args[2]);
moveToLevelWithOnOffCommand.optionsOverride = static_cast<chip::BitMask<LevelControlOptions>>(data->args[3]);
moveToLevelWithOnOffCommand.optionsMask = static_cast<chip::BitMask<OptionsBitmap>>(data->args[2]);
moveToLevelWithOnOffCommand.optionsOverride = static_cast<chip::BitMask<OptionsBitmap>>(data->args[3]);
Controller::InvokeGroupCommandRequest(&exchangeMgr, binding.fabricIndex, binding.groupId, moveToLevelWithOnOffCommand);
break;

case Clusters::LevelControl::Commands::MoveWithOnOff::Id:
moveWithOnOffCommand.moveMode = static_cast<EmberAfMoveMode>(data->args[0]);
moveWithOnOffCommand.moveMode = from_underlying<MoveModeEnum>(data->args[0]);
moveWithOnOffCommand.rate = static_cast<DataModel::Nullable<uint8_t>>(data->args[1]);
moveWithOnOffCommand.optionsMask = static_cast<chip::BitMask<LevelControlOptions>>(data->args[2]);
moveWithOnOffCommand.optionsOverride = static_cast<chip::BitMask<LevelControlOptions>>(data->args[3]);
moveWithOnOffCommand.optionsMask = static_cast<chip::BitMask<OptionsBitmap>>(data->args[2]);
moveWithOnOffCommand.optionsOverride = static_cast<chip::BitMask<OptionsBitmap>>(data->args[3]);
Controller::InvokeGroupCommandRequest(&exchangeMgr, binding.fabricIndex, binding.groupId, moveWithOnOffCommand);
break;

case Clusters::LevelControl::Commands::StepWithOnOff::Id:
stepWithOnOffCommand.stepMode = static_cast<EmberAfStepMode>(data->args[0]);
stepWithOnOffCommand.stepMode = from_underlying<StepModeEnum>(data->args[0]);
stepWithOnOffCommand.stepSize = static_cast<uint8_t>(data->args[1]);
stepWithOnOffCommand.transitionTime = static_cast<DataModel::Nullable<uint16_t>>(data->args[2]);
stepWithOnOffCommand.optionsMask = static_cast<chip::BitMask<LevelControlOptions>>(data->args[3]);
stepWithOnOffCommand.optionsOverride = static_cast<chip::BitMask<LevelControlOptions>>(data->args[4]);
stepWithOnOffCommand.optionsMask = static_cast<chip::BitMask<OptionsBitmap>>(data->args[3]);
stepWithOnOffCommand.optionsOverride = static_cast<chip::BitMask<OptionsBitmap>>(data->args[4]);
Controller::InvokeGroupCommandRequest(&exchangeMgr, binding.fabricIndex, binding.groupId, stepWithOnOffCommand);
break;

case Clusters::LevelControl::Commands::StopWithOnOff::Id:
stopWithOnOffCommand.optionsMask = static_cast<chip::BitMask<LevelControlOptions>>(data->args[0]);
stopWithOnOffCommand.optionsOverride = static_cast<chip::BitMask<LevelControlOptions>>(data->args[1]);
stopWithOnOffCommand.optionsMask = static_cast<chip::BitMask<OptionsBitmap>>(data->args[0]);
stopWithOnOffCommand.optionsOverride = static_cast<chip::BitMask<OptionsBitmap>>(data->args[1]);
Controller::InvokeGroupCommandRequest(&exchangeMgr, binding.fabricIndex, binding.groupId, stopWithOnOffCommand);
break;
}
Expand Down
Loading

0 comments on commit 5336110

Please sign in to comment.