Skip to content

Commit fd7e0bf

Browse files
authored
Added code to enable EventList support for Matter (#914)
* Added code to enable EventList support for Matter. - Added new method to extract events from database: selectEndpointClusterEvents() - Added new helper functions to construct list (array) of supported event IDs: chip_endpoint_generated_event_count() chip_endpoint_generated_event_list() - Added eventList and eventCount entries to the EmberAfCluster struct in the generated endpoint_config.h file The EventList data is treated similar to CommandList data. The assumption is that events are always server --> client. * Removed Unused eventMfgCodes variable in the collectAttributes() function * Removed casting for generatedEvents in endpoint-config.zapt file * Updated selectEndpointClusterEvents() function to use existing mapping method dbMapping.map.event * Updated selectEndpointClusterEvents() to select all supported event types. * removed unsupported select field in selectEndpointClusterEvents()
1 parent ffd5670 commit fd7e0bf

File tree

9 files changed

+132
-6
lines changed

9 files changed

+132
-6
lines changed

cypress/matterFixtures/data.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"server2": "Client & Server",
2626
"previewBtnData": "access.out",
2727
"outOfRangeAmount1": "9999999999999999",
28-
"availableAttributes1": "28",
28+
"availableAttributes1": "32",
2929
"availableClusters1": "5",
3030
"enum8inputpath": "2",
3131
"int16inputpath": "1",

src-electron/db/query-endpoint.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,45 @@ ORDER BY C.CODE
265265
})
266266
}
267267

