Skip to content

Commit

Permalink
final updates
Browse files Browse the repository at this point in the history
  • Loading branch information
emargolis committed Feb 1, 2023
1 parent 55b051b commit f99dd93
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 245 deletions.
24 changes: 0 additions & 24 deletions src-electron/db/query-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -905,30 +905,6 @@ async function insertDeviceTypeCommands(db, dtClusterRefDataPairs) {
)
}

/**
* This handles the loading of device type event requirements into the database.
* There is a need to post-process to attach the actual event ref after the fact
* @param {*} db
* @param {*} dtClusterRefDataPairs
*/
async function insertDeviceTypeEvents(db, dtClusterRefDataPairs) {
let events = []
dtClusterRefDataPairs.map((dtClusterRefDataPair) => {
let dtClusterRef = dtClusterRefDataPair.dtClusterRef
let clusterData = dtClusterRefDataPair.clusterData
if ('requiredEvents' in clusterData) {
clusterData.requiredEvents.forEach((eventName) => {
events.push([dtClusterRef, eventName])
})
}
})
return dbApi.dbMultiInsert(
db,
'INSERT INTO DEVICE_TYPE_EVENT (DEVICE_TYPE_CLUSTER_REF, EVENT_NAME) VALUES (?, ?)',
events
)
}

