Skip to content

Commit

Permalink
Bug/non determinism commands/GitHub#342 (#14708)
Browse files Browse the repository at this point in the history
* - Adding changes to the zap templates such that the incoming and outgoing commands are generated with determinism. Using the upto date helpers in the *.zapt templates
Currently pointing to a zap repo which has new helpers as well. These changes have not been merged into the github zap repo
gihub#342

* - Generation for outgoing commands which originate from the client side only.
- All commands originating on the server sides are response commands which do not need to be generated here
Github#342

* - Reverting from zcl_command_arguments to chip_cluster_command_arguments_with_structs_expanded
- Applying changes to chip_cluster_command_arguments_with_structs_expanded such that it can be used within all_outgoing_commands_for_cluster block helper instead of chip_cluster_command_arguments
- Github#342

* - Cleaning the templates further such that we have lesser diff to what we generated before
Github#342

* Making sure that outgoing commands are generated for both mfg and non-mfg specific clusters and commands
Github#342

* Generating for clusters which do not have any outgoing commands because there is code which depends on this generated code
Github#342

* Using chip_client_clusters instead of all_user_clusters_with_outgoing_commands in CHIPClusters-src.zapt just like we do in CHIPClusters.zapt to maintain consistency
Also reverting the changes in helper.js since those are no longer required
Github#342

* Cleaning up asBlock and regening
Github#342

* Regening light switch app with the right content after rebasing from upstream master
Github#342

* Cleaning up the typo in helper.js
Github#342

* Restore the previous asBlocks behavior

* Fixing the request structs for commands in .matter generated files such that request struct  should be defined for all incoming commands from client to server and outgoing commands from client to server
Github#342

* Fixing the response structs for commands in .matter generated files such that response struct should be defined for all incoming commands from server to client and outgoing commands from server to client
Github#342

* Regening after rebasing master
Github#342

* Remove unnecessary isMfgSpecific="false" and fix rebase problem in cluster-objects.h

* Cleaning up the remaining non determinism in MatterIDL template
Github#342

* Formatting the MatterIDL.zapt template
Github#342

* Formatting the MatterIDL.zapt template
Github#342

* Adding partials to remove duplication in the template and cleaning up
Github#342

* minor cleanup
Github#342

* Using responseRef instead of the complicated logic in the template
Adding some endpoint config changes which came up after pulling the latest zap repo
Github#342

* Regening after rebase
Github#342

* Remove stray CommandSenderHandle bit that is not used.

Co-authored-by: Boris Zbarsky <[email protected]>
  • Loading branch information
brdandu and bzbarsky-apple authored Feb 4, 2022
1 parent 792167c commit 44c2895
Show file tree
Hide file tree
Showing 11 changed files with 115 additions and 78 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1678,8 +1678,7 @@ server cluster IasZone = 1280 {
INT16U delay = 3;
}

command ZoneEnrollRequest(ZoneEnrollRequestRequest): ZoneEnrollResponse = 1;
command ZoneStatusChangeNotification(ZoneStatusChangeNotificationRequest): DefaultSuccess = 0;
command ZoneEnrollResponse(ZoneEnrollResponseRequest): DefaultSuccess = 0;
}

server cluster Identify = 3 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -640,6 +640,13 @@ client cluster Groups = 4 {
request struct ViewGroupRequest {
INT16U groupId = 0;
}

command AddGroup(AddGroupRequest): AddGroupResponse = 0;
command AddGroupIfIdentifying(AddGroupIfIdentifyingRequest): DefaultSuccess = 5;
command GetGroupMembership(GetGroupMembershipRequest): GetGroupMembershipResponse = 2;
command RemoveAllGroups(): DefaultSuccess = 4;
command RemoveGroup(RemoveGroupRequest): RemoveGroupResponse = 3;
command ViewGroup(ViewGroupRequest): ViewGroupResponse = 1;
}

