Skip to content

Commit

Permalink
make writes actually work
Browse files Browse the repository at this point in the history
  • Loading branch information
andy31415 committed Jan 22, 2025
1 parent 08a2bc8 commit 0b7c13b
Showing 1 changed file with 33 additions and 1 deletion.
34 changes: 33 additions & 1 deletion examples/common/pigweed/rpc_services/Attributes.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,27 @@ class Attributes : public pw_rpc::nanopb::Attributes::Service<Attributes>
{
// We can directly reference the embedded TLV data here
result.Init(data.tlv_data.bytes, data.tlv_data.size);
CHIP_ERROR err = result.Next();
if (err != CHIP_NO_ERROR)
{
ChipLogError(Support, "Input TLV data did not have data: %" CHIP_ERROR_FORMAT, err.Format());
return pw::Status::InvalidArgument();
}

TLV::TLVType outer;
err = result.EnterContainer(outer);
if (err != CHIP_NO_ERROR)
{
ChipLogError(Support, "Input TLV data has no wrapper container: %" CHIP_ERROR_FORMAT, err.Format());
return pw::Status::InvalidArgument();
}

err = result.Next();
if (err != CHIP_NO_ERROR)
{
ChipLogError(Support, "Input TLV stucture did not have a first element: %" CHIP_ERROR_FORMAT, err.Format());
return pw::Status::InvalidArgument();
}
return result;
}

Expand All @@ -64,6 +85,10 @@ class Attributes : public pw_rpc::nanopb::Attributes::Service<Attributes>

constexpr TLV::Tag kDataTag = TLV::ContextTag(to_underlying(chip::app::AttributeDataIB::Tag::kData));

TLV::TLVType outer;
VerifyOrReturnError(writer.StartContainer(TLV::AnonymousTag(), TLV::kTLVType_Structure, outer) == CHIP_NO_ERROR,
pw::Status::Internal());

switch (data.which_data)
{
case chip_rpc_AttributeData_data_bool_tag:
Expand Down Expand Up @@ -106,7 +131,14 @@ class Attributes : public pw_rpc::nanopb::Attributes::Service<Attributes>
return pw::Status::Internal();
}

return pw::OkStatus();
VerifyOrReturnValue(writer.EndContainer(outer) == CHIP_NO_ERROR, pw::Status::Internal());
result.Init(tempBuffer.data(), writer.GetLengthWritten());

VerifyOrReturnError(result.Next() == CHIP_NO_ERROR, pw::Status::Internal());
VerifyOrReturnError(result.EnterContainer(outer) == CHIP_NO_ERROR, pw::Status::Internal());
VerifyOrReturnError(result.Next() == CHIP_NO_ERROR, pw::Status::Internal());

return result;
}

::pw::Status Write(const chip_rpc_AttributeWrite & request, pw_protobuf_Empty & response)
Expand Down

0 comments on commit 0b7c13b

Please sign in to comment.