From d747aa05ee6941cc71d3555a065a5c2c528f48e1 Mon Sep 17 00:00:00 2001 From: Rohit Jadhav Date: Wed, 17 May 2023 17:47:59 +0530 Subject: [PATCH 1/9] Add server implementation for refrigerator alarm cluster --- .../all-clusters-app.matter | 44 ++ .../all-clusters-common/all-clusters-app.zap | 430 ++++++++++++++++++ .../esp32/main/CMakeLists.txt | 1 + .../refrigerator-alarm-server.cpp | 92 ++++ 4 files changed, 567 insertions(+) create mode 100644 src/app/clusters/refrigerator-alarm-server/refrigerator-alarm-server.cpp diff --git a/examples/all-clusters-app/all-clusters-common/all-clusters-app.matter b/examples/all-clusters-app/all-clusters-common/all-clusters-app.matter index a28f341209feea..a8d15ef7392130 100644 --- a/examples/all-clusters-app/all-clusters-common/all-clusters-app.matter +++ b/examples/all-clusters-app/all-clusters-common/all-clusters-app.matter @@ -2350,6 +2350,37 @@ server cluster ModeSelect = 80 { command ChangeToMode(ChangeToModeRequest): DefaultSuccess = 0; } +/** Attributes and commands for configuring the Refrigerator alarm. */ +server cluster RefrigeratorAlarm = 87 { + bitmap AlarmMap : BITMAP32 { + kDoorOpen = 0x1; + } + + info event Notify = 0 { + AlarmMap active = 0; + AlarmMap inactive = 1; + AlarmMap state = 2; + AlarmMap mask = 3; + } + + attribute AlarmMap mask = 0; + readonly attribute AlarmMap latch = 1; + readonly attribute AlarmMap state = 2; + readonly attribute command_id generatedCommandList[] = 65528; + readonly attribute command_id acceptedCommandList[] = 65529; + readonly attribute event_id eventList[] = 65530; + readonly attribute attrib_id attributeList[] = 65531; + readonly attribute bitmap32 featureMap = 65532; + readonly attribute int16u clusterRevision = 65533; + + request struct ResetRequest { + AlarmMap alarms = 0; + optional AlarmMap mask = 1; + } + + command Reset(ResetRequest): DefaultSuccess = 0; +} + /** Attributes for reporting air quality classification */ server cluster AirQuality = 91 { enum AirQualityEnum : ENUM8 { @@ -6133,6 +6164,19 @@ endpoint 1 { ram attribute manufacturerExtension default = 255; } + server cluster RefrigeratorAlarm { + emits event Notify; + ram attribute mask default = 0; + ram attribute latch default = 0; + ram attribute state default = 0; + callback attribute generatedCommandList; + callback attribute acceptedCommandList; + callback attribute eventList; + callback attribute attributeList; + ram attribute featureMap default = 0; + ram attribute clusterRevision default = 1; + } + server cluster AirQuality { ram attribute airQuality default = 0; callback attribute generatedCommandList; diff --git a/examples/all-clusters-app/all-clusters-common/all-clusters-app.zap b/examples/all-clusters-app/all-clusters-common/all-clusters-app.zap index bbdf3a2c461b57..a471209f67f7ea 100644 --- a/examples/all-clusters-app/all-clusters-common/all-clusters-app.zap +++ b/examples/all-clusters-app/all-clusters-common/all-clusters-app.zap @@ -6536,6 +6536,221 @@ } ] }, + { + "name": "Refrigerator Alarm", + "code": 87, + "mfgCode": null, + "define": "REFRIGERATOR_ALARM", + "side": "client", + "enabled": 0, + "commands": [ + { + "name": "Reset", + "code": 0, + "mfgCode": null, + "source": "client", + "incoming": 1, + "outgoing": 1 + } + ], + "attributes": [ + { + "name": "FeatureMap", + "code": 65532, + "mfgCode": null, + "side": "client", + "type": "bitmap32", + "included": 1, + "storageOption": "RAM", + "singleton": 0, + "bounded": 0, + "defaultValue": "0", + "reportable": 1, + "minInterval": 1, + "maxInterval": 65534, + "reportableChange": 0 + }, + { + "name": "ClusterRevision", + "code": 65533, + "mfgCode": null, + "side": "client", + "type": "int16u", + "included": 1, + "storageOption": "RAM", + "singleton": 0, + "bounded": 0, + "defaultValue": "1", + "reportable": 1, + "minInterval": 1, + "maxInterval": 65534, + "reportableChange": 0 + } + ] + }, + { + "name": "Refrigerator Alarm", + "code": 87, + "mfgCode": null, + "define": "REFRIGERATOR_ALARM", + "side": "server", + "enabled": 0, + "attributes": [ + { + "name": "Mask", + "code": 0, + "mfgCode": null, + "side": "server", + "type": "AlarmMap", + "included": 1, + "storageOption": "RAM", + "singleton": 0, + "bounded": 0, + "defaultValue": "1", + "reportable": 1, + "minInterval": 1, + "maxInterval": 65534, + "reportableChange": 0 + }, + { + "name": "Latch", + "code": 1, + "mfgCode": null, + "side": "server", + "type": "AlarmMap", + "included": 1, + "storageOption": "RAM", + "singleton": 0, + "bounded": 0, + "defaultValue": "1", + "reportable": 1, + "minInterval": 1, + "maxInterval": 65534, + "reportableChange": 0 + }, + { + "name": "State", + "code": 2, + "mfgCode": null, + "side": "server", + "type": "AlarmMap", + "included": 1, + "storageOption": "RAM", + "singleton": 0, + "bounded": 0, + "defaultValue": "1", + "reportable": 1, + "minInterval": 1, + "maxInterval": 65534, + "reportableChange": 0 + }, + { + "name": "GeneratedCommandList", + "code": 65528, + "mfgCode": null, + "side": "server", + "type": "array", + "included": 1, + "storageOption": "External", + "singleton": 0, + "bounded": 0, + "defaultValue": "", + "reportable": 1, + "minInterval": 1, + "maxInterval": 65534, + "reportableChange": 0 + }, + { + "name": "AcceptedCommandList", + "code": 65529, + "mfgCode": null, + "side": "server", + "type": "array", + "included": 1, + "storageOption": "External", + "singleton": 0, + "bounded": 0, + "defaultValue": "", + "reportable": 1, + "minInterval": 1, + "maxInterval": 65534, + "reportableChange": 0 + }, + { + "name": "EventList", + "code": 65530, + "mfgCode": null, + "side": "server", + "type": "array", + "included": 1, + "storageOption": "External", + "singleton": 0, + "bounded": 0, + "defaultValue": "", + "reportable": 1, + "minInterval": 1, + "maxInterval": 65534, + "reportableChange": 0 + }, + { + "name": "AttributeList", + "code": 65531, + "mfgCode": null, + "side": "server", + "type": "array", + "included": 1, + "storageOption": "External", + "singleton": 0, + "bounded": 0, + "defaultValue": "", + "reportable": 1, + "minInterval": 1, + "maxInterval": 65534, + "reportableChange": 0 + }, + { + "name": "FeatureMap", + "code": 65532, + "mfgCode": null, + "side": "server", + "type": "bitmap32", + "included": 1, + "storageOption": "RAM", + "singleton": 0, + "bounded": 0, + "defaultValue": "0", + "reportable": 1, + "minInterval": 1, + "maxInterval": 65534, + "reportableChange": 0 + }, + { + "name": "ClusterRevision", + "code": 65533, + "mfgCode": null, + "side": "server", + "type": "int16u", + "included": 1, + "storageOption": "RAM", + "singleton": 0, + "bounded": 0, + "defaultValue": "1", + "reportable": 1, + "minInterval": 1, + "maxInterval": 65534, + "reportableChange": 0 + } + ], + "events": [ + { + "name": "Notify", + "code": 0, + "mfgCode": null, + "side": "server", + "included": 1 + } + ] + }, { "name": "Door Lock", "code": 257, @@ -13076,6 +13291,221 @@ } ] }, + { + "name": "Refrigerator Alarm", + "code": 87, + "mfgCode": null, + "define": "REFRIGERATOR_ALARM", + "side": "client", + "enabled": 0, + "commands": [ + { + "name": "Reset", + "code": 0, + "mfgCode": null, + "source": "client", + "incoming": 1, + "outgoing": 1 + } + ], + "attributes": [ + { + "name": "FeatureMap", + "code": 65532, + "mfgCode": null, + "side": "client", + "type": "bitmap32", + "included": 1, + "storageOption": "RAM", + "singleton": 0, + "bounded": 0, + "defaultValue": "0", + "reportable": 1, + "minInterval": 1, + "maxInterval": 65534, + "reportableChange": 0 + }, + { + "name": "ClusterRevision", + "code": 65533, + "mfgCode": null, + "side": "client", + "type": "int16u", + "included": 1, + "storageOption": "RAM", + "singleton": 0, + "bounded": 0, + "defaultValue": "1", + "reportable": 1, + "minInterval": 1, + "maxInterval": 65534, + "reportableChange": 0 + } + ] + }, + { + "name": "Refrigerator Alarm", + "code": 87, + "mfgCode": null, + "define": "REFRIGERATOR_ALARM", + "side": "server", + "enabled": 1, + "attributes": [ + { + "name": "Mask", + "code": 0, + "mfgCode": null, + "side": "server", + "type": "AlarmMap", + "included": 1, + "storageOption": "RAM", + "singleton": 0, + "bounded": 0, + "defaultValue": "0", + "reportable": 1, + "minInterval": 1, + "maxInterval": 65534, + "reportableChange": 0 + }, + { + "name": "Latch", + "code": 1, + "mfgCode": null, + "side": "server", + "type": "AlarmMap", + "included": 1, + "storageOption": "RAM", + "singleton": 0, + "bounded": 0, + "defaultValue": "0", + "reportable": 1, + "minInterval": 1, + "maxInterval": 65534, + "reportableChange": 0 + }, + { + "name": "State", + "code": 2, + "mfgCode": null, + "side": "server", + "type": "AlarmMap", + "included": 1, + "storageOption": "RAM", + "singleton": 0, + "bounded": 0, + "defaultValue": "0", + "reportable": 1, + "minInterval": 1, + "maxInterval": 65534, + "reportableChange": 0 + }, + { + "name": "GeneratedCommandList", + "code": 65528, + "mfgCode": null, + "side": "server", + "type": "array", + "included": 1, + "storageOption": "External", + "singleton": 0, + "bounded": 0, + "defaultValue": "", + "reportable": 1, + "minInterval": 1, + "maxInterval": 65534, + "reportableChange": 0 + }, + { + "name": "AcceptedCommandList", + "code": 65529, + "mfgCode": null, + "side": "server", + "type": "array", + "included": 1, + "storageOption": "External", + "singleton": 0, + "bounded": 0, + "defaultValue": "", + "reportable": 1, + "minInterval": 1, + "maxInterval": 65534, + "reportableChange": 0 + }, + { + "name": "EventList", + "code": 65530, + "mfgCode": null, + "side": "server", + "type": "array", + "included": 1, + "storageOption": "External", + "singleton": 0, + "bounded": 0, + "defaultValue": "", + "reportable": 1, + "minInterval": 1, + "maxInterval": 65534, + "reportableChange": 0 + }, + { + "name": "AttributeList", + "code": 65531, + "mfgCode": null, + "side": "server", + "type": "array", + "included": 1, + "storageOption": "External", + "singleton": 0, + "bounded": 0, + "defaultValue": "", + "reportable": 1, + "minInterval": 1, + "maxInterval": 65534, + "reportableChange": 0 + }, + { + "name": "FeatureMap", + "code": 65532, + "mfgCode": null, + "side": "server", + "type": "bitmap32", + "included": 1, + "storageOption": "RAM", + "singleton": 0, + "bounded": 0, + "defaultValue": "0", + "reportable": 1, + "minInterval": 1, + "maxInterval": 65534, + "reportableChange": 0 + }, + { + "name": "ClusterRevision", + "code": 65533, + "mfgCode": null, + "side": "server", + "type": "int16u", + "included": 1, + "storageOption": "RAM", + "singleton": 0, + "bounded": 0, + "defaultValue": "1", + "reportable": 1, + "minInterval": 1, + "maxInterval": 65534, + "reportableChange": 0 + } + ], + "events": [ + { + "name": "Notify", + "code": 0, + "mfgCode": null, + "side": "server", + "included": 1 + } + ] + }, { "name": "Air Quality", "code": 91, diff --git a/examples/all-clusters-app/esp32/main/CMakeLists.txt b/examples/all-clusters-app/esp32/main/CMakeLists.txt index ed62e67b6d26f7..e2311a75f51f76 100644 --- a/examples/all-clusters-app/esp32/main/CMakeLists.txt +++ b/examples/all-clusters-app/esp32/main/CMakeLists.txt @@ -71,6 +71,7 @@ set(SRC_DIRS_LIST "${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/clusters/thread-network-diagnostics-server" "${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/clusters/channel-server" "${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/clusters/scenes-server" + "${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/clusters/refrigerator-alarm-server" "${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/clusters/software-diagnostics-server" "${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/clusters/switch-server" "${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/clusters/general-diagnostics-server" diff --git a/src/app/clusters/refrigerator-alarm-server/refrigerator-alarm-server.cpp b/src/app/clusters/refrigerator-alarm-server/refrigerator-alarm-server.cpp new file mode 100644 index 00000000000000..ff29f84fb95ba9 --- /dev/null +++ b/src/app/clusters/refrigerator-alarm-server/refrigerator-alarm-server.cpp @@ -0,0 +1,92 @@ +/** + * + * Copyright (c) 2023 Project CHIP Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include +#include +#include +#include +#include + +using namespace chip; +using namespace chip::app; +using namespace chip::app::Clusters; +using namespace chip::app::Clusters::RefrigeratorAlarm; +using namespace chip::app::Clusters::RefrigeratorAlarm::Attributes; +using namespace chip::DeviceLayer; +using chip::Protocols::InteractionModel::Status; + +static Status resetHandler(app::CommandHandler * commandObj, const app::ConcreteCommandPath & commandPath, const chip::BitMask alarms, const chip::Optional> mask); + +static Status resetHandler(app::CommandHandler * commandObj, const app::ConcreteCommandPath & commandPath, const chip::BitMask alarms, const chip::Optional> mask) +{ + EndpointId endpoint = commandPath.mEndpointId; + + EmberAfStatus status; + chip::BitMask state = 0; + status = State::Get(endpoint, &state); + if (status != EMBER_ZCL_STATUS_SUCCESS) + { + return Status::Failure; + } + + uint32_t alarmValue = alarms.Raw(); + uint32_t stateValue = state.Raw(); + + // Flip the bits of alarms (i.e. ~alarms) + alarmValue = 0xFFFF ^ alarmValue; + + // Reset state from active to inactive + stateValue = stateValue & alarmValue; + + state.SetRaw(stateValue); + status = State::Set(endpoint, state); + if (status != EMBER_ZCL_STATUS_SUCCESS) + { + return Status::Failure; + } + + if(mask.HasValue()) + { + status = Mask::Set(endpoint, mask.Value()); + if (status != EMBER_ZCL_STATUS_SUCCESS) + { + return Status::Failure; + } + } + + return Status::Success; + +} +/********************************************************** + * Callbacks Implementation + *********************************************************/ + +bool emberAfRefrigeratorAlarmClusterResetCallback(app::CommandHandler * commandObj, const app::ConcreteCommandPath & commandPath, const Commands::Reset::DecodableType & commandData) +{ + auto & alarms = commandData.alarms; + auto & mask = commandData.mask; + + Status status = resetHandler(commandObj, commandPath, alarms, mask); + commandObj->AddStatus(commandPath, status); + + return true; +} + +void emberAfRefrigeratorAlarmClusterServerInitCallback(chip::EndpointId endpoint) {} + +void MatterRefrigeratorAlarmPluginServerInitCallback() {} From f996f21fffefdadd72db38c48f7d43873b0abd89 Mon Sep 17 00:00:00 2001 From: Rohit Jadhav <69809379+jadhavrohit924@users.noreply.github.com> Date: Mon, 22 May 2023 17:21:40 +0530 Subject: [PATCH 2/9] Apply suggestions from code review Co-authored-by: Boris Zbarsky --- .../all-clusters-app.matter | 13 +++++++++ .../refrigerator-alarm-server.cpp | 29 +++++++------------ 2 files changed, 24 insertions(+), 18 deletions(-) diff --git a/examples/all-clusters-app/all-clusters-common/all-clusters-app.matter b/examples/all-clusters-app/all-clusters-common/all-clusters-app.matter index a8d15ef7392130..0997df0b147a4c 100644 --- a/examples/all-clusters-app/all-clusters-common/all-clusters-app.matter +++ b/examples/all-clusters-app/all-clusters-common/all-clusters-app.matter @@ -5997,6 +5997,19 @@ endpoint 0 { ram attribute clusterRevision default = 1; } + server cluster RefrigeratorAlarm { + emits event Notify; + ram attribute mask default = 1; + ram attribute latch default = 1; + ram attribute state default = 1; + callback attribute generatedCommandList; + callback attribute acceptedCommandList; + callback attribute eventList; + callback attribute attributeList; + ram attribute featureMap default = 0; + ram attribute clusterRevision default = 1; + } + server cluster RelativeHumidityMeasurement { ram attribute measuredValue; ram attribute minMeasuredValue default = 0; diff --git a/src/app/clusters/refrigerator-alarm-server/refrigerator-alarm-server.cpp b/src/app/clusters/refrigerator-alarm-server/refrigerator-alarm-server.cpp index ff29f84fb95ba9..a796206f531858 100644 --- a/src/app/clusters/refrigerator-alarm-server/refrigerator-alarm-server.cpp +++ b/src/app/clusters/refrigerator-alarm-server/refrigerator-alarm-server.cpp @@ -17,8 +17,8 @@ */ #include -#include #include +#include #include #include @@ -30,39 +30,32 @@ using namespace chip::app::Clusters::RefrigeratorAlarm::Attributes; using namespace chip::DeviceLayer; using chip::Protocols::InteractionModel::Status; -static Status resetHandler(app::CommandHandler * commandObj, const app::ConcreteCommandPath & commandPath, const chip::BitMask alarms, const chip::Optional> mask); +static Status resetHandler(CommandHandler * commandObj, const ConcreteCommandPath & commandPath, const BitMask & alarms, + const Optional> & mask); -static Status resetHandler(app::CommandHandler * commandObj, const app::ConcreteCommandPath & commandPath, const chip::BitMask alarms, const chip::Optional> mask) +static Status resetHandler(CommandHandler * commandObj, const ConcreteCommandPath & commandPath, const BitMask & alarms, + const Optional> & mask) { EndpointId endpoint = commandPath.mEndpointId; EmberAfStatus status; chip::BitMask state = 0; - status = State::Get(endpoint, &state); + status = State::Get(endpoint, &state); if (status != EMBER_ZCL_STATUS_SUCCESS) { return Status::Failure; } - - uint32_t alarmValue = alarms.Raw(); - uint32_t stateValue = state.Raw(); - - // Flip the bits of alarms (i.e. ~alarms) - alarmValue = 0xFFFF ^ alarmValue; - // Reset state from active to inactive - stateValue = stateValue & alarmValue; - - state.SetRaw(stateValue); + state.Clear(alarms); status = State::Set(endpoint, state); if (status != EMBER_ZCL_STATUS_SUCCESS) { return Status::Failure; } - if(mask.HasValue()) + if (mask.HasValue()) { - status = Mask::Set(endpoint, mask.Value()); + status = Mask::Set(endpoint, mask.Value()); if (status != EMBER_ZCL_STATUS_SUCCESS) { return Status::Failure; @@ -70,13 +63,13 @@ static Status resetHandler(app::CommandHandler * commandObj, const app::Concrete } return Status::Success; - } /********************************************************** * Callbacks Implementation *********************************************************/ -bool emberAfRefrigeratorAlarmClusterResetCallback(app::CommandHandler * commandObj, const app::ConcreteCommandPath & commandPath, const Commands::Reset::DecodableType & commandData) +bool emberAfRefrigeratorAlarmClusterResetCallback(app::CommandHandler * commandObj, const app::ConcreteCommandPath & commandPath, + const Commands::Reset::DecodableType & commandData) { auto & alarms = commandData.alarms; auto & mask = commandData.mask; From f2f2bd6fea94382563f6030b5fa66a223b743eda Mon Sep 17 00:00:00 2001 From: Rohit Jadhav Date: Fri, 26 May 2023 12:42:36 +0530 Subject: [PATCH 3/9] Add read/write attribute APIs and generate event --- .../refrigerator-alarm-server.cpp | 133 ++++++++++++++++-- .../refrigerator-alarm-server.h | 48 +++++++ 2 files changed, 166 insertions(+), 15 deletions(-) create mode 100644 src/app/clusters/refrigerator-alarm-server/refrigerator-alarm-server.h diff --git a/src/app/clusters/refrigerator-alarm-server/refrigerator-alarm-server.cpp b/src/app/clusters/refrigerator-alarm-server/refrigerator-alarm-server.cpp index a796206f531858..abc9ecf1bcd9a8 100644 --- a/src/app/clusters/refrigerator-alarm-server/refrigerator-alarm-server.cpp +++ b/src/app/clusters/refrigerator-alarm-server/refrigerator-alarm-server.cpp @@ -15,12 +15,15 @@ * limitations under the License. * */ +#include "refrigerator-alarm-server.h" #include #include #include +#include #include #include +#include using namespace chip; using namespace chip::app; @@ -30,27 +33,130 @@ using namespace chip::app::Clusters::RefrigeratorAlarm::Attributes; using namespace chip::DeviceLayer; using chip::Protocols::InteractionModel::Status; -static Status resetHandler(CommandHandler * commandObj, const ConcreteCommandPath & commandPath, const BitMask & alarms, - const Optional> & mask); +RefrigeratorAlarmServer RefrigeratorAlarmServer::instance; -static Status resetHandler(CommandHandler * commandObj, const ConcreteCommandPath & commandPath, const BitMask & alarms, - const Optional> & mask) +RefrigeratorAlarmServer & RefrigeratorAlarmServer::Instance() { + return instance; +} + +EmberAfStatus RefrigeratorAlarmServer::getMaskValue(chip::EndpointId endpoint, chip::BitMask * mask) +{ + EmberAfStatus status = Attributes::Mask::Get(endpoint, mask); + if (status != EMBER_ZCL_STATUS_SUCCESS) + { + emberAfPrintln(EMBER_AF_PRINT_DEBUG, "Refrigerator Alarm: ERR: reading mask %x", status); + } + + emberAfPrintln(EMBER_AF_PRINT_DEBUG, "Refrigerator Alarm: Mask ep%d value: %" PRIu32 "", endpoint, mask->Raw()); + + return status; +} + +EmberAfStatus RefrigeratorAlarmServer::getLatchValue(chip::EndpointId endpoint, chip::BitMask * latch) +{ + EmberAfStatus status = Attributes::Latch::Get(endpoint, latch); + if (status != EMBER_ZCL_STATUS_SUCCESS) + { + emberAfPrintln(EMBER_AF_PRINT_DEBUG, "Refrigerator Alarm: ERR: reading latch %x", status); + } + + emberAfPrintln(EMBER_AF_PRINT_DEBUG, "Refrigerator Alarm: Latch ep%d value: %" PRIu32 "", endpoint, latch->Raw()); + + return status; +} + +EmberAfStatus RefrigeratorAlarmServer::getStateValue(chip::EndpointId endpoint, chip::BitMask * state) +{ + EmberAfStatus status = Attributes::State::Get(endpoint, state); + if (status != EMBER_ZCL_STATUS_SUCCESS) + { + emberAfPrintln(EMBER_AF_PRINT_DEBUG, "Refrigerator Alarm: ERR: reading state %x", status); + } + + emberAfPrintln(EMBER_AF_PRINT_DEBUG, "Refrigerator Alarm: State ep%d value: %" PRIu32 "", endpoint, state->Raw()); + + return status; +} + +EmberAfStatus RefrigeratorAlarmServer::setMaskValue(chip::EndpointId endpoint, chip::BitMask mask) +{ + chip::BitMask * currentMask = nullptr; + EmberAfStatus status = Attributes::Mask::Get(endpoint, currentMask); + if (status != EMBER_ZCL_STATUS_SUCCESS) + { + emberAfPrintln(EMBER_AF_PRINT_DEBUG, "Refrigerator Alarm: ERR: reading mask %x", status); + } + if (currentMask->Raw() == mask.Raw()) + { + emberAfPrintln(EMBER_AF_PRINT_DEBUG, "Refrigerator Alarm: Mask value already set to %" PRIu32 "", mask.Raw()); + } + else + { + status = Attributes::Mask::Set(endpoint, mask); + if (status != EMBER_ZCL_STATUS_SUCCESS) + { + emberAfPrintln(EMBER_AF_PRINT_DEBUG, "Refrigerator Alarm: ERR: writing mask %x", status); + } + } + + emberAfPrintln(EMBER_AF_PRINT_DEBUG, "Refrigerator Alarm: Mask ep%d value: %" PRIu32 "", endpoint, mask.Raw()); + + return status; +} + +bool RefrigeratorAlarmServer::SendNotifyEvent(chip::EndpointId endpointId, chip::BitMask active, + chip::BitMask inActive, chip::BitMask state, + chip::BitMask mask) +{ + Events::Notify::Type event{ active, inActive, state, mask }; + EventNumber eventNumber; + CHIP_ERROR error = app::LogEvent(event, endpointId, eventNumber); + if (CHIP_NO_ERROR != error) + { + ChipLogError(Zcl, "[Notify] Unable to send notify event: %s [endpointId=%d]", error.AsString(), endpointId); + return false; + } + + return true; +} + +bool RefrigeratorAlarmServer::ResetCommand(CommandHandler * commandObj, const ConcreteCommandPath & commandPath, + const Commands::Reset::DecodableType & commandData) +{ + auto & alarms = commandData.alarms; + auto & mask = commandData.mask; + EndpointId endpoint = commandPath.mEndpointId; EmberAfStatus status; + + chip::BitMask eActive = 0; + chip::BitMask eInActive = alarms; + chip::BitMask eMask = 0; + chip::BitMask eState = 0; + chip::BitMask state = 0; status = State::Get(endpoint, &state); + + eActive.Clear(alarms); + eInActive.Clear(state); + Mask::Get(endpoint, &eMask); + eActive = state; + eState = state; + if (status != EMBER_ZCL_STATUS_SUCCESS) { - return Status::Failure; + commandObj->AddStatus(commandPath, app::ToInteractionModelStatus(status)); + return false; } state.Clear(alarms); status = State::Set(endpoint, state); if (status != EMBER_ZCL_STATUS_SUCCESS) { - return Status::Failure; + commandObj->AddStatus(commandPath, app::ToInteractionModelStatus(status)); + return false; } if (mask.HasValue()) @@ -58,11 +164,14 @@ static Status resetHandler(CommandHandler * commandObj, const ConcreteCommandPat status = Mask::Set(endpoint, mask.Value()); if (status != EMBER_ZCL_STATUS_SUCCESS) { - return Status::Failure; + commandObj->AddStatus(commandPath, app::ToInteractionModelStatus(status)); + return false; } } - return Status::Success; + SendNotifyEvent(endpoint, eActive, eInActive, eMask, eState); + commandObj->AddStatus(commandPath, Status::Success); + return true; } /********************************************************** * Callbacks Implementation @@ -71,13 +180,7 @@ static Status resetHandler(CommandHandler * commandObj, const ConcreteCommandPat bool emberAfRefrigeratorAlarmClusterResetCallback(app::CommandHandler * commandObj, const app::ConcreteCommandPath & commandPath, const Commands::Reset::DecodableType & commandData) { - auto & alarms = commandData.alarms; - auto & mask = commandData.mask; - - Status status = resetHandler(commandObj, commandPath, alarms, mask); - commandObj->AddStatus(commandPath, status); - - return true; + return RefrigeratorAlarmServer::Instance().ResetCommand(commandObj, commandPath, commandData); } void emberAfRefrigeratorAlarmClusterServerInitCallback(chip::EndpointId endpoint) {} diff --git a/src/app/clusters/refrigerator-alarm-server/refrigerator-alarm-server.h b/src/app/clusters/refrigerator-alarm-server/refrigerator-alarm-server.h new file mode 100644 index 00000000000000..12da4025a4d788 --- /dev/null +++ b/src/app/clusters/refrigerator-alarm-server/refrigerator-alarm-server.h @@ -0,0 +1,48 @@ +/* + * + * Copyright (c) 2023 Project CHIP Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include +#include +#include +#include +#include +#include + +class RefrigeratorAlarmServer +{ +public: + static RefrigeratorAlarmServer & Instance(); + + bool ResetCommand(chip::app::CommandHandler * commandObj, const chip::app::ConcreteCommandPath & commandPath, + const chip::app::Clusters::RefrigeratorAlarm::Commands::Reset::DecodableType & commandData); + + EmberAfStatus getMaskValue(chip::EndpointId endpoint, chip::BitMask * mask); + EmberAfStatus getLatchValue(chip::EndpointId endpoint, chip::BitMask * latch); + EmberAfStatus getStateValue(chip::EndpointId endpoint, chip::BitMask * state); + + EmberAfStatus setMaskValue(chip::EndpointId endpoint, chip::BitMask mask); + + bool SendNotifyEvent(chip::EndpointId endpointId, chip::BitMask active, + chip::BitMask inActive, + chip::BitMask state, + chip::BitMask mask); + +private: + static RefrigeratorAlarmServer instance; +}; From e0e2a91c6fc3b848ce4ff1243c3a46a732ac50b5 Mon Sep 17 00:00:00 2001 From: Rohit Jadhav Date: Fri, 26 May 2023 22:19:37 +0530 Subject: [PATCH 4/9] Zap regen --- .../all-clusters-common/all-clusters-app.matter | 13 ------------- .../all-clusters-common/all-clusters-app.zap | 2 +- 2 files changed, 1 insertion(+), 14 deletions(-) diff --git a/examples/all-clusters-app/all-clusters-common/all-clusters-app.matter b/examples/all-clusters-app/all-clusters-common/all-clusters-app.matter index 0997df0b147a4c..a8d15ef7392130 100644 --- a/examples/all-clusters-app/all-clusters-common/all-clusters-app.matter +++ b/examples/all-clusters-app/all-clusters-common/all-clusters-app.matter @@ -5997,19 +5997,6 @@ endpoint 0 { ram attribute clusterRevision default = 1; } - server cluster RefrigeratorAlarm { - emits event Notify; - ram attribute mask default = 1; - ram attribute latch default = 1; - ram attribute state default = 1; - callback attribute generatedCommandList; - callback attribute acceptedCommandList; - callback attribute eventList; - callback attribute attributeList; - ram attribute featureMap default = 0; - ram attribute clusterRevision default = 1; - } - server cluster RelativeHumidityMeasurement { ram attribute measuredValue; ram attribute minMeasuredValue default = 0; diff --git a/examples/all-clusters-app/all-clusters-common/all-clusters-app.zap b/examples/all-clusters-app/all-clusters-common/all-clusters-app.zap index a471209f67f7ea..733305e2cc8c08 100644 --- a/examples/all-clusters-app/all-clusters-common/all-clusters-app.zap +++ b/examples/all-clusters-app/all-clusters-common/all-clusters-app.zap @@ -32366,4 +32366,4 @@ } ], "log": [] -} \ No newline at end of file +} From 1479926f680e7a5e08d112f9050b18047db7337e Mon Sep 17 00:00:00 2001 From: Rohit Jadhav Date: Mon, 29 May 2023 17:53:46 +0530 Subject: [PATCH 5/9] Addressed review comments --- .../all-clusters-common/all-clusters-app.zap | 215 ------------------ .../refrigerator-alarm-server.cpp | 97 ++++---- .../refrigerator-alarm-server.h | 2 +- 3 files changed, 49 insertions(+), 265 deletions(-) diff --git a/examples/all-clusters-app/all-clusters-common/all-clusters-app.zap b/examples/all-clusters-app/all-clusters-common/all-clusters-app.zap index 733305e2cc8c08..6aa21a8978e23d 100644 --- a/examples/all-clusters-app/all-clusters-common/all-clusters-app.zap +++ b/examples/all-clusters-app/all-clusters-common/all-clusters-app.zap @@ -6536,221 +6536,6 @@ } ] }, - { - "name": "Refrigerator Alarm", - "code": 87, - "mfgCode": null, - "define": "REFRIGERATOR_ALARM", - "side": "client", - "enabled": 0, - "commands": [ - { - "name": "Reset", - "code": 0, - "mfgCode": null, - "source": "client", - "incoming": 1, - "outgoing": 1 - } - ], - "attributes": [ - { - "name": "FeatureMap", - "code": 65532, - "mfgCode": null, - "side": "client", - "type": "bitmap32", - "included": 1, - "storageOption": "RAM", - "singleton": 0, - "bounded": 0, - "defaultValue": "0", - "reportable": 1, - "minInterval": 1, - "maxInterval": 65534, - "reportableChange": 0 - }, - { - "name": "ClusterRevision", - "code": 65533, - "mfgCode": null, - "side": "client", - "type": "int16u", - "included": 1, - "storageOption": "RAM", - "singleton": 0, - "bounded": 0, - "defaultValue": "1", - "reportable": 1, - "minInterval": 1, - "maxInterval": 65534, - "reportableChange": 0 - } - ] - }, - { - "name": "Refrigerator Alarm", - "code": 87, - "mfgCode": null, - "define": "REFRIGERATOR_ALARM", - "side": "server", - "enabled": 0, - "attributes": [ - { - "name": "Mask", - "code": 0, - "mfgCode": null, - "side": "server", - "type": "AlarmMap", - "included": 1, - "storageOption": "RAM", - "singleton": 0, - "bounded": 0, - "defaultValue": "1", - "reportable": 1, - "minInterval": 1, - "maxInterval": 65534, - "reportableChange": 0 - }, - { - "name": "Latch", - "code": 1, - "mfgCode": null, - "side": "server", - "type": "AlarmMap", - "included": 1, - "storageOption": "RAM", - "singleton": 0, - "bounded": 0, - "defaultValue": "1", - "reportable": 1, - "minInterval": 1, - "maxInterval": 65534, - "reportableChange": 0 - }, - { - "name": "State", - "code": 2, - "mfgCode": null, - "side": "server", - "type": "AlarmMap", - "included": 1, - "storageOption": "RAM", - "singleton": 0, - "bounded": 0, - "defaultValue": "1", - "reportable": 1, - "minInterval": 1, - "maxInterval": 65534, - "reportableChange": 0 - }, - { - "name": "GeneratedCommandList", - "code": 65528, - "mfgCode": null, - "side": "server", - "type": "array", - "included": 1, - "storageOption": "External", - "singleton": 0, - "bounded": 0, - "defaultValue": "", - "reportable": 1, - "minInterval": 1, - "maxInterval": 65534, - "reportableChange": 0 - }, - { - "name": "AcceptedCommandList", - "code": 65529, - "mfgCode": null, - "side": "server", - "type": "array", - "included": 1, - "storageOption": "External", - "singleton": 0, - "bounded": 0, - "defaultValue": "", - "reportable": 1, - "minInterval": 1, - "maxInterval": 65534, - "reportableChange": 0 - }, - { - "name": "EventList", - "code": 65530, - "mfgCode": null, - "side": "server", - "type": "array", - "included": 1, - "storageOption": "External", - "singleton": 0, - "bounded": 0, - "defaultValue": "", - "reportable": 1, - "minInterval": 1, - "maxInterval": 65534, - "reportableChange": 0 - }, - { - "name": "AttributeList", - "code": 65531, - "mfgCode": null, - "side": "server", - "type": "array", - "included": 1, - "storageOption": "External", - "singleton": 0, - "bounded": 0, - "defaultValue": "", - "reportable": 1, - "minInterval": 1, - "maxInterval": 65534, - "reportableChange": 0 - }, - { - "name": "FeatureMap", - "code": 65532, - "mfgCode": null, - "side": "server", - "type": "bitmap32", - "included": 1, - "storageOption": "RAM", - "singleton": 0, - "bounded": 0, - "defaultValue": "0", - "reportable": 1, - "minInterval": 1, - "maxInterval": 65534, - "reportableChange": 0 - }, - { - "name": "ClusterRevision", - "code": 65533, - "mfgCode": null, - "side": "server", - "type": "int16u", - "included": 1, - "storageOption": "RAM", - "singleton": 0, - "bounded": 0, - "defaultValue": "1", - "reportable": 1, - "minInterval": 1, - "maxInterval": 65534, - "reportableChange": 0 - } - ], - "events": [ - { - "name": "Notify", - "code": 0, - "mfgCode": null, - "side": "server", - "included": 1 - } - ] - }, { "name": "Door Lock", "code": 257, diff --git a/src/app/clusters/refrigerator-alarm-server/refrigerator-alarm-server.cpp b/src/app/clusters/refrigerator-alarm-server/refrigerator-alarm-server.cpp index abc9ecf1bcd9a8..ada436a661403e 100644 --- a/src/app/clusters/refrigerator-alarm-server/refrigerator-alarm-server.cpp +++ b/src/app/clusters/refrigerator-alarm-server/refrigerator-alarm-server.cpp @@ -40,12 +40,13 @@ RefrigeratorAlarmServer & RefrigeratorAlarmServer::Instance() return instance; } -EmberAfStatus RefrigeratorAlarmServer::getMaskValue(chip::EndpointId endpoint, chip::BitMask * mask) +EmberAfStatus RefrigeratorAlarmServer::getMaskValue(EndpointId endpoint, BitMask * mask) { EmberAfStatus status = Attributes::Mask::Get(endpoint, mask); if (status != EMBER_ZCL_STATUS_SUCCESS) { emberAfPrintln(EMBER_AF_PRINT_DEBUG, "Refrigerator Alarm: ERR: reading mask %x", status); + return status; } emberAfPrintln(EMBER_AF_PRINT_DEBUG, "Refrigerator Alarm: Mask ep%d value: %" PRIu32 "", endpoint, mask->Raw()); @@ -53,12 +54,13 @@ EmberAfStatus RefrigeratorAlarmServer::getMaskValue(chip::EndpointId endpoint, c return status; } -EmberAfStatus RefrigeratorAlarmServer::getLatchValue(chip::EndpointId endpoint, chip::BitMask * latch) +EmberAfStatus RefrigeratorAlarmServer::getLatchValue(EndpointId endpoint, BitMask * latch) { EmberAfStatus status = Attributes::Latch::Get(endpoint, latch); if (status != EMBER_ZCL_STATUS_SUCCESS) { emberAfPrintln(EMBER_AF_PRINT_DEBUG, "Refrigerator Alarm: ERR: reading latch %x", status); + return status; } emberAfPrintln(EMBER_AF_PRINT_DEBUG, "Refrigerator Alarm: Latch ep%d value: %" PRIu32 "", endpoint, latch->Raw()); @@ -66,12 +68,13 @@ EmberAfStatus RefrigeratorAlarmServer::getLatchValue(chip::EndpointId endpoint, return status; } -EmberAfStatus RefrigeratorAlarmServer::getStateValue(chip::EndpointId endpoint, chip::BitMask * state) +EmberAfStatus RefrigeratorAlarmServer::getStateValue(EndpointId endpoint, BitMask * state) { EmberAfStatus status = Attributes::State::Get(endpoint, state); if (status != EMBER_ZCL_STATUS_SUCCESS) { emberAfPrintln(EMBER_AF_PRINT_DEBUG, "Refrigerator Alarm: ERR: reading state %x", status); + return status; } emberAfPrintln(EMBER_AF_PRINT_DEBUG, "Refrigerator Alarm: State ep%d value: %" PRIu32 "", endpoint, state->Raw()); @@ -79,25 +82,14 @@ EmberAfStatus RefrigeratorAlarmServer::getStateValue(chip::EndpointId endpoint, return status; } -EmberAfStatus RefrigeratorAlarmServer::setMaskValue(chip::EndpointId endpoint, chip::BitMask mask) +EmberAfStatus RefrigeratorAlarmServer::setMaskValue(EndpointId endpoint, BitMask mask) { - chip::BitMask * currentMask = nullptr; - EmberAfStatus status = Attributes::Mask::Get(endpoint, currentMask); + EmberAfStatus status = EMBER_ZCL_STATUS_SUCCESS; + status = Attributes::Mask::Set(endpoint, mask); if (status != EMBER_ZCL_STATUS_SUCCESS) { - emberAfPrintln(EMBER_AF_PRINT_DEBUG, "Refrigerator Alarm: ERR: reading mask %x", status); - } - if (currentMask->Raw() == mask.Raw()) - { - emberAfPrintln(EMBER_AF_PRINT_DEBUG, "Refrigerator Alarm: Mask value already set to %" PRIu32 "", mask.Raw()); - } - else - { - status = Attributes::Mask::Set(endpoint, mask); - if (status != EMBER_ZCL_STATUS_SUCCESS) - { - emberAfPrintln(EMBER_AF_PRINT_DEBUG, "Refrigerator Alarm: ERR: writing mask %x", status); - } + emberAfPrintln(EMBER_AF_PRINT_DEBUG, "Refrigerator Alarm: ERR: writing mask %x", status); + return status; } emberAfPrintln(EMBER_AF_PRINT_DEBUG, "Refrigerator Alarm: Mask ep%d value: %" PRIu32 "", endpoint, mask.Raw()); @@ -105,13 +97,12 @@ EmberAfStatus RefrigeratorAlarmServer::setMaskValue(chip::EndpointId endpoint, c return status; } -bool RefrigeratorAlarmServer::SendNotifyEvent(chip::EndpointId endpointId, chip::BitMask active, - chip::BitMask inActive, chip::BitMask state, - chip::BitMask mask) +bool RefrigeratorAlarmServer::SendNotifyEvent(EndpointId endpointId, BitMask active, BitMask inActive, + BitMask state, BitMask mask) { Events::Notify::Type event{ active, inActive, state, mask }; EventNumber eventNumber; - CHIP_ERROR error = app::LogEvent(event, endpointId, eventNumber); + CHIP_ERROR error = LogEvent(event, endpointId, eventNumber); if (CHIP_NO_ERROR != error) { ChipLogError(Zcl, "[Notify] Unable to send notify event: %s [endpointId=%d]", error.AsString(), endpointId); @@ -121,42 +112,50 @@ bool RefrigeratorAlarmServer::SendNotifyEvent(chip::EndpointId endpointId, chip: return true; } -bool RefrigeratorAlarmServer::ResetCommand(CommandHandler * commandObj, const ConcreteCommandPath & commandPath, +void RefrigeratorAlarmServer::ResetCommand(CommandHandler * commandObj, const ConcreteCommandPath & commandPath, const Commands::Reset::DecodableType & commandData) { - auto & alarms = commandData.alarms; - auto & mask = commandData.mask; - + auto & alarms = commandData.alarms; + auto & mask = commandData.mask; EndpointId endpoint = commandPath.mEndpointId; EmberAfStatus status; + BitMask state = 0; - chip::BitMask eActive = 0; - chip::BitMask eInActive = alarms; - chip::BitMask eMask = 0; - chip::BitMask eState = 0; - - chip::BitMask state = 0; - status = State::Get(endpoint, &state); - - eActive.Clear(alarms); - eInActive.Clear(state); - Mask::Get(endpoint, &eMask); - eActive = state; - eState = state; + status = State::Get(endpoint, &state); + if (status != EMBER_ZCL_STATUS_SUCCESS) + { + commandObj->AddStatus(commandPath, ToInteractionModelStatus(status)); + return; + } + // This field SHALL indicate those alarms that have become active. + // Reset command will never active any alarm so eActive = 0. + BitMask eActive = 0; + // This field SHALL indicate those alarms that have become inactive. + BitMask eInActive = 0; + // This field SHALL be a copy of the Mask attribute when this event was generated. + BitMask eMask = 0; + // This field SHALL be a copy of the State attribute when this event was generated. + BitMask eState = 0; + + // Set the parameters for the notify event. + eInActive = state & alarms; + status = Mask::Get(endpoint, &eMask); if (status != EMBER_ZCL_STATUS_SUCCESS) { - commandObj->AddStatus(commandPath, app::ToInteractionModelStatus(status)); - return false; + commandObj->AddStatus(commandPath, ToInteractionModelStatus(status)); + return; } + eState = state; + // Reset command handeling state.Clear(alarms); status = State::Set(endpoint, state); if (status != EMBER_ZCL_STATUS_SUCCESS) { - commandObj->AddStatus(commandPath, app::ToInteractionModelStatus(status)); - return false; + commandObj->AddStatus(commandPath, ToInteractionModelStatus(status)); + return; } if (mask.HasValue()) @@ -164,14 +163,13 @@ bool RefrigeratorAlarmServer::ResetCommand(CommandHandler * commandObj, const Co status = Mask::Set(endpoint, mask.Value()); if (status != EMBER_ZCL_STATUS_SUCCESS) { - commandObj->AddStatus(commandPath, app::ToInteractionModelStatus(status)); - return false; + commandObj->AddStatus(commandPath, ToInteractionModelStatus(status)); + return; } } SendNotifyEvent(endpoint, eActive, eInActive, eMask, eState); commandObj->AddStatus(commandPath, Status::Success); - return true; } /********************************************************** * Callbacks Implementation @@ -180,9 +178,10 @@ bool RefrigeratorAlarmServer::ResetCommand(CommandHandler * commandObj, const Co bool emberAfRefrigeratorAlarmClusterResetCallback(app::CommandHandler * commandObj, const app::ConcreteCommandPath & commandPath, const Commands::Reset::DecodableType & commandData) { - return RefrigeratorAlarmServer::Instance().ResetCommand(commandObj, commandPath, commandData); + RefrigeratorAlarmServer::Instance().ResetCommand(commandObj, commandPath, commandData); + return true; } -void emberAfRefrigeratorAlarmClusterServerInitCallback(chip::EndpointId endpoint) {} +void emberAfRefrigeratorAlarmClusterServerInitCallback(EndpointId endpoint) {} void MatterRefrigeratorAlarmPluginServerInitCallback() {} diff --git a/src/app/clusters/refrigerator-alarm-server/refrigerator-alarm-server.h b/src/app/clusters/refrigerator-alarm-server/refrigerator-alarm-server.h index 12da4025a4d788..2cdf099d242e01 100644 --- a/src/app/clusters/refrigerator-alarm-server/refrigerator-alarm-server.h +++ b/src/app/clusters/refrigerator-alarm-server/refrigerator-alarm-server.h @@ -29,7 +29,7 @@ class RefrigeratorAlarmServer public: static RefrigeratorAlarmServer & Instance(); - bool ResetCommand(chip::app::CommandHandler * commandObj, const chip::app::ConcreteCommandPath & commandPath, + void ResetCommand(chip::app::CommandHandler * commandObj, const chip::app::ConcreteCommandPath & commandPath, const chip::app::Clusters::RefrigeratorAlarm::Commands::Reset::DecodableType & commandData); EmberAfStatus getMaskValue(chip::EndpointId endpoint, chip::BitMask * mask); From 8585f79a68e581c9c237737513b6ca5989f48646 Mon Sep 17 00:00:00 2001 From: Rohit Jadhav Date: Fri, 2 Jun 2023 18:41:43 +0530 Subject: [PATCH 6/9] Update implementation based on updated spec --- .../refrigerator-alarm-server.cpp | 94 +++++++++---------- .../refrigerator-alarm-server.h | 14 +-- 2 files changed, 50 insertions(+), 58 deletions(-) diff --git a/src/app/clusters/refrigerator-alarm-server/refrigerator-alarm-server.cpp b/src/app/clusters/refrigerator-alarm-server/refrigerator-alarm-server.cpp index ada436a661403e..49858fffc070d3 100644 --- a/src/app/clusters/refrigerator-alarm-server/refrigerator-alarm-server.cpp +++ b/src/app/clusters/refrigerator-alarm-server/refrigerator-alarm-server.cpp @@ -40,7 +40,7 @@ RefrigeratorAlarmServer & RefrigeratorAlarmServer::Instance() return instance; } -EmberAfStatus RefrigeratorAlarmServer::getMaskValue(EndpointId endpoint, BitMask * mask) +EmberAfStatus RefrigeratorAlarmServer::GetMaskValue(EndpointId endpoint, BitMask * mask) { EmberAfStatus status = Attributes::Mask::Get(endpoint, mask); if (status != EMBER_ZCL_STATUS_SUCCESS) @@ -54,53 +54,68 @@ EmberAfStatus RefrigeratorAlarmServer::getMaskValue(EndpointId endpoint, BitMask return status; } -EmberAfStatus RefrigeratorAlarmServer::getLatchValue(EndpointId endpoint, BitMask * latch) +EmberAfStatus RefrigeratorAlarmServer::GetStateValue(EndpointId endpoint, BitMask * state) { - EmberAfStatus status = Attributes::Latch::Get(endpoint, latch); + EmberAfStatus status = Attributes::State::Get(endpoint, state); if (status != EMBER_ZCL_STATUS_SUCCESS) { - emberAfPrintln(EMBER_AF_PRINT_DEBUG, "Refrigerator Alarm: ERR: reading latch %x", status); + emberAfPrintln(EMBER_AF_PRINT_DEBUG, "Refrigerator Alarm: ERR: reading state %x", status); return status; } - emberAfPrintln(EMBER_AF_PRINT_DEBUG, "Refrigerator Alarm: Latch ep%d value: %" PRIu32 "", endpoint, latch->Raw()); + emberAfPrintln(EMBER_AF_PRINT_DEBUG, "Refrigerator Alarm: State ep%d value: %" PRIu32 "", endpoint, state->Raw()); return status; } -EmberAfStatus RefrigeratorAlarmServer::getStateValue(EndpointId endpoint, BitMask * state) +EmberAfStatus RefrigeratorAlarmServer::SetMaskValue(EndpointId endpoint, const BitMask & mask) { - EmberAfStatus status = Attributes::State::Get(endpoint, state); + EmberAfStatus status = EMBER_ZCL_STATUS_SUCCESS; + status = Attributes::Mask::Set(endpoint, mask); if (status != EMBER_ZCL_STATUS_SUCCESS) { - emberAfPrintln(EMBER_AF_PRINT_DEBUG, "Refrigerator Alarm: ERR: reading state %x", status); + emberAfPrintln(EMBER_AF_PRINT_DEBUG, "Refrigerator Alarm: ERR: writing mask %x", status); return status; } - emberAfPrintln(EMBER_AF_PRINT_DEBUG, "Refrigerator Alarm: State ep%d value: %" PRIu32 "", endpoint, state->Raw()); + emberAfPrintln(EMBER_AF_PRINT_DEBUG, "Refrigerator Alarm: Mask ep%d value: %" PRIu32 "", endpoint, mask.Raw()); return status; } -EmberAfStatus RefrigeratorAlarmServer::setMaskValue(EndpointId endpoint, BitMask mask) +EmberAfStatus RefrigeratorAlarmServer::SetStateValue(EndpointId endpoint, BitMask state) { EmberAfStatus status = EMBER_ZCL_STATUS_SUCCESS; - status = Attributes::Mask::Set(endpoint, mask); + status = Attributes::State::Set(endpoint, state); if (status != EMBER_ZCL_STATUS_SUCCESS) { - emberAfPrintln(EMBER_AF_PRINT_DEBUG, "Refrigerator Alarm: ERR: writing mask %x", status); + emberAfPrintln(EMBER_AF_PRINT_DEBUG, "Refrigerator Alarm: ERR: writing state %x", status); return status; } - emberAfPrintln(EMBER_AF_PRINT_DEBUG, "Refrigerator Alarm: Mask ep%d value: %" PRIu32 "", endpoint, mask.Raw()); + emberAfPrintln(EMBER_AF_PRINT_DEBUG, "Refrigerator Alarm: State ep%d value: %" PRIu32 "", endpoint, state.Raw()); + + // Generate Notify evenet. + BitMask becameActive = state; + BitMask becameInActive = ~state.Raw(); + // This field SHALL be a copy of the Mask attribute when this event was generated. + BitMask eMask; + BitMask newState = becameActive; + + status = GetMaskValue(endpoint, &eMask); + if (status != EMBER_ZCL_STATUS_SUCCESS) + { + return status; + } + SendNotifyEvent(endpoint, becameActive, becameInActive, eMask, newState); return status; } -bool RefrigeratorAlarmServer::SendNotifyEvent(EndpointId endpointId, BitMask active, BitMask inActive, - BitMask state, BitMask mask) +bool RefrigeratorAlarmServer::SendNotifyEvent(EndpointId endpointId, BitMask becameActive, + BitMask becameInactive, BitMask state, BitMask mask) { - Events::Notify::Type event{ active, inActive, state, mask }; + Events::Notify::Type event{ .active = becameInactive, .inactive = becameInactive, .state = state, .mask = mask }; EventNumber eventNumber; CHIP_ERROR error = LogEvent(event, endpointId, eventNumber); if (CHIP_NO_ERROR != error) @@ -112,73 +127,48 @@ bool RefrigeratorAlarmServer::SendNotifyEvent(EndpointId endpointId, BitMask state = 0; + BitMask state; - status = State::Get(endpoint, &state); + status = SetMaskValue(endpoint, mask); if (status != EMBER_ZCL_STATUS_SUCCESS) { commandObj->AddStatus(commandPath, ToInteractionModelStatus(status)); return; } - // This field SHALL indicate those alarms that have become active. - // Reset command will never active any alarm so eActive = 0. - BitMask eActive = 0; - // This field SHALL indicate those alarms that have become inactive. - BitMask eInActive = 0; - // This field SHALL be a copy of the Mask attribute when this event was generated. - BitMask eMask = 0; - // This field SHALL be a copy of the State attribute when this event was generated. - BitMask eState = 0; - - // Set the parameters for the notify event. - eInActive = state & alarms; - status = Mask::Get(endpoint, &eMask); + status = GetStateValue(endpoint, &state); if (status != EMBER_ZCL_STATUS_SUCCESS) { commandObj->AddStatus(commandPath, ToInteractionModelStatus(status)); return; } - eState = state; - // Reset command handeling - state.Clear(alarms); - status = State::Set(endpoint, state); + state = state & mask; + status = SetStateValue(endpoint, state); if (status != EMBER_ZCL_STATUS_SUCCESS) { commandObj->AddStatus(commandPath, ToInteractionModelStatus(status)); return; } - if (mask.HasValue()) - { - status = Mask::Set(endpoint, mask.Value()); - if (status != EMBER_ZCL_STATUS_SUCCESS) - { - commandObj->AddStatus(commandPath, ToInteractionModelStatus(status)); - return; - } - } - - SendNotifyEvent(endpoint, eActive, eInActive, eMask, eState); commandObj->AddStatus(commandPath, Status::Success); } /********************************************************** * Callbacks Implementation *********************************************************/ -bool emberAfRefrigeratorAlarmClusterResetCallback(app::CommandHandler * commandObj, const app::ConcreteCommandPath & commandPath, - const Commands::Reset::DecodableType & commandData) +bool emberAfRefrigeratorAlarmClusterModifyEnabledAlarmsCallback(app::CommandHandler * commandObj, + const app::ConcreteCommandPath & commandPath, + const Commands::ModifyEnabledAlarms::DecodableType & commandData) { - RefrigeratorAlarmServer::Instance().ResetCommand(commandObj, commandPath, commandData); + RefrigeratorAlarmServer::Instance().ModifyEnabledAlarmsCommand(commandObj, commandPath, commandData); return true; } diff --git a/src/app/clusters/refrigerator-alarm-server/refrigerator-alarm-server.h b/src/app/clusters/refrigerator-alarm-server/refrigerator-alarm-server.h index 2cdf099d242e01..e727958c14651c 100644 --- a/src/app/clusters/refrigerator-alarm-server/refrigerator-alarm-server.h +++ b/src/app/clusters/refrigerator-alarm-server/refrigerator-alarm-server.h @@ -29,14 +29,16 @@ class RefrigeratorAlarmServer public: static RefrigeratorAlarmServer & Instance(); - void ResetCommand(chip::app::CommandHandler * commandObj, const chip::app::ConcreteCommandPath & commandPath, - const chip::app::Clusters::RefrigeratorAlarm::Commands::Reset::DecodableType & commandData); + void ModifyEnabledAlarmsCommand( + chip::app::CommandHandler * commandObj, const chip::app::ConcreteCommandPath & commandPath, + const chip::app::Clusters::RefrigeratorAlarm::Commands::ModifyEnabledAlarms::DecodableType & commandData); - EmberAfStatus getMaskValue(chip::EndpointId endpoint, chip::BitMask * mask); - EmberAfStatus getLatchValue(chip::EndpointId endpoint, chip::BitMask * latch); - EmberAfStatus getStateValue(chip::EndpointId endpoint, chip::BitMask * state); + EmberAfStatus GetMaskValue(chip::EndpointId endpoint, chip::BitMask * mask); + EmberAfStatus GetStateValue(chip::EndpointId endpoint, chip::BitMask * state); - EmberAfStatus setMaskValue(chip::EndpointId endpoint, chip::BitMask mask); + EmberAfStatus SetMaskValue(chip::EndpointId endpoint, + const chip::BitMask & mask); + EmberAfStatus SetStateValue(chip::EndpointId endpoint, chip::BitMask state); bool SendNotifyEvent(chip::EndpointId endpointId, chip::BitMask active, chip::BitMask inActive, From e1c8df8b938fd0bd712785141b3fa414b3d086c4 Mon Sep 17 00:00:00 2001 From: Rohit Jadhav Date: Mon, 5 Jun 2023 17:13:51 +0530 Subject: [PATCH 7/9] Addressed review comments --- .../all-clusters-app.matter | 13 +-- .../all-clusters-common/all-clusters-app.zap | 30 +----- .../refrigerator-alarm-server.cpp | 95 ++++++------------- .../refrigerator-alarm-server.h | 16 ++-- src/app/zap_cluster_list.json | 3 +- 5 files changed, 43 insertions(+), 114 deletions(-) diff --git a/examples/all-clusters-app/all-clusters-common/all-clusters-app.matter b/examples/all-clusters-app/all-clusters-common/all-clusters-app.matter index a8d15ef7392130..9d332ab0d7509b 100644 --- a/examples/all-clusters-app/all-clusters-common/all-clusters-app.matter +++ b/examples/all-clusters-app/all-clusters-common/all-clusters-app.matter @@ -2363,8 +2363,7 @@ server cluster RefrigeratorAlarm = 87 { AlarmMap mask = 3; } - attribute AlarmMap mask = 0; - readonly attribute AlarmMap latch = 1; + readonly attribute AlarmMap mask = 0; readonly attribute AlarmMap state = 2; readonly attribute command_id generatedCommandList[] = 65528; readonly attribute command_id acceptedCommandList[] = 65529; @@ -2372,13 +2371,6 @@ server cluster RefrigeratorAlarm = 87 { readonly attribute attrib_id attributeList[] = 65531; readonly attribute bitmap32 featureMap = 65532; readonly attribute int16u clusterRevision = 65533; - - request struct ResetRequest { - AlarmMap alarms = 0; - optional AlarmMap mask = 1; - } - - command Reset(ResetRequest): DefaultSuccess = 0; } /** Attributes for reporting air quality classification */ @@ -6166,8 +6158,7 @@ endpoint 1 { server cluster RefrigeratorAlarm { emits event Notify; - ram attribute mask default = 0; - ram attribute latch default = 0; + ram attribute mask default = 1; ram attribute state default = 0; callback attribute generatedCommandList; callback attribute acceptedCommandList; diff --git a/examples/all-clusters-app/all-clusters-common/all-clusters-app.zap b/examples/all-clusters-app/all-clusters-common/all-clusters-app.zap index 6aa21a8978e23d..7136a62988b61c 100644 --- a/examples/all-clusters-app/all-clusters-common/all-clusters-app.zap +++ b/examples/all-clusters-app/all-clusters-common/all-clusters-app.zap @@ -13083,16 +13083,6 @@ "define": "REFRIGERATOR_ALARM", "side": "client", "enabled": 0, - "commands": [ - { - "name": "Reset", - "code": 0, - "mfgCode": null, - "source": "client", - "incoming": 1, - "outgoing": 1 - } - ], "attributes": [ { "name": "FeatureMap", @@ -13146,23 +13136,7 @@ "storageOption": "RAM", "singleton": 0, "bounded": 0, - "defaultValue": "0", - "reportable": 1, - "minInterval": 1, - "maxInterval": 65534, - "reportableChange": 0 - }, - { - "name": "Latch", - "code": 1, - "mfgCode": null, - "side": "server", - "type": "AlarmMap", - "included": 1, - "storageOption": "RAM", - "singleton": 0, - "bounded": 0, - "defaultValue": "0", + "defaultValue": "1", "reportable": 1, "minInterval": 1, "maxInterval": 65534, @@ -32151,4 +32125,4 @@ } ], "log": [] -} +} \ No newline at end of file diff --git a/src/app/clusters/refrigerator-alarm-server/refrigerator-alarm-server.cpp b/src/app/clusters/refrigerator-alarm-server/refrigerator-alarm-server.cpp index 49858fffc070d3..a3841d239f36e2 100644 --- a/src/app/clusters/refrigerator-alarm-server/refrigerator-alarm-server.cpp +++ b/src/app/clusters/refrigerator-alarm-server/refrigerator-alarm-server.cpp @@ -33,6 +33,7 @@ using namespace chip::app::Clusters::RefrigeratorAlarm::Attributes; using namespace chip::DeviceLayer; using chip::Protocols::InteractionModel::Status; +using namespace std; RefrigeratorAlarmServer RefrigeratorAlarmServer::instance; RefrigeratorAlarmServer & RefrigeratorAlarmServer::Instance() @@ -45,11 +46,11 @@ EmberAfStatus RefrigeratorAlarmServer::GetMaskValue(EndpointId endpoint, BitMask EmberAfStatus status = Attributes::Mask::Get(endpoint, mask); if (status != EMBER_ZCL_STATUS_SUCCESS) { - emberAfPrintln(EMBER_AF_PRINT_DEBUG, "Refrigerator Alarm: ERR: reading mask %x", status); + ChipLogProgress(Zcl, "Refrigerator Alarm: ERR: reading mask %x", status); return status; } - emberAfPrintln(EMBER_AF_PRINT_DEBUG, "Refrigerator Alarm: Mask ep%d value: %" PRIu32 "", endpoint, mask->Raw()); + ChipLogProgress(Zcl, "Refrigerator Alarm: Mask ep%d value: %" PRIu32 "", endpoint, mask->Raw()); return status; } @@ -59,11 +60,11 @@ EmberAfStatus RefrigeratorAlarmServer::GetStateValue(EndpointId endpoint, BitMas EmberAfStatus status = Attributes::State::Get(endpoint, state); if (status != EMBER_ZCL_STATUS_SUCCESS) { - emberAfPrintln(EMBER_AF_PRINT_DEBUG, "Refrigerator Alarm: ERR: reading state %x", status); + ChipLogProgress(Zcl, "Refrigerator Alarm: ERR: reading state %x", status); return status; } - emberAfPrintln(EMBER_AF_PRINT_DEBUG, "Refrigerator Alarm: State ep%d value: %" PRIu32 "", endpoint, state->Raw()); + ChipLogProgress(Zcl, "Refrigerator Alarm: State ep%d value: %" PRIu32 "", endpoint, state->Raw()); return status; } @@ -74,104 +75,70 @@ EmberAfStatus RefrigeratorAlarmServer::SetMaskValue(EndpointId endpoint, const B status = Attributes::Mask::Set(endpoint, mask); if (status != EMBER_ZCL_STATUS_SUCCESS) { - emberAfPrintln(EMBER_AF_PRINT_DEBUG, "Refrigerator Alarm: ERR: writing mask %x", status); + ChipLogProgress(Zcl, "Refrigerator Alarm: ERR: writing mask %x", status); return status; } - emberAfPrintln(EMBER_AF_PRINT_DEBUG, "Refrigerator Alarm: Mask ep%d value: %" PRIu32 "", endpoint, mask.Raw()); + ChipLogProgress(Zcl, "Refrigerator Alarm: Mask ep%d value: %" PRIu32 "", endpoint, mask.Raw()); return status; } -EmberAfStatus RefrigeratorAlarmServer::SetStateValue(EndpointId endpoint, BitMask state) +EmberAfStatus RefrigeratorAlarmServer::SetStateValue(EndpointId endpoint, BitMask newState) { EmberAfStatus status = EMBER_ZCL_STATUS_SUCCESS; - status = Attributes::State::Set(endpoint, state); + BitMask currentState; + + status = Attributes::State::Get(endpoint, ¤tState); if (status != EMBER_ZCL_STATUS_SUCCESS) { - emberAfPrintln(EMBER_AF_PRINT_DEBUG, "Refrigerator Alarm: ERR: writing state %x", status); + ChipLogProgress(Zcl, "Refrigerator Alarm: ERR: reading state %x", status); return status; } - emberAfPrintln(EMBER_AF_PRINT_DEBUG, "Refrigerator Alarm: State ep%d value: %" PRIu32 "", endpoint, state.Raw()); + status = Attributes::State::Set(endpoint, newState); + if (status != EMBER_ZCL_STATUS_SUCCESS) + { + ChipLogProgress(Zcl, "Refrigerator Alarm: ERR: writing state %x", status); + return status; + } + + ChipLogProgress(Zcl, "Refrigerator Alarm: State ep%d value: %" PRIu32 "", endpoint, newState.Raw()); - // Generate Notify evenet. - BitMask becameActive = state; - BitMask becameInActive = ~state.Raw(); + // Generate Notify event. + BitMask becameActive; + becameActive.Set(newState).Clear(currentState); + BitMask becameInactive; + becameInactive.Set(currentState).Clear(newState); // This field SHALL be a copy of the Mask attribute when this event was generated. - BitMask eMask; - BitMask newState = becameActive; + BitMask mask; - status = GetMaskValue(endpoint, &eMask); + status = GetMaskValue(endpoint, &mask); if (status != EMBER_ZCL_STATUS_SUCCESS) { return status; } - SendNotifyEvent(endpoint, becameActive, becameInActive, eMask, newState); + SendNotifyEvent(endpoint, becameActive, becameInactive, newState, mask); return status; } -bool RefrigeratorAlarmServer::SendNotifyEvent(EndpointId endpointId, BitMask becameActive, - BitMask becameInactive, BitMask state, BitMask mask) +void RefrigeratorAlarmServer::SendNotifyEvent(EndpointId endpointId, BitMask becameActive, + BitMask becameInactive, BitMask newState, BitMask mask) { - Events::Notify::Type event{ .active = becameInactive, .inactive = becameInactive, .state = state, .mask = mask }; + Events::Notify::Type event{ .active = becameActive, .inactive = becameInactive, .state = newState, .mask = mask }; EventNumber eventNumber; CHIP_ERROR error = LogEvent(event, endpointId, eventNumber); if (CHIP_NO_ERROR != error) { ChipLogError(Zcl, "[Notify] Unable to send notify event: %s [endpointId=%d]", error.AsString(), endpointId); - return false; } - - return true; } -void RefrigeratorAlarmServer::ModifyEnabledAlarmsCommand(CommandHandler * commandObj, const ConcreteCommandPath & commandPath, - const Commands::ModifyEnabledAlarms::DecodableType & commandData) -{ - auto & mask = commandData.mask; - EndpointId endpoint = commandPath.mEndpointId; - - EmberAfStatus status; - BitMask state; - - status = SetMaskValue(endpoint, mask); - if (status != EMBER_ZCL_STATUS_SUCCESS) - { - commandObj->AddStatus(commandPath, ToInteractionModelStatus(status)); - return; - } - - status = GetStateValue(endpoint, &state); - if (status != EMBER_ZCL_STATUS_SUCCESS) - { - commandObj->AddStatus(commandPath, ToInteractionModelStatus(status)); - return; - } - - state = state & mask; - status = SetStateValue(endpoint, state); - if (status != EMBER_ZCL_STATUS_SUCCESS) - { - commandObj->AddStatus(commandPath, ToInteractionModelStatus(status)); - return; - } - - commandObj->AddStatus(commandPath, Status::Success); -} /********************************************************** * Callbacks Implementation *********************************************************/ -bool emberAfRefrigeratorAlarmClusterModifyEnabledAlarmsCallback(app::CommandHandler * commandObj, - const app::ConcreteCommandPath & commandPath, - const Commands::ModifyEnabledAlarms::DecodableType & commandData) -{ - RefrigeratorAlarmServer::Instance().ModifyEnabledAlarmsCommand(commandObj, commandPath, commandData); - return true; -} - void emberAfRefrigeratorAlarmClusterServerInitCallback(EndpointId endpoint) {} void MatterRefrigeratorAlarmPluginServerInitCallback() {} diff --git a/src/app/clusters/refrigerator-alarm-server/refrigerator-alarm-server.h b/src/app/clusters/refrigerator-alarm-server/refrigerator-alarm-server.h index e727958c14651c..9c98268936b8ec 100644 --- a/src/app/clusters/refrigerator-alarm-server/refrigerator-alarm-server.h +++ b/src/app/clusters/refrigerator-alarm-server/refrigerator-alarm-server.h @@ -29,22 +29,20 @@ class RefrigeratorAlarmServer public: static RefrigeratorAlarmServer & Instance(); - void ModifyEnabledAlarmsCommand( - chip::app::CommandHandler * commandObj, const chip::app::ConcreteCommandPath & commandPath, - const chip::app::Clusters::RefrigeratorAlarm::Commands::ModifyEnabledAlarms::DecodableType & commandData); - EmberAfStatus GetMaskValue(chip::EndpointId endpoint, chip::BitMask * mask); EmberAfStatus GetStateValue(chip::EndpointId endpoint, chip::BitMask * state); EmberAfStatus SetMaskValue(chip::EndpointId endpoint, const chip::BitMask & mask); - EmberAfStatus SetStateValue(chip::EndpointId endpoint, chip::BitMask state); - bool SendNotifyEvent(chip::EndpointId endpointId, chip::BitMask active, - chip::BitMask inActive, - chip::BitMask state, - chip::BitMask mask); + // When State changes we are generating Notify event + EmberAfStatus SetStateValue(chip::EndpointId endpoint, chip::BitMask newState); private: static RefrigeratorAlarmServer instance; + + void SendNotifyEvent(chip::EndpointId endpointId, chip::BitMask becameActive, + chip::BitMask becameInactive, + chip::BitMask newState, + chip::BitMask mask); }; diff --git a/src/app/zap_cluster_list.json b/src/app/zap_cluster_list.json index 7925bbf5ee5fd9..6975c5cfe70164 100644 --- a/src/app/zap_cluster_list.json +++ b/src/app/zap_cluster_list.json @@ -263,11 +263,10 @@ ], "PWM_CLUSTER": [], "RADON_CONCENTRATION_MEASUREMENT_CLUSTER": [], - "REFRIGERATOR_ALARM_CLUSTER": ["refrigerator-alarm-server"], + "REFRIGERATOR_ALARM": ["refrigerator-alarm-server"], "REFRIGERATOR_AND_TEMPERATURE_CONTROLLED_CABINET_MODE_CLUSTER": [ "mode-select-server" ], - "REFRIGERATOR_ALARM_CLUSTER": ["refrigerator-alarm-server"], "RELATIVE_HUMIDITY_MEASUREMENT_CLUSTER": [], "RVC_CLEAN_MODE_CLUSTER": ["mode-select-server"], "RVC_RUN_MODE_CLUSTER": ["mode-select-server"], From 59d7cd40f30990bc0ff751aab28ee32813794b6b Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Thu, 8 Jun 2023 14:13:47 +0000 Subject: [PATCH 8/9] Restyled by clang-format --- .../refrigerator-alarm-server/refrigerator-alarm-server.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/app/clusters/refrigerator-alarm-server/refrigerator-alarm-server.h b/src/app/clusters/refrigerator-alarm-server/refrigerator-alarm-server.h index 9c98268936b8ec..10cc29f3345708 100644 --- a/src/app/clusters/refrigerator-alarm-server/refrigerator-alarm-server.h +++ b/src/app/clusters/refrigerator-alarm-server/refrigerator-alarm-server.h @@ -36,7 +36,8 @@ class RefrigeratorAlarmServer const chip::BitMask & mask); // When State changes we are generating Notify event - EmberAfStatus SetStateValue(chip::EndpointId endpoint, chip::BitMask newState); + EmberAfStatus SetStateValue(chip::EndpointId endpoint, + chip::BitMask newState); private: static RefrigeratorAlarmServer instance; From 0cfd28b7688891e96a4978b4ad2b45fd48486ea8 Mon Sep 17 00:00:00 2001 From: Rohit Jadhav Date: Mon, 12 Jun 2023 11:10:21 +0530 Subject: [PATCH 9/9] Change state when mask changes --- .../refrigerator-alarm-server.cpp | 25 ++++++++++++++----- .../refrigerator-alarm-server.h | 5 ++-- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/src/app/clusters/refrigerator-alarm-server/refrigerator-alarm-server.cpp b/src/app/clusters/refrigerator-alarm-server/refrigerator-alarm-server.cpp index a3841d239f36e2..719b144902776d 100644 --- a/src/app/clusters/refrigerator-alarm-server/refrigerator-alarm-server.cpp +++ b/src/app/clusters/refrigerator-alarm-server/refrigerator-alarm-server.cpp @@ -46,7 +46,7 @@ EmberAfStatus RefrigeratorAlarmServer::GetMaskValue(EndpointId endpoint, BitMask EmberAfStatus status = Attributes::Mask::Get(endpoint, mask); if (status != EMBER_ZCL_STATUS_SUCCESS) { - ChipLogProgress(Zcl, "Refrigerator Alarm: ERR: reading mask %x", status); + ChipLogProgress(Zcl, "Refrigerator Alarm: ERR: reading mask, err:0x%x", status); return status; } @@ -60,7 +60,7 @@ EmberAfStatus RefrigeratorAlarmServer::GetStateValue(EndpointId endpoint, BitMas EmberAfStatus status = Attributes::State::Get(endpoint, state); if (status != EMBER_ZCL_STATUS_SUCCESS) { - ChipLogProgress(Zcl, "Refrigerator Alarm: ERR: reading state %x", status); + ChipLogProgress(Zcl, "Refrigerator Alarm: ERR: reading state, err:0x%x", status); return status; } @@ -69,18 +69,31 @@ EmberAfStatus RefrigeratorAlarmServer::GetStateValue(EndpointId endpoint, BitMas return status; } -EmberAfStatus RefrigeratorAlarmServer::SetMaskValue(EndpointId endpoint, const BitMask & mask) +EmberAfStatus RefrigeratorAlarmServer::SetMaskValue(EndpointId endpoint, const BitMask mask) { EmberAfStatus status = EMBER_ZCL_STATUS_SUCCESS; status = Attributes::Mask::Set(endpoint, mask); if (status != EMBER_ZCL_STATUS_SUCCESS) { - ChipLogProgress(Zcl, "Refrigerator Alarm: ERR: writing mask %x", status); + ChipLogProgress(Zcl, "Refrigerator Alarm: ERR: writing mask, err:0x%x", status); return status; } ChipLogProgress(Zcl, "Refrigerator Alarm: Mask ep%d value: %" PRIu32 "", endpoint, mask.Raw()); + // Whenever there is change in Mask, State should change accordingly. + BitMask state; + status = GetStateValue(endpoint, &state); + if (status != EMBER_ZCL_STATUS_SUCCESS) + { + return status; + } + + if (state != (mask & state)) + { + state = mask & state; + status = SetStateValue(endpoint, state); + } return status; } @@ -92,14 +105,14 @@ EmberAfStatus RefrigeratorAlarmServer::SetStateValue(EndpointId endpoint, BitMas status = Attributes::State::Get(endpoint, ¤tState); if (status != EMBER_ZCL_STATUS_SUCCESS) { - ChipLogProgress(Zcl, "Refrigerator Alarm: ERR: reading state %x", status); + ChipLogProgress(Zcl, "Refrigerator Alarm: ERR: reading state, err:0x%x", status); return status; } status = Attributes::State::Set(endpoint, newState); if (status != EMBER_ZCL_STATUS_SUCCESS) { - ChipLogProgress(Zcl, "Refrigerator Alarm: ERR: writing state %x", status); + ChipLogProgress(Zcl, "Refrigerator Alarm: ERR: writing state, err:0x%x", status); return status; } diff --git a/src/app/clusters/refrigerator-alarm-server/refrigerator-alarm-server.h b/src/app/clusters/refrigerator-alarm-server/refrigerator-alarm-server.h index 10cc29f3345708..a165a6c62d0d15 100644 --- a/src/app/clusters/refrigerator-alarm-server/refrigerator-alarm-server.h +++ b/src/app/clusters/refrigerator-alarm-server/refrigerator-alarm-server.h @@ -32,10 +32,11 @@ class RefrigeratorAlarmServer EmberAfStatus GetMaskValue(chip::EndpointId endpoint, chip::BitMask * mask); EmberAfStatus GetStateValue(chip::EndpointId endpoint, chip::BitMask * state); + // Whenever there is change on Mask we should change State accordingly. EmberAfStatus SetMaskValue(chip::EndpointId endpoint, - const chip::BitMask & mask); + const chip::BitMask mask); - // When State changes we are generating Notify event + // When State changes we are generating Notify event. EmberAfStatus SetStateValue(chip::EndpointId endpoint, chip::BitMask newState);