Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for typedef #1458

Open
wants to merge 19 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,930 changes: 1,171 additions & 759 deletions docs/api.md

Large diffs are not rendered by default.

75 changes: 75 additions & 0 deletions docs/helpers.md
Original file line number Diff line number Diff line change
Expand Up @@ -3322,12 +3322,15 @@ This module contains the API for templating. For more detailed instructions, rea
* [~zcl_bitmaps(options)](#module_Templating API_ static zcl helpers..zcl_bitmaps) ⇒
* [~zcl_bitmap_items(options)](#module_Templating API_ static zcl helpers..zcl_bitmap_items)
* [~zcl_enums(options)](#module_Templating API_ static zcl helpers..zcl_enums) ⇒
* [~zcl_typedefs(options)](#module_Templating API_ static zcl helpers..zcl_typedefs) ⇒
* [~zcl_structs(options)](#module_Templating API_ static zcl helpers..zcl_structs) ⇒
* [~zcl_enum_items(options)](#module_Templating API_ static zcl helpers..zcl_enum_items)
* [~first_unused_enum_value(options)](#module_Templating API_ static zcl helpers..first_unused_enum_value) ⇒
* [~zcl_struct_items(options)](#module_Templating API_ static zcl helpers..zcl_struct_items) ⇒
* [~zcl_struct_items_by_struct_name(name, options)](#module_Templating API_ static zcl helpers..zcl_struct_items_by_struct_name) ⇒
* [~zcl_struct_items_by_struct_and_cluster_name(name, clusterName, options)](#module_Templating API_ static zcl helpers..zcl_struct_items_by_struct_and_cluster_name) ⇒
* [~zcl_typedef_by_typedef(name, options)](#module_Templating API_ static zcl helpers..zcl_typedef_by_typedef) ⇒
* [~zcl_typedef_by_typedef_and_cluster_name(name, clusterName, options)](#module_Templating API_ static zcl helpers..zcl_typedef_by_typedef_and_cluster_name) ⇒
* [~zcl_device_types(options)](#module_Templating API_ static zcl helpers..zcl_device_types) ⇒
* [~zcl_device_type_clusters(options)](#module_Templating API_ static zcl helpers..zcl_device_type_clusters) ⇒
* [~zcl_device_type_cluster_commands(options)](#module_Templating API_ static zcl helpers..zcl_device_type_cluster_commands) ⇒
Expand Down Expand Up @@ -3357,6 +3360,7 @@ This module contains the API for templating. For more detailed instructions, rea
* [~zcl_command_arguments(options)](#module_Templating API_ static zcl helpers..zcl_command_arguments) ⇒
* [~zcl_event_fields(options)](#module_Templating API_ static zcl helpers..zcl_event_fields)
* [~zcl_command_argument_data_type(typeName, options)](#module_Templating API_ static zcl helpers..zcl_command_argument_data_type)
* [~asResolvedUnderlyingZclType()](#module_Templating API_ static zcl helpers..asResolvedUnderlyingZclType)
* [~asUnderlyingZclType(typeName, options)](#module_Templating API_ static zcl helpers..asUnderlyingZclType)
* [~zcl_string_type_return(type, options)](#module_Templating API_ static zcl helpers..zcl_string_type_return)
* [~is_zcl_string(type)](#module_Templating API_ static zcl helpers..is_zcl_string)
Expand All @@ -3370,6 +3374,7 @@ This module contains the API for templating. For more detailed instructions, rea
* [~if_is_bitmap(type)](#module_Templating API_ static zcl helpers..if_is_bitmap) ⇒
* [~if_is_enum(type)](#module_Templating API_ static zcl helpers..if_is_enum) ⇒
* [~if_is_struct(type)](#module_Templating API_ static zcl helpers..if_is_struct) ⇒
* [~if_is_typedef(type)](#module_Templating API_ static zcl helpers..if_is_typedef) ⇒
* [~isClient(side)](#module_Templating API_ static zcl helpers..isClient) ⇒
* [~isServer(side)](#module_Templating API_ static zcl helpers..isServer) ⇒
* [~isStrEqual(str1, str2)](#module_Templating API_ static zcl helpers..isStrEqual) ⇒
Expand Down Expand Up @@ -3441,6 +3446,21 @@ enums belonging to a cluster.
| --- | --- |
| options | <code>\*</code> |

<a name="module_Templating API_ static zcl helpers..zcl_typedefs"></a>

### Templating API: static zcl helpers~zcl\_typedefs(options) ⇒
Block helper iterating over all typedefs.
If existing independently, it iterates over ALL the typedefs.
Within a context of a cluster, it iterates only over the
typedefs belonging to a cluster.

**Kind**: inner method of [<code>Templating API: static zcl helpers</code>](#module_Templating API_ static zcl helpers)
**Returns**: Promise of content.

| Param | Type |
| --- | --- |
| options | <code>\*</code> |

<a name="module_Templating API_ static zcl helpers..zcl_structs"></a>

### Templating API: static zcl helpers~zcl\_structs(options) ⇒
Expand Down Expand Up @@ -3524,6 +3544,36 @@ ignored), or a struct associated with the given cluster.
| clusterName |
| options |

<a name="module_Templating API_ static zcl helpers..zcl_typedef_by_typedef"></a>

### Templating API: static zcl helpers~zcl\_typedef\_by\_typedef(name, options) ⇒
Block helper for getting information for a typedef with a given name.

**Kind**: inner method of [<code>Templating API: static zcl helpers</code>](#module_Templating API_ static zcl helpers)
**Returns**: Promise of content.

| Param |
| --- |
| name |
| options |

<a name="module_Templating API_ static zcl helpers..zcl_typedef_by_typedef_and_cluster_name"></a>

### Templating API: static zcl helpers~zcl\_typedef\_by\_typedef\_and\_cluster\_name(name, clusterName, options) ⇒
Block helper for expanding a typedef. The typedef will be those that correspond to that
typedef name being used within the given cluster. That means the typedef name
must be either a global (in which case the cluster name is just
ignored), or a typedef associated with the given cluster.

**Kind**: inner method of [<code>Templating API: static zcl helpers</code>](#module_Templating API_ static zcl helpers)
**Returns**: Promise of content.

| Param |
| --- |
| name |
| clusterName |
| options |

<a name="module_Templating API_ static zcl helpers..zcl_device_types"></a>

### Templating API: static zcl helpers~zcl\_device\_types(options) ⇒
Expand Down Expand Up @@ -3897,6 +3947,12 @@ Helper that deals with the type of the argument.
| typeName | <code>\*</code> |
| options | <code>\*</code> |

<a name="module_Templating API_ static zcl helpers..asResolvedUnderlyingZclType"></a>

### Templating API: static zcl helpers~asResolvedUnderlyingZclType()
Helper that behaves like asUnderlyingZclType, but resolves typedefs.

**Kind**: inner method of [<code>Templating API: static zcl helpers</code>](#module_Templating API_ static zcl helpers)
<a name="module_Templating API_ static zcl helpers..asUnderlyingZclType"></a>

### Templating API: static zcl helpers~asUnderlyingZclType(typeName, options)
Expand Down Expand Up @@ -4122,6 +4178,25 @@ type is not struct
| --- |
| type |

<a name="module_Templating API_ static zcl helpers..if_is_typedef"></a>

### Templating API: static zcl helpers~if\_is\_typedef(type) ⇒
If helper that checks if a type is a typedef

* example:
{{#if_is_typedef type}}
type is typedef
{{else}}
type is not a typedef
{{/if_is_typedef}}

**Kind**: inner method of [<code>Templating API: static zcl helpers</code>](#module_Templating API_ static zcl helpers)
**Returns**: Promise of content.

| Param |
| --- |
| type |

<a name="module_Templating API_ static zcl helpers..isClient"></a>

### Templating API: static zcl helpers~isClient(side) ⇒
Expand Down
13 changes: 13 additions & 0 deletions src-electron/db/db-mapping.js
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,19 @@ exports.map = {
}
},

typedef: (x) => {
if (x == null) return undefined
return {
id: x.TYPEDEF_ID,
label: x.NAME,
name: x.NAME,
type: x.TYPE,
typeId: x.TYPE_ID,
caption: `Typedef, mapping to {@x.TYPE}`,
typedefClusterCount: x.TYPEDEF_CLUSTER_COUNT
}
},

deviceType: (x) => {
if (x == null) return undefined
return {
Expand Down
5 changes: 5 additions & 0 deletions src-electron/db/query-data-type.js
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,11 @@ async function selectSizeFromType(db, packageIds, value) {
dataType.discriminatorName.toLowerCase() == dbEnum.zclType.string
) {
return null
} else if (
dataType &&
dataType.discriminatorName.toLowerCase() == dbEnum.zclType.typedef
) {
return await selectSizeFromType(db, packageIds, dataType.typeId)
} else {
return null
}
Expand Down
53 changes: 53 additions & 0 deletions src-electron/db/query-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -2277,6 +2277,58 @@ async function insertStructItems(db, packageIds, data) {
)
}

/**
* Insert all typedefs into the TypeDef Table.
*
* @param {*} db
* @param {*} packageIds
* @param {*} data
*/
async function insertTypedef(db, packageIds, data) {
return dbApi.dbMultiInsert(
db,
`
INSERT INTO
TYPEDEF (TYPEDEF_ID, DATA_TYPE_REF)
VALUES (
(SELECT
CASE
WHEN
(${SELECT_CLUSTER_SPECIFIC_DATA_TYPE} AND PACKAGE_REF IN (${dbApi.toInClause(
packageIds
)}))
IS
NULL
THEN
(${SELECT_GENERIC_DATA_TYPE} AND PACKAGE_REF IN (${dbApi.toInClause(
packageIds
)}))
ELSE
(${SELECT_CLUSTER_SPECIFIC_DATA_TYPE} AND PACKAGE_REF IN (${dbApi.toInClause(
packageIds
)}))
END AS DATA_TYPE_ID),
(SELECT
DATA_TYPE_ID
FROM
DATA_TYPE
WHERE
DATA_TYPE.PACKAGE_REF IN (${dbApi.toInClause(packageIds)})
AND DATA_TYPE.NAME = ?))`,
data.map((at) => [
at.name,
at.discriminator_ref,
at.cluster_code ? parseInt(at.cluster_code[0].$.code, 16) : null,
at.name,
at.discriminator_ref,
at.name,
at.discriminator_ref,
at.cluster_code ? parseInt(at.cluster_code[0].$.code, 16) : null,
at.type
])
)
}

exports.insertGlobals = insertGlobals
exports.insertClusterExtensions = insertClusterExtensions
exports.insertClusters = insertClusters
Expand All @@ -2302,6 +2354,7 @@ exports.insertBitmap = insertBitmap
exports.insertBitmapFields = insertBitmapFields
exports.insertStruct = insertStruct
exports.insertStructItems = insertStructItems
exports.insertTypedef = insertTypedef
exports.updateDataTypeClusterReferences = updateDataTypeClusterReferences
exports.insertAttributeMappings = insertAttributeMappings
exports.insertEndpointComposition = insertEndpointComposition
Expand Down
Loading