Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IM event codegen support #10599

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 42 additions & 2 deletions src/app/zap-templates/templates/app/cluster-objects-src.zapt
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,7 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader &reader) {
CHIP_ERROR err = CHIP_NO_ERROR;
TLV::TLVType outer;
VerifyOrReturnError(TLV::kTLVType_Structure == reader.GetType(), CHIP_ERROR_WRONG_TLV_TYPE);
err = reader.EnterContainer(outer);
ReturnErrorOnFailure(err);
ReturnErrorOnFailure(reader.EnterContainer(outer));
while ((err = reader.Next()) == CHIP_NO_ERROR) {
VerifyOrReturnError(TLV::IsContextTag(reader.GetTag()), CHIP_ERROR_INVALID_TLV_TAG);
switch (TLV::TagNumFromTag(reader.GetTag()))
Expand All @@ -93,6 +92,47 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader &reader) {
} // namespace {{asUpperCamelCase name}}.
{{/zcl_commands}}
} // namespace Commands

namespace Events {
{{#zcl_events}}
namespace {{asUpperCamelCase name}} {
CHIP_ERROR Type::Encode(TLV::TLVWriter &writer, TLV::Tag tag) const{
TLV::TLVType outer;
ReturnErrorOnFailure(writer.StartContainer(tag, TLV::kTLVType_Structure, outer));
{{#zcl_event_fields}}
ReturnErrorOnFailure(DataModel::Encode(writer, TLV::ContextTag(to_underlying(Fields::k{{asUpperCamelCase name}})), {{asLowerCamelCase name}}));
{{/zcl_event_fields}}
ReturnErrorOnFailure(writer.EndContainer(outer));
return CHIP_NO_ERROR;
}

CHIP_ERROR DecodableType::Decode(TLV::TLVReader &reader) {
CHIP_ERROR err = CHIP_NO_ERROR;
TLV::TLVType outer;
VerifyOrReturnError(TLV::kTLVType_Structure == reader.GetType(), CHIP_ERROR_WRONG_TLV_TYPE);
ReturnErrorOnFailure(reader.EnterContainer(outer));
while ((err = reader.Next()) == CHIP_NO_ERROR) {
VerifyOrReturnError(TLV::IsContextTag(reader.GetTag()), CHIP_ERROR_INVALID_TLV_TAG);
switch (TLV::TagNumFromTag(reader.GetTag()))
{
{{#zcl_event_fields}}
case to_underlying(Fields::k{{asUpperCamelCase name}}):
ReturnErrorOnFailure(DataModel::Decode(reader, {{asLowerCamelCase name}}));
break;
{{/zcl_event_fields}}
default:
break;
}
}

VerifyOrReturnError(err == CHIP_END_OF_TLV, err);
ReturnErrorOnFailure(reader.ExitContainer(outer));
return CHIP_NO_ERROR;
}
} // namespace {{asUpperCamelCase name}}.
{{/zcl_events}}
} // namespace Commands

} // namespace {{asUpperCamelCase name}}
{{/zcl_clusters}}

Expand Down
50 changes: 48 additions & 2 deletions src/app/zap-templates/templates/app/cluster-objects.zapt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <app/data-model/Decode.h>
#include <app/data-model/Encode.h>
#include <app/data-model/List.h>
#include <app/EventLoggingTypes.h>
#include <app/util/basic-types.h>
#include <lib/support/BitFlags.h>
#include <protocols/interaction_model/Constants.h>
Expand Down Expand Up @@ -49,7 +50,7 @@ k{{asUpperCamelCase label}} = {{asOffset mask}},
{{#first}}
namespace Structs {
{{/first}}
namespace {{name}} {
namespace {{asUpperCamelCase name}} {
enum class Fields {
{{#zcl_struct_items}}
k{{asUpperCamelCase label}} = {{index}},
Expand Down Expand Up @@ -80,7 +81,7 @@ namespace {{name}} {
using DecodableType = Type;
{{/if}}

} // namespace {{name}}
} // namespace {{asUpperCamelCase name}}
{{#last}}
} // namespace Structs
{{/last}}
Expand Down Expand Up @@ -153,6 +154,51 @@ namespace {{asUpperCamelCase label}} {
{{/last}}
{{/if}}
{{/zcl_attributes_server}}
{{#zcl_events}}
{{#first}}
namespace Events {
{{/first}}
namespace {{asUpperCamelCase name}} {
static constexpr PriorityLevel kPriorityLevel = PriorityLevel::{{asUpperCamelCase priority}};
static constexpr EventId kEventId = {{asMEI manufacturerCode code}};

enum class Fields {
{{#zcl_event_fields}}
k{{asUpperCamelCase name}} = {{fieldIdentifier}},
{{/zcl_event_fields}}
};

struct Type
{
public:
static constexpr PriorityLevel priorityLevel = PriorityLevel::{{asUpperCamelCase priority}};
static constexpr EventId eventId = {{asMEI manufacturerCode code}};
static constexpr ClusterId GetClusterId() { return {{asUpperCamelCase parent.name}}::Id; }
yunhanw-google marked this conversation as resolved.
Show resolved Hide resolved

{{#zcl_event_fields}}
{{#if isArray}}DataModel::List<{{/if}}{{zapTypeToEncodableClusterObjectType type}}{{#if isArray}}>{{/if}} {{asLowerCamelCase name}};
{{/zcl_event_fields}}

CHIP_ERROR Encode(TLV::TLVWriter &writer, TLV::Tag tag) const;
};

struct DecodableType {
public:
static constexpr PriorityLevel GetPriorityLevel() { return kPriorityLevel; }
static constexpr EventId GetEventId() { return kEventId; }
static constexpr ClusterId GetClusterId() { return {{asUpperCamelCase parent.name}}::Id; }

{{#zcl_event_fields}}
{{#if isArray}}DataModel::DecodableList<{{/if}}{{zapTypeToDecodableClusterObjectType type}}{{#if isArray}}>{{/if}} {{asLowerCamelCase name}};
{{/zcl_event_fields}}

CHIP_ERROR Decode(TLV::TLVReader &reader);
};
} // namespace {{asUpperCamelCase name}}
{{#last}}
} // namespace Events
{{/last}}
{{/zcl_events}}
} // namespace {{asUpperCamelCase name}}
{{/zcl_clusters}}

Expand Down
9 changes: 9 additions & 0 deletions src/app/zap-templates/zcl/data-model/chip/test-cluster.xml
Original file line number Diff line number Diff line change
Expand Up @@ -271,5 +271,14 @@ limitations under the License.
<arg name="arg6" type="BOOLEAN"/>
</command>

<event code="0x0001" name="TestEvent" priority="info" side="server">
<description>Example test event</description>
<field id="1" name="arg1" type="INT8U"/>
<field id="2" name="arg2" type="SimpleEnum"/>
<field id="3" name="arg3" type="BOOLEAN"/>
<field id="4" name="arg4" type="SimpleStruct"/>
<field id="5" name="arg5" type="SimpleStruct" array="true"/>
<field id="6" name="arg6" type="SimpleEnum" array="true"/>
</event>
</cluster>
</configurator>
Loading