From bdad61a961565909f4e3f4a04f306680b9b35e33 Mon Sep 17 00:00:00 2001 From: Rohit Jadhav Date: Mon, 12 Jun 2023 11:10:21 +0530 Subject: [PATCH] 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);