From 10046911e5ddf8ca7d55646a1c08e07563e831d3 Mon Sep 17 00:00:00 2001 From: mkardous-silabs <84793247+mkardous-silabs@users.noreply.github.com> Date: Mon, 6 Dec 2021 14:22:11 -0500 Subject: [PATCH] Fix missing PR comments (#12562) * review comments * Restyled by clang-format * Added comments Co-authored-by: Restyled.io --- examples/lighting-app/efr32/src/AppTask.cpp | 5 +- .../color-control-server.cpp | 251 +++++++++++++----- .../color-control-server.h | 4 +- .../clusters/on-off-server/on-off-server.cpp | 35 ++- .../clusters/on-off-server/on-off-server.h | 6 + 5 files changed, 222 insertions(+), 79 deletions(-) diff --git a/examples/lighting-app/efr32/src/AppTask.cpp b/examples/lighting-app/efr32/src/AppTask.cpp index 98299c5fc6b990..6e4d3ecb9e791e 100644 --- a/examples/lighting-app/efr32/src/AppTask.cpp +++ b/examples/lighting-app/efr32/src/AppTask.cpp @@ -88,11 +88,12 @@ StaticTask_t appTaskStruct; /********************************************************** * Identify Callbacks *********************************************************/ - -inline void OnTriggerIdentifyEffectCompleted(chip::System::Layer * systemLayer, void * appState) +namespace { +void OnTriggerIdentifyEffectCompleted(chip::System::Layer * systemLayer, void * appState) { sIdentifyEffect = EMBER_ZCL_IDENTIFY_EFFECT_IDENTIFIER_STOP_EFFECT; } +} // namespace void OnTriggerIdentifyEffect(Identify * identify) { diff --git a/src/app/clusters/color-control-server/color-control-server.cpp b/src/app/clusters/color-control-server/color-control-server.cpp index c159b51923a371..602ffb717f17b1 100644 --- a/src/app/clusters/color-control-server/color-control-server.cpp +++ b/src/app/clusters/color-control-server/color-control-server.cpp @@ -63,21 +63,26 @@ ColorControlServer & ColorControlServer::Instance() return instance; } -void ColorControlServer::stopAllColorTransitions(EndpointId endpoint) +EmberAfStatus ColorControlServer::stopAllColorTransitions(EndpointId endpoint) { - emberEventControlSetInactive(getEventControl(endpoint)); + EmberEventControl * event = getEventControl(endpoint); + VerifyOrReturnError(event != nullptr, EMBER_ZCL_STATUS_UNSUPPORTED_ENDPOINT); + + emberEventControlSetInactive(event); + return EMBER_ZCL_STATUS_SUCCESS; } bool ColorControlServer::stopMoveStepCommand(uint8_t optionsMask, uint8_t optionsOverride) { - EndpointId endpoint = emberAfCurrentEndpoint(); + EndpointId endpoint = emberAfCurrentEndpoint(); + EmberAfStatus status = EMBER_ZCL_STATUS_SUCCESS; if (shouldExecuteIfOff(endpoint, optionsMask, optionsOverride)) { - stopAllColorTransitions(endpoint); + status = stopAllColorTransitions(endpoint); } - emberAfSendImmediateDefaultResponse(EMBER_ZCL_STATUS_SUCCESS); + emberAfSendImmediateDefaultResponse(status); return true; } @@ -254,8 +259,14 @@ uint16_t ColorControlServer::computeTransitionTimeFromStateAndRate(ColorControlS */ EmberEventControl * ColorControlServer::getEventControl(EndpointId endpoint) { - uint16_t index = emberAfFindClusterServerEndpointIndex(endpoint, ColorControl::Id); - return &eventControls[index]; + uint16_t index = emberAfFindClusterServerEndpointIndex(endpoint, ColorControl::Id); + EmberEventControl * event = nullptr; + + if (index < EMBER_AF_COLOR_CONTROL_CLUSTER_SERVER_ENDPOINT_COUNT) + { + event = &eventControls[index]; + } + return event; } /** @brief Compute Pwm from HSV @@ -354,8 +365,14 @@ bool ColorControlServer::computeNewColor16uValue(ColorControlServer::Color16uTra */ ColorControlServer::ColorHueTransitionState * ColorControlServer::getColorHueTransitionState(EndpointId endpoint) { - uint16_t index = emberAfFindClusterServerEndpointIndex(endpoint, ColorControl::Id); - return &colorHueTransitionStates[index]; + uint16_t index = emberAfFindClusterServerEndpointIndex(endpoint, ColorControl::Id); + ColorHueTransitionState * state = nullptr; + + if (index < EMBER_AF_COLOR_CONTROL_CLUSTER_SERVER_ENDPOINT_COUNT) + { + state = &colorHueTransitionStates[index]; + } + return state; } /** @@ -366,8 +383,14 @@ ColorControlServer::ColorHueTransitionState * ColorControlServer::getColorHueTra */ ColorControlServer::Color16uTransitionState * ColorControlServer::getSaturationTransitionState(EndpointId endpoint) { - uint16_t index = emberAfFindClusterServerEndpointIndex(endpoint, ColorControl::Id); - return &colorSatTransitionStates[index]; + uint16_t index = emberAfFindClusterServerEndpointIndex(endpoint, ColorControl::Id); + Color16uTransitionState * state = nullptr; + + if (index < EMBER_AF_COLOR_CONTROL_CLUSTER_SERVER_ENDPOINT_COUNT) + { + state = &colorSatTransitionStates[index]; + } + return state; } /** @@ -713,6 +736,7 @@ bool ColorControlServer::computeNewHueValue(ColorControlServer::ColorHueTransiti EmberEventControl * ColorControlServer::configureHSVEventControl(EndpointId endpoint) { EmberEventControl * controller = getEventControl(endpoint); + VerifyOrReturnError(controller != nullptr, nullptr); controller->endpoint = endpoint; controller->callback = &emberAfPluginColorControlServerHueSatTransitionEventHandler; @@ -738,10 +762,14 @@ bool ColorControlServer::moveHueCommand(uint8_t moveMode, uint16_t rate, uint8_t uint8_t currentHue = 0; uint16_t currentEnhancedHue = 0; EndpointId endpoint = emberAfCurrentEndpoint(); + EmberAfStatus status = EMBER_ZCL_STATUS_SUCCESS; ColorHueTransitionState * colorHueTransitionState = getColorHueTransitionState(endpoint); Color16uTransitionState * colorSaturationTransitionState = getSaturationTransitionState(endpoint); + VerifyOrExit(colorHueTransitionState != nullptr, status = EMBER_ZCL_STATUS_UNSUPPORTED_ENDPOINT); + VerifyOrExit(colorSaturationTransitionState != nullptr, status = EMBER_ZCL_STATUS_UNSUPPORTED_ENDPOINT); + if (!shouldExecuteIfOff(endpoint, optionsMask, optionsOverride)) { emberAfSendImmediateDefaultResponse(EMBER_ZCL_STATUS_SUCCESS); @@ -820,7 +848,8 @@ bool ColorControlServer::moveHueCommand(uint8_t moveMode, uint16_t rate, uint8_t // kick off the state machine: emberEventControlSetDelayMS(configureHSVEventControl(endpoint), UPDATE_TIME_MS); - emberAfSendImmediateDefaultResponse(EMBER_ZCL_STATUS_SUCCESS); +exit: + emberAfSendImmediateDefaultResponse(status); return true; } @@ -840,17 +869,23 @@ bool ColorControlServer::moveHueCommand(uint8_t moveMode, uint16_t rate, uint8_t bool ColorControlServer::moveToHueCommand(uint16_t hue, uint8_t hueMoveMode, uint16_t transitionTime, uint8_t optionsMask, uint8_t optionsOverride, bool isEnhanced) { - EndpointId endpoint = emberAfCurrentEndpoint(); + EndpointId endpoint = emberAfCurrentEndpoint(); + EmberAfStatus status = EMBER_ZCL_STATUS_SUCCESS; + uint16_t currentHue = 0; + uint8_t direction; + ColorHueTransitionState * colorHueTransitionState = getColorHueTransitionState(endpoint); Color16uTransitionState * colorSaturationTransitionState = getSaturationTransitionState(endpoint); + VerifyOrExit(colorHueTransitionState != nullptr, status = EMBER_ZCL_STATUS_UNSUPPORTED_ENDPOINT); + VerifyOrExit(colorSaturationTransitionState != nullptr, status = EMBER_ZCL_STATUS_UNSUPPORTED_ENDPOINT); + if (!shouldExecuteIfOff(endpoint, optionsMask, optionsOverride)) { emberAfSendImmediateDefaultResponse(EMBER_ZCL_STATUS_SUCCESS); return true; } - uint16_t currentHue = 0; if (isEnhanced) { Attributes::EnhancedCurrentHue::Get(endpoint, ¤tHue); @@ -863,8 +898,6 @@ bool ColorControlServer::moveToHueCommand(uint16_t hue, uint8_t hueMoveMode, uin currentHue = static_cast(current8bitHue); } - uint8_t direction; - if (transitionTime == 0) { transitionTime++; @@ -953,7 +986,8 @@ bool ColorControlServer::moveToHueCommand(uint16_t hue, uint8_t hueMoveMode, uin // kick off the state machine: emberEventControlSetDelayMS(configureHSVEventControl(endpoint), UPDATE_TIME_MS); - emberAfSendImmediateDefaultResponse(EMBER_ZCL_STATUS_SUCCESS); +exit: + emberAfSendImmediateDefaultResponse(status); return true; } @@ -973,11 +1007,18 @@ bool ColorControlServer::moveToHueCommand(uint16_t hue, uint8_t hueMoveMode, uin bool ColorControlServer::moveToHueAndSaturationCommand(uint16_t hue, uint8_t saturation, uint16_t transitionTime, uint8_t optionsMask, uint8_t optionsOverride, bool isEnhanced) { - EndpointId endpoint = emberAfCurrentEndpoint(); + EndpointId endpoint = emberAfCurrentEndpoint(); + EmberAfStatus status = EMBER_ZCL_STATUS_SUCCESS; + uint16_t currentHue = 0; + uint16_t halfWay = isEnhanced ? HALF_MAX_UINT16T : HALF_MAX_UINT8T; + bool moveUp; + Color16uTransitionState * colorSaturationTransitionState = getSaturationTransitionState(endpoint); ColorHueTransitionState * colorHueTransitionState = getColorHueTransitionState(endpoint); - uint16_t currentHue = 0; + VerifyOrExit(colorSaturationTransitionState != nullptr, status = EMBER_ZCL_STATUS_UNSUPPORTED_ENDPOINT); + VerifyOrExit(colorHueTransitionState != nullptr, status = EMBER_ZCL_STATUS_UNSUPPORTED_ENDPOINT); + if (isEnhanced) { Attributes::EnhancedCurrentHue::Get(endpoint, ¤tHue); @@ -990,8 +1031,6 @@ bool ColorControlServer::moveToHueAndSaturationCommand(uint16_t hue, uint8_t sat currentHue = static_cast(current8bitHue); } - bool moveUp; - if (transitionTime == 0) { transitionTime++; @@ -1012,7 +1051,6 @@ bool ColorControlServer::moveToHueAndSaturationCommand(uint16_t hue, uint8_t sat } // compute shortest direction - uint16_t halfWay = isEnhanced ? HALF_MAX_UINT16T : HALF_MAX_UINT8T; if (hue > currentHue) { moveUp = (hue - currentHue) < halfWay; @@ -1065,7 +1103,8 @@ bool ColorControlServer::moveToHueAndSaturationCommand(uint16_t hue, uint8_t sat // kick off the state machine: emberEventControlSetDelayMS(configureHSVEventControl(endpoint), UPDATE_TIME_MS); - emberAfSendImmediateDefaultResponse(EMBER_ZCL_STATUS_SUCCESS); +exit: + emberAfSendImmediateDefaultResponse(status); return true; } @@ -1085,10 +1124,15 @@ bool ColorControlServer::moveToHueAndSaturationCommand(uint16_t hue, uint8_t sat bool ColorControlServer::stepHueCommand(uint8_t stepMode, uint16_t stepSize, uint16_t transitionTime, uint8_t optionsMask, uint8_t optionsOverride, bool isEnhanced) { - EndpointId endpoint = emberAfCurrentEndpoint(); + EndpointId endpoint = emberAfCurrentEndpoint(); + EmberAfStatus status = EMBER_ZCL_STATUS_SUCCESS; + ColorHueTransitionState * colorHueTransitionState = getColorHueTransitionState(endpoint); Color16uTransitionState * colorSaturationTransitionState = getSaturationTransitionState(endpoint); + VerifyOrExit(colorHueTransitionState != nullptr, status = EMBER_ZCL_STATUS_UNSUPPORTED_ENDPOINT); + VerifyOrExit(colorSaturationTransitionState != nullptr, status = EMBER_ZCL_STATUS_UNSUPPORTED_ENDPOINT); + if (!shouldExecuteIfOff(endpoint, optionsMask, optionsOverride)) { emberAfSendImmediateDefaultResponse(EMBER_ZCL_STATUS_SUCCESS); @@ -1160,16 +1204,22 @@ bool ColorControlServer::stepHueCommand(uint8_t stepMode, uint16_t stepSize, uin // kick off the state machine: emberEventControlSetDelayMS(configureHSVEventControl(endpoint), UPDATE_TIME_MS); - emberAfSendImmediateDefaultResponse(EMBER_ZCL_STATUS_SUCCESS); +exit: + emberAfSendImmediateDefaultResponse(status); return true; } bool ColorControlServer::moveSaturationCommand(uint8_t moveMode, uint8_t rate, uint8_t optionsMask, uint8_t optionsOverride) { - EndpointId endpoint = emberAfCurrentEndpoint(); + EndpointId endpoint = emberAfCurrentEndpoint(); + EmberAfStatus status = EMBER_ZCL_STATUS_SUCCESS; + ColorHueTransitionState * colorHueTransitionState = getColorHueTransitionState(endpoint); Color16uTransitionState * colorSaturationTransitionState = getSaturationTransitionState(endpoint); + VerifyOrExit(colorHueTransitionState != nullptr, status = EMBER_ZCL_STATUS_UNSUPPORTED_ENDPOINT); + VerifyOrExit(colorSaturationTransitionState != nullptr, status = EMBER_ZCL_STATUS_UNSUPPORTED_ENDPOINT); + if (!shouldExecuteIfOff(endpoint, optionsMask, optionsOverride)) { emberAfSendImmediateDefaultResponse(EMBER_ZCL_STATUS_SUCCESS); @@ -1219,7 +1269,8 @@ bool ColorControlServer::moveSaturationCommand(uint8_t moveMode, uint8_t rate, u // kick off the state machine: emberEventControlSetDelayMS(configureHSVEventControl(endpoint), UPDATE_TIME_MS); - emberAfSendImmediateDefaultResponse(EMBER_ZCL_STATUS_SUCCESS); +exit: + emberAfSendImmediateDefaultResponse(status); return true; } @@ -1236,10 +1287,15 @@ bool ColorControlServer::moveSaturationCommand(uint8_t moveMode, uint8_t rate, u bool ColorControlServer::moveToSaturationCommand(uint8_t saturation, uint16_t transitionTime, uint8_t optionsMask, uint8_t optionsOverride) { - EndpointId endpoint = emberAfCurrentEndpoint(); + EndpointId endpoint = emberAfCurrentEndpoint(); + EmberAfStatus status = EMBER_ZCL_STATUS_SUCCESS; + ColorHueTransitionState * colorHueTransitionState = getColorHueTransitionState(endpoint); Color16uTransitionState * colorSaturationTransitionState = getSaturationTransitionState(endpoint); + VerifyOrExit(colorHueTransitionState != nullptr, status = EMBER_ZCL_STATUS_UNSUPPORTED_ENDPOINT); + VerifyOrExit(colorSaturationTransitionState != nullptr, status = EMBER_ZCL_STATUS_UNSUPPORTED_ENDPOINT); + if (!shouldExecuteIfOff(endpoint, optionsMask, optionsOverride)) { emberAfSendImmediateDefaultResponse(EMBER_ZCL_STATUS_SUCCESS); @@ -1284,24 +1340,31 @@ bool ColorControlServer::moveToSaturationCommand(uint8_t saturation, uint16_t tr // kick off the state machine: emberEventControlSetDelayMS(configureHSVEventControl(endpoint), UPDATE_TIME_MS); - emberAfSendImmediateDefaultResponse(EMBER_ZCL_STATUS_SUCCESS); +exit: + emberAfSendImmediateDefaultResponse(status); return true; } bool ColorControlServer::stepSaturationCommand(uint8_t stepMode, uint8_t stepSize, uint8_t transitionTime, uint8_t optionsMask, uint8_t optionsOverride) { - EndpointId endpoint = emberAfCurrentEndpoint(); + EndpointId endpoint = emberAfCurrentEndpoint(); + EmberAfStatus status = EMBER_ZCL_STATUS_SUCCESS; + uint8_t currentSaturation = 0; + ColorHueTransitionState * colorHueTransitionState = getColorHueTransitionState(endpoint); Color16uTransitionState * colorSaturationTransitionState = getSaturationTransitionState(endpoint); + VerifyOrExit(colorHueTransitionState != nullptr, status = EMBER_ZCL_STATUS_UNSUPPORTED_ENDPOINT); + VerifyOrExit(colorSaturationTransitionState != nullptr, status = EMBER_ZCL_STATUS_UNSUPPORTED_ENDPOINT); + if (!shouldExecuteIfOff(endpoint, optionsMask, optionsOverride)) { emberAfSendImmediateDefaultResponse(EMBER_ZCL_STATUS_SUCCESS); return true; } - uint8_t currentSaturation = getSaturation(endpoint); + currentSaturation = getSaturation(endpoint); if (transitionTime == 0) { @@ -1347,15 +1410,21 @@ bool ColorControlServer::stepSaturationCommand(uint8_t stepMode, uint8_t stepSiz // kick off the state machine: emberEventControlSetDelayMS(configureHSVEventControl(endpoint), UPDATE_TIME_MS); - emberAfSendImmediateDefaultResponse(EMBER_ZCL_STATUS_SUCCESS); +exit: + emberAfSendImmediateDefaultResponse(status); return true; } bool ColorControlServer::colorLoopCommand(uint8_t updateFlags, uint8_t action, uint8_t direction, uint16_t time, uint16_t startHue, uint8_t optionsMask, uint8_t optionsOverride) { - EndpointId endpoint = emberAfCurrentEndpoint(); + EndpointId endpoint = emberAfCurrentEndpoint(); + EmberAfStatus status = EMBER_ZCL_STATUS_SUCCESS; + uint8_t isColorLoopActive = 0; + uint8_t deactiveColorLoop = 0; + ColorHueTransitionState * colorHueTransitionState = getColorHueTransitionState(endpoint); + VerifyOrExit(colorHueTransitionState != nullptr, status = EMBER_ZCL_STATUS_UNSUPPORTED_ENDPOINT); if (!shouldExecuteIfOff(endpoint, optionsMask, optionsOverride)) { @@ -1363,10 +1432,9 @@ bool ColorControlServer::colorLoopCommand(uint8_t updateFlags, uint8_t action, u return true; } - uint8_t isColorLoopActive = 0; Attributes::ColorLoopActive::Get(endpoint, &isColorLoopActive); - uint8_t deactiveColorLoop = + deactiveColorLoop = (updateFlags & EMBER_AF_COLOR_LOOP_UPDATE_FLAGS_UPDATE_ACTION) && (action == EMBER_ZCL_COLOR_LOOP_ACTION_DEACTIVATE); if (updateFlags & EMBER_AF_COLOR_LOOP_UPDATE_FLAGS_UPDATE_DIRECTION) @@ -1452,7 +1520,8 @@ bool ColorControlServer::colorLoopCommand(uint8_t updateFlags, uint8_t action, u } } - emberAfSendImmediateDefaultResponse(EMBER_ZCL_STATUS_SUCCESS); +exit: + emberAfSendImmediateDefaultResponse(status); return true; } @@ -1518,7 +1587,14 @@ void ColorControlServer::updateHueSatCommand(EndpointId endpoint) ColorControlServer::Color16uTransitionState * ColorControlServer::getXTransitionState(EndpointId endpoint) { uint16_t index = emberAfFindClusterServerEndpointIndex(endpoint, ColorControl::Id); - return &colorXtransitionStates[index]; + + Color16uTransitionState * state = nullptr; + if (index < EMBER_AF_COLOR_CONTROL_CLUSTER_SERVER_ENDPOINT_COUNT) + { + state = &colorXtransitionStates[index]; + } + + return state; } /** @@ -1530,7 +1606,14 @@ ColorControlServer::Color16uTransitionState * ColorControlServer::getXTransition ColorControlServer::Color16uTransitionState * ColorControlServer::getYTransitionState(EndpointId endpoint) { uint16_t index = emberAfFindClusterServerEndpointIndex(endpoint, ColorControl::Id); - return &colorYtransitionStates[index]; + + Color16uTransitionState * state = nullptr; + if (index < EMBER_AF_COLOR_CONTROL_CLUSTER_SERVER_ENDPOINT_COUNT) + { + state = &colorYtransitionStates[index]; + } + + return state; } uint16_t ColorControlServer::findNewColorValueFromStep(uint16_t oldValue, int16_t step) @@ -1564,6 +1647,7 @@ uint16_t ColorControlServer::findNewColorValueFromStep(uint16_t oldValue, int16_ EmberEventControl * ColorControlServer::configureXYEventControl(EndpointId endpoint) { EmberEventControl * controller = getEventControl(endpoint); + VerifyOrReturnError(controller != nullptr, nullptr); controller->endpoint = endpoint; controller->callback = &emberAfPluginColorControlServerXyTransitionEventHandler; @@ -1574,10 +1658,15 @@ EmberEventControl * ColorControlServer::configureXYEventControl(EndpointId endpo bool ColorControlServer::moveToColorCommand(uint16_t colorX, uint16_t colorY, uint16_t transitionTime, uint8_t optionsMask, uint8_t optionsOverride) { - EndpointId endpoint = emberAfCurrentEndpoint(); + EndpointId endpoint = emberAfCurrentEndpoint(); + EmberAfStatus status = EMBER_ZCL_STATUS_SUCCESS; + Color16uTransitionState * colorXTransitionState = getXTransitionState(endpoint); Color16uTransitionState * colorYTransitionState = getYTransitionState(endpoint); + VerifyOrExit(colorXTransitionState != nullptr, status = EMBER_ZCL_STATUS_UNSUPPORTED_ENDPOINT); + VerifyOrExit(colorYTransitionState != nullptr, status = EMBER_ZCL_STATUS_UNSUPPORTED_ENDPOINT); + if (!shouldExecuteIfOff(endpoint, optionsMask, optionsOverride)) { emberAfSendImmediateDefaultResponse(EMBER_ZCL_STATUS_SUCCESS); @@ -1619,16 +1708,22 @@ bool ColorControlServer::moveToColorCommand(uint16_t colorX, uint16_t colorY, ui // kick off the state machine: emberEventControlSetDelayMS(configureXYEventControl(endpoint), UPDATE_TIME_MS); - emberAfSendImmediateDefaultResponse(EMBER_ZCL_STATUS_SUCCESS); +exit: + emberAfSendImmediateDefaultResponse(status); return true; } bool ColorControlServer::moveColorCommand(int16_t rateX, int16_t rateY, uint8_t optionsMask, uint8_t optionsOverride) { - EndpointId endpoint = emberAfCurrentEndpoint(); + EndpointId endpoint = emberAfCurrentEndpoint(); + EmberAfStatus status = EMBER_ZCL_STATUS_SUCCESS; + Color16uTransitionState * colorXTransitionState = getXTransitionState(endpoint); Color16uTransitionState * colorYTransitionState = getYTransitionState(endpoint); + VerifyOrExit(colorXTransitionState != nullptr, status = EMBER_ZCL_STATUS_UNSUPPORTED_ENDPOINT); + VerifyOrExit(colorYTransitionState != nullptr, status = EMBER_ZCL_STATUS_UNSUPPORTED_ENDPOINT); + if (!shouldExecuteIfOff(endpoint, optionsMask, optionsOverride)) { emberAfSendImmediateDefaultResponse(EMBER_ZCL_STATUS_SUCCESS); @@ -1701,31 +1796,39 @@ bool ColorControlServer::moveColorCommand(int16_t rateX, int16_t rateY, uint8_t // kick off the state machine: emberEventControlSetDelayMS(configureXYEventControl(endpoint), UPDATE_TIME_MS); - emberAfSendImmediateDefaultResponse(EMBER_ZCL_STATUS_SUCCESS); +exit: + emberAfSendImmediateDefaultResponse(status); return true; } bool ColorControlServer::stepColorCommand(int16_t stepX, int16_t stepY, uint16_t transitionTime, uint8_t optionsMask, uint8_t optionsOverride) { - EndpointId endpoint = emberAfCurrentEndpoint(); + EndpointId endpoint = emberAfCurrentEndpoint(); + uint16_t currentColorX = 0; + uint16_t currentColorY = 0; + uint16_t colorX = 0; + uint16_t colorY = 0; + + EmberAfStatus status = EMBER_ZCL_STATUS_SUCCESS; + Color16uTransitionState * colorXTransitionState = getXTransitionState(endpoint); Color16uTransitionState * colorYTransitionState = getYTransitionState(endpoint); + VerifyOrExit(colorXTransitionState != nullptr, status = EMBER_ZCL_STATUS_UNSUPPORTED_ENDPOINT); + VerifyOrExit(colorYTransitionState != nullptr, status = EMBER_ZCL_STATUS_UNSUPPORTED_ENDPOINT); + if (!shouldExecuteIfOff(endpoint, optionsMask, optionsOverride)) { emberAfSendImmediateDefaultResponse(EMBER_ZCL_STATUS_SUCCESS); return true; } - uint16_t currentColorX = 0; Attributes::CurrentX::Get(endpoint, ¤tColorX); - - uint16_t currentColorY = 0; Attributes::CurrentY::Get(endpoint, ¤tColorY); - uint16_t colorX = findNewColorValueFromStep(currentColorX, stepX); - uint16_t colorY = findNewColorValueFromStep(currentColorY, stepY); + colorX = findNewColorValueFromStep(currentColorX, stepX); + colorY = findNewColorValueFromStep(currentColorY, stepY); if (transitionTime == 0) { @@ -1762,7 +1865,8 @@ bool ColorControlServer::stepColorCommand(int16_t stepX, int16_t stepY, uint16_t // kick off the state machine: emberEventControlSetDelayMS(configureXYEventControl(endpoint), UPDATE_TIME_MS); - emberAfSendImmediateDefaultResponse(EMBER_ZCL_STATUS_SUCCESS); +exit: + emberAfSendImmediateDefaultResponse(status); return true; } @@ -1813,7 +1917,14 @@ void ColorControlServer::updateXYCommand(EndpointId endpoint) ColorControlServer::Color16uTransitionState * ColorControlServer::getTempTransitionState(EndpointId endpoint) { uint16_t index = emberAfFindClusterServerEndpointIndex(endpoint, ColorControl::Id); - return &colorTempTransitionStates[index]; + + Color16uTransitionState * state = nullptr; + if (index < EMBER_AF_COLOR_CONTROL_CLUSTER_SERVER_ENDPOINT_COUNT) + { + state = &colorTempTransitionStates[index]; + } + + return state; } /** @@ -1823,10 +1934,12 @@ ColorControlServer::Color16uTransitionState * ColorControlServer::getTempTransit * @param colorTemperature * @param transitionTime */ -void ColorControlServer::moveToColorTemp(EndpointId aEndpoint, uint16_t colorTemperature, uint16_t transitionTime) +EmberAfStatus ColorControlServer::moveToColorTemp(EndpointId aEndpoint, uint16_t colorTemperature, uint16_t transitionTime) { - EndpointId endpoint = emberAfCurrentEndpoint(); + EndpointId endpoint = emberAfCurrentEndpoint(); + Color16uTransitionState * colorTempTransitionState = getTempTransitionState(endpoint); + VerifyOrReturnError(colorTempTransitionState != nullptr, EMBER_ZCL_STATUS_UNSUPPORTED_ENDPOINT); uint16_t temperatureMin = MIN_TEMPERATURE_VALUE; Attributes::ColorTempPhysicalMin::Get(endpoint, &temperatureMin); @@ -1868,6 +1981,7 @@ void ColorControlServer::moveToColorTemp(EndpointId aEndpoint, uint16_t colorTem // kick off the state machine emberEventControlSetDelayMS(configureTempEventControl(endpoint), UPDATE_TIME_MS); + return EMBER_ZCL_STATUS_SUCCESS; } /** @@ -1900,6 +2014,7 @@ uint16_t ColorControlServer::getTemperatureCoupleToLevelMin(EndpointId endpoint) EmberEventControl * ColorControlServer::configureTempEventControl(EndpointId endpoint) { EmberEventControl * controller = getEventControl(endpoint); + VerifyOrReturnError(controller != nullptr, nullptr); controller->endpoint = endpoint; controller->callback = &emberAfPluginColorControlServerTempTransitionEventHandler; @@ -2002,8 +2117,14 @@ void ColorControlServer::updateTempCommand(EndpointId endpoint) bool ColorControlServer::moveColorTempCommand(uint8_t moveMode, uint16_t rate, uint16_t colorTemperatureMinimum, uint16_t colorTemperatureMaximum, uint8_t optionsMask, uint8_t optionsOverride) { - EndpointId endpoint = emberAfCurrentEndpoint(); + EndpointId endpoint = emberAfCurrentEndpoint(); + EmberAfStatus status = EMBER_ZCL_STATUS_SUCCESS; + uint16_t tempPhysicalMin = MIN_TEMPERATURE_VALUE; + uint16_t tempPhysicalMax = MAX_TEMPERATURE_VALUE; + uint16_t transitionTime; + Color16uTransitionState * colorTempTransitionState = getTempTransitionState(endpoint); + VerifyOrExit(colorTempTransitionState != nullptr, status = EMBER_ZCL_STATUS_UNSUPPORTED_ENDPOINT); if (!shouldExecuteIfOff(endpoint, optionsMask, optionsOverride)) { @@ -2011,14 +2132,9 @@ bool ColorControlServer::moveColorTempCommand(uint8_t moveMode, uint16_t rate, u return true; } - uint16_t tempPhysicalMin = MIN_TEMPERATURE_VALUE; Attributes::ColorTempPhysicalMin::Get(endpoint, &tempPhysicalMin); - - uint16_t tempPhysicalMax = MAX_TEMPERATURE_VALUE; Attributes::ColorTempPhysicalMax::Get(endpoint, &tempPhysicalMax); - uint16_t transitionTime; - // New command. Need to stop any active transitions. stopAllColorTransitions(endpoint); @@ -2085,7 +2201,8 @@ bool ColorControlServer::moveColorTempCommand(uint8_t moveMode, uint16_t rate, u // kick off the state machine: emberEventControlSetDelayMS(configureTempEventControl(endpoint), UPDATE_TIME_MS); - emberAfSendImmediateDefaultResponse(EMBER_ZCL_STATUS_SUCCESS); +exit: + emberAfSendImmediateDefaultResponse(status); return true; } @@ -2100,9 +2217,9 @@ bool ColorControlServer::moveToColorTempCommand(uint16_t colorTemperature, uint1 return true; } - moveToColorTemp(endpoint, colorTemperature, transitionTime); + EmberAfStatus error = moveToColorTemp(endpoint, colorTemperature, transitionTime); - emberAfSendImmediateDefaultResponse(EMBER_ZCL_STATUS_SUCCESS); + emberAfSendImmediateDefaultResponse(error); return true; } @@ -2110,8 +2227,13 @@ bool ColorControlServer::stepColorTempCommand(uint8_t stepMode, uint16_t stepSiz uint16_t colorTemperatureMinimum, uint16_t colorTemperatureMaximum, uint8_t optionsMask, uint8_t optionsOverride) { - EndpointId endpoint = emberAfCurrentEndpoint(); + EndpointId endpoint = emberAfCurrentEndpoint(); + EmberAfStatus status = EMBER_ZCL_STATUS_SUCCESS; + uint16_t tempPhysicalMin = MIN_TEMPERATURE_VALUE; + uint16_t tempPhysicalMax = MAX_TEMPERATURE_VALUE; + Color16uTransitionState * colorTempTransitionState = getTempTransitionState(endpoint); + VerifyOrExit(colorTempTransitionState != nullptr, status = EMBER_ZCL_STATUS_UNSUPPORTED_ENDPOINT); if (!shouldExecuteIfOff(endpoint, optionsMask, optionsOverride)) { @@ -2119,10 +2241,8 @@ bool ColorControlServer::stepColorTempCommand(uint8_t stepMode, uint16_t stepSiz return true; } - uint16_t tempPhysicalMin = MIN_TEMPERATURE_VALUE; Attributes::ColorTempPhysicalMin::Get(endpoint, &tempPhysicalMin); - uint16_t tempPhysicalMax = MAX_TEMPERATURE_VALUE; Attributes::ColorTempPhysicalMax::Get(endpoint, &tempPhysicalMax); if (transitionTime == 0) @@ -2191,7 +2311,8 @@ bool ColorControlServer::stepColorTempCommand(uint8_t stepMode, uint16_t stepSiz // kick off the state machine: emberEventControlSetDelayMS(configureTempEventControl(endpoint), UPDATE_TIME_MS); - emberAfSendImmediateDefaultResponse(EMBER_ZCL_STATUS_SUCCESS); +exit: + emberAfSendImmediateDefaultResponse(status); return true; } diff --git a/src/app/clusters/color-control-server/color-control-server.h b/src/app/clusters/color-control-server/color-control-server.h index 0749c2a01ce0c0..20de96e460deb5 100644 --- a/src/app/clusters/color-control-server/color-control-server.h +++ b/src/app/clusters/color-control-server/color-control-server.h @@ -140,7 +140,7 @@ class ColorControlServer * Functions Definitions *********************************************************/ static ColorControlServer & Instance(); - void stopAllColorTransitions(chip::EndpointId endpoint); + EmberAfStatus stopAllColorTransitions(chip::EndpointId endpoint); bool stopMoveStepCommand(uint8_t optionsMask, uint8_t optionsOverride); #ifdef EMBER_AF_PLUGIN_COLOR_CONTROL_SERVER_HSV @@ -220,7 +220,7 @@ class ColorControlServer #ifdef EMBER_AF_PLUGIN_COLOR_CONTROL_SERVER_TEMP Color16uTransitionState * getTempTransitionState(chip::EndpointId endpoint); - void moveToColorTemp(chip::EndpointId aEndpoint, uint16_t colorTemperature, uint16_t transitionTime); + EmberAfStatus moveToColorTemp(chip::EndpointId aEndpoint, uint16_t colorTemperature, uint16_t transitionTime); uint16_t getTemperatureCoupleToLevelMin(chip::EndpointId endpoint); EmberEventControl * configureTempEventControl(chip::EndpointId); #endif // EMBER_AF_PLUGIN_COLOR_CONTROL_SERVER_TEMP diff --git a/src/app/clusters/on-off-server/on-off-server.cpp b/src/app/clusters/on-off-server/on-off-server.cpp index 6ebdf146ef4093..a92fba179ec750 100644 --- a/src/app/clusters/on-off-server/on-off-server.cpp +++ b/src/app/clusters/on-off-server/on-off-server.cpp @@ -138,8 +138,12 @@ EmberAfStatus OnOffServer::setOnOffValue(chip::EndpointId endpoint, uint8_t comm Attributes::OffWaitTime::Set(endpoint, 0); // Stop timer on the endpoint - emberEventControlSetInactive(getEventControl(endpoint)); - emberAfOnOffClusterPrintln("On/Toggle Command - Stop Timer"); + EmberEventControl * event = getEventControl(endpoint); + if (event != nullptr) + { + emberEventControlSetInactive(event); + emberAfOnOffClusterPrintln("On/Toggle Command - Stop Timer"); + } } Attributes::GlobalSceneControl::Set(endpoint, true); @@ -352,10 +356,15 @@ bool OnOffServer::OnWithRecallGlobalSceneCommand() bool OnOffServer::OnWithTimedOffCommand(BitFlags onOffControl, uint16_t onTime, uint16_t offWaitTime) { - EmberAfStatus status = EMBER_ZCL_STATUS_SUCCESS; - chip::EndpointId endpoint = emberAfCurrentEndpoint(); + EmberAfStatus status = EMBER_ZCL_STATUS_SUCCESS; + chip::EndpointId endpoint = emberAfCurrentEndpoint(); + bool isOn = false; + uint16_t currentOffWaitTime = MAX_TIME_VALUE; + uint16_t currentOnTime = 0; + + EmberEventControl * event = configureEventControl(endpoint); + VerifyOrExit(event != nullptr, status = EMBER_ZCL_STATUS_UNSUPPORTED_ENDPOINT); - bool isOn = false; OnOff::Attributes::OnOff::Get(endpoint, &isOn); // OnOff is off and the commands is only accepted if on @@ -365,10 +374,7 @@ bool OnOffServer::OnWithTimedOffCommand(BitFlags onOffControl, uin return true; } - uint16_t currentOffWaitTime = MAX_TIME_VALUE; OnOff::Attributes::OffWaitTime::Get(endpoint, ¤tOffWaitTime); - - uint16_t currentOnTime = 0; OnOff::Attributes::OnTime::Get(endpoint, ¤tOnTime); if (currentOffWaitTime > 0 && !isOn) @@ -397,6 +403,7 @@ bool OnOffServer::OnWithTimedOffCommand(BitFlags onOffControl, uin emberEventControlSetDelayMS(configureEventControl(endpoint), UPDATE_TIME_MS); } +exit: emberAfSendImmediateDefaultResponse(status); return true; } @@ -498,8 +505,15 @@ bool OnOffServer::areStartUpOnOffServerAttributesTokenized(EndpointId endpoint) */ EmberEventControl * OnOffServer::getEventControl(EndpointId endpoint) { - uint16_t index = emberAfFindClusterServerEndpointIndex(endpoint, OnOff::Id); - return &eventControls[index]; + uint16_t index = emberAfFindClusterServerEndpointIndex(endpoint, OnOff::Id); + EmberEventControl * event = nullptr; + + if (index < EMBER_AF_ON_OFF_CLUSTER_SERVER_ENDPOINT_COUNT) + { + event = &eventControls[index]; + } + + return event; } /** @@ -511,6 +525,7 @@ EmberEventControl * OnOffServer::getEventControl(EndpointId endpoint) EmberEventControl * OnOffServer::configureEventControl(EndpointId endpoint) { EmberEventControl * controller = getEventControl(endpoint); + VerifyOrReturnError(controller != nullptr, nullptr); controller->endpoint = endpoint; controller->callback = &onOffWaitTimeOffEventHandler; diff --git a/src/app/clusters/on-off-server/on-off-server.h b/src/app/clusters/on-off-server/on-off-server.h index 2465517e7591be..932a756ea21f48 100644 --- a/src/app/clusters/on-off-server/on-off-server.h +++ b/src/app/clusters/on-off-server/on-off-server.h @@ -87,6 +87,12 @@ struct OnOffEffect OnOffEffect( chip::EndpointId endpoint, OffWithEffectTriggerCommand offWithEffectTrigger, uint8_t effectIdentifier = static_cast(EMBER_ZCL_ON_OFF_EFFECT_IDENTIFIER_DELAYED_ALL_OFF), + + /* + * effectVariant's type depends on the effect effectIdentifier so we don't know the type at compile time. + * Casting to uint8_t for more flexibilty since the type can be OnOffDelayedAllOffEffectVariant or + * OnOffDelayedAllOffEffectVariant + */ uint8_t effectVariant = static_cast(EMBER_ZCL_ON_OFF_DELAYED_ALL_OFF_EFFECT_VARIANT_FADE_TO_OFF_IN_0P8_SECONDS)); ~OnOffEffect(); };