Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
Co-authored-by: Boris Zbarsky <[email protected]>
  • Loading branch information
jadhavrohit924 and bzbarsky-apple committed May 22, 2023
1 parent 4053d4c commit 3adb592
Showing 1 changed file with 11 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
*/

#include <app-common/zap-generated/attributes/Accessors.h>
#include <app-common/zap-generated/cluster-objects.h>
#include <app-common/zap-generated/cluster-enums.h>
#include <app-common/zap-generated/cluster-objects.h>
#include <app/InteractionModelEngine.h>
#include <app/util/attribute-storage.h>

Expand All @@ -30,53 +30,46 @@ 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<AlarmMap> alarms, const chip::Optional<chip::BitMask<AlarmMap>> mask);
static Status resetHandler(app::CommandHandler * commandObj, const app::ConcreteCommandPath & commandPath,
const chip::BitMask<AlarmMap> alarms, const chip::Optional<chip::BitMask<AlarmMap>> mask);

static Status resetHandler(app::CommandHandler * commandObj, const app::ConcreteCommandPath & commandPath, const chip::BitMask<AlarmMap> alarms, const chip::Optional<chip::BitMask<AlarmMap>> mask)
static Status resetHandler(CommandHandler * commandObj, const ConcreteCommandPath & commandPath, const BitMask<AlarmMap> & alarms,
const Optional<BitMask<AlarmMap>> & mask)
{
EndpointId endpoint = commandPath.mEndpointId;

EmberAfStatus status;
chip::BitMask<AlarmMap> 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;
}
}

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;
Expand Down

0 comments on commit 3adb592

Please sign in to comment.