Skip to content
代码片段 群组 项目
提交 34e629c6 编辑于 作者: Timotej Ecimovic's avatar Timotej Ecimovic
浏览文件

Work up towards generated structs.

上级 dbf93719
No related branches found
No related tags found
无相关合并请求
......@@ -1344,6 +1344,23 @@ function insertAtomics(db, packageId, data) {
)
}
/**
* Locates atomic type based on a type name.
*
* @param {*} db
* @param {*} packageId
* @param {*} typeName
*/
function selectAtomicType(db, packageId, typeName) {
return dbApi
.dbGet(
db,
'SELECT ATOMIC_IDENTIFIER, NAME, DESCRIPTION, ATOMIC_SIZE FROM ATOMIC WHERE PACKAGE_REF = ? AND NAME = ?',
[packageId, typeName.toLowerCase()]
)
.then(dbMapping.map.atomic)
}
/**
* Retrieves all atomic types under a given package Id.
* @param {*} db
......@@ -1470,4 +1487,5 @@ exports.selectEndpointType = selectEndpointType
exports.insertAtomics = insertAtomics
exports.selectAllAtomics = selectAllAtomics
exports.getAtomicSizeFromType = getAtomicSizeFromType
exports.selectAtomicType = selectAtomicType
exports.selectAllBitmapFieldsById = selectAllBitmapFieldsById
......@@ -19,6 +19,10 @@ const queryZcl = require('../db/query-zcl.js')
const templateUtil = require('./template-util.js')
const bin = require('../util/bin.js')
function asAtomicTypeName(name) {
return `ZclAtomic_${name}`
}
/**
* This module contains the API for templating. For more detailed instructions, read {@tutorial template-tutorial}
*
......@@ -107,6 +111,25 @@ function asHex(value) {
}
}
/**
* Converts the actual zcl type into an underlying usable C type.
* @param {*} value
*/
function asUnderlyingType(value) {
return templateUtil
.ensurePackageId(this)
.then((packageId) =>
queryZcl.selectAtomicType(this.global.db, packageId, value)
)
.then((atomic) => {
if (atomic == null) {
return `EmberAf${value}`
} else {
return asAtomicTypeName(atomic.name)
}
})
}
/**
* Formats label as a C type.
*
......@@ -201,3 +224,5 @@ exports.asSymbol = asSymbol
exports.asBytes = asBytes
exports.asDelimitedMacro = asDelimitedMacro
exports.asOffset = asOffset
exports.asUnderlyingType = asUnderlyingType
exports.asAtomicTypeName = asAtomicTypeName
......@@ -19,6 +19,11 @@ enum {
{{/zcl_atomics}}
}
// ZCL attomic typedefs
{{#zcl_atomics}}
typedef uint8_t {{asAtomicTypeName name}};
{{/zcl_atomics}}
// ZCL enums
{{#zcl_enums}}
......@@ -40,8 +45,6 @@ typedef enum {
{{/zcl_bitmap_items}}
{{/zcl_bitmaps}}
/* COMMENT ALL THIS OUT TEMPORARILY
// ZCL Structs
{{#zcl_structs}}
......@@ -49,11 +52,9 @@ typedef enum {
// Struct for {{label}}
typedef struct _{{asType label}} {
{{#zcl_struct_items}}
{{ident}}{{asType type}} {{asSymbol label}};
{{ident}}{{asUnderlyingType type}} {{asSymbol label}};
{{/zcl_struct_items}}
} {{asType label}};
{{/zcl_structs}}
*/
#endif
\ No newline at end of file
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册