Skip to content
代码片段 群组 项目
未验证 提交 9303ae4b 编辑于 作者: Timotej Ecimovic's avatar Timotej Ecimovic 提交者: GitHub
浏览文件

Merge pull request #134 from tecimovic/silabs

Silabs
No related branches found
No related tags found
无相关合并请求
显示
405 个添加261 个删除
......@@ -4,7 +4,7 @@ label=Zigbee Cluster Configurator
description=Graphical configuration tool for application and libraries based on Zigbee Cluster Library.
path=.,node_modules/.bin/,ZAP.app/Contents/MacOS
requiredFeatureLevel=apack.core:8
featureLevel=25
featureLevel=27
id=zclConfigurator
......@@ -26,33 +26,12 @@ executable(zap:macosx.x86_64) {
optional=true
}
executable(zap_regen:win32.x86_64) {
exe=zap.exe
optional=true
}
executable(zap_regen:linux.x86_64) {
exe=zap
optional=true
}
executable(zap_regen:macosx.x86_64) {
exe=zap.app/Contents/MacOS/zap
optional=true
}
executable(zap) {
engine=node
optional=true
exe=src-script/zap-start.js
}
executable(zap_regen) {
engine=node
optional=true
exe=src-script/zap-generate.js
}
function(ui:uc_cli) {
cmd=$(zap)
}
......@@ -66,7 +45,7 @@ function(version:uc_cli) {
}
function(uc_generate) {
cmd=$(zap_regen) generate --noUi --noServer -o ${generationOutput} --zcl ${sdkRoot}/app/zcl/zcl-zap.json --generationTemplate ${sdkRoot}/protocol/zigbee/app/framework/gen-template/gen-templates.json --in ${contentFolder}
cmd=$(zap) generate --noUi --noServer -o ${generationOutput} --zcl ${sdkRoot}/app/zcl/zcl-zap.json --generationTemplate ${sdkRoot}/protocol/zigbee/app/framework/gen-template/gen-templates.json --in ${contentFolder}
}
function(zapHelp) {
......
# Frequently Asked Questions
**Q: How to start up UI in a development mode?**
**A:**
You can start UI in a development mode, which will result in a
following setup:
- separate quasar development HTTP server which does live refresh on port 8080
- zap backend running on port 9070
- chrome or other browser, running independently
In order to get to that setup, follow this instructions.
1. First run the zap development server (which starts on port 9070)
```
npm run zap-devserver
```
2. Then run the quasar development server (which starts on port 8080)
```
quasar dev
```
3. Point your browser or run one against the proper URL with the `restPort` argument:
```
google-chrome http://localhost:8080/?restPort=9070
```
---
**Q: How to make this work on Mac/Linux?**
**A:**
......@@ -24,7 +57,7 @@ src-script/install-packages-fedora
```
apt-get update
apt-get install --fix-missing libpixman-1-dev libcairo-dev libsdl-pango-dev libjpeg-dev libgif-dev
apt-get install --fix-missing libpixman-1-dev libcairo-dev libsdl-pango-dev libjpeg-dev libgif-devhttp://localhost:8080
```
or run script:
......
......@@ -13,11 +13,14 @@
SC_HOME=~/schemacrawler-16.4.1-distribution/
SC_BIN=${SC_HOME}/_schemacrawler/schemacrawler.sh
SQLITE=~/.zap/zap.sqlite
SQLITE=~/.zap/self-check.sqlite
SVG=zap-schema.svg
echo "Creating schema diagram to ${SVG} from database at ${SQLITE} ..."
echo "First run self-check to make sure database is present..."
npm run self-check
if [ ! -s ${SQLITE} ]; then
echo ""
echo "Can't locate ${SQLITE} file. Database file is required to read schema from."
......
此差异已折叠。
{
"name": "zap",
"version": "0.99.6",
"featureLevel": 26,
"featureLevel": 27,
"description": "Configuration tool for the Zigbee Cluster Library",
"productName": "zap",
"cordovaId": "",
......@@ -27,6 +27,7 @@
"test:unit:watchAll": "jest --watchAll",
"postinstall": "electron-builder install-app-deps && husky install",
"zap": "node src-script/zap-start.js --logToStdout --gen ./test/gen-template/zigbee/gen-templates.json",
"zap-devserver": "node src-script/zap-start.js server --allowCors --logToStdout --gen ./test/gen-template/zigbee/gen-templates.json",
"zap-server": "node src-script/zap-start.js server --logToStdout --gen ./test/gen-template/zigbee/gen-templates.json --reuseZapInstance",
"zap-status": "node src-script/zap-start.js status --reuseZapInstance",
"zaphelp": "node src-script/zap-start.js --help",
......@@ -43,10 +44,12 @@
"gen": "node src-script/zap-generate.js --stateDirectory ~/.zap/gen -z ./zcl-builtin/silabs/zcl.json -g ./test/gen-template/zigbee/gen-templates.json -i ./test/resource/three-endpoint-device.zap -o ./tmp",
"gen2": "node src-script/zap-generate.js -z ./zcl-builtin/silabs/zcl.json -g ./test/gen-template/zigbee/gen-templates.json -i ./test/resource/generation-test-file-1.zap -o ./tmp",
"gen3": "node src-script/zap-generate.js --stateDirectory ~/.zap/gen3 -z ./zcl-builtin/dotdot/library.xml -g ./test/gen-template/zigbee/gen-templates.json -i ./test/resource/generation-test-file-1.zap -o ./tmp",
"convert": "node src-script/zap-convert.js -o {basename}.zap -z ./zcl-builtin/silabs/zcl.json -g test/gen-template/zigbee/gen-templates.json ./test/resource/test-light.isc ./test/resource/*.zap",
"genchip": "node src-script/zap-generate.js --stateDirectory ~/.zap/genchip -z ./zcl-builtin/silabs/zcl.json -g ./test/gen-template/chip/gen-test.json -i ./test/resource/chip/chip_test.zap -o ./tmp",
"gendotdot": "node src-script/zap-generate.js -z ./zcl-builtin/dotdot/library.xml -g ./test/gen-template/dotdot/dotdot-templates.json -o ./tmp",
"genblank": "node src-script/zap-generate.js -z ./zcl-builtin/silabs/zcl.json -g ./test/gen-template/zigbee/gen-templates.json -o ./tmp",
"convert": "node src-script/zap-convert.js -o {basename}.zap -z ./zcl-builtin/silabs/zcl.json -g test/gen-template/zigbee/gen-templates.json ./test/resource/isc/*.isc ./test/resource/*.zap",
"convert-dl": "node src-script/zap-convert.js -o {basename}.zap -z ./zcl-builtin/silabs/zcl.json -g test/gen-template/zigbee/gen-templates.json ./test/resource/isc/ha-door-lock.isc",
"analyze": "node src-script/zap-start.js analyze -z ./zcl-builtin/silabs/zcl.json -g ./test/gen-template/zigbee/gen-templates.json ./test/resource/three-endpoint-device.zap -o ./tmp",
"genchip": "node src-script/zap-generate.js --stateDirectory ~/.zap/genchip -z ./zcl-builtin/silabs/zcl.json -g ./test/gen-template/chip/gen-test.json -i ./test/resource/chip/chip_test.zap -o ./tmp",
"pack": "node src-script/build-spa.js && electron-builder --dir",
"dist": "electron-builder",
"dist-all": "electron-builder -mwl",
......
......@@ -101,7 +101,12 @@ module.exports = function (ctx) {
devServer: {
https: false,
port: 8080,
open: true, // opens browser window automatically
open: false,
headers: {
// 'Access-Control-Allow-Methods': 'GET, POST, PUT, PATCH, DELETE, OPTIONS',
// 'Access-Control-Allow-Headers': 'Content-Type, Authorization',
'Access-Control-Allow-Origin': '*',
},
},
// animations: 'all', // --- includes all animations
......
......@@ -275,6 +275,7 @@ exports.map = {
endpointTypeRef: x.ENDPOINT_TYPE_REF,
profileId: x.PROFILE,
networkId: x.NETWORK_IDENTIFIER,
endpointVersion: x.ENDPOINT_VERSION,
}
},
endpointType: (x) => {
......@@ -387,5 +388,6 @@ exports.reverseMap = {
endpointTypeRef: 'ENDPOINT_TYPE_REF',
profileId: 'PROFILE',
networkId: 'NETWORK_IDENTIFIER',
endpointVersion: 'ENDPOINT_VERSION',
},
}
......@@ -195,6 +195,8 @@ function convertRestKeyToDbColumn(key) {
return 'ENDPOINT_TYPE_REF'
case restApi.updateKey.networkId:
return 'NETWORK_IDENTIFIER'
case restApi.updateKey.endpointVersion:
return 'ENDPOINT_VERSION'
case restApi.updateKey.deviceTypeRef:
return 'DEVICE_TYPE_REF'
case restApi.updateKey.name:
......@@ -361,14 +363,15 @@ async function insertEndpoint(
sessionId,
endpointIdentifier,
endpointTypeRef,
networkIdentifier
networkIdentifier,
endpointVersion
) {
return dbApi.dbInsert(
db,
`
INSERT OR REPLACE
INTO ENDPOINT ( SESSION_REF, ENDPOINT_IDENTIFIER, ENDPOINT_TYPE_REF, NETWORK_IDENTIFIER, PROFILE)
VALUES ( ?, ?, ?, ?,
INTO ENDPOINT ( SESSION_REF, ENDPOINT_IDENTIFIER, ENDPOINT_TYPE_REF, NETWORK_IDENTIFIER, ENDPOINT_VERSION, PROFILE)
VALUES ( ?, ?, ?, ?, ?,
( SELECT DEVICE_TYPE.PROFILE_ID
FROM DEVICE_TYPE, ENDPOINT_TYPE
WHERE ENDPOINT_TYPE.ENDPOINT_TYPE_ID = ?
......@@ -378,6 +381,7 @@ VALUES ( ?, ?, ?, ?,
endpointIdentifier,
endpointTypeRef,
networkIdentifier,
endpointVersion,
endpointTypeRef,
]
)
......@@ -453,7 +457,8 @@ SELECT
ENDPOINT_TYPE_REF,
PROFILE,
ENDPOINT_IDENTIFIER,
NETWORK_IDENTIFIER
NETWORK_IDENTIFIER,
ENDPOINT_VERSION
FROM ENDPOINT
WHERE SESSION_REF = ?
ORDER BY ENDPOINT_IDENTIFIER
......@@ -468,10 +473,10 @@ ORDER BY ENDPOINT_IDENTIFIER
* Mayb resolve into null if invalid reference.
*
* @param {*} db
* @param {*} endpointRef
* @param {*} endpointId
* @returns Promise of an endpoint.
*/
async function selectEndpoint(db, endpointRef) {
async function selectEndpoint(db, endpointId) {
return dbApi
.dbGet(
db,
......@@ -482,10 +487,11 @@ SELECT
ENDPOINT_IDENTIFIER,
ENDPOINT_TYPE_REF,
PROFILE,
NETWORK_IDENTIFIER
NETWORK_IDENTIFIER,
ENDPOINT_VERSION
FROM ENDPOINT
WHERE ENDPOINT_ID = ?`,
[endpointRef]
[endpointId]
)
.then(dbMapping.map.endpoint)
}
......@@ -1242,11 +1248,27 @@ ORDER BY
async function setClusterIncluded(
db,
packageId,
endpointTypeId,
clusterCode,
isIncluded,
side
) {
return true
let cluster = await queryZcl.selectClusterByCode(db, packageId, clusterCode)
let clusterState = await getClusterState(db, endpointTypeId, cluster.id, side)
let insertDefaults = clusterState == null
await insertOrReplaceClusterState(
db,
endpointTypeId,
cluster.id,
side,
isIncluded
)
if (insertDefaults) {
await insertClusterDefaults(db, endpointTypeId, {
clusterRef: cluster.id,
side: side,
})
}
}
// exports
......
......@@ -39,12 +39,14 @@ INSERT INTO ENDPOINT (
ENDPOINT_TYPE_REF,
PROFILE,
ENDPOINT_IDENTIFIER,
NETWORK_IDENTIFIER
NETWORK_IDENTIFIER,
ENDPOINT_VERSION
) VALUES (
?,
?,
?,
?,
?,
?
)
`,
......@@ -54,6 +56,7 @@ INSERT INTO ENDPOINT (
endpoint.profileId,
endpoint.endpointId,
endpoint.networkId,
endpoint.endpointVersion,
]
)
}
......@@ -77,6 +80,7 @@ async function exportEndpoints(db, sessionId, endpointTypes) {
profileId: x.PROFILE,
endpointId: x.ENDPOINT_IDENTIFIER,
networkId: x.NETWORK_IDENTIFIER,
endpointVersion: x.ENDPOINT_VERSION,
}
}
return dbApi
......@@ -88,7 +92,8 @@ SELECT
ENDPOINT.ENDPOINT_TYPE_REF,
ENDPOINT.PROFILE,
ENDPOINT.ENDPOINT_IDENTIFIER,
ENDPOINT.NETWORK_IDENTIFIER
ENDPOINT.NETWORK_IDENTIFIER,
ENDPOINT.ENDPOINT_VERSION
FROM
ENDPOINT
LEFT JOIN
......
......@@ -262,6 +262,19 @@ ORDER BY CODE`,
.then((rows) => rows.map(dbMapping.map.cluster))
}
async function selectClusterByCode(db, packageId, code, mfgCode = null) {
let query
let args
if (mfgCode == null) {
query = `SELECT CLUSTER_ID, CODE, MANUFACTURER_CODE, NAME, DESCRIPTION, DEFINE, DOMAIN_NAME, IS_SINGLETON FROM CLUSTER WHERE PACKAGE_REF = ? AND CODE = ? AND MANUFACTURER_CODE IS NULL`
args = [packageId, code]
} else {
query = `SELECT CLUSTER_ID, CODE, MANUFACTURER_CODE, NAME, DESCRIPTION, DEFINE, DOMAIN_NAME, IS_SINGLETON FROM CLUSTER WHERE PACKAGE_REF = ? AND CODE = ? AND MANUFACTURER_CODE = ?`
args = [packageId, code, mfgCode]
}
return dbApi.dbGet(db, query, args).then(dbMapping.map.cluster)
}
/**
* Returns a promise that resolves into a cluster.
*
......@@ -1958,6 +1971,7 @@ exports.selectAllStructItemsById = selectAllStructItemsById
exports.selectAllStructItemsByStructName = selectAllStructItemsByStructName
exports.selectAllClusters = selectAllClusters
exports.selectClusterById = selectClusterById
exports.selectClusterByCode = selectClusterByCode
exports.selectAllDeviceTypes = selectAllDeviceTypes
exports.selectDeviceTypeById = selectDeviceTypeById
exports.selectDeviceTypeByCodeAndName = selectDeviceTypeByCodeAndName
......
......@@ -525,6 +525,7 @@ CREATE TABLE IF NOT EXISTS "ENDPOINT" (
"PROFILE" integer,
"ENDPOINT_IDENTIFIER" integer,
"NETWORK_IDENTIFIER" integer,
"ENDPOINT_VERSION" integer,
foreign key (SESSION_REF) references SESSION(SESSION_ID) on delete cascade,
foreign key (ENDPOINT_TYPE_REF) references ENDPOINT_TYPE(ENDPOINT_TYPE_ID) on delete
set NULL
......
......@@ -110,10 +110,10 @@ function subentityExtension(context, prop, entityType) {
} else {
let val = null
f[0].defaults.forEach((d) => {
if (
d.entityCode == context.code &&
d.parentCode == context.clusterCode
) {
let clusterCode = context.clusterCode
if (clusterCode == null && context.parent)
clusterCode = context.parent.code
if (d.entityCode == context.code && d.parentCode == clusterCode) {
val = d.value
}
})
......@@ -155,6 +155,23 @@ function if_extension_true(options) {
})
}
function if_extension_false(options) {
let prop = options.hash.property
if (prop == '') return ''
return subentityExtension(
this,
prop,
dbEnum.packageExtensionEntity.command
).then((val) => {
if (val == false || val == 0) {
return options.fn(this)
} else {
return ''
}
})
}
/**
* When inside a context that contains 'code' and parent 'code', this
* helper will output the value of the attribute extension
......@@ -173,3 +190,4 @@ exports.command_extension = command_extension
exports.attribute_extension = attribute_extension
exports.device_type_extension = device_type_extension
exports.if_extension_true = if_extension_true
exports.if_extension_false = if_extension_false
......@@ -193,22 +193,24 @@ function all_user_cluster_command_util(
endpointTypes
)
)
.then((endpointsAndClusters) =>
isIrrespectiveOfManufacturingSpecification
? queryZcl.exportCommandDetailsFromAllEndpointTypesAndClusters(
currentContext.global.db,
endpointsAndClusters
)
: isManufacturingSpecific
? queryZcl.exportManufacturerSpecificCommandDetailsFromAllEndpointTypesAndClusters(
currentContext.global.db,
endpointsAndClusters
)
: queryZcl.exportNonManufacturerSpecificCommandDetailsFromAllEndpointTypesAndClusters(
currentContext.global.db,
endpointsAndClusters
)
)
.then((endpointsAndClusters) => {
if (isIrrespectiveOfManufacturingSpecification) {
return queryZcl.exportCommandDetailsFromAllEndpointTypesAndClusters(
currentContext.global.db,
endpointsAndClusters
)
} else if (isManufacturingSpecific) {
return queryZcl.exportManufacturerSpecificCommandDetailsFromAllEndpointTypesAndClusters(
currentContext.global.db,
endpointsAndClusters
)
} else {
return queryZcl.exportNonManufacturerSpecificCommandDetailsFromAllEndpointTypesAndClusters(
currentContext.global.db,
endpointsAndClusters
)
}
})
.then(
(endpointCommands) =>
new Promise((resolve, reject) => {
......
......@@ -117,6 +117,7 @@ function parseZclAfv2Line(state, line) {
// Create a temporary state.endpointType
state.endpointType = {
typeName: line.substring('beginEndpointType:'.length),
clusterOverride: [],
}
} else if (line.startsWith('endEndpointType')) {
// Stick the endpoint into `state.endpointTypes[endpointType.typeName]'
......@@ -138,7 +139,7 @@ function parseZclAfv2Line(state, line) {
isIncluded: idOnOff[1] == 'yes',
side: dbEnum.side.client,
}
state.clusterOverride.push(override)
state.endpointType.clusterOverride.push(override)
} else if (line.startsWith('overrideServerCluster:')) {
let idOnOff = line.substring('overrideServerCluster:'.length).split(',')
let override = {
......@@ -146,7 +147,7 @@ function parseZclAfv2Line(state, line) {
isIncluded: idOnOff[1] == 'yes',
side: dbEnum.side.server,
}
state.clusterOverride.push(override)
state.endpointType.clusterOverride.push(override)
} else if (line == 'beginAttributeDefaults') {
state.parseState = line
} else if (line == 'endAttributeDefaults') {
......@@ -250,7 +251,6 @@ async function readIscData(filePath, data, zclMetafile) {
parseState: 'init',
// These are not the same as with zap files
attributeType: [],
clusterOverride: [],
zclMetafile: zclMetafile,
}
......@@ -489,14 +489,35 @@ async function iscDataLoader(db, state, sessionId) {
for (let key in endpointTypes) {
promises.push(
loadEndpointType(db, sessionId, packageId, endpointTypes[key]).then(
(newEndpointTypeId) => {
loadEndpointType(db, sessionId, packageId, endpointTypes[key])
.then((newEndpointTypeId) => {
return {
endpointTypeId: newEndpointTypeId,
endpointType: endpointTypes[key],
}
}
)
})
.then((endpointTypeIds) => {
// Now load the cluster configs
let clusterOverridePromises = []
endpointTypes[key].clusterOverride.forEach((cl) => {
let clusterCode = cl.clusterId
let isIncluded = cl.isIncluded
let side = cl.side
clusterOverridePromises.push(
queryConfig.setClusterIncluded(
db,
packageId,
endpointTypeIds.endpointTypeId,
clusterCode,
isIncluded,
side
)
)
})
return Promise.all(clusterOverridePromises).then(
() => endpointTypeIds
)
})
)
}
......@@ -521,7 +542,8 @@ async function iscDataLoader(db, state, sessionId) {
sessionId,
ep.endpoint,
endpointTypeId,
ep.network
ep.network,
ep.deviceVersion
)
)
}
......@@ -534,30 +556,11 @@ async function iscDataLoader(db, state, sessionId) {
results.map((r) => r.endpointTypeId)
)
let individualOverridePromises = []
if (state.clusterOverride.length > 0) {
state.clusterOverride.forEach((cl) => {
let clusterCode = cl.clusterId
let isIncluded = cl.isIncluded
let side = cl.side
individualOverridePromises.push(
queryConfig.setClusterIncluded(
db,
packageId,
clusterCode,
isIncluded,
side
)
)
})
}
if (state.log != null) {
querySession.writeLog(db, sessionId, state.log)
}
return Promise.all(endpointInsertionPromises)
.then(() => Promise.all(individualOverridePromises))
.then(() => Promise.all(attributeUpdatePromises))
.then(() => querySession.setSessionClean(db, sessionId))
.then(() => {
......
......@@ -52,6 +52,7 @@ async function readDataFromFile(
/**
* Writes the data from the file into a new session.
* NOTE: This function does NOT initialize session packages.
*
* @export
* @param {*} db
......
......@@ -89,6 +89,7 @@ async function startNormal(
.initHttpServer(ctx.db, argv.httpPort, argv.studioHttpPort, {
zcl: argv.zclProperties,
template: argv.generationTemplate,
allowCors: argv.allowCors,
})
.then(() => {
ipcServer.initServer(ctx.db, argv.httpPort)
......@@ -136,10 +137,15 @@ async function startNormal(
*/
function outputFile(inputFile, outputPattern) {
let output = outputPattern
let hadDir = false
if (output.startsWith('{dir}/')) {
let dir = path.dirname(inputFile)
output = path.join(dir, output.substring(6))
} else if (output.includes('{')) {
hadDir = true
}
if (output.includes('{')) {
let dir = path.dirname(inputFile)
let name = path.basename(inputFile)
let basename
......@@ -151,11 +157,43 @@ function outputFile(inputFile, outputPattern) {
}
output = output.replace('{name}', name)
output = output.replace('{basename}', basename)
output = path.join(dir, output)
if (!hadDir) output = path.join(dir, output)
}
return output
}
const BLANK_SESSION = '-- blank session --'
/**
* This method gathers all the files to process.
*
* @param {*} filesArg array of files arguments
* @param {*} options
*/
function gatherFiles(filesArg, options = { suffix: '.zap', doBlank: true }) {
let list = []
if (filesArg == null || filesArg.length == 0) {
if (options.doBlank) list.push(BLANK_SESSION)
} else {
filesArg.forEach((f) => {
let stat = fs.statSync(f)
if (stat.isDirectory()) {
let dirents = fs.readdirSync(f, { withFileTypes: true })
dirents.forEach((element) => {
if (
element.name.endsWith(options.suffix.toLowerCase()) ||
element.name.endsWith(options.suffix.toUpperCase())
) {
list.push(path.join(f, element.name))
}
})
} else {
list.push(f)
}
})
}
return list
}
/**
* Perform file conversion.
*
......@@ -171,9 +209,9 @@ async function startConvert(
) {
let files = argv.zapFiles
let output = argv.output
options.logger(`🤖 Conversion started`)
options.logger(` 🔍 input files: ${files}`)
options.logger(` 🔍 output pattern: ${output}`)
options.logger(`🤖 Conversion started
🔍 input files: ${files}
🔍 output pattern: ${output}`)
let dbFile = env.sqliteFile('convert')
let db = await dbApi.initDatabaseAndLoadSchema(
......@@ -320,6 +358,7 @@ async function startServer(argv, options = {}) {
.initHttpServer(ctx.db, argv.httpPort, argv.studioHttpPort, {
zcl: argv.zclProperties,
template: argv.generationTemplate,
allowCors: argv.allowCors,
})
.then(() => {
ipcServer.initServer(ctx.db, argv.httpPort)
......@@ -389,6 +428,46 @@ async function startSelfCheck(
})
}
async function generateSingleFile(
db,
f,
packageId,
outputPattern,
options = {
logger: console.log,
zcl: env.builtinSilabsZclMetafile,
template: env.builtinTemplateMetafile,
}
) {
let sessionId
let output
if (f === BLANK_SESSION) {
options.logger(`👉 using empty configuration`)
sessionId = await querySession.createBlankSession(db)
output = outputPattern
} else {
options.logger(`👉 using input file: ${f}`)
let importResult = await importJs.importDataFromFile(db, f)
sessionId = importResult.sessionId
output = outputFile(f, outputPattern)
}
options.logger(`👉 using output destination: ${output}`)
await util.initializeSessionPackage(db, sessionId, options)
let genResult = await generatorEngine.generateAndWriteFiles(
db,
sessionId,
packageId,
output,
options
)
if (genResult.hasErrors) throw new Error(`Generation failed: ${f}`)
return genResult
}
/**
* Performs headless regeneration for given parameters.
*
......@@ -410,53 +489,14 @@ async function startGeneration(
let skipPostGeneration = argv.skipPostGeneration
options.logger(
`🤖 ZAP generation information:
👉 into: ${output}
👉 using templates: ${templateMetafile}
👉 using zcl data: ${zclProperties}`
`🤖 ZAP generation started:
🔍 input files: ${zapFiles}
🔍 output pattern: ${output}
🔍 using templates: ${templateMetafile}
🔍 using zcl data: ${zclProperties}
🔍 zap version: ${env.zapVersionAsString()}`
)
let zapFile = null
if (zapFiles != null && zapFiles.length > 0) {
zapFile = zapFiles[0]
if (zapFiles.length > 1) {
options.logger(` ⚠️ Multiple files passed. Using only first one.`)
}
}
if (zapFile != null) {
if (fs.existsSync(zapFile)) {
let stat = fs.statSync(zapFile)
if (stat.isDirectory()) {
options.logger(` 👉 using input directory: ${zapFile}`)
let dirents = fs.readdirSync(zapFile, { withFileTypes: true })
let usedFile = []
dirents.forEach((element) => {
if (element.name.endsWith('.zap') || element.name.endsWith('.ZAP')) {
usedFile.push(path.join(zapFile, element.name))
}
})
if (usedFile.length == 0) {
options.logger(` 👎 no zap files found in directory: ${zapFile}`)
throw `👎 no zap files found in directory: ${zapFile}`
} else if (usedFile.length > 1) {
options.logger(
` 👎 multiple zap files found in directory, only one is allowed: ${zapFile}`
)
throw `👎 multiple zap files found in directory, only one is allowed: ${zapFile}`
} else {
zapFile = usedFile[0]
options.logger(` 👉 using input file: ${zapFile}`)
}
} else {
options.logger(` 👉 using input file: ${zapFile}`)
}
} else {
options.logger(` 👎 file not found: ${zapFile}`)
throw `👎 file not found: ${zapFile}`
}
} else {
options.logger(` 👉 using empty configuration`)
}
options.logger(` 👉 zap version: ${env.zapVersionAsString()}`)
let dbFile = env.sqliteFile('generate')
if (options.cleanDb && fs.existsSync(dbFile)) fs.unlinkSync(dbFile)
let mainDb = await dbApi.initDatabaseAndLoadSchema(
......@@ -464,43 +504,31 @@ async function startGeneration(
env.schemaFile(),
env.zapVersion()
)
let ctx = await zclLoader.loadZcl(mainDb, zclProperties)
ctx = await generatorEngine.loadTemplates(ctx.db, templateMetafile)
if (ctx.error) {
throw ctx.error
}
let packageId = ctx.packageId
let sessionId
if (zapFile == null) {
sessionId = await querySession.createBlankSession(mainDb)
} else {
let importResult = await importJs.importDataFromFile(mainDb, zapFile)
sessionId = importResult.sessionId
let files = gatherFiles(zapFiles, { suffix: '.zap', doBlank: true })
if (files.length == 0) {
options.logger(` 👎 no zap files found in: ${zapFiles}`)
throw `👎 no zap files found in: ${zapFiles}`
}
await util.initializeSessionPackage(mainDb, sessionId, {
zcl: zclProperties,
template: templateMetafile,
})
options.zcl = zclProperties
options.template = templateMetafile
options.backup = false
options.genResultFile = genResultFile
options.skipPostGeneration = skipPostGeneration
let packageId = ctx.packageId
let genResult = await generatorEngine.generateAndWriteFiles(
mainDb,
sessionId,
packageId,
output,
{
logger: options.logger,
backup: false,
genResultFile: genResultFile,
skipPostGeneration: skipPostGeneration,
}
await util.executePromisesSequentially(files, (f) =>
generateSingleFile(mainDb, f, packageId, output, options)
)
if (genResult.hasErrors) throw 'Generation failed.'
if (options.quit && app != null) app.quit()
return genResult
}
/**
* Move database file out of the way into the backup location.
......
......@@ -70,10 +70,17 @@ function httpDeleteEndpointType(db) {
*/
function httpPostEndpoint(db) {
return (request, response) => {
let { endpointId, networkId, endpointType } = request.body
let { endpointId, networkId, endpointType, endpointVersion } = request.body
let sessionIdexport = request.zapSessionId
queryConfig
.insertEndpoint(db, sessionIdexport, endpointId, endpointType, networkId)
.insertEndpoint(
db,
sessionIdexport,
endpointId,
endpointType,
networkId,
endpointVersion
)
.then((newId) =>
validation.validateEndpoint(db, newId).then((validationData) => {
response.json({
......@@ -81,6 +88,7 @@ function httpPostEndpoint(db) {
endpointId: endpointId,
endpointType: endpointType,
networkId: networkId,
endpointVersion: endpointVersion,
validationIssues: validationData,
})
})
......@@ -92,16 +100,20 @@ function httpPostEndpoint(db) {
/**
* HTTP POST: endpoint
*
* @param {*} db
* @param {*} db Main database to use for the operation.
* @returns callback for the express uri registration
*/
function httpPatchEndpoint(db) {
return (request, response) => {
let { context } = request.body
let context = request.body
let sessionIdexport = request.zapSessionId
let changes = context.changes.map((data) => {
let paramType = ''
return { key: data.updatedKey, value: data.value, type: paramType }
return {
key: data.updatedKey,
value: data.value,
type: paramType,
}
})
queryConfig
......
......@@ -29,9 +29,6 @@ const queryPackage = require('../db/query-package.js')
const validation = require('../validation/validation.js')
const restApi = require('../../src-shared/rest-api.js')
const zclLoader = require('../zcl/zcl-loader.js')
const session = require('express-session')
const dbEnum = require('../../src-shared/db-enum.js')
const ideIntegrationZcl = require('../ide-integration/zcl.js')
/**
* HTTP GET: session key values
......
......@@ -105,13 +105,31 @@ async function initHttpServer(
db,
port,
studioPort,
metafiles = {
options = {
allowCors: false,
zcl: env.builtinSilabsZclMetafile,
template: env.builtinTemplateMetafile,
}
) {
return new Promise((resolve, reject) => {
const app = express()
if (options.allowCors) {
env.logWarning('CORS is enabled. Please be careful.')
app.use(function (req, res, next) {
res.setHeader('Access-Control-Allow-Origin', '*')
res.setHeader(
'Access-Control-Allow-Methods',
'GET,POST,PUT,PATCH,DELETE,OPTIONS'
)
res.setHeader(
'Access-Control-Allow-Headers',
'Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With'
)
next()
})
}
//app.use(express.urlencoded({ extended: true }))
app.use(express.json())
app.use(
......@@ -122,7 +140,7 @@ async function initHttpServer(
})
)
app.use(userSessionHandler(db, metafiles))
app.use(userSessionHandler(db, options))
// REST modules
registerAllRestModules(db, app)
......
......@@ -89,6 +89,18 @@ async function progressStart(browserWindow, message) {
)
}
async function debugNavBarOn(browserWindow) {
await browserWindow.webContents.executeJavaScript(
`window.global_renderer_api_execute('${restApi.rendererApiId.debugNavBarOn}')`
)
}
async function debugNavBarOff(browserWindow) {
await browserWindow.webContents.executeJavaScript(
`window.global_renderer_api_execute('${restApi.rendererApiId.debugNavBarOff}')`
)
}
async function getFileLocation(browserWindow, key) {
return null
}
......@@ -185,6 +197,8 @@ exports.executeLoad = executeLoad
exports.executeSave = executeSave
exports.progressEnd = progressEnd
exports.progressStart = progressStart
exports.debugNavBarOn = debugNavBarOn
exports.debugNavBarOff = debugNavBarOff
exports.reportFiles = reportFiles
exports.processRendererNotify = processRendererNotify
exports.getFileLocation = getFileLocation
......
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册