Skip to content

Commit

Permalink
update buffer read in read call back
Browse files Browse the repository at this point in the history
  • Loading branch information
stingchang committed May 28, 2024
1 parent c6314be commit 1bc1757
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 12 deletions.
5 changes: 2 additions & 3 deletions examples/chef/common/chef-rvc-mode-delegate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -290,9 +290,8 @@ chip::Protocols::InteractionModel::Status chefRvcCleanModeReadCallback(chip::End
const EmberAfAttributeMetadata * attributeMetadata,
uint8_t * buffer, uint16_t maxReadLength)
{
uint8_t m = gRvcCleanModeInstance->GetCurrentMode();
memcpy(buffer, &m, sizeof(m));

VerifyOrReturnValue(maxReadLength > 0, chip::Protocols::InteractionModel::Status::ResourceExhausted);
buffer[0] = gRvcCleanModeInstance->GetCurrentMode();
return chip::Protocols::InteractionModel::Status::Success;
}

Expand Down
35 changes: 27 additions & 8 deletions examples/chef/common/chef-rvc-operational-state-delegate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ static void onOperationalStateTimerTick(System::Layer * systemLayer, void * data

DataModel::Nullable<uint32_t> RvcOperationalStateDelegate::GetCountdownTime()
{
if (mCountDownTime.IsNull())
if (mRunningTime > mPhaseDuration.Value())
return DataModel::NullNullable;

return DataModel::MakeNullable((uint32_t) (mCountDownTime.Value() - mRunningTime));
return DataModel::MakeNullable((uint32_t) (mPhaseDuration.Value() - mRunningTime));
}

CHIP_ERROR RvcOperationalStateDelegate::GetOperationalStateAtIndex(size_t index, GenericOperationalState & operationalState)
Expand Down Expand Up @@ -203,7 +203,7 @@ chip::Protocols::InteractionModel::Status chefRvcOperationalStateWriteCallback(c
{
break;
}
ret = chip::Protocols::InteractionModel::Status::UnsupportedWrite;
ret = chip::Protocols::InteractionModel::Status::ConstraintError;
ChipLogError(DeviceLayer, "Invalid Attribute Update status: %" CHIP_ERROR_FORMAT, err.Format());
}
break;
Expand All @@ -214,7 +214,7 @@ chip::Protocols::InteractionModel::Status chefRvcOperationalStateWriteCallback(c
{
break;
}
ret = chip::Protocols::InteractionModel::Status::UnsupportedWrite;
ret = chip::Protocols::InteractionModel::Status::ConstraintError;
ChipLogError(DeviceLayer, "Invalid Attribute Update status: %" CHIP_ERROR_FORMAT, err.Format());
}
break;
Expand All @@ -231,10 +231,30 @@ chip::Protocols::InteractionModel::Status chefRvcOperationalStateReadCallback(ch
const EmberAfAttributeMetadata * attributeMetadata,
uint8_t * buffer, uint16_t maxReadLength)
{
app::DataModel::Nullable<uint8_t> m = gRvcOperationalStateInstance->GetCurrentPhase();
memcpy(buffer, &m, sizeof(m));
chip::Protocols::InteractionModel::Status ret = chip::Protocols::InteractionModel::Status::Success;
chip::AttributeId attributeId = attributeMetadata->attributeId;
switch(attributeId) {
case chip::app::Clusters::RvcOperationalState::Attributes::CurrentPhase::Id: {

return chip::Protocols::InteractionModel::Status::Success;
app::DataModel::Nullable<uint8_t> currentPhase = gRvcOperationalStateInstance->GetCurrentPhase();
if(currentPhase.IsNull())
{
ret = chip::Protocols::InteractionModel::Status::UnsupportedAttribute;
break;
}
*buffer = currentPhase.Value();
}
break;
case chip::app::Clusters::RvcOperationalState::Attributes::OperationalState::Id: {
*buffer = gRvcOperationalStateInstance->GetCurrentOperationalState();
}
break;
default:
ChipLogError(DeviceLayer, "Unsupported Attribute ID: %d", static_cast<int>(attributeId));
break;
}

return ret;
}

void emberAfRvcOperationalStateClusterInitCallback(chip::EndpointId endpointId)
Expand All @@ -247,7 +267,6 @@ void emberAfRvcOperationalStateClusterInitCallback(chip::EndpointId endpointId)
gRvcOperationalStateInstance = new RvcOperationalState::Instance(gRvcOperationalStateDelegate, operationalStateEndpoint);

gRvcOperationalStateInstance->SetOperationalState(to_underlying(OperationalState::OperationalStateEnum::kStopped));

gRvcOperationalStateInstance->Init();
}
#endif // MATTER_DM_PLUGIN_RVC_OPERATIONAL_STATE_SERVER
2 changes: 1 addition & 1 deletion examples/chef/common/chef-rvc-operational-state-delegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class RvcOperationalStateDelegate : public RvcOperationalState::Delegate

uint32_t mRunningTime = 0;
uint32_t mPausedTime = 0;
app::DataModel::Nullable<uint32_t> mCountDownTime;
app::DataModel::Nullable<uint32_t> mPhaseDuration;

private:
Span<const OperationalState::GenericOperationalState> mOperationalStateList;
Expand Down

0 comments on commit 1bc1757

Please sign in to comment.