client cluster Identify = 3 {
Expand Down Expand Up @@ -1009,6 +1016,10 @@ client cluster OnOff = 6 {
readonly global attribute attrib_id attributeList[] = 65531;
readonly global attribute bitmap32 featureMap = 65532;
readonly global attribute int16u clusterRevision = 65533;

command Off(): DefaultSuccess = 0;
command On(): DefaultSuccess = 1;
command Toggle(): DefaultSuccess = 2;
}

server cluster OperationalCredentials = 62 {
Expand Down Expand Up @@ -1215,6 +1226,14 @@ client cluster Scenes = 5 {
CHAR_STRING sceneName = 4;
SceneExtensionFieldSet extensionFieldSets[] = 5;
}

command AddScene(AddSceneRequest): AddSceneResponse = 0;
command GetSceneMembership(GetSceneMembershipRequest): GetSceneMembershipResponse = 6;
command RecallScene(RecallSceneRequest): DefaultSuccess = 5;
command RemoveAllScenes(RemoveAllScenesRequest): RemoveAllScenesResponse = 3;
command RemoveScene(RemoveSceneRequest): RemoveSceneResponse = 2;
command StoreScene(StoreSceneRequest): StoreSceneResponse = 4;
command ViewScene(ViewSceneRequest): ViewSceneResponse = 1;
}

server cluster SoftwareDiagnostics = 52 {
Expand Down
7 changes: 7 additions & 0 deletions examples/lighting-app/lighting-common/lighting-app.matter
Original file line number Diff line number Diff line change
Expand Up @@ -1116,6 +1116,13 @@ client cluster OnOff = 6 {
int16u onTime = 1;
int16u offWaitTime = 2;
}

command Off(): DefaultSuccess = 0;
command OffWithEffect(OffWithEffectRequest): DefaultSuccess = 64;
command On(): DefaultSuccess = 1;
command OnWithRecallGlobalScene(): DefaultSuccess = 65;
command OnWithTimedOff(OnWithTimedOffRequest): DefaultSuccess = 66;
command Toggle(): DefaultSuccess = 2;
}

server cluster OnOff = 6 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1559,8 +1559,7 @@ server cluster IasZone = 1280 {
INT16U delay = 3;
}

command ZoneEnrollRequest(ZoneEnrollRequestRequest): ZoneEnrollResponse = 1;
command ZoneStatusChangeNotification(ZoneStatusChangeNotificationRequest): DefaultSuccess = 0;
command ZoneEnrollResponse(ZoneEnrollResponseRequest): DefaultSuccess = 0;
}