async function insertAccessOperations(db, packageId, operations) {
let data = operations.map((o) => [packageId, o.name, o.description])
return dbApi.dbMultiInsert(
Expand Down
23 changes: 20 additions & 3 deletions src-electron/generator/helper-endpointconfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -513,10 +513,12 @@ async function collectAttributes(endpointTypes, options) {
let commandMfgCodes = [] // Array of { index, mfgCode } objects
let clusterMfgCodes = [] // Array of { index, mfgCode } objects
let attributeMfgCodes = [] // Array of { index, mfgCode } objects
let eventMfgCodes = [] // Array of { index, mfgCode } objects
let eventList = []
let attributeList = []
let commandList = []
let endpointList = [] // Array of { clusterIndex, clusterCount, attributeSize }
let clusterList = [] // Array of { clusterId, attributeIndex, attributeCount, attributeSize, mask, functions, comment }
let clusterList = [] // Array of { clusterId, attributeIndex, attributeCount, attributeSize, eventIndex, eventCount, mask, functions, comment }
let longDefaults = [] // Array of strings representing bytes
let longDefaultsIndex = 0
let minMaxIndex = 0
Expand All @@ -531,6 +533,7 @@ async function collectAttributes(endpointTypes, options) {
let reportList = [] // Array of { direction, endpoint, clusterId, attributeId, mask, mfgCode, minOrSource, maxOrEndpoint, reportableChangeOrTimeout }
let longDefaultsList = [] // Array of { value, size. comment }
let attributeIndex = 0
let eventIndex = 0
let spaceForDefaultValue =
options.spaceForDefaultValue !== undefined
? options.spaceForDefaultValue
Expand Down Expand Up @@ -563,9 +566,10 @@ async function collectAttributes(endpointTypes, options) {
attributeIndex: attributeIndex,
attributeCount: c.attributes.length,
attributeSize: 0,
eventIndex: eventIndex,
eventCount: c.events.length,
mask: [],
commands: [],
events: [],
functions: 'NULL',
comment: `Endpoint: ${ept.endpointId}, Cluster: ${c.name} (${c.side})`,
}
Expand All @@ -574,6 +578,7 @@ async function collectAttributes(endpointTypes, options) {

clusterIndex++
attributeIndex += c.attributes.length
eventIndex += c.events.length

c.attributes.sort(zclUtil.attributeComparator)

Expand Down Expand Up @@ -854,12 +859,22 @@ async function collectAttributes(endpointTypes, options) {

// Go over the events
c.events.sort(zclUtil.eventComparator)

c.events.forEach((ev) => {
let event = {
eventId: asMEI(ev.manufacturerCode, ev.code),
name: ev.name,
comment: cluster.comment,
}
eventList.push(event)

if (ev.manufacturerCode) {
let mfgEv = {
index: eventList.length - 1,
mfgCode: ev.manufacturerCode,
}
eventMfgCodes.push(mfgEv)
}
cluster.events.push(event)
})

endpointAttributeSize += clusterAttributeSize
Expand All @@ -883,7 +898,9 @@ async function collectAttributes(endpointTypes, options) {
clusterList: clusterList,
attributeList: attributeList,
commandList: commandList,
eventList: eventList,
longDefaults: longDefaults,
eventMfgCodes: eventMfgCodes,
clusterMfgCodes: clusterMfgCodes,
commandMfgCodes: commandMfgCodes,
attributeMfgCodes: attributeMfgCodes,
Expand Down
179 changes: 12 additions & 167 deletions src-electron/generator/matter/app/zap-templates/templates/app/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,157 +188,23 @@ function chip_endpoint_generated_commands_list(options) {
return templateUtil.collectBlocks(ret, options, this);
}

function chip_endpoint_generated_event_count() {
let packageIds = templateUtil.ensureZclPackageIds(this)
let count = 0
this.clusterList.forEach((c) => {
queryEvents.selectEventsByClusterId(this.global.db, c.clusterId, packageIds).then((events) => {
events.forEach((event) => {
count++
});
});
});
return count
}

function chip_endpoint_generated_event_count2() {
let packageIds = templateUtil.ensureZclPackageIds(this)
let count = 0
this.clusterList.forEach((c) => {
queryEvents.selectEventsByClusterId(this.global.db, c.clusterId, packageIds).then((events) => {
count += events.length
});
});
return count
}

function chip_endpoint_generated_event_count3() {
let packageIds = templateUtil.ensureZclPackageIds(this)
let count = 0
this.clusterList.forEach((c) => {
queryEvents.selectEventsByClusterId(this.global.db, c.code, packageIds).then((events) => {
events.forEach((event) => {
count++
});
});
});
return count
}

function chip_endpoint_generated_event_count4() {
let packageIds = templateUtil.ensureZclPackageIds(this)
let count = 0
this.clusterList.forEach((c) => {
queryEvents.selectEventsByClusterId(this.global.db, c.code, packageIds).then((events) => {
count += events.length
});
});
return count
}

function chip_endpoint_generated_event_count5() {
return this.clusterList.length
}

function chip_endpoint_generated_event_count6() {
let count = 0
this.clusterList.forEach((c) => {
count++
});
return count
}

async function chip_endpoint_generated_event_count7() {
let count = 0
this.clusterList.forEach((c) => {
count++
});
return count
}

async function chip_endpoint_generated_event_count8() {
const { db, sessionId } = this.global;
const packageIds = await templateUtil.ensureZclPackageIds(this);

let count = 0
this.clusterList.forEach((c) => {
queryEvents.selectEventsByClusterId(db, c.clusterId, packageIds).then((events) => {
events.forEach((event) => {
count++
});
});
});
return count
}

async function chip_endpoint_generated_event_count9() {
const { db, sessionId } = this.global;
const packageIds = await templateUtil.ensureZclPackageIds(this);

let count = 0
this.clusterList.forEach((c) => {
queryEvents.selectEventsByClusterId(db, c.clusterId, packageIds).then((events) => {
count += events.length
});
});
return count
}

async function chip_endpoint_generated_event_count10() {
const { db, sessionId } = this.global;
const packageIds = await templateUtil.ensureZclPackageIds(this);

let count = 0
this.clusterList.forEach((c) => {
queryEvents.selectEventsByClusterId(db, c.code, packageIds).then((events) => {
events.forEach((event) => {
count++
});
});
});
return count
}

async function chip_endpoint_generated_event_count11() {
const { db, sessionId } = this.global;
const packageIds = await templateUtil.ensureZclPackageIds(this);

let count = 0
this.clusterList.forEach((c) => {
queryEvents.selectEventsByClusterId(db, c.code, packageIds).then((events) => {
count += events.length
});
});
return count
}

async function chip_endpoint_generated_event_count12() {
const { db, sessionId } = this.global;
const packageIds = await templateUtil.ensureZclPackageIds(this);

queryEvents.selectAllEvents(db, packageIds).then((events) => {
return events.length
});
return -1
function chip_endpoint_generated_event_count(options) {
return this.eventList.length
}

function chip_endpoint_generated_event_list(options) {
let packageIds = templateUtil.ensureZclPackageIds(this)
let comment = null

let index = 0
let ret = '{ \\\n'
this.clusterList.forEach((c) => {
let events = queryEvents.selectEventsByClusterId(this.global.db, c.clusterId, packageIds)

if (events.length > 0) {
ret += ` /* ${c.comment} */ \\\n`
this.eventList.forEach((ev) => {
if (ev.comment != comment) {
ret += ` /* ${ev.comment} */ \\\n`
ret += ` /* EventList (index=${index}) */ \\\n`
comment = ev.comment
}

events.forEach((ev) => {
let eventId = asMEI(ev.manufacturerCode, ev.code)
ret += ` ${eventId}, /* ${ev.name} */ \\\n`
index++
})
ret += ` ${ev.eventId}, /* ${ev.name} */ \\\n`
index++
})
ret += '}\n'
return ret
Expand All @@ -352,7 +218,6 @@ function chip_endpoint_generated_event_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;
Expand Down Expand Up @@ -416,15 +281,6 @@ function chip_endpoint_cluster_list() {
} )`;
}

let packageIds = templateUtil.ensureZclPackageIds(this)
let events = queryEvents.selectEventsByClusterId(this.global.db, c.clusterId, packageIds)
let generatedEventListVal = 'nullptr';
let generatedEventCount = events.length;
if (generatedEventCount > 0) {
totalEvents += generatedEventCount;
generatedEventListVal = `ZAP_GENERATED_EVENTS_INDEX( ${totalEvents} )`;
}

ret = ret.concat(` { \\
/* ${c.comment} */ \\
.clusterId = ${c.clusterId}, \\
Expand All @@ -435,8 +291,8 @@ function chip_endpoint_cluster_list() {
.functions = ${functionArray}, \\
.acceptedCommandList = ${acceptedCommandsListVal} ,\\
.generatedCommandList = ${generatedCommandsListVal} ,\\
.eventList = ${generatedEventListVal}, \\
.eventCount = ${generatedEventCount}, \\
.eventList = ZAP_GENERATED_EVENTS_INDEX(${c.eventIndex}), \\
.eventCount = ${c.eventCount}, \\
},\\\n`);

totalCommands = totalCommands + acceptedCommands + generatedCommands;
Expand Down Expand Up @@ -1090,17 +946,6 @@ 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_count2 = chip_endpoint_generated_event_count2;
exports.chip_endpoint_generated_event_count3 = chip_endpoint_generated_event_count3;
exports.chip_endpoint_generated_event_count4 = chip_endpoint_generated_event_count4;
exports.chip_endpoint_generated_event_count5 = chip_endpoint_generated_event_count5;
exports.chip_endpoint_generated_event_count6 = chip_endpoint_generated_event_count6;
exports.chip_endpoint_generated_event_count7 = chip_endpoint_generated_event_count7;
exports.chip_endpoint_generated_event_count8 = chip_endpoint_generated_event_count8;
exports.chip_endpoint_generated_event_count9 = chip_endpoint_generated_event_count9;
exports.chip_endpoint_generated_event_count10 = chip_endpoint_generated_event_count10;
exports.chip_endpoint_generated_event_count11 = chip_endpoint_generated_event_count11;
exports.chip_endpoint_generated_event_count12 = chip_endpoint_generated_event_count12;
exports.chip_endpoint_generated_event_list = chip_endpoint_generated_event_list;
exports.asTypedExpression = asTypedExpression;
exports.asTypedLiteral = asTypedLiteral;
Expand Down
5 changes: 0 additions & 5 deletions src-electron/zcl/zcl-loader-dotdot.js
Original file line number Diff line number Diff line change
Expand Up @@ -612,16 +612,12 @@ function prepareDeviceType(deviceType) {
cluster.include.forEach((include) => {
let attributes = []
let commands = []
let events = []
if ('requireAttribute' in include) {
attributes = include.requireAttribute
}
if ('requireCommand' in include) {
commands = include.requireCommand
}
if ('requireEvent' in include) {
events = include.requireEvent
}
ret.clusters.push({
client: 'true' == include.$.client,
server: 'true' == include.$.server,
Expand All @@ -631,7 +627,6 @@ function prepareDeviceType(deviceType) {
include.$.cluster != undefined ? include.$.cluster : include._,
requiredAttributes: attributes,
requiredCommands: commands,
requiredEvents: events,
})
})
}
Expand Down
5 changes: 0 additions & 5 deletions src-electron/zcl/zcl-loader-silabs.js
Original file line number Diff line number Diff line change
Expand Up @@ -1492,16 +1492,12 @@ function prepareDeviceType(deviceType) {
cluster.include.forEach((include) => {
let attributes = []
let commands = []
let events = []
if ('requireAttribute' in include) {
attributes = include.requireAttribute
}
if ('requireCommand' in include) {
commands = include.requireCommand
}
if ('requireEvent' in include) {
events = include.requireEvent
}
ret.clusters.push({
client: 'true' == include.$.client,
server: 'true' == include.$.server,
Expand All @@ -1511,7 +1507,6 @@ function prepareDeviceType(deviceType) {
include.$.cluster != undefined ? include.$.cluster : include._,
requiredAttributes: attributes,
requiredCommands: commands,
requiredEvents: events,
})
})
}
Expand Down
Loading

0 comments on commit f99dd93

Please sign in to comment.