Skip to content

Commit

Permalink
Update server implemetation of refrigerator cluster to sync spec (#27475
Browse files Browse the repository at this point in the history
)

* Update server implemetation of refrigerator cluster to sync spec

* Addressed review comments
  • Loading branch information
jadhavrohit924 authored and pull[bot] committed Jan 9, 2024
1 parent d7bbd5e commit 1808800
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2505,6 +2505,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;
Expand Down Expand Up @@ -6321,6 +6322,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;
Expand Down
16 changes: 16 additions & 0 deletions examples/all-clusters-app/all-clusters-common/all-clusters-app.zap
Original file line number Diff line number Diff line change
Expand Up @@ -13603,6 +13603,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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,11 @@ EmberAfStatus RefrigeratorAlarmServer::GetMaskValue(EndpointId endpoint, BitMask
if (status != EMBER_ZCL_STATUS_SUCCESS)
{
ChipLogProgress(Zcl, "Refrigerator Alarm: ERR: reading mask, err:0x%x", status);
return status;
}

ChipLogProgress(Zcl, "Refrigerator Alarm: Mask ep%d value: %" PRIu32 "", endpoint, mask->Raw());
else
{
ChipLogDetail(Zcl, "Refrigerator Alarm: Mask ep%d value: %" PRIx32 "", endpoint, mask->Raw());
}

return status;
}
Expand All @@ -61,10 +62,26 @@ EmberAfStatus RefrigeratorAlarmServer::GetStateValue(EndpointId endpoint, BitMas
if (status != EMBER_ZCL_STATUS_SUCCESS)
{
ChipLogProgress(Zcl, "Refrigerator Alarm: ERR: reading state, err:0x%x", status);
return status;
}
else
{
ChipLogDetail(Zcl, "Refrigerator Alarm: State ep%d value: %" PRIx32 "", endpoint, state->Raw());
}

return status;
}

ChipLogProgress(Zcl, "Refrigerator Alarm: State ep%d value: %" PRIu32 "", endpoint, state->Raw());
EmberAfStatus RefrigeratorAlarmServer::GetSupportedValue(EndpointId endpoint, BitMask<AlarmMap> * supported)
{
EmberAfStatus status = Attributes::Supported::Get(endpoint, supported);
if (status != EMBER_ZCL_STATUS_SUCCESS)
{
ChipLogProgress(Zcl, "Refrigerator Alarm: ERR: reading supported, err:0x%x", status);
}
else
{
ChipLogDetail(Zcl, "Refrigerator Alarm: Supported ep%d value: %" PRIx32 "", endpoint, supported->Raw());
}

return status;
}
Expand All @@ -79,7 +96,7 @@ EmberAfStatus RefrigeratorAlarmServer::SetMaskValue(EndpointId endpoint, const B
return status;
}

ChipLogProgress(Zcl, "Refrigerator Alarm: Mask ep%d value: %" PRIu32 "", endpoint, mask.Raw());
ChipLogProgress(Zcl, "Refrigerator Alarm: Mask ep%d value: %" PRIx32 "", endpoint, mask.Raw());

// Whenever there is change in Mask, State should change accordingly.
BitMask<AlarmMap> state;
Expand Down Expand Up @@ -116,7 +133,7 @@ EmberAfStatus RefrigeratorAlarmServer::SetStateValue(EndpointId endpoint, BitMas
return status;
}

ChipLogProgress(Zcl, "Refrigerator Alarm: State ep%d value: %" PRIu32 "", endpoint, newState.Raw());
ChipLogProgress(Zcl, "Refrigerator Alarm: State ep%d value: %" PRIx32 "", endpoint, newState.Raw());

// Generate Notify event.
BitMask<AlarmMap> becameActive;
Expand All @@ -136,6 +153,34 @@ EmberAfStatus RefrigeratorAlarmServer::SetStateValue(EndpointId endpoint, BitMas
return status;
}

EmberAfStatus RefrigeratorAlarmServer::SetSupportedValue(EndpointId endpoint, const BitMask<AlarmMap> 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: %" PRIx32 "", endpoint, supported.Raw());

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

if (!supported.HasAll(mask))
{
mask = supported & mask;
status = SetMaskValue(endpoint, mask);
}
return status;
}

void RefrigeratorAlarmServer::SendNotifyEvent(EndpointId endpointId, BitMask<AlarmMap> becameActive,
BitMask<AlarmMap> becameInactive, BitMask<AlarmMap> newState, BitMask<AlarmMap> mask)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,21 @@ 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);
EmberAfStatus GetSupportedValue(chip::EndpointId endpoint,
chip::BitMask<chip::app::Clusters::RefrigeratorAlarm::AlarmMap> * suppported);

// Whenever there is change on Mask we should change State accordingly.
// A change in mask value will result in a corresponding change in state.
EmberAfStatus SetMaskValue(chip::EndpointId endpoint,
const chip::BitMask<chip::app::Clusters::RefrigeratorAlarm::AlarmMap> mask);

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

// A change in supported value will result in a corresponding change in mask and state.
EmberAfStatus SetSupportedValue(chip::EndpointId endpoint,
const chip::BitMask<chip::app::Clusters::RefrigeratorAlarm::AlarmMap> supported);

private:
static RefrigeratorAlarmServer instance;

Expand Down

0 comments on commit 1808800

Please sign in to comment.