Skip to content

Commit

Permalink
Add ways to get a command name by ID, for known commands, to Matter.f…
Browse files Browse the repository at this point in the history
…ramework. (#35882)
  • Loading branch information
bzbarsky-apple authored Oct 3, 2024
1 parent af1b0ee commit f2d3381
Show file tree
Hide file tree
Showing 4 changed files with 4,037 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/darwin/Framework/CHIP/MTRClusterNames.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,24 @@ MTR_EXTERN MTR_AVAILABLE(ios(17.6), macos(14.6), watchos(10.6), tvos(17.6)) NSSt
*/
MTR_EXTERN MTR_AVAILABLE(ios(17.6), macos(14.6), watchos(10.6), tvos(17.6)) NSString * MTRAttributeNameForID(MTRClusterIDType clusterID, MTRAttributeIDType attributeID);

/**
* Resolve Matter request (client to server) command IDs into a descriptive string.
*
* For unknown IDs, a string '<Unknown clusterID %d>' (if the cluster ID is not known)
* or '<Unknown commandID %d>' (if the cluster ID is known but the command ID is not known)
* will be returned.
*/
MTR_EXTERN MTR_NEWLY_AVAILABLE NSString * MTRRequestCommandNameForID(MTRClusterIDType clusterID, MTRCommandIDType commandID);

/**
* Resolve Matter response (server to client) command IDs into a descriptive string.
*
* For unknown IDs, a string '<Unknown clusterID %d>' (if the cluster ID is not known)
* or '<Unknown commandID %d>' (if the cluster ID is known but the command ID is not known)
* will be returned.
*/
MTR_EXTERN MTR_NEWLY_AVAILABLE NSString * MTRResponseCommandNameForID(MTRClusterIDType clusterID, MTRCommandIDType commandID);

/**
* Resolve Matter event IDs into a descriptive string.
*
Expand Down
56 changes: 56 additions & 0 deletions src/darwin/Framework/CHIP/templates/MTRClusterNames-src.zapt
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,62 @@ NSString * MTRAttributeNameForID(MTRClusterIDType clusterID, MTRAttributeIDType
return result;
}

#pragma mark - Command IDs

{{!Takes "source" as an argument, can be "client" or "server"}}
{{~#*inline "commandIDOutput"}}
NSString * result = nil;

switch (clusterID) {

{{#zcl_clusters}}
{{#if (isSupported (asUpperCamelCase label preserveAcronyms=true) isForIds=true)}}
{{~#*inline "cluster"}}{{asUpperCamelCase label preserveAcronyms=true}}{{/inline~}}
case MTRClusterIDType{{>cluster}}ID:

switch (commandID) {

{{#*inline "commandIDs"}}
{{#zcl_commands}}
{{~#*inline "cluster"}}{{asUpperCamelCase ../clusterName preserveAcronyms=true}}{{/inline~}}
{{~#*inline "command"}}{{asUpperCamelCase label preserveAcronyms=true}}{{/inline~}}
{{#if (and (isSupported (asUpperCamelCase ../clusterName preserveAcronyms=true) command=(asUpperCamelCase label preserveAcronyms=true) isForIds=true)
(isStrEqual source ../../../source))}}
case MTRCommandIDTypeCluster{{>cluster}}Command{{>command}}ID:
result = @"{{>command}}";
break;

{{/if}}
{{/zcl_commands}}
{{/inline}}

{{> commandIDs clusterName=label}}

default:
result = [NSString stringWithFormat:@"<Unknown commandID %d>", commandID];
break;
}
break;
{{/if}}

{{/zcl_clusters}}
default:
result = [NSString stringWithFormat:@"<Unknown clusterID %d>", clusterID];
break;
}

return result;
{{/inline}}

NSString * MTRRequestCommandNameForID(MTRClusterIDType clusterID, MTRCommandIDType commandID)
{
{{> commandIDOutput source="client"}}
}

NSString * MTRResponseCommandNameForID(MTRClusterIDType clusterID, MTRCommandIDType commandID)
{
{{> commandIDOutput source="server"}}
}

#pragma mark - Event IDs

Expand Down
Loading

0 comments on commit f2d3381

Please sign in to comment.