diff --git a/src-electron/generator/helper-endpointconfig.js b/src-electron/generator/helper-endpointconfig.js index 14c13fa3d2..06ef1209af 100644 --- a/src-electron/generator/helper-endpointconfig.js +++ b/src-electron/generator/helper-endpointconfig.js @@ -562,6 +562,7 @@ async function collectAttributes(endpointTypes, options) { attributeSize: 0, mask: [], commands: [], + events: [], functions: 'NULL', comment: `Endpoint: ${ept.endpointId}, Cluster: ${c.name} (${c.side})`, } @@ -847,6 +848,17 @@ async function collectAttributes(endpointTypes, options) { commandMfgCodes.push(mfgCmd) } }) + + // Go over the events + c.events.sort(zclUtil.eventComparator) + c.events.forEach((ev) => { + let event = { + eventId: asMEI(ev.manufacturerCode, ev.code), + name: cmd.name, + } + cluster.events.push(event) + }) + endpointAttributeSize += clusterAttributeSize cluster.attributeSize = clusterAttributeSize clusterList.push(cluster) diff --git a/src-electron/generator/matter/app/zap-templates/templates/app/helper.js b/src-electron/generator/matter/app/zap-templates/templates/app/helper.js index fde74f87d5..d2d1c9cc37 100644 --- a/src-electron/generator/matter/app/zap-templates/templates/app/helper.js +++ b/src-electron/generator/matter/app/zap-templates/templates/app/helper.js @@ -38,6 +38,7 @@ const TestHelper = require('../../common/ClusterTestGeneration.js'); const kGlobalAttributes = [ 0xfff8, // GeneratedCommandList 0xfff9, // AcceptedCommandList + 0xfffa, // EventList 0xfffb, // AttributeList 0xfffc, // ClusterRevision 0xfffd, // FeatureMap @@ -187,6 +188,37 @@ function chip_endpoint_generated_commands_list(options) { return templateUtil.collectBlocks(ret, options, this); } +function chip_endpoint_generated_event_count(options) { + let count = 0; + this.clusterList.forEach((c) => { + count += c.events.length + }); + return count; +} + +function chip_endpoint_generated_event_list(options) { + let ret = []; + let index = 0; + this.clusterList.forEach((c) => { + let events = []; + + c.events.forEach((ev) => { + events.push(`${ev.eventId} /* ${ev.name} */`); + }); + + if (events.length > 0) { + ret.push({ text: ` /* ${c.comment} */\\` }); + ret.push({ + text: ` /* EventList (index=${index}) */ \\\n ${events.join( + ', \\\n ' + )}, \\`, + }); + index += events.length; + } + }); + return templateUtil.collectBlocks(ret, options, this); +} + /** * Return endpoint config GENERATED_CLUSTER MACRO * To be used as a replacement of endpoint_cluster_list since this one @@ -195,6 +227,7 @@ function chip_endpoint_generated_commands_list(options) { function chip_endpoint_cluster_list() { let ret = '{ \\\n'; let totalCommands = 0; + let totalEvents = 0; this.clusterList.forEach((c) => { let mask = ''; let functionArray = c.functions; @@ -258,6 +291,17 @@ function chip_endpoint_cluster_list() { } )`; } + let generatedEventListVal = 'nullptr'; + let generatedEventCount = 0; + c.events.forEach((event) => { + generatedEventCount++; + }); + + if (generatedEventCount > 0) { + totalEvents += generatedEventCount; + generatedEventListVal = `ZAP_GENERATED_EVENTS_INDEX( ${totalEvents} )`; + } + ret = ret.concat(` { \\ /* ${c.comment} */ \\ .clusterId = ${c.clusterId}, \\ @@ -268,6 +312,8 @@ function chip_endpoint_cluster_list() { .functions = ${functionArray}, \\ .acceptedCommandList = ${acceptedCommandsListVal} ,\\ .generatedCommandList = ${generatedCommandsListVal} ,\\ + .eventList = ${generatedEventListVal}, \\ + .eventCount = ${generatedEventCount}, \\ },\\\n`); totalCommands = totalCommands + acceptedCommands + generatedCommands; @@ -917,6 +963,10 @@ exports.chip_endpoint_cluster_list = chip_endpoint_cluster_list; exports.chip_endpoint_data_version_count = chip_endpoint_data_version_count; exports.chip_endpoint_generated_commands_list = chip_endpoint_generated_commands_list; +exports.chip_endpoint_generated_event_count = + chip_endpoint_generated_event_count; +exports.chip_endpoint_generated_event_list = + chip_endpoint_generated_event_list; exports.asTypedExpression = asTypedExpression; exports.asTypedLiteral = asTypedLiteral; exports.asLowerCamelCase = asLowerCamelCase; diff --git a/src-electron/util/zcl-util.js b/src-electron/util/zcl-util.js index d6714b7abc..718ff77351 100644 --- a/src-electron/util/zcl-util.js +++ b/src-electron/util/zcl-util.js @@ -75,6 +75,23 @@ function commandComparator(a, b) { return 0 } +/** + * Comparator for sorting events. + * + * @param {*} a + * @param {*} b + * @returns -1, 0 or 1 + */ +function eventComparator(a, b) { + if (a.manufacturerCode < b.manufacturerCode) return -1 + if (a.manufacturerCode > b.manufacturerCode) return 1 + + if (a.hexCode < b.hexCode) return -1 + if (a.hexCode > b.hexCode) return 1 + + return 0 +} + function findStructByName(structs, name) { for (const s of structs) { if (s.name == name) { @@ -783,6 +800,7 @@ async function createCommandSignature(db, packageId, cmd) { exports.clusterComparator = clusterComparator exports.attributeComparator = attributeComparator exports.commandComparator = commandComparator +exports.eventComparator = eventComparator exports.sortStructsByDependency = sortStructsByDependency exports.isEnum = isEnum exports.isBitmap = isBitmap diff --git a/test/gen-template/matter/endpoint-config.zapt b/test/gen-template/matter/endpoint-config.zapt index b025eb2ed1..45dceefe1d 100644 --- a/test/gen-template/matter/endpoint-config.zapt +++ b/test/gen-template/matter/endpoint-config.zapt @@ -37,6 +37,11 @@ #define ZAP_GENERATED_COMMANDS_INDEX(index) ((chip::CommandId *) (&generatedCommands[index])) +#define GENERATED_EVENT_COUNT {{ chip_endpoint_generated_event_count }} +#define GENERATED_EVENTS {{ chip_endpoint_generated_event_list }} + +#define ZAP_GENERATED_EVENTS_INDEX(index) ((chip::EventId *) (&generatedEvents[index])) + // Cluster function static arrays #define GENERATED_FUNCTION_ARRAYS {{chip_endpoint_generated_functions}} diff --git a/test/helper-api-baseline.json b/test/helper-api-baseline.json index f9f26c2dbc..906ec6b8d0 100644 --- a/test/helper-api-baseline.json +++ b/test/helper-api-baseline.json @@ -272,6 +272,16 @@ "isDeprecated": false, "category": "matter" }, + { + "name": "chip_endpoint_generated_event_count", + "isDeprecated": false, + "category": "matter" + }, + { + "name": "chip_endpoint_generated_event_list", + "isDeprecated": false, + "category": "matter" + }, { "name": "chip_endpoint_generated_functions", "isDeprecated": false,