Skip to content

Commit

Permalink
Use enum class for TLVElementType and TLVTagControl. (#3157)
Browse files Browse the repository at this point in the history
* Use enum class for TLVElementType and TLVTagControl.

This makes it easy to give them as specific size spec, which will
prevent issues with people adding out-of-range values and simplify
-Wconversion work.

* Check if the result of EncodeCommand is successful before trying to send the command (#3151)

* Remove verbose code comments (#3187)

Some devices are configured to act as Thread router instead of
sleepy-end device. This PR removes these incorrect or verbose comments.

* Remove {#mainpage} from the main README.md file (#3190)

* Remove Makefiles introduced by #3099 (#3191)

* [nRF Connect] README updates on Docker for MacOS and NCS version (#3175)

* [nRF Connect] README updates on Docker for MacOS and NCS version

* Restyled by prettier-markdown

* Rephrase a sentence

Co-authored-by: Restyled.io <commits@restyled.io>

* Modify the generated files for example lighting and lock apps to include server init callbacks. (#3180)

This allows the app to implement
emberAfPluginOnOffClusterServerPostInitCallback to sync up the data
model state with the state of the actual device when the data model
initializes.

* Use pragma once in more places (#3182)

* Add a lot of pragma once changes. Now scripted!

* update pragma once in setup payload

* More pragma once

* Pragma once within platform and more

* pragma once in the crypto layer

* pragma once in examples

* Fix by restyle-diff

* [android] Use ATT Write Request instead of ATT Write Command (#3161)

Co-authored-by: Vivien Nicolas <vnicolas@apple.com>
Co-authored-by: Yakun Xu <xyk@google.com>
Co-authored-by: Damian Królik <66667989+Damian-Nordic@users.noreply.github.com>
Co-authored-by: Restyled.io <commits@restyled.io>
Co-authored-by: Andrei Litvin <andrei@andy314.com>
Co-authored-by: Łukasz Duda <lukasz.duda@nordicsemi.no>
  • Loading branch information
7 people authored Oct 12, 2020
1 parent a0dc81e commit aa1f11c
Show file tree
Hide file tree
Showing 9 changed files with 202 additions and 159 deletions.
10 changes: 10 additions & 0 deletions src/lib/core/CHIPTLV.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,16 @@ class PacketBuffer;
namespace chip {
namespace TLV {

inline uint8_t operator|(TLVElementType lhs, TLVTagControl rhs)
{
return static_cast<uint8_t>(lhs) | static_cast<uint8_t>(rhs);
}

inline uint8_t operator|(TLVTagControl lhs, TLVElementType rhs)
{
return static_cast<uint8_t>(lhs) | static_cast<uint8_t>(rhs);
}

using chip::System::PacketBuffer;

enum
Expand Down
64 changes: 32 additions & 32 deletions src/lib/core/CHIPTLVData.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,41 +104,41 @@
/*
* @brief Specifies an anonymous TLV element, which doesn't have any tag
*/
#define CHIP_TLV_TAG_ANONYMOUS chip::TLV::kTLVTagControl_Anonymous
#define CHIP_TLV_TAG_ANONYMOUS chip::TLV::TLVTagControl::Anonymous

/*
* @brief Specifies a TLV element with a context-specific tag
* @param Tag The context-specific tag for this TLV element. Would be truncated to 8 bits.
*/
#define CHIP_TLV_TAG_CONTEXT_SPECIFIC(Tag) chip::TLV::kTLVTagControl_ContextSpecific, CHIP_TLV_Serialize8(Tag)
#define CHIP_TLV_TAG_CONTEXT_SPECIFIC(Tag) chip::TLV::TLVTagControl::ContextSpecific, CHIP_TLV_Serialize8(Tag)

/*
* @brief Specifies a TLV element with a Common Profile tag
* @param Tag The tag for this TLV element, defined under Common Profile.
* Would be truncated to 16 bites.
*/
#define CHIP_TLV_TAG_COMMON_PROFILE_2Bytes(Tag) chip::TLV::kTLVTagControl_CommonProfile_2Bytes, CHIP_TLV_Serialize16(Tag)
#define CHIP_TLV_TAG_COMMON_PROFILE_2Bytes(Tag) chip::TLV::TLVTagControl::CommonProfile_2Bytes, CHIP_TLV_Serialize16(Tag)

/*
* @brief Specifies a TLV element with a Common Profile tag
* @param Tag The tag for this TLV element, defined under Common Profile.
* Would be truncated to 32 bites.
*/
#define CHIP_TLV_TAG_COMMON_PROFILE_4Bytes(Tag) chip::TLV::kTLVTagControl_CommonProfile_4Bytes, CHIP_TLV_Serialize32(Tag)
#define CHIP_TLV_TAG_COMMON_PROFILE_4Bytes(Tag) chip::TLV::TLVTagControl::CommonProfile_4Bytes, CHIP_TLV_Serialize32(Tag)

/*
* @brief Specifies a TLV element with an Implicit Profile tag
* @param Tag The tag for this TLV element, defined under the current implicit profile.
* Would be truncated to 16 bits.
*/
#define CHIP_TLV_TAG_IMPLICIT_PROFILE_2Bytes(Tag) chip::TLV::kTLVTagControl_ImplicitProfile_2Bytes, CHIP_TLV_Serialize16(Tag)
#define CHIP_TLV_TAG_IMPLICIT_PROFILE_2Bytes(Tag) chip::TLV::TLVTagControl::ImplicitProfile_2Bytes, CHIP_TLV_Serialize16(Tag)

/*
* @brief Specifies a TLV element with an Implicit Profile tag
* @param Tag The tag for this TLV element, defined under the current implicit profile.
* Would be truncated to 32 bits.
*/
#define CHIP_TLV_TAG_IMPLICIT_PROFILE_4Bytes(Tag) chip::TLV::kTLVTagControl_ImplicitProfile_4Bytes, CHIP_TLV_Serialize32(Tag)
#define CHIP_TLV_TAG_IMPLICIT_PROFILE_4Bytes(Tag) chip::TLV::TLVTagControl::ImplicitProfile_4Bytes, CHIP_TLV_Serialize32(Tag)

/*
* @brief Specifies a TLV element with a Fully Qualified tag
Expand All @@ -147,7 +147,7 @@
* Would be truncated to 16 bits.
*/
#define CHIP_TLV_TAG_FULLY_QUALIFIED_6Bytes(ProfileId, Tag) \
chip::TLV::kTLVTagControl_FullyQualified_6Bytes, CHIP_TLV_Serialize16(ProfileId >> 16), CHIP_TLV_Serialize16(ProfileId), \
chip::TLV::TLVTagControl::FullyQualified_6Bytes, CHIP_TLV_Serialize16(ProfileId >> 16), CHIP_TLV_Serialize16(ProfileId), \
CHIP_TLV_Serialize16(Tag)

/*
Expand All @@ -157,40 +157,40 @@
* Would be truncated to 32 bits.
*/
#define CHIP_TLV_TAG_FULLY_QUALIFIED_8Bytes(ProfileId, Tag) \
chip::TLV::kTLVTagControl_FullyQualified_8Bytes, CHIP_TLV_Serialize16(ProfileId >> 16), CHIP_TLV_Serialize16(ProfileId), \
chip::TLV::TLVTagControl::FullyQualified_8Bytes, CHIP_TLV_Serialize16(ProfileId >> 16), CHIP_TLV_Serialize16(ProfileId), \
CHIP_TLV_Serialize32(Tag)

/*
* @brief Specifies a NULL TLV element, which has just the tag but no value
* @param TagSpec Should be filled with macros begin with CHIP_TLV_TAG_
*/
#define CHIP_TLV_NULL(TagSpec) chip::TLV::kTLVElementType_Null | TagSpec
#define CHIP_TLV_NULL(TagSpec) chip::TLV::TLVElementType::Null | TagSpec

/*
* @brief Specifies a Structure TLV element, marking the beginning of a Structure
* @param TagSpec Should be filled with macros begin with CHIP_TLV_TAG_
*/
#define CHIP_TLV_STRUCTURE(TagSpec) chip::TLV::kTLVElementType_Structure | TagSpec
#define CHIP_TLV_STRUCTURE(TagSpec) chip::TLV::TLVElementType::Structure | TagSpec

/*
* @brief Specifies a Array TLV element, marking the beginning of an Array
* @param TagSpec Should be filled with macros begin with CHIP_TLV_TAG_
*/
#define CHIP_TLV_ARRAY(TagSpec) chip::TLV::kTLVElementType_Array | TagSpec
#define CHIP_TLV_ARRAY(TagSpec) chip::TLV::TLVElementType::Array | TagSpec

/*
* @brief Specifies a Path TLV element, marking the beginning of a Path
* @param TagSpec Should be filled with macros begin with CHIP_TLV_TAG_
*/
#define CHIP_TLV_PATH(TagSpec) chip::TLV::kTLVElementType_Path | TagSpec
#define CHIP_TLV_PATH(TagSpec) chip::TLV::TLVElementType::Path | TagSpec

/*
* @brief Specifies a Boolean TLV element, which can be either true or false
* @param TagSpec Should be filled with macros begin with CHIP_TLV_TAG_
* @param Value Should be either true or false
*/
#define CHIP_TLV_BOOL(TagSpec, Value) \
((Value) ? chip::TLV::kTLVElementType_BooleanTrue : chip::TLV::kTLVElementType_BooleanFalse) | TagSpec
((Value) ? chip::TLV::TLVElementType::BooleanTrue : chip::TLV::TLVElementType::BooleanFalse) | TagSpec

/**
* @brief
Expand All @@ -200,7 +200,7 @@
*
* @param ... Bytes representing the floating point value to serialize
*/
#define CHIP_TLV_FLOAT32(TagSpec, ...) chip::TLV::kTLVElementType_FloatingPointNumber32 | TagSpec, ##__VA_ARGS__
#define CHIP_TLV_FLOAT32(TagSpec, ...) chip::TLV::TLVElementType::FloatingPointNumber32 | TagSpec, ##__VA_ARGS__

/**
* @brief
Expand All @@ -210,12 +210,12 @@
*
* @param ... Bytes representing the floating point value to serialize
*/
#define CHIP_TLV_FLOAT64(TagSpec, ...) chip::TLV::kTLVElementType_FloatingPointNumber64 | TagSpec, ##__VA_ARGS__
#define CHIP_TLV_FLOAT64(TagSpec, ...) chip::TLV::TLVElementType::FloatingPointNumber64 | TagSpec, ##__VA_ARGS__

/*
* @brief Specifies a EndOfContainer TLV element, marking the end of a Structure, Array, or Path
*/
#define CHIP_TLV_END_OF_CONTAINER chip::TLV::kTLVElementType_EndOfContainer | chip::TLV::kTLVTagControl_Anonymous
#define CHIP_TLV_END_OF_CONTAINER chip::TLV::TLVElementType::EndOfContainer | chip::TLV::TLVTagControl::Anonymous

/*
* @brief Specifies a EndOfContainer TLV element, marking the end of a Structure, Array, or Path
Expand All @@ -237,56 +237,56 @@
* @param TagSpec Should be filled with macros begin with CHIP_TLV_TAG_
* @param Value Would be first converted to int8_t, and then serialized
*/
#define CHIP_TLV_INT8(TagSpec, Value) chip::TLV::kTLVElementType_Int8 | TagSpec, CHIP_TLV_Serialize8(int8_t(Value))
#define CHIP_TLV_INT8(TagSpec, Value) chip::TLV::TLVElementType::Int8 | TagSpec, CHIP_TLV_Serialize8(int8_t(Value))

/*
* @brief Specifies a 16-bit Signed Integer TLV element
* @param TagSpec Should be filled with macros begin with CHIP_TLV_TAG_
* @param Value Would be first converted to int16_t, and then serialized
*/
#define CHIP_TLV_INT16(TagSpec, Value) chip::TLV::kTLVElementType_Int16 | TagSpec, CHIP_TLV_Serialize16(int16_t(Value))
#define CHIP_TLV_INT16(TagSpec, Value) chip::TLV::TLVElementType::Int16 | TagSpec, CHIP_TLV_Serialize16(int16_t(Value))

/*
* @brief Specifies a 32-bit Signed Integer TLV element
* @param TagSpec Should be filled with macros begin with CHIP_TLV_TAG_
* @param Value Would be first converted to int32_t, and then serialized
*/
#define CHIP_TLV_INT32(TagSpec, Value) chip::TLV::kTLVElementType_Int32 | TagSpec, CHIP_TLV_Serialize32(int32_t(Value))
#define CHIP_TLV_INT32(TagSpec, Value) chip::TLV::TLVElementType::Int32 | TagSpec, CHIP_TLV_Serialize32(int32_t(Value))

/*
* @brief Specifies a 32-bit Signed Integer TLV element
* @param TagSpec Should be filled with macros begin with CHIP_TLV_TAG_
* @param Value Would be first converted to int64_t, and then serialized
*/
#define CHIP_TLV_INT64(TagSpec, Value) chip::TLV::kTLVElementType_Int64 | TagSpec, CHIP_TLV_Serialize64(int64_t(Value))
#define CHIP_TLV_INT64(TagSpec, Value) chip::TLV::TLVElementType::Int64 | TagSpec, CHIP_TLV_Serialize64(int64_t(Value))

/*
* @brief Specifies an 8-bit Unsigned Integer TLV element
* @param TagSpec Should be filled with macros begin with CHIP_TLV_TAG_
* @param Value Would be first converted to (uint8_t), and then serialized
*/
#define CHIP_TLV_UINT8(TagSpec, Value) chip::TLV::kTLVElementType_UInt8 | TagSpec, CHIP_TLV_Serialize8((uint8_t)(Value))
#define CHIP_TLV_UINT8(TagSpec, Value) chip::TLV::TLVElementType::UInt8 | TagSpec, CHIP_TLV_Serialize8((uint8_t)(Value))

/*
* @brief Specifies a 16-bit Unsigned Integer TLV element
* @param TagSpec Should be filled with macros begin with CHIP_TLV_TAG_
* @param Value Would be first converted to (uint16_t), and then serialized
*/
#define CHIP_TLV_UINT16(TagSpec, Value) chip::TLV::kTLVElementType_UInt16 | TagSpec, CHIP_TLV_Serialize16((uint16_t)(Value))
#define CHIP_TLV_UINT16(TagSpec, Value) chip::TLV::TLVElementType::UInt16 | TagSpec, CHIP_TLV_Serialize16((uint16_t)(Value))

/*
* @brief Specifies a 32-bit Unsigned Integer TLV element
* @param TagSpec Should be filled with macros begin with CHIP_TLV_TAG_
* @param Value Would be first converted to (uint32_t), and then serialized
*/
#define CHIP_TLV_UINT32(TagSpec, Value) chip::TLV::kTLVElementType_UInt32 | TagSpec, CHIP_TLV_Serialize32((uint32_t)(Value))
#define CHIP_TLV_UINT32(TagSpec, Value) chip::TLV::TLVElementType::UInt32 | TagSpec, CHIP_TLV_Serialize32((uint32_t)(Value))

/*
* @brief Specifies a 64-bit Unsigned Integer TLV element
* @param TagSpec Should be filled with macros begin with CHIP_TLV_TAG_
* @param Value Would be first converted to (uint64_t), and then serialized
*/
#define CHIP_TLV_UINT64(TagSpec, Value) chip::TLV::kTLVElementType_UInt64 | TagSpec, CHIP_TLV_Serialize64((uint64_t)(Value))
#define CHIP_TLV_UINT64(TagSpec, Value) chip::TLV::TLVElementType::UInt64 | TagSpec, CHIP_TLV_Serialize64((uint64_t)(Value))

/**
* @brief
Expand All @@ -299,7 +299,7 @@
* @param ... Bytes representing the string characters to serialize
*/
#define CHIP_TLV_UTF8_STRING_1ByteLength(TagSpec, StringLength, ...) \
chip::TLV::kTLVElementType_UTF8String_1ByteLength | TagSpec, CHIP_TLV_Serialize8((uint8_t)(StringLength)), ##__VA_ARGS__
chip::TLV::TLVElementType::UTF8String_1ByteLength | TagSpec, CHIP_TLV_Serialize8((uint8_t)(StringLength)), ##__VA_ARGS__

/**
* @brief
Expand All @@ -312,7 +312,7 @@
* @param ... Bytes representing the string characters to serialize
*/
#define CHIP_TLV_UTF8_STRING_2ByteLength(TagSpec, StringLength, ...) \
chip::TLV::kTLVElementType_UTF8String_2ByteLength | TagSpec, CHIP_TLV_Serialize16((uint16_t)(StringLength)), ##__VA_ARGS__
chip::TLV::TLVElementType::UTF8String_2ByteLength | TagSpec, CHIP_TLV_Serialize16((uint16_t)(StringLength)), ##__VA_ARGS__

/**
* @brief
Expand All @@ -325,7 +325,7 @@
* @param ... Bytes representing the string characters to serialize
*/
#define CHIP_TLV_UTF8_STRING_4ByteLength(TagSpec, StringLength, ...) \
chip::TLV::kTLVElementType_UTF8String_4ByteLength | TagSpec, CHIP_TLV_Serialize32((uint32_t)(StringLength)), ##__VA_ARGS__
chip::TLV::TLVElementType::UTF8String_4ByteLength | TagSpec, CHIP_TLV_Serialize32((uint32_t)(StringLength)), ##__VA_ARGS__

/**
* @brief
Expand All @@ -338,7 +338,7 @@
* @param ... Bytes representing the string characters to serialize
*/
#define CHIP_TLV_UTF8_STRING_8ByteLength(TagSpec, StringLength, ...) \
chip::TLV::kTLVElementType_UTF8String_8ByteLength | TagSpec, CHIP_TLV_Serialize64((uint64_t)(StringLength)), ##__VA_ARGS__
chip::TLV::TLVElementType::UTF8String_8ByteLength | TagSpec, CHIP_TLV_Serialize64((uint64_t)(StringLength)), ##__VA_ARGS__

/**
* @brief
Expand All @@ -351,7 +351,7 @@
* @param ... Bytes to serialize
*/
#define CHIP_TLV_BYTE_STRING_1ByteLength(TagSpec, StringLength, ...) \
chip::TLV::kTLVElementType_ByteString_1ByteLength | TagSpec, CHIP_TLV_Serialize8((uint8_t)(StringLength)), ##__VA_ARGS__
chip::TLV::TLVElementType::ByteString_1ByteLength | TagSpec, CHIP_TLV_Serialize8((uint8_t)(StringLength)), ##__VA_ARGS__

/**
* @brief
Expand All @@ -364,7 +364,7 @@
* @param ... Bytes to serialize
*/
#define CHIP_TLV_BYTE_STRING_2ByteLength(TagSpec, StringLength, ...) \
chip::TLV::kTLVElementType_ByteString_2ByteLength | TagSpec, CHIP_TLV_Serialize16((uint16_t)(StringLength)), ##__VA_ARGS__
chip::TLV::TLVElementType::ByteString_2ByteLength | TagSpec, CHIP_TLV_Serialize16((uint16_t)(StringLength)), ##__VA_ARGS__

/**
* @brief
Expand All @@ -377,7 +377,7 @@
* @param ... Bytes to serialize
*/
#define CHIP_TLV_BYTE_STRING_4ByteLength(TagSpec, StringLength, ...) \
chip::TLV::kTLVElementType_ByteString_4ByteLength | TagSpec, CHIP_TLV_Serialize32((uint32_t)(StringLength)), ##__VA_ARGS__
chip::TLV::TLVElementType::ByteString_4ByteLength | TagSpec, CHIP_TLV_Serialize32((uint32_t)(StringLength)), ##__VA_ARGS__

/**
* @brief
Expand All @@ -390,4 +390,4 @@
* @param ... Bytes to serialize
*/
#define CHIP_TLV_BYTE_STRING_8ByteLength(TagSpec, StringLength, ...) \
chip::TLV::kTLVElementType_ByteString_8ByteLength | TagSpec, CHIP_TLV_Serialize64((uint64_t)(StringLength)), ##__VA_ARGS__
chip::TLV::TLVElementType::ByteString_8ByteLength | TagSpec, CHIP_TLV_Serialize64((uint64_t)(StringLength)), ##__VA_ARGS__
16 changes: 8 additions & 8 deletions src/lib/core/CHIPTLVDebug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,35 +185,35 @@ const char * DecodeTagControl(const TLVTagControl aTagControl)
switch (aTagControl)
{

case kTLVTagControl_Anonymous:
case TLVTagControl::Anonymous:
retval = "Anonymous";
break;

case kTLVTagControl_ContextSpecific:
case TLVTagControl::ContextSpecific:
retval = "Context Specific";
break;

case kTLVTagControl_CommonProfile_2Bytes:
case TLVTagControl::CommonProfile_2Bytes:
retval = "Common Profile (2 Bytes)";
break;

case kTLVTagControl_CommonProfile_4Bytes:
case TLVTagControl::CommonProfile_4Bytes:
retval = "Common Profile (4 Bytes)";
break;

case kTLVTagControl_ImplicitProfile_2Bytes:
case TLVTagControl::ImplicitProfile_2Bytes:
retval = "Implicit Profile (2 Bytes)";
break;

case kTLVTagControl_ImplicitProfile_4Bytes:
case TLVTagControl::ImplicitProfile_4Bytes:
retval = "Implicit Profile (4 Bytes)";
break;

case kTLVTagControl_FullyQualified_6Bytes:
case TLVTagControl::FullyQualified_6Bytes:
retval = "Fully Qualified (6 Bytes)";
break;

case kTLVTagControl_FullyQualified_8Bytes:
case TLVTagControl::FullyQualified_8Bytes:
retval = "Fully Qualified (8 Bytes)";
break;

Expand Down
Loading

0 comments on commit aa1f11c

Please sign in to comment.