diff --git a/src/app/MessageDef/CommandDataIB.cpp b/src/app/MessageDef/CommandDataIB.cpp index 4222c4d919719b..ea9bc3390b1f61 100644 --- a/src/app/MessageDef/CommandDataIB.cpp +++ b/src/app/MessageDef/CommandDataIB.cpp @@ -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; @@ -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(); diff --git a/src/app/MessageDef/CommandDataIB.h b/src/app/MessageDef/CommandDataIB.h index c3cce65f2e8511..a9b3d27cf0a3a6 100644 --- a/src/app/MessageDef/CommandDataIB.h +++ b/src/app/MessageDef/CommandDataIB.h @@ -37,6 +37,7 @@ enum class Tag : uint8_t { kPath = 0, kFields = 1, + kRef = 2, }; class Parser : public StructParser @@ -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 @@ -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 *