From d9df456f3a1548fbe273b3d758ba20a5106ed3d8 Mon Sep 17 00:00:00 2001 From: dhchandw Date: Tue, 17 Sep 2024 15:19:43 -0400 Subject: [PATCH] handling sub-atomic types in dotdot loader + few other fixes --- docs/api.md | 52 +++++++++++++++++++++++++++ src-electron/zcl/zcl-loader-dotdot.js | 35 ++++++++++++++---- 2 files changed, 81 insertions(+), 6 deletions(-) diff --git a/docs/api.md b/docs/api.md index 7601ac611e..88b919d97a 100644 --- a/docs/api.md +++ b/docs/api.md @@ -19614,6 +19614,7 @@ This module provides the APIs for dotdot Loading * [~prepareCommands(commands, side, types)](#module_Loader API_ Loader APIs..prepareCommands) ⇒ * [~prepareCluster(cluster, isExtension, types)](#module_Loader API_ Loader APIs..prepareCluster) ⇒ * [~prepareAtomic(type)](#module_Loader API_ Loader APIs..prepareAtomic) ⇒ + * [~prepareSubAtomic(type)](#module_Loader API_ Loader APIs..prepareSubAtomic) ⇒ * [~prepareBitmap(type, isContained)](#module_Loader API_ Loader APIs..prepareBitmap) ⇒ * [~prepareEnum(type)](#module_Loader API_ Loader APIs..prepareEnum) ⇒ * [~prepareStruct(type)](#module_Loader API_ Loader APIs..prepareStruct) ⇒ @@ -19881,6 +19882,18 @@ Parses xml type into the atomic object for insertion into the DB | --- | --- | --- | | type | \* | an xml object which conforms to the atomic format in the dotdot xml | + + +### Loader API: Loader APIs~prepareSubAtomic(type) ⇒ +Parses xml type into the sub-atomic object for insertion into the DB + +**Kind**: inner method of [Loader API: Loader APIs](#module_Loader API_ Loader APIs) +**Returns**: object ready for insertion into the DB + +| Param | Type | Description | +| --- | --- | --- | +| type | \* | an xml object which conforms to the sub-atomic format in the dotdot xml | + ### Loader API: Loader APIs~prepareBitmap(type, isContained) ⇒ @@ -21414,6 +21427,7 @@ This module provides the APIs for new data model loading * [~prepareCommands(commands, side, types)](#module_Loader API_ Loader APIs..prepareCommands) ⇒ * [~prepareCluster(cluster, isExtension, types)](#module_Loader API_ Loader APIs..prepareCluster) ⇒ * [~prepareAtomic(type)](#module_Loader API_ Loader APIs..prepareAtomic) ⇒ + * [~prepareSubAtomic(type)](#module_Loader API_ Loader APIs..prepareSubAtomic) ⇒ * [~prepareBitmap(type, isContained)](#module_Loader API_ Loader APIs..prepareBitmap) ⇒ * [~prepareEnum(type)](#module_Loader API_ Loader APIs..prepareEnum) ⇒ * [~prepareStruct(type)](#module_Loader API_ Loader APIs..prepareStruct) ⇒ @@ -21681,6 +21695,18 @@ Parses xml type into the atomic object for insertion into the DB | --- | --- | --- | | type | \* | an xml object which conforms to the atomic format in the dotdot xml | + + +### Loader API: Loader APIs~prepareSubAtomic(type) ⇒ +Parses xml type into the sub-atomic object for insertion into the DB + +**Kind**: inner method of [Loader API: Loader APIs](#module_Loader API_ Loader APIs) +**Returns**: object ready for insertion into the DB + +| Param | Type | Description | +| --- | --- | --- | +| type | \* | an xml object which conforms to the sub-atomic format in the dotdot xml | + ### Loader API: Loader APIs~prepareBitmap(type, isContained) ⇒ @@ -23214,6 +23240,7 @@ This module provides the APIs for ZCL/Data-Model loading. * [~prepareCommands(commands, side, types)](#module_Loader API_ Loader APIs..prepareCommands) ⇒ * [~prepareCluster(cluster, isExtension, types)](#module_Loader API_ Loader APIs..prepareCluster) ⇒ * [~prepareAtomic(type)](#module_Loader API_ Loader APIs..prepareAtomic) ⇒ + * [~prepareSubAtomic(type)](#module_Loader API_ Loader APIs..prepareSubAtomic) ⇒ * [~prepareBitmap(type, isContained)](#module_Loader API_ Loader APIs..prepareBitmap) ⇒ * [~prepareEnum(type)](#module_Loader API_ Loader APIs..prepareEnum) ⇒ * [~prepareStruct(type)](#module_Loader API_ Loader APIs..prepareStruct) ⇒ @@ -23481,6 +23508,18 @@ Parses xml type into the atomic object for insertion into the DB | --- | --- | --- | | type | \* | an xml object which conforms to the atomic format in the dotdot xml | + + +### Loader API: Loader APIs~prepareSubAtomic(type) ⇒ +Parses xml type into the sub-atomic object for insertion into the DB + +**Kind**: inner method of [Loader API: Loader APIs](#module_Loader API_ Loader APIs) +**Returns**: object ready for insertion into the DB + +| Param | Type | Description | +| --- | --- | --- | +| type | \* | an xml object which conforms to the sub-atomic format in the dotdot xml | + ### Loader API: Loader APIs~prepareBitmap(type, isContained) ⇒ @@ -25014,6 +25053,7 @@ This module provides the APIs for for common functionality related to loading. * [~prepareCommands(commands, side, types)](#module_Loader API_ Loader APIs..prepareCommands) ⇒ * [~prepareCluster(cluster, isExtension, types)](#module_Loader API_ Loader APIs..prepareCluster) ⇒ * [~prepareAtomic(type)](#module_Loader API_ Loader APIs..prepareAtomic) ⇒ + * [~prepareSubAtomic(type)](#module_Loader API_ Loader APIs..prepareSubAtomic) ⇒ * [~prepareBitmap(type, isContained)](#module_Loader API_ Loader APIs..prepareBitmap) ⇒ * [~prepareEnum(type)](#module_Loader API_ Loader APIs..prepareEnum) ⇒ * [~prepareStruct(type)](#module_Loader API_ Loader APIs..prepareStruct) ⇒ @@ -25281,6 +25321,18 @@ Parses xml type into the atomic object for insertion into the DB | --- | --- | --- | | type | \* | an xml object which conforms to the atomic format in the dotdot xml | + + +### Loader API: Loader APIs~prepareSubAtomic(type) ⇒ +Parses xml type into the sub-atomic object for insertion into the DB + +**Kind**: inner method of [Loader API: Loader APIs](#module_Loader API_ Loader APIs) +**Returns**: object ready for insertion into the DB + +| Param | Type | Description | +| --- | --- | --- | +| type | \* | an xml object which conforms to the sub-atomic format in the dotdot xml | + ### Loader API: Loader APIs~prepareBitmap(type, isContained) ⇒ diff --git a/src-electron/zcl/zcl-loader-dotdot.js b/src-electron/zcl/zcl-loader-dotdot.js index c467464734..9962be5dc0 100644 --- a/src-electron/zcl/zcl-loader-dotdot.js +++ b/src-electron/zcl/zcl-loader-dotdot.js @@ -469,6 +469,30 @@ function prepareAtomic(type) { } } +/** + * Parses xml type into the sub-atomic object for insertion into the DB + * + * @param {*} type an xml object which conforms to the sub-atomic format in the dotdot xml + * @returns object ready for insertion into the DB + */ +function prepareSubAtomic(type) { + let desc = type.$.inheritsFrom + return { + name: type.$.short, + id: parseInt(normalizeHexValue(type.$.id)), + size: getNumBytesFromShortName(type.$.inheritsFrom), + description: desc, + isDiscrete: false, + isSigned: + !a.name.startsWith('u') && !a.name.endsWith('u') && a.name.includes('int') + ? 1 + : 0, + isString: desc.includes('str'), + isLong: desc.includes('str') && desc.includes('Long'), + isChar: desc.includes('str') && desc.includes('haracter') + } +} + /** * * Parses xml type into the bitmap object for insertion into the DB @@ -593,14 +617,11 @@ function prepareTypes(zclTypes, types) { } else if (type.$.inheritsFrom === undefined) { types.atomics.push(prepareAtomic(type)) } else { - // TODO: Need to handle sub-atomic types, these are types that impose restrictions - // and inherit from an atomic type but are not a struct, bitmap or enum - droppedTypes.push(type.$.name) + // Handling sub-atomic types by adding to atomic + // and inferring details such as size, signed, string etc from the inherited type + types.atomics.push(prepareSubAtomic(type)) } }) - if (droppedTypes.length > 0) { - env.logDebug(`Dropped types in DotDot loader: ${droppedTypes}`) - } } /** @@ -721,6 +742,8 @@ function prepareDataType(a, dataType, typeMap) { a.name.toLowerCase().includes(dbEnum.zclType.string) ) { dataTypeRef = typeMap.get(dbEnum.zclType.string) + } else if (!dataType && a.isString !== undefined && a.isString == 1) { + dataTypeRef = typeMap.get(dbEnum.zclType.string) } else if ( !dataType && a.name.toLowerCase().includes(dbEnum.zclType.struct)