268+
/**
269+
* Retrieves endpoint cluster events.
270+
*
271+
* @param {*} db
272+
* @param {*} clusterId
273+
* @param {*} endpointTypeId
274+
* @returns promise that resolves into endpoint cluster events
275+
*/
276+
async function selectEndpointClusterEvents(db, clusterId, endpointTypeId) {
277+
return dbApi.dbAll(
278+
db,
279+
`
280+
SELECT
281+
E.EVENT_ID,
282+
E.CLUSTER_REF,
283+
E.CODE,
284+
E.MANUFACTURER_CODE,
285+
E.NAME,
286+
E.DESCRIPTION,
287+
E.SIDE,
288+
E.IS_OPTIONAL,
289+
E.IS_FABRIC_SENSITIVE,
290+
E.PRIORITY
291+
FROM
292+
EVENT AS E
293+
LEFT JOIN
294+
ENDPOINT_TYPE_EVENT AS ETE
295+
ON
296+
E.EVENT_ID = ETE.EVENT_REF
297+
WHERE
298+
E.CLUSTER_REF = ?
299+
AND ETE.ENDPOINT_TYPE_REF = ?
300+
ORDER BY E.MANUFACTURER_CODE, E.CODE
301+
`,
302+
[clusterId, endpointTypeId]
303+
)
304+
.then((rows) => rows.map(dbMapping.map.event))
305+
}
306+
268307
/**
269308
* Deletes an endpoint.
270309
*
@@ -379,6 +418,7 @@ WHERE
379418
exports.selectEndpointClusters = selectEndpointClusters
380419
exports.selectEndpointClusterAttributes = selectEndpointClusterAttributes
381420
exports.selectEndpointClusterCommands = selectEndpointClusterCommands
421+
exports.selectEndpointClusterEvents = selectEndpointClusterEvents
382422
exports.insertEndpoint = insertEndpoint
383423
exports.deleteEndpoint = deleteEndpoint
384424
exports.selectEndpoint = selectEndpoint

src-electron/generator/helper-endpointconfig.js

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -513,10 +513,11 @@ async function collectAttributes(endpointTypes, options) {
513513
let commandMfgCodes = [] // Array of { index, mfgCode } objects
514514
let clusterMfgCodes = [] // Array of { index, mfgCode } objects
515515
let attributeMfgCodes = [] // Array of { index, mfgCode } objects
516+
let eventList = []
516517
let attributeList = []
517518
let commandList = []
518519
let endpointList = [] // Array of { clusterIndex, clusterCount, attributeSize }
519-
let clusterList = [] // Array of { clusterId, attributeIndex, attributeCount, attributeSize, mask, functions, comment }
520+
let clusterList = [] // Array of { clusterId, attributeIndex, attributeCount, attributeSize, eventIndex, eventCount, mask, functions, comment }
520521
let longDefaults = [] // Array of strings representing bytes
521522
let longDefaultsIndex = 0
522523
let minMaxIndex = 0
@@ -531,6 +532,7 @@ async function collectAttributes(endpointTypes, options) {
531532
let reportList = [] // Array of { direction, endpoint, clusterId, attributeId, mask, mfgCode, minOrSource, maxOrEndpoint, reportableChangeOrTimeout }
532533
let longDefaultsList = [] // Array of { value, size. comment }
533534
let attributeIndex = 0
535+
let eventIndex = 0
534536
let spaceForDefaultValue =
535537
options.spaceForDefaultValue !== undefined
536538
? options.spaceForDefaultValue
@@ -563,6 +565,8 @@ async function collectAttributes(endpointTypes, options) {
563565
attributeIndex: attributeIndex,
564566
attributeCount: c.attributes.length,
565567
attributeSize: 0,
568+
eventIndex: eventIndex,
569+
eventCount: c.events.length,
566570
mask: [],
567571
commands: [],
568572
functions: 'NULL',
@@ -573,6 +577,7 @@ async function collectAttributes(endpointTypes, options) {
573577

574578
clusterIndex++
575579
attributeIndex += c.attributes.length
580+
eventIndex += c.events.length
576581

577582
c.attributes.sort(zclUtil.attributeComparator)
578583

@@ -850,6 +855,19 @@ async function collectAttributes(endpointTypes, options) {
850855
commandMfgCodes.push(mfgCmd)
851856
}
852857
})
858+
859+
// Go over the events
860+
c.events.sort(zclUtil.eventComparator)
861+
862+
c.events.forEach((ev) => {
863+
let event = {
864+
eventId: asMEI(ev.manufacturerCode, ev.code),
865+
name: ev.name,
866+
comment: cluster.comment,
867+
}
868+
eventList.push(event)
869+
})
870+
853871
endpointAttributeSize += clusterAttributeSize
854872
cluster.attributeSize = clusterAttributeSize
855873
clusterList.push(cluster)
@@ -871,6 +889,7 @@ async function collectAttributes(endpointTypes, options) {
871889
clusterList: clusterList,
872890
attributeList: attributeList,
873891
commandList: commandList,
892+
eventList: eventList,
874893
longDefaults: longDefaults,
875894
clusterMfgCodes: clusterMfgCodes,
876895
commandMfgCodes: commandMfgCodes,
@@ -1011,11 +1030,12 @@ function endpoint_config(options) {
10111030
ept.clusters = clusters // Put 'clusters' into endpoint
10121031
let ps = []
10131032
clusters.forEach((cl) => {
1014-
// No client-side attributes or commands (at least for
1033+
// No client-side attributes, commands, and events (at least for
10151034
// endpoint_config purposes) in Matter.
10161035
if (cl.side == dbEnum.side.client) {
10171036
cl.attributes = []
10181037
cl.commands = []
1038+
cl.events = []
10191039
return
10201040
}
10211041
ps.push(
@@ -1042,6 +1062,13 @@ function endpoint_config(options) {
10421062
cl.commands = commands
10431063
})
10441064
)
1065+
ps.push(
1066+
queryEndpoint
1067+
.selectEndpointClusterEvents(db, cl.clusterId, ept.id)
1068+
.then((events) => {
1069+
cl.events = events
1070+
})
1071+
)
10451072
})
10461073
return Promise.all(ps)
10471074
})

src-electron/generator/matter/app/zap-templates/templates/app/helper.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ const TestHelper = require('../../common/ClusterTestGeneration.js');
3838
const kGlobalAttributes = [
3939
0xfff8, // GeneratedCommandList
4040
0xfff9, // AcceptedCommandList
41+
0xfffa, // EventList
4142
0xfffb, // AttributeList
4243
0xfffc, // ClusterRevision
4344
0xfffd, // FeatureMap
@@ -187,6 +188,28 @@ function chip_endpoint_generated_commands_list(options) {
187188
return templateUtil.collectBlocks(ret, options, this);
188189
}
189190

191+
function chip_endpoint_generated_event_count(options) {
192+
return this.eventList.length
193+
}
194+
195+
function chip_endpoint_generated_event_list(options) {
196+
let comment = null
197+
198+
let index = 0
199+
let ret = '{ \\\n'
200+
this.eventList.forEach((ev) => {
201+
if (ev.comment != comment) {
202+
ret += ` /* ${ev.comment} */ \\\n`
203+
ret += ` /* EventList (index=${index}) */ \\\n`
204+
comment = ev.comment
205+
}
206+
ret += ` ${ev.eventId}, /* ${ev.name} */ \\\n`
207+
index++
208+
})
209+
ret += '}\n'
210+
return ret
211+
}
212+
190213
/**
191214
* Return endpoint config GENERATED_CLUSTER MACRO
192215
* To be used as a replacement of endpoint_cluster_list since this one
@@ -258,6 +281,12 @@ function chip_endpoint_cluster_list() {
258281
} )`;
259282
}
260283

284+
let eventCount = c.eventCount;
285+
let eventList = 'nullptr';
286+
if (eventCount > 0) {
287+
eventList = `ZAP_GENERATED_EVENTS_INDEX( ${c.eventIndex} )`;
288+
}
289+
261290
ret = ret.concat(` { \\
262291
/* ${c.comment} */ \\
263292
.clusterId = ${c.clusterId}, \\
@@ -268,6 +297,8 @@ function chip_endpoint_cluster_list() {
268297
.functions = ${functionArray}, \\
269298
.acceptedCommandList = ${acceptedCommandsListVal} ,\\
270299
.generatedCommandList = ${generatedCommandsListVal} ,\\
300+
.eventList = ${eventList}, \\
301+
.eventCount = ${eventCount}, \\
271302
},\\\n`);
272303

