Skip to content

Commit

Permalink
[example] Fix CommandList for GeneralCommissioning cluster on all-clu…
Browse files Browse the repository at this point in the history
…sters-app (#17833)

* [examples] Fix GeneratedCommandList and AcceptedCommandList

* Run Codegen

* Fix test case -- yes, it should contain 8

* Fix Test - Run Codegen

* Fix generated code format
  • Loading branch information
erjiaqing authored May 10, 2022
1 parent 3e58a0e commit 2580fb3
Show file tree
Hide file tree
Showing 21 changed files with 808 additions and 697 deletions.
2 changes: 1 addition & 1 deletion src/app/tests/suites/TestCluster.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3778,7 +3778,7 @@ tests:
command: "readAttribute"
attribute: "GeneratedCommandList"
response:
value: [0, 1, 4, 5, 6, 9, 10, 11]
value: [0, 1, 4, 5, 6, 8, 9, 10, 11]

# Struct-typed attribute
- label: "Write struct-typed attribute"
Expand Down
30 changes: 22 additions & 8 deletions src/app/zap-templates/templates/app/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,30 +141,35 @@ function chip_endpoint_generated_functions()

function chip_endpoint_generated_commands_list(options)
{
let ret = [];
let ret = [];
let index = 0;
this.clusterList.forEach((c) => {
let acceptedCommands = [];
let generatedCommands = [];

c.commands.forEach((cmd) => {
if (cmd.mask.includes('incoming_server')) {
acceptedCommands.push(`${cmd.commandId} /* ${cmd.name} */`);
}
if (cmd.mask.includes('incoming_client')) {
generatedCommands.push(`${cmd.commandId} /* ${cmd.name} */`);
if (cmd.responseId !== null) {
generatedCommands.push(`${cmd.responseId} /* ${cmd.responseName} */`);
}
}
});

generatedCommands = [...new Set(generatedCommands) ].sort();

if (acceptedCommands.length > 0 || generatedCommands.length > 0) {
ret.push({ text : ` /* ${c.comment} */\\` });
}
if (acceptedCommands.length > 0) {
acceptedCommands.push('chip::kInvalidCommandId /* end of list */')
ret.push({ text : ` /* client_generated */ \\\n ${acceptedCommands.join(', \\\n ')}, \\` });
ret.push({ text : ` /* AcceptedCommandList (index=${index}) */ \\\n ${acceptedCommands.join(', \\\n ')}, \\` });
index += acceptedCommands.length;
}
if (generatedCommands.length > 0) {
generatedCommands.push('chip::kInvalidCommandId /* end of list */')
ret.push({ text : ` /* server_generated */ \\\n ${generatedCommands.join(', \\\n ')}, \\` });
ret.push({ text : ` /* GeneratedCommandList (index=${index})*/ \\\n ${generatedCommands.join(', \\\n ')}, \\` });
index += generatedCommands.length;
}
})
return templateUtil.collectBlocks(ret, options, this);
Expand Down Expand Up @@ -217,8 +222,17 @@ function chip_endpoint_cluster_list()
mask = c.mask.map((m) => `ZAP_CLUSTER_MASK(${m.toUpperCase()})`).join(' | ')
}

let acceptedCommands = c.commands.reduce(((acc, cmd) => (acc + (cmd.mask.includes('incoming_server') ? 1 : 0))), 0);
let generatedCommands = c.commands.reduce(((acc, cmd) => (acc + (cmd.mask.includes('incoming_client') ? 1 : 0))), 0);
let acceptedCommands = 0;
let generatedCommandList = [];
c.commands.forEach((cmd) => {
if (cmd.mask.includes('incoming_server')) {
acceptedCommands++;
if (cmd.responseId !== null) {
generatedCommandList.push(cmd.responseId);
}
}
});
let generatedCommands = new Set(generatedCommandList).size;

let acceptedCommandsListVal = "nullptr";
let generatedCommandsListVal = "nullptr";
Expand Down
Loading

0 comments on commit 2580fb3

Please sign in to comment.