Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use accessors into the level control cluster, the occupancy sensor cl…
Browse files Browse the repository at this point in the history
…uster and some parts of door lock (#10920)
vivien-apple authored and pull[bot] committed Oct 26, 2022
1 parent 482a822 commit 864ef32
Showing 3 changed files with 85 additions and 133 deletions.
61 changes: 26 additions & 35 deletions src/app/clusters/door-lock-server/door-lock-server-schedule.cpp
Original file line number Diff line number Diff line change
@@ -38,10 +38,8 @@
******************************************************************************/

#include "door-lock-server.h"
#include <app-common/zap-generated/attribute-id.h>
#include <app-common/zap-generated/cluster-id.h>
#include <app-common/zap-generated/attributes/Accessors.h>
#include <app-common/zap-generated/cluster-objects.h>
#include <app-common/zap-generated/command-id.h>
#include <app/util/af.h>

#include <app/CommandHandler.h>
@@ -108,15 +106,15 @@ void emAfPluginDoorLockServerInitSchedule(void)
defined(ZCL_USING_DOOR_LOCK_CLUSTER_NUM_HOLIDAY_SCHEDULES_SUPPORTED_PER_USER_ATTRIBUTE)
const EmAfPluginDoorLockServerAttributeData data[] = {
#ifdef ZCL_USING_DOOR_LOCK_CLUSTER_NUM_WEEKDAY_SCHEDULES_SUPPORTED_PER_USER_ATTRIBUTE
{ ZCL_NUM_WEEKDAY_SCHEDULES_SUPPORTED_PER_USER_ATTRIBUTE_ID, EMBER_AF_PLUGIN_DOOR_LOCK_SERVER_WEEKDAY_SCHEDULE_TABLE_SIZE },
{ Attributes::NumWeekdaySchedulesSupportedPerUser::Id, EMBER_AF_PLUGIN_DOOR_LOCK_SERVER_WEEKDAY_SCHEDULE_TABLE_SIZE },
#endif

#ifdef ZCL_USING_DOOR_LOCK_CLUSTER_NUM_YEARDAY_SCHEDULES_SUPPORTED_PER_USER_ATTRIBUTE
{ ZCL_NUM_YEARDAY_SCHEDULES_SUPPORTED_PER_USER_ATTRIBUTE_ID, EMBER_AF_PLUGIN_DOOR_LOCK_SERVER_YEARDAY_SCHEDULE_TABLE_SIZE },
{ Attributes::NumYeardaySchedulesSupportedPerUser::Id, EMBER_AF_PLUGIN_DOOR_LOCK_SERVER_YEARDAY_SCHEDULE_TABLE_SIZE },
#endif

#ifdef ZCL_USING_DOOR_LOCK_CLUSTER_NUM_HOLIDAY_SCHEDULES_SUPPORTED_PER_USER_ATTRIBUTE
{ ZCL_NUM_HOLIDAY_SCHEDULES_SUPPORTED_PER_USER_ATTRIBUTE_ID, EMBER_AF_PLUGIN_DOOR_LOCK_SERVER_HOLIDAY_SCHEDULE_TABLE_SIZE },
{ Attributes::NumHolidaySchedulesSupportedPerUser::Id, EMBER_AF_PLUGIN_DOOR_LOCK_SERVER_HOLIDAY_SCHEDULE_TABLE_SIZE },
#endif
};
emAfPluginDoorLockServerWriteAttributes(data, ArraySize(data), "schedule table");
@@ -160,9 +158,8 @@ bool emberAfDoorLockClusterSetWeekdayScheduleCallback(app::CommandHandler * comm
}

{
app::CommandPathParams cmdParams = { emberAfCurrentEndpoint(), /* group id */ 0, ZCL_DOOR_LOCK_CLUSTER_ID,
ZCL_SET_WEEKDAY_SCHEDULE_RESPONSE_COMMAND_ID,
(app::CommandPathFlags::kEndpointIdValid) };
app::CommandPathParams cmdParams = { emberAfCurrentEndpoint(), /* group id */ 0, ::Id,
Commands::SetWeekdayScheduleResponse::Id, (app::CommandPathFlags::kEndpointIdValid) };
TLV::TLVWriter * writer = nullptr;
SuccessOrExit(err = commandObj->PrepareCommand(cmdParams));
VerifyOrExit((writer = commandObj->GetCommandDataIBTLVWriter()) != nullptr, err = CHIP_ERROR_INCORRECT_STATE);
@@ -171,14 +168,13 @@ bool emberAfDoorLockClusterSetWeekdayScheduleCallback(app::CommandHandler * comm
}

// get bitmask so we can check if we should send event notification
emberAfReadServerAttribute(DOOR_LOCK_SERVER_ENDPOINT, ZCL_DOOR_LOCK_CLUSTER_ID, ZCL_RF_PROGRAMMING_EVENT_MASK_ATTRIBUTE_ID,
(uint8_t *) &rfProgrammingEventMask, sizeof(rfProgrammingEventMask));
Attributes::RfProgrammingEventMask::Get(DOOR_LOCK_SERVER_ENDPOINT, &rfProgrammingEventMask);

if (rfProgrammingEventMask & EMBER_BIT(0))
{
emberAfFillExternalBuffer((ZCL_CLUSTER_SPECIFIC_COMMAND | ZCL_FRAME_CONTROL_SERVER_TO_CLIENT), ZCL_DOOR_LOCK_CLUSTER_ID,
ZCL_PROGRAMMING_EVENT_NOTIFICATION_COMMAND_ID, "uuvsuuws", 0x01, 0x00, userId, &userPin, 0x00,
0x00, 0x00, &userPin);
emberAfFillExternalBuffer((ZCL_CLUSTER_SPECIFIC_COMMAND | ZCL_FRAME_CONTROL_SERVER_TO_CLIENT), ::Id,
Commands::ProgrammingEventNotification::Id, "uuvsuuws", 0x01, 0x00, userId, &userPin, 0x00, 0x00,
0x00, &userPin);
SEND_COMMAND_UNICAST_TO_BINDINGS();
}
exit:
@@ -209,9 +205,8 @@ bool emberAfDoorLockClusterGetWeekdayScheduleCallback(app::CommandHandler * comm
}

{
app::CommandPathParams cmdParams = { emberAfCurrentEndpoint(), /* group id */ 0, ZCL_DOOR_LOCK_CLUSTER_ID,
ZCL_GET_WEEKDAY_SCHEDULE_RESPONSE_COMMAND_ID,
(app::CommandPathFlags::kEndpointIdValid) };
app::CommandPathParams cmdParams = { emberAfCurrentEndpoint(), /* group id */ 0, ::Id,
Commands::GetWeekdayScheduleResponse::Id, (app::CommandPathFlags::kEndpointIdValid) };
TLV::TLVWriter * writer = nullptr;
SuccessOrExit(err = commandObj->PrepareCommand(cmdParams));
VerifyOrExit((writer = commandObj->GetCommandDataIBTLVWriter()) != nullptr, err = CHIP_ERROR_INCORRECT_STATE);
@@ -251,8 +246,8 @@ bool emberAfDoorLockClusterClearWeekdayScheduleCallback(app::CommandHandler * co
}

{
app::CommandPathParams cmdParams = { emberAfCurrentEndpoint(), /* group id */ 0, ZCL_DOOR_LOCK_CLUSTER_ID,
ZCL_CLEAR_WEEKDAY_SCHEDULE_RESPONSE_COMMAND_ID,
app::CommandPathParams cmdParams = { emberAfCurrentEndpoint(), /* group id */ 0, ::Id,
Commands::ClearWeekdayScheduleResponse::Id,
(app::CommandPathFlags::kEndpointIdValid) };
TLV::TLVWriter * writer = nullptr;
SuccessOrExit(err = commandObj->PrepareCommand(cmdParams));
@@ -293,9 +288,8 @@ bool emberAfDoorLockClusterSetYeardayScheduleCallback(app::CommandHandler * comm
}

{
app::CommandPathParams cmdParams = { emberAfCurrentEndpoint(), /* group id */ 0, ZCL_DOOR_LOCK_CLUSTER_ID,
ZCL_SET_YEARDAY_SCHEDULE_RESPONSE_COMMAND_ID,
(app::CommandPathFlags::kEndpointIdValid) };
app::CommandPathParams cmdParams = { emberAfCurrentEndpoint(), /* group id */ 0, ::Id,
Commands::SetYeardayScheduleResponse::Id, (app::CommandPathFlags::kEndpointIdValid) };
TLV::TLVWriter * writer = nullptr;
SuccessOrExit(err = commandObj->PrepareCommand(cmdParams));
VerifyOrExit((writer = commandObj->GetCommandDataIBTLVWriter()) != nullptr, err = CHIP_ERROR_INCORRECT_STATE);
@@ -339,9 +333,8 @@ bool emberAfDoorLockClusterGetYeardayScheduleCallback(app::CommandHandler * comm
}

{
app::CommandPathParams cmdParams = { emberAfCurrentEndpoint(), /* group id */ 0, ZCL_DOOR_LOCK_CLUSTER_ID,
ZCL_GET_YEARDAY_SCHEDULE_RESPONSE_COMMAND_ID,
(app::CommandPathFlags::kEndpointIdValid) };
app::CommandPathParams cmdParams = { emberAfCurrentEndpoint(), /* group id */ 0, ::Id,
Commands::GetYeardayScheduleResponse::Id, (app::CommandPathFlags::kEndpointIdValid) };
TLV::TLVWriter * writer = nullptr;
SuccessOrExit(err = commandObj->PrepareCommand(cmdParams));
VerifyOrExit((writer = commandObj->GetCommandDataIBTLVWriter()) != nullptr, err = CHIP_ERROR_INCORRECT_STATE);
@@ -381,8 +374,8 @@ bool emberAfDoorLockClusterClearYeardayScheduleCallback(app::CommandHandler * co
}

{
app::CommandPathParams cmdParams = { emberAfCurrentEndpoint(), /* group id */ 0, ZCL_DOOR_LOCK_CLUSTER_ID,
ZCL_CLEAR_YEARDAY_SCHEDULE_RESPONSE_COMMAND_ID,
app::CommandPathParams cmdParams = { emberAfCurrentEndpoint(), /* group id */ 0, ::Id,
Commands::ClearYeardayScheduleResponse::Id,
(app::CommandPathFlags::kEndpointIdValid) };
TLV::TLVWriter * writer = nullptr;
SuccessOrExit(err = commandObj->PrepareCommand(cmdParams));
@@ -425,9 +418,8 @@ bool emberAfDoorLockClusterSetHolidayScheduleCallback(app::CommandHandler * comm
}

{
app::CommandPathParams cmdParams = { emberAfCurrentEndpoint(), /* group id */ 0, ZCL_DOOR_LOCK_CLUSTER_ID,
ZCL_SET_HOLIDAY_SCHEDULE_RESPONSE_COMMAND_ID,
(app::CommandPathFlags::kEndpointIdValid) };
app::CommandPathParams cmdParams = { emberAfCurrentEndpoint(), /* group id */ 0, ::Id,
Commands::SetHolidayScheduleResponse::Id, (app::CommandPathFlags::kEndpointIdValid) };
TLV::TLVWriter * writer = nullptr;
SuccessOrExit(err = commandObj->PrepareCommand(cmdParams));
VerifyOrExit((writer = commandObj->GetCommandDataIBTLVWriter()) != nullptr, err = CHIP_ERROR_INCORRECT_STATE);
@@ -469,9 +461,8 @@ bool emberAfDoorLockClusterGetHolidayScheduleCallback(app::CommandHandler * comm
}

{
app::CommandPathParams cmdParams = { emberAfCurrentEndpoint(), /* group id */ 0, ZCL_DOOR_LOCK_CLUSTER_ID,
ZCL_GET_HOLIDAY_SCHEDULE_RESPONSE_COMMAND_ID,
(app::CommandPathFlags::kEndpointIdValid) };
app::CommandPathParams cmdParams = { emberAfCurrentEndpoint(), /* group id */ 0, ::Id,
Commands::GetHolidayScheduleResponse::Id, (app::CommandPathFlags::kEndpointIdValid) };
TLV::TLVWriter * writer = nullptr;
SuccessOrExit(err = commandObj->PrepareCommand(cmdParams));
VerifyOrExit((writer = commandObj->GetCommandDataIBTLVWriter()) != nullptr, err = CHIP_ERROR_INCORRECT_STATE);
@@ -509,8 +500,8 @@ bool emberAfDoorLockClusterClearHolidayScheduleCallback(app::CommandHandler * co
}

{
app::CommandPathParams cmdParams = { emberAfCurrentEndpoint(), /* group id */ 0, ZCL_DOOR_LOCK_CLUSTER_ID,
ZCL_CLEAR_HOLIDAY_SCHEDULE_RESPONSE_COMMAND_ID,
app::CommandPathParams cmdParams = { emberAfCurrentEndpoint(), /* group id */ 0, ::Id,
Commands::ClearHolidayScheduleResponse::Id,
(app::CommandPathFlags::kEndpointIdValid) };
TLV::TLVWriter * writer = nullptr;
SuccessOrExit(err = commandObj->PrepareCommand(cmdParams));
130 changes: 53 additions & 77 deletions src/app/clusters/level-control/level-control.cpp
Original file line number Diff line number Diff line change
@@ -43,11 +43,8 @@

// this file contains all the common includes for clusters in the util
#include <app-common/zap-generated/af-structs.h>
#include <app-common/zap-generated/attribute-id.h>
#include <app-common/zap-generated/attribute-type.h>
#include <app-common/zap-generated/cluster-id.h>
#include <app-common/zap-generated/attributes/Accessors.h>
#include <app-common/zap-generated/cluster-objects.h>
#include <app-common/zap-generated/command-id.h>
#include <app/CommandHandler.h>
#include <app/ConcreteCommandPath.h>
#include <app/util/af.h>
@@ -69,6 +66,7 @@
#include <assert.h>

using namespace chip;
using namespace chip::app::Clusters;
using namespace chip::app::Clusters::LevelControl;

#ifdef ZCL_USING_LEVEL_CONTROL_CLUSTER_START_UP_CURRENT_LEVEL_ATTRIBUTE
@@ -131,26 +129,25 @@ static void reallyUpdateCoupledColorTemp(EndpointId endpoint);

static void schedule(EndpointId endpoint, uint32_t delayMs)
{
emberAfScheduleServerTickExtended(endpoint, ZCL_LEVEL_CONTROL_CLUSTER_ID, delayMs, EMBER_AF_LONG_POLL, EMBER_AF_OK_TO_SLEEP);
emberAfScheduleServerTickExtended(endpoint, LevelControl::Id, delayMs, EMBER_AF_LONG_POLL, EMBER_AF_OK_TO_SLEEP);
}

static void deactivate(EndpointId endpoint)
{
emberAfDeactivateServerTick(endpoint, ZCL_LEVEL_CONTROL_CLUSTER_ID);
emberAfDeactivateServerTick(endpoint, LevelControl::Id);
}

static EmberAfLevelControlState * getState(EndpointId endpoint)
{
uint16_t ep = emberAfFindClusterServerEndpointIndex(endpoint, ZCL_LEVEL_CONTROL_CLUSTER_ID);
uint16_t ep = emberAfFindClusterServerEndpointIndex(endpoint, LevelControl::Id);
return (ep == 0xFFFF ? NULL : &stateTable[ep]);
}

#if defined(ZCL_USING_LEVEL_CONTROL_CLUSTER_OPTIONS_ATTRIBUTE) && defined(EMBER_AF_PLUGIN_COLOR_CONTROL_SERVER_TEMP)
static void reallyUpdateCoupledColorTemp(EndpointId endpoint)
{
uint8_t options;
EmberAfStatus status =
emberAfReadServerAttribute(endpoint, ZCL_LEVEL_CONTROL_CLUSTER_ID, ZCL_OPTIONS_ATTRIBUTE_ID, &options, sizeof(options));
EmberAfStatus status = Attributes::Options::Get(endpoint, &options);
if (status != EMBER_ZCL_STATUS_SUCCESS)
{
emberAfLevelControlClusterPrintln("Unable to read Options attribute: 0x%X", status);
@@ -185,8 +182,7 @@ void emberAfLevelControlClusterServerTickCallback(EndpointId endpoint)
#endif

// Read the attribute; print error message and return if it can't be read
status = emberAfReadServerAttribute(endpoint, ZCL_LEVEL_CONTROL_CLUSTER_ID, ZCL_CURRENT_LEVEL_ATTRIBUTE_ID,
(uint8_t *) &currentLevel, sizeof(currentLevel));
status = Attributes::CurrentLevel::Get(endpoint, &currentLevel);
if (status != EMBER_ZCL_STATUS_SUCCESS)
{
emberAfLevelControlClusterPrintln("ERR: reading current level %x", status);
@@ -218,8 +214,7 @@ void emberAfLevelControlClusterServerTickCallback(EndpointId endpoint)
emberAfLevelControlClusterPrint(" to %d ", currentLevel);
emberAfLevelControlClusterPrintln("(diff %c1)", state->increasing ? '+' : '-');

status = emberAfWriteServerAttribute(endpoint, ZCL_LEVEL_CONTROL_CLUSTER_ID, ZCL_CURRENT_LEVEL_ATTRIBUTE_ID,
(uint8_t *) &currentLevel, ZCL_INT8U_ATTRIBUTE_TYPE);
status = Attributes::CurrentLevel::Set(endpoint, currentLevel);
if (status != EMBER_ZCL_STATUS_SUCCESS)
{
emberAfLevelControlClusterPrintln("ERR: writing current level %x", status);
@@ -231,7 +226,7 @@ void emberAfLevelControlClusterServerTickCallback(EndpointId endpoint)

#ifdef EMBER_AF_PLUGIN_SCENES
// The level has changed, so the scene is no longer valid.
if (emberAfContainsServer(endpoint, ZCL_SCENES_CLUSTER_ID))
if (emberAfContainsServer(endpoint, Scenes::Id))
{
emberAfScenesClusterMakeInvalidCallback(endpoint);
}
@@ -240,14 +235,13 @@ void emberAfLevelControlClusterServerTickCallback(EndpointId endpoint)
// Are we at the requested level?
if (currentLevel == state->moveToLevel)
{
if (state->commandId == ZCL_MOVE_TO_LEVEL_WITH_ON_OFF_COMMAND_ID || state->commandId == ZCL_MOVE_WITH_ON_OFF_COMMAND_ID ||
state->commandId == ZCL_STEP_WITH_ON_OFF_COMMAND_ID)
if (state->commandId == Commands::MoveToLevelWithOnOff::Id || state->commandId == Commands::MoveWithOnOff::Id ||
state->commandId == Commands::StepWithOnOff::Id)
{
setOnOffValue(endpoint, (currentLevel != MIN_LEVEL));
if (currentLevel == MIN_LEVEL && state->useOnLevel)
{
status = emberAfWriteServerAttribute(endpoint, ZCL_LEVEL_CONTROL_CLUSTER_ID, ZCL_CURRENT_LEVEL_ATTRIBUTE_ID,
(uint8_t *) &state->onLevel, ZCL_INT8U_ATTRIBUTE_TYPE);
status = Attributes::CurrentLevel::Set(endpoint, state->onLevel);
if (status != EMBER_ZCL_STATUS_SUCCESS)
{
emberAfLevelControlClusterPrintln("ERR: writing current level %x", status);
@@ -263,8 +257,7 @@ void emberAfLevelControlClusterServerTickCallback(EndpointId endpoint)
if (state->storedLevel != INVALID_STORED_LEVEL)
{
uint8_t storedLevel8u = (uint8_t) state->storedLevel;
status = emberAfWriteServerAttribute(endpoint, ZCL_LEVEL_CONTROL_CLUSTER_ID, ZCL_CURRENT_LEVEL_ATTRIBUTE_ID,
(uint8_t *) &storedLevel8u, ZCL_INT8U_ATTRIBUTE_TYPE);
status = Attributes::CurrentLevel::Set(endpoint, storedLevel8u);
if (status != EMBER_ZCL_STATUS_SUCCESS)
{
emberAfLevelControlClusterPrintln("ERR: writing current level %x", status);
@@ -303,9 +296,7 @@ static void writeRemainingTime(EndpointId endpoint, uint16_t remainingTimeMs)
// This is done to ensure that the attribute, in tenths of a second, only
// goes to zero when the remaining time in milliseconds is actually zero.
uint16_t remainingTimeDs = (remainingTimeMs + 99) / 100;
EmberStatus status =
emberAfWriteServerAttribute(endpoint, ZCL_LEVEL_CONTROL_CLUSTER_ID, ZCL_LEVEL_CONTROL_REMAINING_TIME_ATTRIBUTE_ID,
(uint8_t *) &remainingTimeDs, ZCL_INT16U_ATTRIBUTE_TYPE);
EmberStatus status = Attributes::LevelControlRemainingTime::Set(endpoint, remainingTypeDs);
if (status != EMBER_ZCL_STATUS_SUCCESS)
{
emberAfLevelControlClusterPrintln("ERR: writing remaining time %x", status);
@@ -316,10 +307,10 @@ static void writeRemainingTime(EndpointId endpoint, uint16_t remainingTimeMs)
static void setOnOffValue(EndpointId endpoint, bool onOff)
{
#ifdef EMBER_AF_PLUGIN_ON_OFF
if (emberAfContainsServer(endpoint, ZCL_ON_OFF_CLUSTER_ID))
if (emberAfContainsServer(endpoint, OnOff::Id))
{
emberAfLevelControlClusterPrintln("Setting on/off to %p due to level change", onOff ? "ON" : "OFF");
emberAfOnOffClusterSetValueCallback(endpoint, (onOff ? ZCL_ON_COMMAND_ID : ZCL_OFF_COMMAND_ID), true);
emberAfOnOffClusterSetValueCallback(endpoint, (onOff ? OnOff::Commands::On::Id : OnOff::Commands::Off::Id), true);
}
#endif // EMBER_AF_PLUGIN_ON_OFF
}
@@ -336,19 +327,18 @@ static bool shouldExecuteIfOff(EndpointId endpoint, CommandId commandId, uint8_t
// - The OnOff attribute of the On/Off cluster, on this endpoint, is 0x00
// (FALSE).
// - The value of the ExecuteIfOff bit is 0."
if (commandId > ZCL_STOP_COMMAND_ID)
if (commandId > Commands::Stop::Id)
{
return true;
}

if (!emberAfContainsServer(endpoint, ZCL_ON_OFF_CLUSTER_ID))
if (!emberAfContainsServer(endpoint, OnOff::Id))
{
return true;
}

uint8_t options;
EmberAfStatus status =
emberAfReadServerAttribute(endpoint, ZCL_LEVEL_CONTROL_CLUSTER_ID, ZCL_OPTIONS_ATTRIBUTE_ID, &options, sizeof(options));
EmberAfStatus status = Attributes::Options::Get(&options);
if (status != EMBER_ZCL_STATUS_SUCCESS)
{
emberAfLevelControlClusterPrintln("Unable to read Options attribute: 0x%X", status);
@@ -358,7 +348,7 @@ static bool shouldExecuteIfOff(EndpointId endpoint, CommandId commandId, uint8_t
}

bool on;
status = emberAfReadServerAttribute(endpoint, ZCL_ON_OFF_CLUSTER_ID, ZCL_ON_OFF_ATTRIBUTE_ID, (uint8_t *) &on, sizeof(on));
status = OnOff::Attributes::OnOff::Get(endpoint, &on);
if (status != EMBER_ZCL_STATUS_SUCCESS)
{
emberAfLevelControlClusterPrintln("Unable to read OnOff attribute: 0x%X", status);
@@ -419,7 +409,7 @@ bool emberAfLevelControlClusterMoveToLevelCallback(app::CommandHandler * command

emberAfLevelControlClusterPrintln("%pMOVE_TO_LEVEL %x %2x %x %x", "RX level-control:", level, transitionTime, optionMask,
optionOverride);
moveToLevelHandler(ZCL_MOVE_TO_LEVEL_COMMAND_ID, level, transitionTime, optionMask, optionOverride,
moveToLevelHandler(Commands::MoveToLevel::Id, level, transitionTime, optionMask, optionOverride,
INVALID_STORED_LEVEL); // Don't revert to the stored level
return true;
}
@@ -432,7 +422,7 @@ bool emberAfLevelControlClusterMoveToLevelWithOnOffCallback(app::CommandHandler
auto & transitionTime = commandData.transitionTime;

emberAfLevelControlClusterPrintln("%pMOVE_TO_LEVEL_WITH_ON_OFF %x %2x", "RX level-control:", level, transitionTime);
moveToLevelHandler(ZCL_MOVE_TO_LEVEL_WITH_ON_OFF_COMMAND_ID, level, transitionTime, 0xFF, 0xFF,
moveToLevelHandler(Commands::MoveToLevelWithOnOff::Id, level, transitionTime, 0xFF, 0xFF,
INVALID_STORED_LEVEL); // Don't revert to the stored level
return true;
}
@@ -446,7 +436,7 @@ bool emberAfLevelControlClusterMoveCallback(app::CommandHandler * commandObj, co
auto & optionOverride = commandData.optionOverride;

emberAfLevelControlClusterPrintln("%pMOVE %x %x", "RX level-control:", moveMode, rate);
moveHandler(ZCL_MOVE_COMMAND_ID, moveMode, rate, optionMask, optionOverride);
moveHandler(Commands::Move::Id, moveMode, rate, optionMask, optionOverride);
return true;
}

@@ -457,7 +447,7 @@ bool emberAfLevelControlClusterMoveWithOnOffCallback(app::CommandHandler * comma
auto & rate = commandData.rate;

emberAfLevelControlClusterPrintln("%pMOVE_WITH_ON_OFF %x %x", "RX level-control:", moveMode, rate);
moveHandler(ZCL_MOVE_WITH_ON_OFF_COMMAND_ID, moveMode, rate, 0xFF, 0xFF);
moveHandler(Commands::MoveWithOnOff::Id, moveMode, rate, 0xFF, 0xFF);
return true;
}

@@ -471,7 +461,7 @@ bool emberAfLevelControlClusterStepCallback(app::CommandHandler * commandObj, co
auto & optionOverride = commandData.optionOverride;

emberAfLevelControlClusterPrintln("%pSTEP %x %x %2x", "RX level-control:", stepMode, stepSize, transitionTime);
stepHandler(ZCL_STEP_COMMAND_ID, stepMode, stepSize, transitionTime, optionMask, optionOverride);
stepHandler(Commands::Step::Id, stepMode, stepSize, transitionTime, optionMask, optionOverride);
return true;
}

@@ -483,7 +473,7 @@ bool emberAfLevelControlClusterStepWithOnOffCallback(app::CommandHandler * comma
auto & transitionTime = commandData.transitionTime;

emberAfLevelControlClusterPrintln("%pSTEP_WITH_ON_OFF %x %x %2x", "RX level-control:", stepMode, stepSize, transitionTime);
stepHandler(ZCL_STEP_WITH_ON_OFF_COMMAND_ID, stepMode, stepSize, transitionTime, 0xFF, 0xFF);
stepHandler(Commands::StepWithOnOff::Id, stepMode, stepSize, transitionTime, 0xFF, 0xFF);
return true;
}

@@ -494,15 +484,15 @@ bool emberAfLevelControlClusterStopCallback(app::CommandHandler * commandObj, co
auto & optionOverride = commandData.optionOverride;

emberAfLevelControlClusterPrintln("%pSTOP", "RX level-control:");
stopHandler(ZCL_STOP_COMMAND_ID, optionMask, optionOverride);
stopHandler(Commands::Stop::Id, optionMask, optionOverride);
return true;
}

bool emberAfLevelControlClusterStopWithOnOffCallback(app::CommandHandler * commandObj, const app::ConcreteCommandPath & commandPath,
const Commands::StopWithOnOff::DecodableType & commandData)
{
emberAfLevelControlClusterPrintln("%pSTOP_WITH_ON_OFF", "RX level-control:");
stopHandler(ZCL_STOP_WITH_ON_OFF_COMMAND_ID, 0xFF, 0xFF);
stopHandler(Commands::StopWithOnOff::Id, 0xFF, 0xFF);
return true;
}

@@ -530,8 +520,7 @@ static void moveToLevelHandler(CommandId commandId, uint8_t level, uint16_t tran
// Cancel any currently active command before fiddling with the state.
deactivate(endpoint);

status = emberAfReadServerAttribute(endpoint, ZCL_LEVEL_CONTROL_CLUSTER_ID, ZCL_CURRENT_LEVEL_ATTRIBUTE_ID,
(uint8_t *) &currentLevel, sizeof(currentLevel));
status = Attributes::CurrentLevel::Get(endpoint, &currentLevel);
if (status != EMBER_ZCL_STATUS_SUCCESS)
{
emberAfLevelControlClusterPrintln("ERR: reading current level %x", status);
@@ -561,7 +550,7 @@ static void moveToLevelHandler(CommandId commandId, uint8_t level, uint16_t tran
// reached.
if (currentLevel <= state->moveToLevel)
{
if (commandId == ZCL_MOVE_TO_LEVEL_WITH_ON_OFF_COMMAND_ID)
if (commandId == Commands::MoveToLevelWithOnOff::Id)
{
setOnOffValue(endpoint, (state->moveToLevel != MIN_LEVEL));
}
@@ -587,8 +576,7 @@ static void moveToLevelHandler(CommandId commandId, uint8_t level, uint16_t tran
if (transitionTimeDs == 0xFFFF)
{
#ifdef ZCL_USING_LEVEL_CONTROL_CLUSTER_ON_OFF_TRANSITION_TIME_ATTRIBUTE
status = emberAfReadServerAttribute(endpoint, ZCL_LEVEL_CONTROL_CLUSTER_ID, ZCL_ON_OFF_TRANSITION_TIME_ATTRIBUTE_ID,
(uint8_t *) &transitionTimeDs, sizeof(transitionTimeDs));
status = Attributes::OnOffTransitionTime::Get(endpoint, &transitionTimeDs);
if (status != EMBER_ZCL_STATUS_SUCCESS)
{
emberAfLevelControlClusterPrintln("ERR: reading on/off transition time %x", status);
@@ -627,14 +615,14 @@ static void moveToLevelHandler(CommandId commandId, uint8_t level, uint16_t tran
status = EMBER_ZCL_STATUS_SUCCESS;

#ifdef EMBER_AF_PLUGIN_ZLL_LEVEL_CONTROL_SERVER
if (commandId == ZCL_MOVE_TO_LEVEL_WITH_ON_OFF_COMMAND_ID)
if (commandId == Commands::MoveToLevelWithOnOff::Id)
{
emberAfPluginZllLevelControlServerMoveToLevelWithOnOffZllExtensions(emberAfCurrentCommand());
}
#endif

send_default_response:
if (emberAfCurrentCommand()->apsFrame->clusterId == ZCL_LEVEL_CONTROL_CLUSTER_ID)
if (emberAfCurrentCommand()->apsFrame->clusterId == LevelControl::Id)
{
emberAfSendImmediateDefaultResponse(status);
}
@@ -663,8 +651,7 @@ static void moveHandler(CommandId commandId, uint8_t moveMode, uint8_t rate, uin
// Cancel any currently active command before fiddling with the state.
deactivate(endpoint);

status = emberAfReadServerAttribute(endpoint, ZCL_LEVEL_CONTROL_CLUSTER_ID, ZCL_CURRENT_LEVEL_ATTRIBUTE_ID,
(uint8_t *) &currentLevel, sizeof(currentLevel));
status = Attributes::CurrentLevel::Get(endpoint, &currentLevel);
if (status != EMBER_ZCL_STATUS_SUCCESS)
{
emberAfLevelControlClusterPrintln("ERR: reading current level %x", status);
@@ -698,7 +685,7 @@ static void moveHandler(CommandId commandId, uint8_t moveMode, uint8_t rate, uin
// reached.
if (currentLevel <= state->moveToLevel)
{
if (commandId == ZCL_MOVE_WITH_ON_OFF_COMMAND_ID)
if (commandId == Commands::MoveWithOnOff::Id)
{
setOnOffValue(endpoint, (state->moveToLevel != MIN_LEVEL));
}
@@ -713,9 +700,8 @@ static void moveHandler(CommandId commandId, uint8_t moveMode, uint8_t rate, uin
// Otherwise, move as fast as possible
if (rate == 0xFF)
{
uint16_t defaultMoveRate;
status = emberAfReadServerAttribute(endpoint, ZCL_LEVEL_CONTROL_CLUSTER_ID, ZCL_DEFAULT_MOVE_RATE_ATTRIBUTE_ID,
(uint8_t *) &defaultMoveRate, sizeof(defaultMoveRate));
uint8_t defaultMoveRate;
status = Attributes::DefaultMoveRate::Get(endpoint, &defaultMoveRate);
if (status != EMBER_ZCL_STATUS_SUCCESS)
{
emberAfLevelControlClusterPrintln("ERR: reading default move rate %x", status);
@@ -778,8 +764,7 @@ static void stepHandler(CommandId commandId, uint8_t stepMode, uint8_t stepSize,
// Cancel any currently active command before fiddling with the state.
deactivate(endpoint);

status = emberAfReadServerAttribute(endpoint, ZCL_LEVEL_CONTROL_CLUSTER_ID, ZCL_CURRENT_LEVEL_ATTRIBUTE_ID,
(uint8_t *) &currentLevel, sizeof(currentLevel));
status = Attributes::CurrentLevel::Get(endpoint, &currentLevel);
if (status != EMBER_ZCL_STATUS_SUCCESS)
{
emberAfLevelControlClusterPrintln("ERR: reading current level %x", status);
@@ -827,7 +812,7 @@ static void stepHandler(CommandId commandId, uint8_t stepMode, uint8_t stepSize,
// reached.
if (currentLevel <= state->moveToLevel)
{
if (commandId == ZCL_STEP_WITH_ON_OFF_COMMAND_ID)
if (commandId == Commands::StepWithOnOff::Id)
{
setOnOffValue(endpoint, (state->moveToLevel != MIN_LEVEL));
}
@@ -915,8 +900,7 @@ void emberAfOnOffClusterLevelControlEffectCallback(EndpointId endpoint, bool new
EmberAfStatus status;

// "Temporarily store CurrentLevel."
status = emberAfReadServerAttribute(endpoint, ZCL_LEVEL_CONTROL_CLUSTER_ID, ZCL_CURRENT_LEVEL_ATTRIBUTE_ID,
(uint8_t *) &temporaryCurrentLevelCache, sizeof(temporaryCurrentLevelCache));
status = Attributes::CurrentLevel::Get(endpoint, &temporaryCurrentLevelCache);
if (status != EMBER_ZCL_STATUS_SUCCESS)
{
emberAfLevelControlClusterPrintln("ERR: reading current level %x", status);
@@ -925,9 +909,7 @@ void emberAfOnOffClusterLevelControlEffectCallback(EndpointId endpoint, bool new

// Read the OnLevel attribute.
#ifdef ZCL_USING_LEVEL_CONTROL_CLUSTER_ON_LEVEL_ATTRIBUTE
status = emberAfReadServerAttribute(endpoint, ZCL_LEVEL_CONTROL_CLUSTER_ID, ZCL_ON_LEVEL_ATTRIBUTE_ID,
(uint8_t *) &resolvedLevel, // OnLevel value
sizeof(resolvedLevel));
status = Attributes::OnLevel::Get(endpoint, &resolvedLevel);
if (status != EMBER_ZCL_STATUS_SUCCESS)
{
emberAfLevelControlClusterPrintln("ERR: reading current level %x", status);
@@ -945,8 +927,7 @@ void emberAfOnOffClusterLevelControlEffectCallback(EndpointId endpoint, bool new

// Read the OnOffTransitionTime attribute.
#ifdef ZCL_USING_LEVEL_CONTROL_CLUSTER_ON_OFF_TRANSITION_TIME_ATTRIBUTE
status = emberAfReadServerAttribute(endpoint, ZCL_LEVEL_CONTROL_CLUSTER_ID, ZCL_ON_OFF_TRANSITION_TIME_ATTRIBUTE_ID,
(uint8_t *) &currentOnOffTransitionTime, sizeof(currentOnOffTransitionTime));
status = Attributes::OnOffTransitionTime::Get(endpoint, &currentOnOffTransitionTime);
if (status != EMBER_ZCL_STATUS_SUCCESS)
{
emberAfLevelControlClusterPrintln("ERR: reading current level %x", status);
@@ -958,10 +939,9 @@ void emberAfOnOffClusterLevelControlEffectCallback(EndpointId endpoint, bool new

if (newValue)
{
// If newValue is ZCL_ON_COMMAND_ID...
// If newValue is OnOff::Commands::On::Id...
// "Set CurrentLevel to minimum level allowed for the device."
status = emberAfWriteServerAttribute(endpoint, ZCL_LEVEL_CONTROL_CLUSTER_ID, ZCL_CURRENT_LEVEL_ATTRIBUTE_ID,
(uint8_t *) &minimumLevelAllowedForTheDevice, ZCL_INT8U_ATTRIBUTE_TYPE);
status = Attributes::CurrentLevel::Set(endpoint, minimumLevelAllowedForTheDevice);
if (status != EMBER_ZCL_STATUS_SUCCESS)
{
emberAfLevelControlClusterPrintln("ERR: reading current level %x", status);
@@ -970,15 +950,15 @@ void emberAfOnOffClusterLevelControlEffectCallback(EndpointId endpoint, bool new

// "Move CurrentLevel to OnLevel, or to the stored level if OnLevel is not
// defined, over the time period OnOffTransitionTime."
moveToLevelHandler(ZCL_MOVE_TO_LEVEL_COMMAND_ID, resolvedLevel, currentOnOffTransitionTime, 0xFF, 0xFF,
moveToLevelHandler(Commands::MoveToLevel::Id, resolvedLevel, currentOnOffTransitionTime, 0xFF, 0xFF,
INVALID_STORED_LEVEL); // Don't revert to stored level
}
else
{
// ...else if newValue is ZCL_OFF_COMMAND_ID...
// ...else if newValue is OnOff::Commands::Off::Id...
// "Move CurrentLevel to the minimum level allowed for the device over the
// time period OnOffTransitionTime."
moveToLevelHandler(ZCL_MOVE_TO_LEVEL_COMMAND_ID, minimumLevelAllowedForTheDevice, currentOnOffTransitionTime, 0xFF, 0xFF,
moveToLevelHandler(Commands::MoveToLevel::Id, minimumLevelAllowedForTheDevice, currentOnOffTransitionTime, 0xFF, 0xFF,
temporaryCurrentLevelCache);

// "If OnLevel is not defined, set the CurrentLevel to the stored level."
@@ -1008,14 +988,11 @@ void emberAfLevelControlClusterServerInitCallback(EndpointId endpoint)

// Initialize startUpCurrentLevel to assume previous value for currentLevel.
uint8_t startUpCurrentLevel = STARTUP_CURRENT_LEVEL_USE_PREVIOUS_LEVEL;
EmberAfStatus status =
emberAfReadAttribute(endpoint, ZCL_LEVEL_CONTROL_CLUSTER_ID, ZCL_START_UP_CURRENT_LEVEL_ATTRIBUTE_ID,
CLUSTER_MASK_SERVER, (uint8_t *) &startUpCurrentLevel, sizeof(startUpCurrentLevel), NULL);
EmberAfStatus status = Attributes::StartUpCurrentLevel::Get(endpoint, &startUpCurrentLevel);
if (status == EMBER_ZCL_STATUS_SUCCESS)
{
uint8_t currentLevel = 0;
status = emberAfReadAttribute(endpoint, ZCL_LEVEL_CONTROL_CLUSTER_ID, ZCL_CURRENT_LEVEL_ATTRIBUTE_ID,
CLUSTER_MASK_SERVER, (uint8_t *) &currentLevel, sizeof(currentLevel), NULL);
status = Attributes::CurrentLevel::Get(endpoint, &currentLevel);
if (status == EMBER_ZCL_STATUS_SUCCESS)
{
switch (startUpCurrentLevel)
@@ -1044,8 +1021,7 @@ void emberAfLevelControlClusterServerInitCallback(EndpointId endpoint)
}
break;
}
status = emberAfWriteAttribute(endpoint, ZCL_LEVEL_CONTROL_CLUSTER_ID, ZCL_CURRENT_LEVEL_ATTRIBUTE_ID,
CLUSTER_MASK_SERVER, (uint8_t *) &currentLevel, ZCL_INT8U_ATTRIBUTE_TYPE);
status = Attributes::CurrentLevel::Set(endpoint, currentLevel);
}
}
}
@@ -1058,14 +1034,14 @@ static bool areStartUpLevelControlServerAttributesTokenized(EndpointId endpoint)
{
EmberAfAttributeMetadata * metadata;

metadata = emberAfLocateAttributeMetadata(endpoint, ZCL_LEVEL_CONTROL_CLUSTER_ID, ZCL_CURRENT_LEVEL_ATTRIBUTE_ID,
CLUSTER_MASK_SERVER, EMBER_AF_NULL_MANUFACTURER_CODE);
metadata = emberAfLocateAttributeMetadata(endpoint, LevelControl::Id, ZCL_CURRENT_LEVEL_ATTRIBUTE_ID, CLUSTER_MASK_SERVER,
EMBER_AF_NULL_MANUFACTURER_CODE);
if (!emberAfAttributeIsTokenized(metadata))
{
return false;
}

metadata = emberAfLocateAttributeMetadata(endpoint, ZCL_LEVEL_CONTROL_CLUSTER_ID, ZCL_START_UP_CURRENT_LEVEL_ATTRIBUTE_ID,
metadata = emberAfLocateAttributeMetadata(endpoint, LevelControl::Id, ZCL_START_UP_CURRENT_LEVEL_ATTRIBUTE_ID,
CLUSTER_MASK_SERVER, EMBER_AF_NULL_MANUFACTURER_CODE);
if (!emberAfAttributeIsTokenized(metadata))
{
Original file line number Diff line number Diff line change
@@ -42,34 +42,21 @@

#include <app/util/af.h>

#include <app-common/zap-generated/att-storage.h>
#include <app-common/zap-generated/attribute-id.h>
#include <app-common/zap-generated/attribute-type.h>
#include <app-common/zap-generated/cluster-id.h>
#include <app-common/zap-generated/command-id.h>
#include <app-common/zap-generated/attributes/Accessors.h>
#include <app-common/zap-generated/enums.h>
#include <app/util/af-event.h>
#include <app/util/attribute-storage.h>

#include "occupancy-hal.h"

#ifdef EMBER_AF_PLUGIN_REPORTING
#include <app/reporting/reporting.h>
#endif

using namespace chip;
using namespace chip::app::Clusters::OccupancySensing;

//******************************************************************************
// Plugin init function
//******************************************************************************
void emberAfOccupancySensingClusterServerInitCallback(EndpointId endpoint)
{
HalOccupancySensorType deviceType;

deviceType = halOccupancyGetSensorType(endpoint);

emberAfWriteAttribute(endpoint, ZCL_OCCUPANCY_SENSING_CLUSTER_ID, ZCL_OCCUPANCY_SENSOR_TYPE_ATTRIBUTE_ID, CLUSTER_MASK_SERVER,
(uint8_t *) &deviceType, ZCL_ENUM8_ATTRIBUTE_TYPE);
auto deviceType = halOccupancyGetSensorType(endpoint);
Attributes::OccupancySensorType::Set(endpoint, deviceType);

uint8_t deviceTypeBitmap = 0;
switch (deviceType)
@@ -93,8 +80,7 @@ void emberAfOccupancySensingClusterServerInitCallback(EndpointId endpoint)
default:
break;
}
emberAfWriteAttribute(endpoint, ZCL_OCCUPANCY_SENSING_CLUSTER_ID, ZCL_OCCUPANCY_SENSOR_TYPE_BITMAP_ATTRIBUTE_ID,
CLUSTER_MASK_SERVER, &deviceTypeBitmap, ZCL_BITMAP8_ATTRIBUTE_TYPE);
Attributes::OccupancySensorTypeBitmap::Set(endpoint, deviceTypeBitmap);

emberAfPluginOccupancyClusterServerPostInitCallback(endpoint);
}
@@ -113,8 +99,7 @@ void halOccupancyStateChangedCallback(EndpointId endpoint, HalOccupancyState occ
emberAfOccupancySensingClusterPrintln("Occupancy no longer detected");
}

emberAfWriteAttribute(endpoint, ZCL_OCCUPANCY_SENSING_CLUSTER_ID, ZCL_OCCUPANCY_ATTRIBUTE_ID, CLUSTER_MASK_SERVER,
(uint8_t *) &occupancyState, ZCL_BITMAP8_ATTRIBUTE_TYPE);
Attributes::Occupancy::Set(endpoint, occupancyState);
}

void emberAfPluginOccupancyClusterServerPostInitCallback(EndpointId endpoint) {}

0 comments on commit 864ef32

Please sign in to comment.