Skip to content

Commit

Permalink
Use mei in more templates (#28815)
Browse files Browse the repository at this point in the history
* Use asMEI in several more tempaltes - specifical chip/framework tool, python and java

* Zap regen

* Fix accidental deletion

* zap regen

* More namespacing for data types

* zap regen

* Ensure IDs headers are included in commands.h

* Proper namespacing for chip-tool commands

* Use PRIx32 for formatting clusterid and commandid

* Also update darwin framework tool to compile

* Add ID headers for the darwin framework tool commands template

* Fix attribute vs command id usage

* Fix typo s/Attribute/Attributes/
  • Loading branch information
andy31415 authored and pull[bot] committed Jan 29, 2024
1 parent ae57d77 commit 431b976
Show file tree
Hide file tree
Showing 11 changed files with 22,566 additions and 6,389 deletions.
15 changes: 11 additions & 4 deletions examples/chip-tool/templates/commands.zapt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
#include <type_traits>

#include <app-common/zap-generated/cluster-objects.h>
#include <app-common/zap-generated/ids/Clusters.h>
#include <app-common/zap-generated/ids/Commands.h>
#include <commands/clusters/ComplexArgument.h>
#include <commands/clusters/ClusterCommand.h>
#include <commands/clusters/ReportCommand.h>
Expand Down Expand Up @@ -40,16 +42,21 @@ public:

CHIP_ERROR SendCommand(chip::DeviceProxy * device, std::vector<chip::EndpointId> endpointIds) override
{
ChipLogProgress(chipTool, "Sending cluster ({{asHex parent.code 8}}) command ({{asHex code 8}}) on endpoint %u", endpointIds.at(0));
constexpr chip::ClusterId clusterId = chip::app::Clusters::{{asUpperCamelCase parent.name}}::Id;
constexpr chip::CommandId commandId = chip::app::Clusters::{{asUpperCamelCase parent.name}}::Commands::{{asUpperCamelCase name}}::Id;

return ClusterCommand::SendCommand(device, endpointIds.at(0), {{asHex parent.code 8}}, {{asHex code 8}}, mRequest);
ChipLogProgress(chipTool, "Sending cluster (0x%08" PRIX32 ") command (0x%08" PRIX32 ") on endpoint %u", clusterId, commandId, endpointIds.at(0));
return ClusterCommand::SendCommand(device, endpointIds.at(0), clusterId, commandId, mRequest);
}

CHIP_ERROR SendGroupCommand(chip::GroupId groupId, chip::FabricIndex fabricIndex) override
{
ChipLogProgress(chipTool, "Sending cluster ({{asHex parent.code 8}}) command ({{asHex code 8}}) on Group %u", groupId);
constexpr chip::ClusterId clusterId = chip::app::Clusters::{{asUpperCamelCase parent.name}}::Id;
constexpr chip::CommandId commandId = chip::app::Clusters::{{asUpperCamelCase parent.name}}::Commands::{{asUpperCamelCase name}}::Id;

return ClusterCommand::SendGroupCommand(groupId, fabricIndex, {{asHex parent.code 8}}, {{asHex code 8}}, mRequest);
ChipLogProgress(chipTool, "Sending cluster (0x%08" PRIX32 ") command (0x%08" PRIX32 ") on Group %u", clusterId, commandId, groupId);

return ClusterCommand::SendGroupCommand(groupId, fabricIndex, clusterId, commandId, mRequest);
}

private:
Expand Down
22 changes: 18 additions & 4 deletions examples/darwin-framework-tool/templates/commands.zapt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
#include <commands/clusters/ReportCommandBridge.h>
#include <commands/clusters/WriteAttributeCommandBridge.h>
#include <app-common/zap-generated/cluster-objects.h>
#include <app-common/zap-generated/ids/Clusters.h>
#include <app-common/zap-generated/ids/Commands.h>

{{> clusters_header}}

Expand Down Expand Up @@ -52,7 +54,10 @@ public:

CHIP_ERROR SendCommand(MTRBaseDevice * device, chip::EndpointId endpointId) override
{
ChipLogProgress(chipTool, "Sending cluster ({{asHex parent.code 8}}) command ({{asHex code 8}}) on endpoint %u", endpointId);
constexpr chip::ClusterId clusterId = chip::app::Clusters::{{asUpperCamelCase parent.name}}::Id;
constexpr chip::CommandId commandId = chip::app::Clusters::{{asUpperCamelCase parent.name}}::Commands::{{asUpperCamelCase name}}::Id;

ChipLogProgress(chipTool, "Sending cluster (0x%08" PRIX32 ") command (0x%08" PRIX32 ") on endpoint %u", clusterId, commandId, endpointId);

dispatch_queue_t callbackQueue = dispatch_queue_create("com.chip.command", DISPATCH_QUEUE_SERIAL);
__auto_type * cluster = [[MTRBaseCluster{{asUpperCamelCase parent.name preserveAcronyms=true}} alloc] initWithDevice:device endpointID:@(endpointId) queue:callbackQueue];
Expand Down Expand Up @@ -127,7 +132,10 @@ public:

CHIP_ERROR SendCommand(MTRBaseDevice * device, chip::EndpointId endpointId) override
{
ChipLogProgress(chipTool, "Sending cluster ({{asHex parent.code 8}}) ReadAttribute ({{asHex code 8}}) on endpoint %u", endpointId);
constexpr chip::ClusterId clusterId = chip::app::Clusters::{{asUpperCamelCase parent.name}}::Id;
constexpr chip::AttributeId attributeId = chip::app::Clusters::{{asUpperCamelCase parent.name}}::Attributes::{{asUpperCamelCase name}}::Id;

ChipLogProgress(chipTool, "Sending cluster (0x%08" PRIX32 ") ReadAttribute (0x%08" PRIX32 ") on endpoint %u", endpointId, clusterId, attributeId);

dispatch_queue_t callbackQueue = dispatch_queue_create("com.chip.command", DISPATCH_QUEUE_SERIAL);
__auto_type * cluster = [[MTRBase{{>cluster}} alloc] initWithDevice:device endpointID:@(endpointId) queue:callbackQueue];
Expand Down Expand Up @@ -180,7 +188,10 @@ public:

CHIP_ERROR SendCommand(MTRBaseDevice * device, chip::EndpointId endpointId) override
{
ChipLogProgress(chipTool, "Sending cluster ({{asHex parent.code 8}}) WriteAttribute ({{asHex code 8}}) on endpoint %u", endpointId);
constexpr chip::ClusterId clusterId = chip::app::Clusters::{{asUpperCamelCase parent.name}}::Id;
constexpr chip::AttributeId attributeId = chip::app::Clusters::{{asUpperCamelCase parent.name}}::Attributes::{{asUpperCamelCase name}}::Id;

ChipLogProgress(chipTool, "Sending cluster (0x%08" PRIX32 ") WriteAttribute (0x%08" PRIX32 ") on endpoint %u", clusterId, attributeId, endpointId);
dispatch_queue_t callbackQueue = dispatch_queue_create("com.chip.command", DISPATCH_QUEUE_SERIAL);
__auto_type * cluster = [[MTRBase{{>cluster}} alloc] initWithDevice:device endpointID:@(endpointId) queue:callbackQueue];
__auto_type * params = [[MTRWriteParams alloc] init];
Expand Down Expand Up @@ -234,7 +245,10 @@ public:

CHIP_ERROR SendCommand(MTRBaseDevice * device, chip::EndpointId endpointId) override
{
ChipLogProgress(chipTool, "Sending cluster ({{asHex parent.code 8}}) ReportAttribute ({{asHex code 8}}) on endpoint %u", endpointId);
constexpr chip::ClusterId clusterId = chip::app::Clusters::{{asUpperCamelCase parent.name}}::Id;
constexpr chip::CommandId attributeId = chip::app::Clusters::{{asUpperCamelCase parent.name}}::Attributes::{{asUpperCamelCase name}}::Id;

ChipLogProgress(chipTool, "Sending cluster (0x%08" PRIX32 ") ReportAttribute (0x%08" PRIX32 ") on endpoint %u", clusterId, attributeId, endpointId);
dispatch_queue_t callbackQueue = dispatch_queue_create("com.chip.command", DISPATCH_QUEUE_SERIAL);
__auto_type * cluster = [[MTRBase{{>cluster}} alloc] initWithDevice:device endpointID:@(endpointId) queue:callbackQueue];
__auto_type * params = [[MTRSubscribeParams alloc] initWithMinInterval:@(mMinInterval) maxInterval:@(mMaxInterval)];
Expand Down
7 changes: 6 additions & 1 deletion src/app/zap-templates/partials/cluster_header.zapt
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
{{pad '/*' 78 '-'}}*\
{{pad (concat "| Cluster " (asUpperCamelCase name)) 70 ' '}}{{pad (concat "| " (asHex code 4)) 9 ' '}}|
{{pad (concat "| Cluster " (asUpperCamelCase name)) 70 ' '~}}
{{~#if manufacturerCode}}
{{~pad (concat "| " (asMEI manufacturerCode code)) ' '}}
{{~else}}
{{~pad (concat "| " (asHex code 4)) ' '}}
{{~/if}} |
{{pad "|" 79 '-'}}|
{{pad "| Commands: " 70 ' '}}{{pad "| " 9 ' '}}|
{{#zcl_commands_source_client}}
Expand Down
2 changes: 1 addition & 1 deletion src/controller/java/templates/ChipClusters-java.zapt
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public class ChipClusters {

{{#zcl_clusters}}
public static class {{asUpperCamelCase name}}Cluster extends BaseChipCluster {
public static final long CLUSTER_ID = {{code}}L;
public static final long CLUSTER_ID = {{asMEI manufacturerCode code}}L;

public {{asUpperCamelCase name}}Cluster(long devicePtr, int endpointId) {
super(devicePtr, endpointId);
Expand Down
Loading

0 comments on commit 431b976

Please sign in to comment.