server cluster Identify = 3 {
Expand Down Expand Up @@ -2497,7 +2496,6 @@ server cluster TestCluster = 1295 {

command Test(): DefaultSuccess = 0;
command TestNotHandled(): DefaultSuccess = 1;
command TestSpecific(): TestSpecificResponse = 2;
}

server cluster Thermostat = 513 {
Expand Down
12 changes: 12 additions & 0 deletions src/app/zap-templates/app-templates.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,18 @@
{
"name": "idl_structure_member",
"path": "partials/idl/structure_member.zapt"
},
{
"name": "idl_command_request_response",
"path": "partials/idl/command_request_response.zapt"
},
{
"name": "idl_command_request_struct",
"path": "partials/idl/command_request_struct.zapt"
},
{
"name": "idl_command_response_struct",
"path": "partials/idl/command_response_struct.zapt"
}
],
"templates": [
Expand Down
19 changes: 19 additions & 0 deletions src/app/zap-templates/partials/idl/command_request_response.zapt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{{#first}}

{{/first}}
{{#if mustUseTimedInvoke}}
{{~indent 1~}}timed command
{{~else}}
{{~indent 1~}}command
{{~/if}} {{asUpperCamelCase commandName}}(
{{~#zcl_command_arguments~}}
{{~#first~}}
{{asUpperCamelCase parent.commandName}}Request
{{~/first~}}
{{~/zcl_command_arguments~}}
): {{#if responseRef~}}
{{getResponseCommandName responseRef}}
{{~else~}}
DefaultSuccess
{{~/if~}}
{{~indent 0}} = {{code}};
10 changes: 10 additions & 0 deletions src/app/zap-templates/partials/idl/command_request_struct.zapt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{{#zcl_command_arguments}}
{{#first}}
{{~new_line 1~}}{{~indent 1~}}request struct {{asUpperCamelCase parent.commandName}}Request {
{{/first}}
{{~indent 2~}}{{> idl_structure_member}}
{{#last}}

{{~indent 1~}}}
{{/last}}
{{/zcl_command_arguments}}
10 changes: 10 additions & 0 deletions src/app/zap-templates/partials/idl/command_response_struct.zapt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{{#zcl_command_arguments}}
{{#first}}
{{~new_line 1~}}{{~indent 1~}}response struct {{asUpperCamelCase parent.commandName}} {
{{/first}}
{{~indent 2~}}{{> idl_structure_member}}
{{#last}}

{{~indent 1~}}}
{{/last}}
{{/zcl_command_arguments}}
102 changes: 33 additions & 69 deletions src/app/zap-templates/templates/app/MatterIDL.zapt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
{{!TODO: consider #chip_clusters as iteration point as well.
{{! Unsure about the differences}}
{{#all_user_clusters}}
{{side}} cluster {{asUpperCamelCase name}} = {{code}} {
{{~side}} cluster {{asUpperCamelCase name}} = {{code}} {
{{#zcl_enums}}
enum {{asUpperCamelCase name}} : {{type}} {
{{#zcl_enum_items}}
Expand All @@ -26,7 +26,7 @@

{{/zcl_bitmaps}}
{{#chip_cluster_specific_structs}}
{{>idl_structure_definition extraIndent=1}}
{{~>idl_structure_definition extraIndent=1}}

{{/chip_cluster_specific_structs}}
{{#zcl_events}}
Expand Down Expand Up @@ -61,80 +61,44 @@
{{/unless}} {{asLowerCamelCase name~}}
{{~#if isArray~}} [] {{~/if}} = {{code}};
{{/chip_server_cluster_attributes}}
{{~!--Open:Generating command request structs for all incoming commands into server side--~}}
{{#if (is_server side)}}
{{#all_incoming_commands_for_cluster name 'server'}}
{{#zcl_command_arguments}}

{{#first}}
request struct {{asUpperCamelCase parent.commandName}}Request {
{{/first}}
{{> idl_structure_member}}
{{#last}}

}
{{/last}}
{{/zcl_command_arguments}}
{{/all_incoming_commands_for_cluster}}
{{#all_incoming_commands_for_cluster name side}}
{{~>idl_command_request_struct}}
{{/all_incoming_commands_for_cluster}}
{{/if}}
{{~!--Close:Generating command request structs for all incoming commands into server side--~}}
{{~!--Open:Generating command request structs for all outgoing commands from client side--~}}
{{#if (is_client side)}}
{{#all_outgoing_commands_for_cluster name 'client'}}
{{#zcl_command_arguments}}

{{#first}}
request struct {{asUpperCamelCase parent.commandName}}Request {
{{/first}}
{{> idl_structure_member}}
{{#last}}

}
{{/last}}
{{/zcl_command_arguments}}
{{/all_outgoing_commands_for_cluster}}
{{#all_outgoing_commands_for_cluster name side}}
{{~>idl_command_request_struct}}
{{/all_outgoing_commands_for_cluster}}
{{/if}}
{{#if (is_client side)}}
{{#all_incoming_commands_for_cluster name 'client'}}
{{#zcl_command_arguments}}

{{#first}}
response struct {{asUpperCamelCase parent.commandName}} {
{{/first}}
{{> idl_structure_member}}
{{#last}}

}
{{/last}}
{{/zcl_command_arguments}}
{{/all_incoming_commands_for_cluster}}
{{~!--Close:Generating command request structs for all outgoing commands from client side--~}}
{{~!--Open:Generating command response structs for all incoming commands into client side--~}}
{{#if (is_client side)}}
{{#all_incoming_commands_for_cluster name side}}
{{~>idl_command_response_struct}}
{{/all_incoming_commands_for_cluster}}
{{/if}}
{{~!--Close:Generating command response structs for all incoming commands into client side--~}}
{{~!--Open:Generating command response structs for all outgoing commands from server side--~}}
{{#if (is_server side)}}
{{#all_outgoing_commands_for_cluster name 'server'}}
{{#zcl_command_arguments}}

{{#first}}
response struct {{asUpperCamelCase parent.commandName}} {
{{/first}}
{{> idl_structure_member}}
{{#last}}

}
{{/last}}
{{/zcl_command_arguments}}
{{/all_outgoing_commands_for_cluster}}
{{#all_outgoing_commands_for_cluster name side}}
{{~>idl_command_response_struct}}
{{/all_outgoing_commands_for_cluster}}
{{/if}}
{{~!--Close:Generating command response structs for all outgoing commands from server side--~}}
{{#if (is_server side)}}
{{#all_incoming_commands_for_cluster name side}}
{{~>idl_command_request_response}}{{~new_line 1~}}
{{/all_incoming_commands_for_cluster}}
{{/if}}
{{#if (is_client side)}}
{{#all_outgoing_commands_for_cluster name side}}
{{~>idl_command_request_response}}{{~new_line 1~}}
{{/all_outgoing_commands_for_cluster}}
{{/if}}
{{#chip_cluster_commands}}
{{#first}}

{{/first}}
{{#if mustUseTimedInvoke}}
timed command
{{~else}}
command
{{~/if}} {{asUpperCamelCase name}}(
{{~#if arguments~}}
{{asUpperCamelCase name}}Request
{{~/if~}}
): {{asUpperCamelCase responseName}} = {{code}};
{{/chip_cluster_commands}}
}

{{/all_user_clusters}}
Expand Down
5 changes: 2 additions & 3 deletions src/app/zap-templates/templates/chip/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,9 @@ function throwErrorIfUndefined(item, errorMsg, conditions)

function checkIsInsideClusterBlock(context, name)
{
const clusterName = context.name;
const clusterSide = context.side;
const clusterName = context.name ? context.name : context.clusterName;
const clusterSide = context.side ? context.side : context.clusterSide;
const errorMsg = name + ': Not inside a ({#chip_server_clusters}} block.';

throwErrorIfUndefined(context, errorMsg, [ clusterName, clusterSide ]);

return { clusterName, clusterSide };
Expand Down

0 comments on commit 44c2895

Please sign in to comment.