Skip to content
代码片段 群组 项目
提交 7f62c584 编辑于 作者: Bharat Dandu's avatar Bharat Dandu
浏览文件

CLI generation for zcl

- Adding the zap-cli.zapt changes for generating the zap-cli.c file which uses template options coming from an external file such as cli.json
- Adding block helpers for generating the zcl cli content for commands in zcl. Also adding other helpers to format the code
- Creating more queries which are used by the helpers to extract the content that is needed
- Adding generation testing for cli and adding a zap file to do this
- JIRA: ZAPP-48
上级 e15c1a95
No related branches found
No related tags found
无相关合并请求
......@@ -504,6 +504,67 @@ VALUES
)
}
/**
* Extracts endpoint type ids.
*
* @export
* @param {*} db
* @param {*} sessionId
* @returns promise that resolves into rows in the database table.
*/
function exportendPointTypeIds(db, sessionId) {
var mapFunction = (x) => {
return {
endpointTypeId: x.ENDPOINT_TYPE_ID,
}
}
return dbApi
.dbAll(
db,
`
SELECT
ENDPOINT_TYPE.ENDPOINT_TYPE_ID
FROM
ENDPOINT_TYPE
LEFT JOIN
DEVICE_TYPE
ON
ENDPOINT_TYPE.DEVICE_TYPE_REF = DEVICE_TYPE.DEVICE_TYPE_ID
WHERE ENDPOINT_TYPE.SESSION_REF = ? ORDER BY ENDPOINT_TYPE.NAME`,
[sessionId]
)
.then((rows) => rows.map(mapFunction))
}
/**
* Returns the count of the number of cluster commands with cli for a cluster
* @param {*} db
* @param {*} endpointTypes
* @param {*} endpointClusterId
*/
function exportCliCommandCountFromEndpointTypeCluster(
db,
endpointTypes,
endpointClusterId
) {
endpointTypeIds = endpointTypes.map((ep) => ep.endpointTypeId).toString()
return dbApi
.dbAll(
db,
`
SELECT COUNT(*) as count
FROM COMMAND
INNER JOIN ENDPOINT_TYPE_COMMAND
ON COMMAND.COMMAND_ID = ENDPOINT_TYPE_COMMAND.COMMAND_REF
INNER JOIN OPTIONS
ON OPTIONS.OPTION_CODE = COMMAND.NAME
WHERE ENDPOINT_TYPE_COMMAND.ENDPOINT_TYPE_REF IN (${endpointTypeIds}) AND ENDPOINT_TYPE_COMMAND.ENDPOINT_TYPE_CLUSTER_REF = ?
`,
[endpointClusterId]
)
.then((res) => res[0].count)
}
exports.exportEndpointTypes = exportEndpointTypes
exports.importEndpointType = importEndpointType
......@@ -520,3 +581,5 @@ exports.importCommandForEndpointType = importCommandForEndpointType
exports.exportEndpoints = exportEndpoints
exports.importEndpoint = importEndpoint
exports.exportendPointTypeIds = exportendPointTypeIds
exports.exportCliCommandCountFromEndpointTypeCluster = exportCliCommandCountFromEndpointTypeCluster
......@@ -1470,6 +1470,230 @@ function insertBitmaps(db, packageId, data) {
})
}
/**
* Exports clusters and endpoint ids
*
* @param {*} db
* @param {*} endpointTypeId
* @returns Promise that resolves with the data that contains cluster
* and endpoint id references
*/
function exportClustersAndEndpointDetailsFromEndpointTypes(db, endpointTypes) {
endpointTypeIds = endpointTypes.map((ep) => ep.endpointTypeId).toString()
var mapFunction = (x) => {
return {
endpointId: x.ENDPOINT_TYPE_REF,
endpointClusterId: x.ENDPOINT_TYPE_CLUSTER_ID,
}
}
return dbApi
.dbAll(
db,
`
SELECT
ENDPOINT_TYPE_CLUSTER.ENDPOINT_TYPE_REF,
ENDPOINT_TYPE_CLUSTER.ENDPOINT_TYPE_CLUSTER_ID
FROM CLUSTER
INNER JOIN ENDPOINT_TYPE_CLUSTER
ON CLUSTER.CLUSTER_ID = ENDPOINT_TYPE_CLUSTER.CLUSTER_REF
WHERE ENDPOINT_TYPE_CLUSTER.ENDPOINT_TYPE_REF IN (${endpointTypeIds})`
)
.then((rows) => rows.map(mapFunction))
}
/**
* Returns a promise of data for commands inside an endpoint type.
*
* @param {*} db
* @param {*} endpointTypeId
* @returns Promise that resolves with the command data.
*/
function exportCommandDetailsFromAllEndpointTypesAndClusters(
db,
endpointsAndClusters
) {
endpointTypeIds = endpointsAndClusters.map((ep) => ep.endpointId).toString()
endpointClusterIds = endpointsAndClusters
.map((ep) => ep.endpointClusterId)
.toString()
var mapFunction = (x) => {
return {
id: x.COMMAND_ID,
name: x.NAME,
code: x.CODE,
mfgCode: x.MANUFACTURER_CODE,
incoming: x.INCOMING,
outgoing: x.OUTGOING,
description: x.DESCRIPTION,
clusterSide: x.SIDE,
clusterName: x.CLUSTER_NAME,
}
}
return dbApi
.dbAll(
db,
`
SELECT
COMMAND.COMMAND_ID,
COMMAND.NAME,
COMMAND.CODE,
COMMAND.MANUFACTURER_CODE,
ENDPOINT_TYPE_COMMAND.INCOMING,
ENDPOINT_TYPE_COMMAND.OUTGOING,
COMMAND.DESCRIPTION,
ENDPOINT_TYPE_CLUSTER.SIDE,
CLUSTER.NAME AS CLUSTER_NAME
FROM COMMAND
INNER JOIN ENDPOINT_TYPE_COMMAND
ON COMMAND.COMMAND_ID = ENDPOINT_TYPE_COMMAND.COMMAND_REF
INNER JOIN ENDPOINT_TYPE_CLUSTER
ON ENDPOINT_TYPE_COMMAND.ENDPOINT_TYPE_CLUSTER_REF = ENDPOINT_TYPE_CLUSTER.ENDPOINT_TYPE_CLUSTER_ID
INNER JOIN CLUSTER
ON COMMAND.CLUSTER_REF = CLUSTER.CLUSTER_ID
WHERE ENDPOINT_TYPE_COMMAND.ENDPOINT_TYPE_REF IN (${endpointTypeIds}) AND ENDPOINT_TYPE_COMMAND.ENDPOINT_TYPE_CLUSTER_REF in (${endpointClusterIds})
GROUP BY COMMAND.NAME
`
)
.then((rows) => rows.map(mapFunction))
}
/**
* Get the number of command arguments for a command
*
* @param {*} db
* @param {*} commandId
* @param {*} [packageId=null]
* @returns A promise with number of command arguments for a command
*/
function selectCommandArgumentsCountByCommandId(
db,
commandId,
packageId = null
) {
return dbApi
.dbAll(
db,
`
SELECT COUNT(*) AS count
FROM COMMAND_ARG WHERE COMMAND_REF = ? `,
[commandId]
)
.then((res) => res[0].count)
}
/**
* Extract the command arguments for a command
*
* @param {*} db
* @param {*} commandId
* @param {*} [packageId=null]
* @returns A promise with command arguments for a command
*/
function selectCommandArgumentsByCommandId(db, commandId, packageId = null) {
return dbApi
.dbAll(
db,
`
SELECT
COMMAND_REF,
NAME,
TYPE,
IS_ARRAY
FROM COMMAND_ARG WHERE COMMAND_REF = ? `,
[commandId]
)
.then((rows) => rows.map(dbMapping.map.commandArgument))
}
/**
* Exports clusters to an externalized form.
*
* @param {*} db
* @param {*} endpointTypeId
* @returns Promise that resolves with the data that should go into the external form.
*/
function exportAllClustersDetailsFromEndpointTypes(db, endpointTypes) {
endpointTypeIds = endpointTypes.map((ep) => ep.endpointTypeId).toString()
var mapFunction = (x) => {
return {
id: x.CLUSTER_ID,
name: x.NAME,
code: x.CODE,
mfgCode: x.MANUFACTURER_CODE,
side: x.SIDE,
enabled: x.ENABLED,
endpointClusterId: x.ENDPOINT_TYPE_CLUSTER_ID,
}
}
return dbApi
.dbAll(
db,
`
SELECT
CLUSTER.CLUSTER_ID,
CLUSTER.CODE,
CLUSTER.MANUFACTURER_CODE,
CLUSTER.NAME,
ENDPOINT_TYPE_CLUSTER.SIDE,
ENDPOINT_TYPE_CLUSTER.ENABLED,
ENDPOINT_TYPE_CLUSTER.ENDPOINT_TYPE_CLUSTER_ID
FROM CLUSTER
INNER JOIN ENDPOINT_TYPE_CLUSTER
ON CLUSTER.CLUSTER_ID = ENDPOINT_TYPE_CLUSTER.CLUSTER_REF
WHERE ENDPOINT_TYPE_CLUSTER.ENDPOINT_TYPE_REF IN (${endpointTypeIds})
GROUP BY NAME, SIDE`
)
.then((rows) => rows.map(mapFunction))
}
/**
* Returns a promise of data for commands inside all existing endpoint types.
*
* @param {*} db
* @param {*} endpointTypeId
* @returns Promise that resolves with the command data.
*/
function exportCommandDetailsFromAllEndpointTypeCluster(
db,
endpointTypes,
endpointClusterId
) {
endpointTypeIds = endpointTypes.map((ep) => ep.endpointTypeId).toString()
var mapFunction = (x) => {
return {
id: x.COMMAND_ID,
name: x.NAME,
code: x.CODE,
mfgCode: x.MANUFACTURER_CODE,
incoming: x.INCOMING,
outgoing: x.OUTGOING,
description: x.DESCRIPTION,
}
}
return dbApi
.dbAll(
db,
`
SELECT
COMMAND.COMMAND_ID,
COMMAND.NAME,
COMMAND.CODE,
COMMAND.MANUFACTURER_CODE,
ENDPOINT_TYPE_COMMAND.INCOMING,
ENDPOINT_TYPE_COMMAND.OUTGOING,
COMMAND.DESCRIPTION
FROM COMMAND
INNER JOIN ENDPOINT_TYPE_COMMAND
ON COMMAND.COMMAND_ID = ENDPOINT_TYPE_COMMAND.COMMAND_REF
WHERE ENDPOINT_TYPE_COMMAND.ENDPOINT_TYPE_REF IN (${endpointTypeIds}) AND ENDPOINT_TYPE_COMMAND.ENDPOINT_TYPE_CLUSTER_REF = ?
`,
[endpointClusterId]
)
.then((rows) => rows.map(mapFunction))
}
// exports
exports.selectAllEnums = selectAllEnums
exports.selectAllEnumItemsById = selectAllEnumItemsById
......@@ -1529,3 +1753,9 @@ exports.getAtomicSizeFromType = getAtomicSizeFromType
exports.selectAtomicType = selectAtomicType
exports.selectAllBitmapFieldsById = selectAllBitmapFieldsById
exports.selectBitmapByName = selectBitmapByName
exports.exportClustersAndEndpointDetailsFromEndpointTypes = exportClustersAndEndpointDetailsFromEndpointTypes
exports.exportCommandDetailsFromAllEndpointTypesAndClusters = exportCommandDetailsFromAllEndpointTypesAndClusters
exports.selectCommandArgumentsCountByCommandId = selectCommandArgumentsCountByCommandId
exports.selectCommandArgumentsByCommandId = selectCommandArgumentsByCommandId
exports.exportAllClustersDetailsFromEndpointTypes = exportAllClustersDetailsFromEndpointTypes
exports.exportCommandDetailsFromAllEndpointTypeCluster = exportCommandDetailsFromAllEndpointTypeCluster
......@@ -284,6 +284,77 @@ function asBytes(value, type) {
}
}
/**
* Given a string convert it into a camelCased string
*
* @param {*} str
* @returns a spaced out string in lowercase
*/
function asCamelCased(label) {
str = label.split(/ |-/)
res = ''
for (let i = 0; i < str.length; i++) {
if (i == 0) {
res += str[i].charAt(0).toLowerCase() + str[i].substring(1)
continue
}
res += str[i].charAt(0).toUpperCase() + str[i].substring(1)
}
return res
}
/**
* returns a string after converting ':' and '-' into '_'
* @param {*} label
*/
function cleanseLabel(label) {
l = label
l = l.replace(/[:/-]/g, '_').toLowerCase()
return l
}
/**
* Given a camel case string, convert it into one with underscore and lowercase
*
* @param {*} str
* @returns String in lowercase with underscores
*/
function asUnderscoreLowercase(str) {
label = str.replace(/\.?([A-Z][a-z])/g, function (x, y) {
return '_' + y
})
if (label.startsWith('_')) {
label = label.substring(1)
}
return label.toLowerCase()
}
/**
* Given a camel case string convert it into one with space and lowercase
*
* @param {*} str
* @returns a spaced out string in lowercase
*/
function asSpacedLowercase(str) {
str = str.replace(/\.?([A-Z][a-z])/g, function (x, y) {
return ' ' + y
})
return str.toLowerCase()
}
/**
* Given a camel case string convert it into one with underscore and uppercase
*
* @param {*} str
* @returns String in uppercase with underscores
*/
function asUnderscoreUppercase(str) {
str = str.replace(/\.?([A-Z][a-z])/g, function (x, y) {
return '_' + y
})
return str.toUpperCase()
}
// WARNING! WARNING! WARNING! WARNING! WARNING! WARNING!
//
// Note: these exports are public API. Templates that might have been created in the past and are
......@@ -296,3 +367,8 @@ exports.asBytes = asBytes
exports.asDelimitedMacro = asDelimitedMacro
exports.asOffset = asOffset
exports.asUnderlyingType = asUnderlyingType
exports.asCamelCased = asCamelCased
exports.cleanseLabel = cleanseLabel
exports.asUnderscoreLowercase = asUnderscoreLowercase
exports.asSpacedLowercase = asSpacedLowercase
exports.asUnderscoreUppercase = asUnderscoreUppercase
......@@ -23,6 +23,7 @@
const templateUtil = require('./template-util.js')
const queryImpexp = require('../db/query-impexp.js')
const queryConfig = require('../db/query-config.js')
const queryZcl = require('../db/query-zcl.js')
/**
* Creates block iterator helper over the endpoint types.
......@@ -105,6 +106,89 @@ function user_all_attributes(options) {
.then((atts) => templateUtil.collectBlocks(atts, options, this))
}
/**
* Creates endpoint type cluster command iterator. This fetches all
* commands which have been enabled on added endpoints
*
* @param {*} options
* @returns Promise of the resolved blocks iterating over cluster commands.
*/
function all_user_cluster_commands(options) {
return queryImpexp
.exportendPointTypeIds(this.global.db, this.global.sessionId)
.then((endpointTypes) =>
queryZcl.exportClustersAndEndpointDetailsFromEndpointTypes(
this.global.db,
endpointTypes
)
)
.then((endpointsAndClusters) =>
queryZcl.exportCommandDetailsFromAllEndpointTypesAndClusters(
this.global.db,
endpointsAndClusters
)
)
.then((endpointCommands) =>
templateUtil.collectBlocks(endpointCommands, options, this)
)
}
/**
* Creates cluster command iterator for all endpoints.
*
* @param {*} options
* @returns Promise of the resolved blocks iterating over cluster commands.
*/
function all_user_clusters(options) {
return queryImpexp
.exportendPointTypeIds(this.global.db, this.global.sessionId)
.then((endpointTypes) =>
queryZcl.exportAllClustersDetailsFromEndpointTypes(
this.global.db,
endpointTypes
)
)
.then((clusters) => templateUtil.collectBlocks(clusters, options, this))
}
/**
* Get the count of the number of clusters commands with cli for a cluster.
* This is used under a cluster block helper
*/
function user_cluster_command_count_with_cli() {
return queryImpexp
.exportendPointTypeIds(this.global.db, this.global.sessionId)
.then((endpointTypes) =>
queryImpexp.exportCliCommandCountFromEndpointTypeCluster(
this.global.db,
endpointTypes,
this.endpointClusterId
)
)
}
/**
* Creates endpoint type cluster command iterator. This works only inside
* cluster block helpers.
*
* @param {*} options
* @returns Promise of the resolved blocks iterating over cluster commands.
*/
function user_cluster_commands_all_endpoints(options) {
return queryImpexp
.exportendPointTypeIds(this.global.db, this.global.sessionId)
.then((endpointTypes) =>
queryZcl.exportCommandDetailsFromAllEndpointTypeCluster(
this.global.db,
endpointTypes,
this.endpointClusterId
)
)
.then((endpointCommands) =>
templateUtil.collectBlocks(endpointCommands, options, this)
)
}
// WARNING! WARNING! WARNING! WARNING! WARNING! WARNING!
//
// Note: these exports are public API. Templates that might have been created in the past and are
......@@ -116,3 +200,7 @@ exports.user_cluster_attributes = user_cluster_attributes
exports.user_cluster_commands = user_cluster_commands
exports.user_endpoint_type_count = user_endpoint_type_count
exports.user_all_attributes = user_all_attributes
exports.all_user_cluster_commands = all_user_cluster_commands
exports.all_user_clusters = all_user_clusters
exports.user_cluster_command_count_with_cli = user_cluster_command_count_with_cli
exports.user_cluster_commands_all_endpoints = user_cluster_commands_all_endpoints
......@@ -113,6 +113,58 @@ function middle(options) {
}
}
/**
* This fetches a promise which returns template options if provided
*
* @param {*} options
* @param {*} key
*/
function template_option_with_code(options, key) {
return templateUtil
.ensureTemplatePackageId(this)
.then((packageId) =>
queryPackage.selectSpecificOptionValue(
this.global.db,
packageId,
options,
key
)
)
}
/**
* This returns a boolean if the 2 strings are same
*
* @param {*} string_a
* @param {*} string_b
*/
function isEqual(string_a, string_b) {
return string_a.trim() === string_b.trim()
}
/**
* Remove leading and trailing spaces from a string
*
* @param {*} str
* @returns A string with no leading and trailing spaces
*/
function trim_string(str) {
var result = str.trim()
return result
}
/**
* Split the string based on spaces and return the last word
* @param {*} str
*/
function asLastWord(str) {
var strings = str.trim().split(' ')
if (strings.length > 0) {
return strings[strings.length - 1]
}
return str.trim()
}
// WARNING! WARNING! WARNING! WARNING! WARNING! WARNING!
//
// Note: these exports are public API. Templates that might have been created in the past and are
......@@ -124,3 +176,7 @@ exports.template_options = template_options
exports.last = last
exports.first = first
exports.middle = middle
exports.template_option_with_code = template_option_with_code
exports.isEqual = isEqual
exports.trim_string = trim_string
exports.asLastWord = asLastWord
......@@ -291,6 +291,47 @@ function largestLabelLength(arr) {
return lengthOfLargestString
}
/**
* Helper to extract the number of command arguments in a command
*
* @param {*} commandId
* @returns Number of command arguments as an integer
*/
function zcl_command_arguments_count(commandId) {
return templateUtil.ensureZclPackageId(this).then((packageId) => {
var res = queryZcl.selectCommandArgumentsCountByCommandId(
this.global.db,
commandId,
packageId
)
return res
})
}
/**
* Block helper iterating over command arguments within a command
*
* @param {*} options
* @returns Promise of command argument iteration.
*/
function zcl_command_arguments(options) {
return templateUtil
.ensureZclPackageId(this)
.then((packageId) => {
if ('id' in this) {
// We're functioning inside a nested context with an id, so we will only query for this cluster.
return queryZcl.selectCommandArgumentsByCommandId(
this.global.db,
this.id,
packageId
)
} else {
return queryZcl.selectAllCommandArguments(this.global.db)
}
})
.then((cmds) => templateUtil.collectBlocks(cmds, options, this))
}
// WARNING! WARNING! WARNING! WARNING! WARNING! WARNING!
//
// Note: these exports are public API. Templates that might have been created in the past and are
......@@ -310,3 +351,5 @@ exports.zcl_attributes_server = zcl_attributes_server
exports.zcl_atomics = zcl_atomics
exports.zcl_global_commands = zcl_global_commands
exports.zcl_cluster_largest_label_length = zcl_cluster_largest_label_length
exports.zcl_command_arguments_count = zcl_command_arguments_count
exports.zcl_command_arguments = zcl_command_arguments
......@@ -37,7 +37,7 @@
{
"path": "zap-cli.zapt",
"name": "ZCL command-line contribution",
"output": "zap-cli.h"
"output": "zap-cli.c"
},
{
"path": "call-command-handler.zapt",
......
......@@ -37,7 +37,7 @@
{
"path": "zap-cli.zapt",
"name": "ZCL command-line contribution",
"output": "zap-cli.h"
"output": "zap-cli.c"
},
{
"path": "zap-command-parser.zapt",
......
{{zap_header}}
{{#template_options category="cli"}}
{{optionCode}} => {{optionLabel}}
{{/template_options}}
\ No newline at end of file
#include <stdlib.h>
#include "sl_cli_config.h"
#include "sl_cli_command.h"
#include "sl_cli_arguments.h"
#include "sl_cli.h"
#include "debug_print.h"
#define ZCL_CLUSTER_SPECIFIC_COMMAND BIT(0)
#define ZCL_FRAME_CONTROL_CLIENT_TO_SERVER 0
#define ZCL_IDENTIFY_CLUSTER_ID 0x0003
#define ZCL_ON_OFF_CLUSTER_ID 0x0006
#define ZCL_IDENTIFY_COMMAND_ID 0x00 // Ver.: always
#define ZCL_IDENTIFY_QUERY_COMMAND_ID 0x01 // Ver.: always
#define ZCL_OFF_COMMAND_ID 0x00 // Ver.: always
#define ZCL_ON_COMMAND_ID 0x01 // Ver.: always
#define ZCL_TOGGLE_COMMAND_ID 0x02 // Ver.: always
#ifdef __cplusplus
extern "C" {
#endif
// Provide function declarations
{{#all_user_cluster_commands}}
{{#if (template_option_with_code "cli" this.name)}}
{{#template_options category="cli"}}
{{#if (isEqual this.optionCode ../name)}}
void {{asCamelCased this.optionLabel}}Command(sl_cli_command_arg_t *arguments);
{{/if}}
{{/template_options}}
{{/if}}
{{/all_user_cluster_commands}}
// Command structs. Names are command names prefixed by cli_cmd_zcl_[cluster name]_cluster
{{#all_user_cluster_commands}}
{{#if (template_option_with_code "cli" this.name)}}
{{#template_options category="cli"}}
{{#if (isEqual this.optionCode ../name)}}
static const sl_cli_command_info_t cli_cmd_zcl_{{cleanseLabel ../clusterName}}_{{../clusterSide}}_cluster_{{asUnderscoreLowercase ../name}} = \
SL_CLI_COMMAND({{asCamelCased this.optionLabel}}Command,
{{/if}}
{{/template_options}}
"{{trim_string description}}",
{{#if (zcl_command_arguments_count this.id)}}
{{#zcl_command_arguments}}"{{asSpacedLowercase label}}" SL_CLI_UNIT_SEPARATOR {{/zcl_command_arguments}},
{{else}}
"",
{{/if}}
{
{{#zcl_command_arguments}}
SL_CLI_ARG_{{asUnderscoreUppercase type}},
{{/zcl_command_arguments}}
SL_CLI_ARG_END,
});
{{/if}}
{{/all_user_cluster_commands}}
// Create group command tables and structs if cli_groups given
// in template. Group name is suffixed with [cluster name]_[cluster_side]_cluster_group_table for tables
// and group commands are cli_cmd_( group name )_group
// Create root command table
{{#all_user_clusters}}
{{#if (user_cluster_command_count_with_cli)}}
static const sl_cli_command_entry_t zcl_{{cleanseLabel name}}_{{side}}_cluster_command_table[] = {
{{#user_cluster_commands_all_endpoints}}
{{#template_options category="cli"}}
{{#if (isEqual this.optionCode ../name)}}
{ "{{asLastWord optionLabel}}", &cli_cmd_zcl_{{cleanseLabel ../../name}}_{{../../side}}_cluster_{{asUnderscoreLowercase ../name}}, false },
{{/if}}
{{/template_options}}
{{/user_cluster_commands_all_endpoints}}
{ NULL, NULL, false },
};
{{/if}}
{{/all_user_clusters}}
{{#all_user_clusters}}
{{#if (user_cluster_command_count_with_cli)}}
static const sl_cli_command_info_t cli_cmd_{{cleanseLabel name}}_{{side}}_group = \
SL_CLI_COMMAND_GROUP(zcl_{{cleanseLabel name}}_{{side}}_cluster_command_table, "ZCL {{cleanseLabel name}} {{side}} cluster commands");
{{/if}}
{{/all_user_clusters}}
static const sl_cli_command_entry_t zcl_group_table[] = {
{{#all_user_clusters}}
{{#if (user_cluster_command_count_with_cli)}}
{ "{{cleanseLabel name}}", &cli_cmd_{{cleanseLabel name}}_{{side}}_group, false },
{{/if}}
{{/all_user_clusters}}
{ NULL, NULL, false },
};
sl_cli_command_info_t cli_cmd_zcl_group = \
SL_CLI_COMMAND_GROUP(zcl_group_table, "ZCL commands");
// Create root command table
const sl_cli_command_entry_t sl_cli_zcl_command_table[] = {
{ "zcl", &cli_cmd_zcl_group, false },
{ NULL, NULL, false },
};
#ifdef __cplusplus
}
#endif
\ No newline at end of file
......@@ -18,6 +18,7 @@
* @jest-environment node
*/
const path = require('path')
const genEngine = require('../src-electron/generator/generation-engine.js')
const args = require('../src-electron/util/args.js')
const env = require('../src-electron/util/env.js')
......@@ -28,10 +29,12 @@ const querySession = require('../src-electron/db/query-session.js')
const utilJs = require('../src-electron/util/util.js')
const zclLoader = require('../src-electron/zcl/zcl-loader.js')
const helperZap = require('../src-electron/generator/helper-zap.js')
const importJs = require('../src-electron/importexport/import.js')
var db
const templateCount = 9
var genTimeout = 3000
var testFile = path.join(__dirname, 'resource/generation-test-file-1.zap')
beforeAll(() => {
var file = env.sqliteTestFile('genengine')
......@@ -206,10 +209,32 @@ test(
).toBeTruthy()
expect(zapTypes.includes('uint32_t snapshotCause')).toBeTruthy()
var zapCli = genResult.content['zap-cli.h']
expect(
zapCli.includes('DisplayProtectedMessage => zcl msg disp-protd')
).toBeTruthy()
var zapCli = genResult.content['zap-cli.c']
expect(zapCli.includes('#include <stdlib.h>')).toBeTruthy()
}),
genTimeout
)
test(
'Test file import and generation',
() =>
importJs
.importDataFromFile(db, testFile)
.then((sessionId) =>
genEngine.generate(db, sessionId, templateContext.packageId)
)
.then((genResult) => {
expect(genResult).not.toBeNull()
expect(genResult.partial).toBeFalsy()
expect(genResult.content).not.toBeNull()
var zapCli = genResult.content['zap-cli.c']
expect(zapCli.includes('#include <stdlib.h>')).toBeTruthy()
//expect(zapCli.includes('void zclIdentifyIdCommand(sl_cli_command_arg_t *arguments);')).toBeTruthy()
//expect(zapCli.includes('SL_CLI_COMMAND(zclIdentifyIdCommand,')).toBeTruthy()
//expect(zapCli.includes('{ "id", &cli_cmd_zcl_identify_client_cluster_identify, false },')).toBeTruthy()
//expect(zapCli.includes('SL_CLI_COMMAND_GROUP(zcl_identify_client_cluster_command_table, "ZCL identify client cluster commands");')).toBeTruthy()
//expect(zapCli.includes('{ "identify", &cli_cmd_identify_client_group, false },')).toBeTruthy()
}),
genTimeout
)
......
此差异已折叠。
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册