273304
totalCommands = totalCommands + acceptedCommands + generatedCommands;
@@ -920,6 +951,8 @@ exports.chip_endpoint_cluster_list = chip_endpoint_cluster_list;
920951
exports.chip_endpoint_data_version_count = chip_endpoint_data_version_count;
921952
exports.chip_endpoint_generated_commands_list =
922953
chip_endpoint_generated_commands_list;
954+
exports.chip_endpoint_generated_event_count = chip_endpoint_generated_event_count;
955+
exports.chip_endpoint_generated_event_list = chip_endpoint_generated_event_list;
923956
exports.asTypedExpression = asTypedExpression;
924957
exports.asTypedLiteral = asTypedLiteral;
925958
exports.asLowerCamelCase = asLowerCamelCase;

src-electron/generator/matter/app/zap-templates/templates/chip/helper.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,7 @@ function chip_server_cluster_attributes(options) {
438438
}
439439

440440
/**
441-
* Creates block iterator over the server side cluster attributes
441+
* Creates block iterator over the server side cluster events
442442
* for a given cluster.
443443
*
444444
* This function is meant to be used inside a {{#chip_server_clusters}}

src-electron/util/zcl-util.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,23 @@ function commandComparator(a, b) {
7575
return 0
7676
}
7777

78+
/**
79+
* Comparator for sorting events.
80+
*
81+
* @param {*} a
82+
* @param {*} b
83+
* @returns -1, 0 or 1
84+
*/
85+
function eventComparator(a, b) {
86+
if (a.manufacturerCode < b.manufacturerCode) return -1
87+
if (a.manufacturerCode > b.manufacturerCode) return 1
88+
89+
if (a.code < b.code) return -1
90+
if (a.code > b.code) return 1
91+
92+
return 0
93+
}
94+
7895
function findStructByName(structs, name) {
7996
for (const s of structs) {
8097
if (s.name == name) {
@@ -783,6 +800,7 @@ async function createCommandSignature(db, packageId, cmd) {
783800
exports.clusterComparator = clusterComparator
784801
exports.attributeComparator = attributeComparator
785802
exports.commandComparator = commandComparator
803+
exports.eventComparator = eventComparator
786804
exports.sortStructsByDependency = sortStructsByDependency
787805
exports.isEnum = isEnum
788806
exports.isBitmap = isBitmap

test/gen-template/matter/endpoint-config.zapt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,13 @@
3737

3838
#define ZAP_GENERATED_COMMANDS_INDEX(index) ((chip::CommandId *) (&generatedCommands[index]))
3939

40+
// clang-format off
41+
#define GENERATED_EVENT_COUNT {{ chip_endpoint_generated_event_count }}
42+
#define GENERATED_EVENTS {{ chip_endpoint_generated_event_list }}
43+
// clang-format on
44+
45+
#define ZAP_GENERATED_EVENTS_INDEX(index) (&generatedEvents[index])
46+
4047
// Cluster function static arrays
4148
#define GENERATED_FUNCTION_ARRAYS {{chip_endpoint_generated_functions}}
4249

test/test-util.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ exports.totalMatterClusters = 58
123123
exports.totalMatterDeviceTypes = 40
124124
exports.totalMatterCommandArgs = 424
125125
exports.totalMatterCommands = 203
126-
exports.totalMatterAttributes = 509
126+
exports.totalMatterAttributes = 510
127127
exports.totalMatterTags = 15
128128
exports.totalMatterEvents = 56
129129
exports.totalMatterEventFields = 83

zcl-builtin/matter/global-attributes.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0"?>
22
<!--
3-
Copyright (c) 2021 Project CHIP Authors
3+
Copyright (c) 2021-2023 Project CHIP Authors
44
55
Licensed under the Apache License, Version 2.0 (the "License");
66
you may not use this file except in compliance with the License.
@@ -21,6 +21,7 @@ limitations under the License.
2121
<attribute side="client" code="0xFFFC" define="FEATURE_MAP_CLIENT" type="bitmap32" default="0" optional="true">FeatureMap</attribute>
2222
<attribute side="server" code="0xFFFC" define="FEATURE_MAP_SERVER" type="bitmap32" default="0" optional="true">FeatureMap</attribute>
2323
<attribute side="server" code="0xFFFB" define="ATTRIBUTE_LIST_SERVER" type="array" entryType="attrib_id">AttributeList</attribute>
24+
<attribute side="server" code="0xFFFA" define="EVENT_LIST" type="array" entryType="event_id">EventList</attribute>
2425
<attribute side="server" code="0xFFF9" define="ACCEPTED_COMMAND_LIST" type="array" entryType="command_id">AcceptedCommandList</attribute>
2526
<attribute side="server" code="0xFFF8" define="GENERATED_COMMAND_LIST" type="array" entryType="command_id">GeneratedCommandList</attribute>
2627

0 commit comments

Comments
 (0)