Skip to content

Commit

Permalink
Change state when mask changes
Browse files Browse the repository at this point in the history
  • Loading branch information
jadhavrohit924 committed Jun 13, 2023
1 parent c647d5a commit 8446431
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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;
}

Expand All @@ -69,19 +69,28 @@ EmberAfStatus RefrigeratorAlarmServer::GetStateValue(EndpointId endpoint, BitMas
return status;
}

EmberAfStatus RefrigeratorAlarmServer::SetMaskValue(EndpointId endpoint, const BitMask<AlarmMap> & mask)
EmberAfStatus RefrigeratorAlarmServer::SetMaskValue(EndpointId endpoint, const BitMask<AlarmMap> 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());

return status;
// Whenever there is change in Mask, State should change accordingly.
BitMask<AlarmMap> state;
status = GetStateValue(endpoint, &state);
if (status != EMBER_ZCL_STATUS_SUCCESS)
{
return status;
}

state = mask & state;
return SetStateValue(endpoint, state);
}

EmberAfStatus RefrigeratorAlarmServer::SetStateValue(EndpointId endpoint, BitMask<AlarmMap> newState)
Expand All @@ -92,14 +101,14 @@ EmberAfStatus RefrigeratorAlarmServer::SetStateValue(EndpointId endpoint, BitMas
status = Attributes::State::Get(endpoint, &currentState);
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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,11 @@ class RefrigeratorAlarmServer
EmberAfStatus GetMaskValue(chip::EndpointId endpoint, chip::BitMask<chip::app::Clusters::RefrigeratorAlarm::AlarmMap> * mask);
EmberAfStatus GetStateValue(chip::EndpointId endpoint, chip::BitMask<chip::app::Clusters::RefrigeratorAlarm::AlarmMap> * state);

// Whenever there is change on Mask we should change State accordingly.
EmberAfStatus SetMaskValue(chip::EndpointId endpoint,
const chip::BitMask<chip::app::Clusters::RefrigeratorAlarm::AlarmMap> & mask);
const chip::BitMask<chip::app::Clusters::RefrigeratorAlarm::AlarmMap> mask);

// When State changes we are generating Notify event
// When State changes we are generating Notify event.
EmberAfStatus SetStateValue(chip::EndpointId endpoint,
chip::BitMask<chip::app::Clusters::RefrigeratorAlarm::AlarmMap> newState);

Expand Down

0 comments on commit 8446431

Please sign in to comment.