From b568c3ce05d4a4316b8413e6d763b58c297d9d1d Mon Sep 17 00:00:00 2001 From: Rohit Jadhav Date: Mon, 26 Jun 2023 17:59:05 +0530 Subject: [PATCH] Update server implemetation of refrigerator cluster to sync spec --- .../all-clusters-app.matter | 2 + .../all-clusters-common/all-clusters-app.zap | 18 +++++++- .../refrigerator-alarm-server.cpp | 43 +++++++++++++++++++ .../refrigerator-alarm-server.h | 6 +++ 4 files changed, 68 insertions(+), 1 deletion(-) 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 1501b06a842527..0fc3654703154e 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 @@ -2365,6 +2365,7 @@ server cluster RefrigeratorAlarm = 87 { readonly attribute AlarmMap mask = 0; readonly attribute AlarmMap state = 2; + readonly attribute AlarmMap supported = 3; readonly attribute command_id generatedCommandList[] = 65528; readonly attribute command_id acceptedCommandList[] = 65529; readonly attribute event_id eventList[] = 65530; @@ -6160,6 +6161,7 @@ endpoint 1 { emits event Notify; ram attribute mask default = 1; ram attribute state default = 0; + ram attribute supported default = 1; callback attribute generatedCommandList; callback attribute acceptedCommandList; callback attribute eventList; 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 c5e15ce673f529..cacb7bc60d9430 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 @@ -13158,6 +13158,22 @@ "maxInterval": 65534, "reportableChange": 0 }, + { + "name": "Supported", + "code": 3, + "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, @@ -32125,4 +32141,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 719b144902776d..cd42897f659d65 100644 --- a/src/app/clusters/refrigerator-alarm-server/refrigerator-alarm-server.cpp +++ b/src/app/clusters/refrigerator-alarm-server/refrigerator-alarm-server.cpp @@ -69,6 +69,21 @@ EmberAfStatus RefrigeratorAlarmServer::GetStateValue(EndpointId endpoint, BitMas return status; } +EmberAfStatus RefrigeratorAlarmServer::GetSupportedValue(EndpointId endpoint, BitMask * supported) +{ + EmberAfStatus status = Attributes::Supported::Get(endpoint, supported); + if (status != EMBER_ZCL_STATUS_SUCCESS) + { + printf("################################################################\n"); + ChipLogProgress(Zcl, "Refrigerator Alarm: ERR: reading supported, err:0x%x", status); + return status; + } + + ChipLogProgress(Zcl, "Refrigerator Alarm: Supported ep%d value: %" PRIu32 "", endpoint, supported->Raw()); + + return status; +} + EmberAfStatus RefrigeratorAlarmServer::SetMaskValue(EndpointId endpoint, const BitMask mask) { EmberAfStatus status = EMBER_ZCL_STATUS_SUCCESS; @@ -136,6 +151,34 @@ EmberAfStatus RefrigeratorAlarmServer::SetStateValue(EndpointId endpoint, BitMas return status; } +EmberAfStatus RefrigeratorAlarmServer::SetSupportedValue(EndpointId endpoint, const BitMask supported) +{ + EmberAfStatus status = EMBER_ZCL_STATUS_SUCCESS; + status = Attributes::Supported::Set(endpoint, supported); + if (status != EMBER_ZCL_STATUS_SUCCESS) + { + ChipLogProgress(Zcl, "Refrigerator Alarm: ERR: writing supported, err:0x%x", status); + return status; + } + + ChipLogProgress(Zcl, "Refrigerator Alarm: Supported ep%d value: %" PRIu32 "", endpoint, supported.Raw()); + + // Whenever there is change in Supported attribute, Mask, State should change accordingly. + BitMask mask; + status = GetMaskValue(endpoint, &mask); + if (status != EMBER_ZCL_STATUS_SUCCESS) + { + return status; + } + + if (mask != (supported & mask)) + { + mask = supported & mask; + status = SetMaskValue(endpoint, mask); + } + return status; +} + void RefrigeratorAlarmServer::SendNotifyEvent(EndpointId endpointId, BitMask becameActive, BitMask becameInactive, BitMask newState, BitMask mask) { 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 a165a6c62d0d15..f8d6b733dc1252 100644 --- a/src/app/clusters/refrigerator-alarm-server/refrigerator-alarm-server.h +++ b/src/app/clusters/refrigerator-alarm-server/refrigerator-alarm-server.h @@ -31,6 +31,8 @@ class RefrigeratorAlarmServer EmberAfStatus GetMaskValue(chip::EndpointId endpoint, chip::BitMask * mask); EmberAfStatus GetStateValue(chip::EndpointId endpoint, chip::BitMask * state); + EmberAfStatus GetSupportedValue(chip::EndpointId endpoint, + chip::BitMask * suppported); // Whenever there is change on Mask we should change State accordingly. EmberAfStatus SetMaskValue(chip::EndpointId endpoint, @@ -40,6 +42,10 @@ class RefrigeratorAlarmServer EmberAfStatus SetStateValue(chip::EndpointId endpoint, chip::BitMask newState); + // Whenever there is change on Supported attribute we should change Mask and State accordingly. + EmberAfStatus SetSupportedValue(chip::EndpointId endpoint, + const chip::BitMask supported); + private: static RefrigeratorAlarmServer instance;