Skip to content

Commit

Permalink
Changes to CommandDataIB to reflect 1.3 spec (#30522)
Browse files Browse the repository at this point in the history
* Changes to CommandDataIB to reflect 1.3 spec

* Fix CI
  • Loading branch information
tehampson authored and pull[bot] committed Nov 30, 2023
1 parent d8b2c78 commit 8b42548
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/app/MessageDef/CommandDataIB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,14 @@ CHIP_ERROR CommandDataIB::Parser::PrettyPrint() const
ReturnErrorOnFailure(CheckIMPayload(reader, 0, "CommandFields"));
PRETTY_PRINT_DECDEPTH();
break;
case to_underlying(Tag::kRef):
VerifyOrReturnError(TLV::kTLVType_UnsignedInteger == reader.GetType(), CHIP_ERROR_WRONG_TLV_TYPE);
{
uint16_t reference;
ReturnErrorOnFailure(reader.Get(reference));
PRETTY_PRINT("\tRef = 0x%x,", reference);
}
break;
default:
PRETTY_PRINT("Unknown tag num %" PRIu32, tagNum);
break;
Expand Down Expand Up @@ -96,12 +104,22 @@ CHIP_ERROR CommandDataIB::Parser::GetFields(TLV::TLVReader * const apReader) con
return CHIP_NO_ERROR;
}

CHIP_ERROR CommandDataIB::Parser::GetRef(uint16_t * const apRef) const
{
return GetUnsignedInteger(to_underlying(Tag::kRef), apRef);
}

CommandPathIB::Builder & CommandDataIB::Builder::CreatePath()
{
mError = mPath.Init(mpWriter, to_underlying(Tag::kPath));
return mPath;
}

CHIP_ERROR CommandDataIB::Builder::Ref(const uint16_t aRef)
{
return mpWriter->Put(TLV::ContextTag(Tag::kRef), aRef);
}

CHIP_ERROR CommandDataIB::Builder::EndOfCommandDataIB()
{
EndOfContainer();
Expand Down
22 changes: 22 additions & 0 deletions src/app/MessageDef/CommandDataIB.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ enum class Tag : uint8_t
{
kPath = 0,
kFields = 1,
kRef = 2,
};

class Parser : public StructParser
Expand Down Expand Up @@ -66,6 +67,17 @@ class Parser : public StructParser
* #CHIP_END_OF_TLV if there is no such element
*/
CHIP_ERROR GetFields(TLV::TLVReader * const apReader) const;

/**
* @brief Get the provided command reference associated with the CommandData
*
* @param [in] apRef A pointer to apRef
*
* @return #CHIP_NO_ERROR on success
* #CHIP_ERROR_WRONG_TLV_TYPE if there is such element but it's not any of the defined unsigned integer types
* #CHIP_END_OF_TLV if there is no such element
*/
CHIP_ERROR GetRef(uint16_t * const apRef) const;
};

class Builder : public StructBuilder
Expand All @@ -78,6 +90,16 @@ class Builder : public StructBuilder
*/
CommandPathIB::Builder & CreatePath();

/**
* @brief Inject Command Ref into the TLV stream.
*
* @param [in] aRef refer to the CommandRef to set in CommandDataIB.
*
* TODO What are some more errors
* @return #CHIP_NO_ERROR on success
*/
CHIP_ERROR Ref(const uint16_t aRef);

/**
* @brief Mark the end of this CommandDataIB
*
Expand Down

0 comments on commit 8b42548

Please sign in to comment.