Skip to content

Commit

Permalink
dealing with subatomics without adding to atomics
Browse files Browse the repository at this point in the history
picking up atomic size from length property

fixing error in zcl-loader-consecutive test
  • Loading branch information
dhchandw committed Sep 23, 2024
1 parent afa3469 commit 803483f
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 24 deletions.
40 changes: 40 additions & 0 deletions docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -19618,6 +19618,7 @@ This module provides the APIs for dotdot Loading
* [~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) ⇒
* [~prepareSubAtomicTypes(types)](#module_Loader API_ Loader APIs..prepareSubAtomicTypes)
* [~prepareTypes(zclTypes, types)](#module_Loader API_ Loader APIs..prepareTypes)
* [~prepareAttributeType(attribute, types, cluster)](#module_Loader API_ Loader APIs..prepareAttributeType)
* [~prepareDeviceType(deviceType)](#module_Loader API_ Loader APIs..prepareDeviceType) ⇒
Expand Down Expand Up @@ -19931,6 +19932,15 @@ Parses xml type into the struct object for insertion into the DB
| --- | --- | --- |
| type | <code>\*</code> | an xml object which conforms to the struct format in the dotdot xml |

<a name="module_Loader API_ Loader APIs..prepareSubAtomicTypes"></a>

### Loader API: Loader APIs~prepareSubAtomicTypes(types)
**Kind**: inner method of [<code>Loader API: Loader APIs</code>](#module_Loader API_ Loader APIs)

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

<a name="module_Loader API_ Loader APIs..prepareTypes"></a>

### Loader API: Loader APIs~prepareTypes(zclTypes, types)
Expand Down Expand Up @@ -21431,6 +21441,7 @@ This module provides the APIs for new data model loading
* [~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) ⇒
* [~prepareSubAtomicTypes(types)](#module_Loader API_ Loader APIs..prepareSubAtomicTypes)
* [~prepareTypes(zclTypes, types)](#module_Loader API_ Loader APIs..prepareTypes)
* [~prepareAttributeType(attribute, types, cluster)](#module_Loader API_ Loader APIs..prepareAttributeType)
* [~prepareDeviceType(deviceType)](#module_Loader API_ Loader APIs..prepareDeviceType) ⇒
Expand Down Expand Up @@ -21744,6 +21755,15 @@ Parses xml type into the struct object for insertion into the DB
| --- | --- | --- |
| type | <code>\*</code> | an xml object which conforms to the struct format in the dotdot xml |

<a name="module_Loader API_ Loader APIs..prepareSubAtomicTypes"></a>

### Loader API: Loader APIs~prepareSubAtomicTypes(types)
**Kind**: inner method of [<code>Loader API: Loader APIs</code>](#module_Loader API_ Loader APIs)

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

<a name="module_Loader API_ Loader APIs..prepareTypes"></a>

### Loader API: Loader APIs~prepareTypes(zclTypes, types)
Expand Down Expand Up @@ -23244,6 +23264,7 @@ This module provides the APIs for ZCL/Data-Model loading.
* [~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) ⇒
* [~prepareSubAtomicTypes(types)](#module_Loader API_ Loader APIs..prepareSubAtomicTypes)
* [~prepareTypes(zclTypes, types)](#module_Loader API_ Loader APIs..prepareTypes)
* [~prepareAttributeType(attribute, types, cluster)](#module_Loader API_ Loader APIs..prepareAttributeType)
* [~prepareDeviceType(deviceType)](#module_Loader API_ Loader APIs..prepareDeviceType) ⇒
Expand Down Expand Up @@ -23557,6 +23578,15 @@ Parses xml type into the struct object for insertion into the DB
| --- | --- | --- |
| type | <code>\*</code> | an xml object which conforms to the struct format in the dotdot xml |

<a name="module_Loader API_ Loader APIs..prepareSubAtomicTypes"></a>

### Loader API: Loader APIs~prepareSubAtomicTypes(types)
**Kind**: inner method of [<code>Loader API: Loader APIs</code>](#module_Loader API_ Loader APIs)

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

<a name="module_Loader API_ Loader APIs..prepareTypes"></a>

### Loader API: Loader APIs~prepareTypes(zclTypes, types)
Expand Down Expand Up @@ -25057,6 +25087,7 @@ This module provides the APIs for for common functionality related to loading.
* [~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) ⇒
* [~prepareSubAtomicTypes(types)](#module_Loader API_ Loader APIs..prepareSubAtomicTypes)
* [~prepareTypes(zclTypes, types)](#module_Loader API_ Loader APIs..prepareTypes)
* [~prepareAttributeType(attribute, types, cluster)](#module_Loader API_ Loader APIs..prepareAttributeType)
* [~prepareDeviceType(deviceType)](#module_Loader API_ Loader APIs..prepareDeviceType) ⇒
Expand Down Expand Up @@ -25370,6 +25401,15 @@ Parses xml type into the struct object for insertion into the DB
| --- | --- | --- |
| type | <code>\*</code> | an xml object which conforms to the struct format in the dotdot xml |

<a name="module_Loader API_ Loader APIs..prepareSubAtomicTypes"></a>

### Loader API: Loader APIs~prepareSubAtomicTypes(types)
**Kind**: inner method of [<code>Loader API: Loader APIs</code>](#module_Loader API_ Loader APIs)

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

<a name="module_Loader API_ Loader APIs..prepareTypes"></a>

### Loader API: Loader APIs~prepareTypes(zclTypes, types)
Expand Down
84 changes: 61 additions & 23 deletions src-electron/zcl/zcl-loader-dotdot.js
Original file line number Diff line number Diff line change
Expand Up @@ -456,10 +456,11 @@ function prepareCluster(cluster, types, isExtension = false) {
*/
function prepareAtomic(type) {
let desc = type.$.name
let length = type.restriction?.[0]?.['type:length']?.[0]?.$?.value
return {
name: type.$.short,
id: parseInt(normalizeHexValue(type.$.id)),
size: getNumBytesFromShortName(type.$.short),
size: length ?? getNumBytesFromShortName(type.$.short),
description: desc,
isDiscrete: type.$.discrete == 'true' ? true : false,
isSigned: desc.includes('Signed'),
Expand All @@ -475,21 +476,26 @@ function prepareAtomic(type) {
* @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:
!desc.startsWith('u') && !desc.endsWith('u') && desc.includes('int')
? 1
: 0,
isString: desc.includes('str'),
isLong: desc.includes('str') && desc.includes('Long'),
isChar: desc.includes('str') && desc.includes('haracter')
function prepareSubAtomic(subAtomic, atomics) {
let relatedAtomic = atomics.find(
(atomic) => atomic.name === subAtomic.inheritsFrom
)
if (relatedAtomic) {
return {
name: subAtomic.short,
id: parseInt(normalizeHexValue(subAtomic.id)),
size: relatedAtomic.size,
description: relatedAtomic.description,
isDiscrete: relatedAtomic.isDiscrete,
isSigned: relatedAtomic.isSigned,
isString: relatedAtomic.isString,
isLong: relatedAtomic.isLong,
isChar: relatedAtomic.isChar
}
} else {
env.log(
`Could not find related atomic type for sub-atomic type ${subAtomic.short} - Dropping this type.`
)
}
}

Expand Down Expand Up @@ -597,6 +603,16 @@ function prepareStruct(type) {
return ret
}

/**
*
* @param {*} types
*/
function prepareSubAtomicTypes(types) {
types.subAtomics = types.subAtomics
.map((subAtomic) => prepareSubAtomic(subAtomic, types.atomics))
.filter((subAtomic) => subAtomic != null || subAtomic != undefined)
}

/**
*
* Parses xml types into the types object for insertion into the DB
Expand All @@ -617,9 +633,9 @@ function prepareTypes(zclTypes, types) {
} else if (type.$.inheritsFrom === undefined) {
types.atomics.push(prepareAtomic(type))
} else {
// 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))
// Sub-atomic types - these are types that impose restrictions and inherit from an atomic type but are not a struct, bitmap or enum
// Will be processed after all other types are processed
types.subAtomics.push(type.$)
}
})
}
Expand Down Expand Up @@ -842,9 +858,13 @@ function prepareNumber(a, dataType) {
return {
size: a.size,
is_signed:
a.name.startsWith('u') || a.name.endsWith('u') || !a.name.includes('int')
? 0
: 1,
a.isSigned !== undefined
? a.isSigned
: a.name.startsWith('u') ||
a.name.endsWith('u') ||
!a.name.includes('int')
? 0
: 1,
name: a.name,
cluster_code: a.cluster ? a.cluster : null,
discriminator_ref: dataType
Expand Down Expand Up @@ -1203,7 +1223,13 @@ async function loadZclData(db, ctx) {
env.logDebug(
`Starting to load Dotdot ZCL data in to DB for: ${ctx.metadataFile}, clusters length=${ctx.zclClusters.length}`
)
let types = { atomics: [], enums: [], bitmaps: [], structs: [] }
let types = {
atomics: [],
enums: [],
bitmaps: [],
structs: [],
subAtomics: []
}
prepareTypes(ctx.zclTypes, types)
prepareTypes(ctx.zclGlobalTypes, types)
let preparedClusters = []
Expand Down Expand Up @@ -1245,6 +1271,8 @@ async function loadZclData(db, ctx) {
await queryLoader.insertAtomics(db, ctx.packageId, types.atomics)
ctx.ZCLDataTypes = ['ARRAY', 'BITMAP', 'ENUM', 'NUMBER', 'STRING', 'STRUCT']
await processDataTypeDiscriminator(db, ctx.packageId, ctx.ZCLDataTypes)
// prepare sub-atomics after all other types are processed
prepareSubAtomicTypes(types)
await processDataType(
db,
ctx.metadataFile,
Expand Down Expand Up @@ -1273,6 +1301,14 @@ async function loadZclData(db, ctx) {
types.structs,
dbEnum.zclType.struct
)
// sub-atomics are in the same format as atomics, so we can use the same prepare function
await processDataType(
db,
ctx.metadataFile,
ctx.packageId,
types.subAtomics,
dbEnum.zclType.atomic
)

await processEnumsFromAtomics(
db,
Expand All @@ -1288,6 +1324,8 @@ async function loadZclData(db, ctx) {
)
await processNumber(db, ctx.metadataFile, ctx.packageId, types.atomics)
await processString(db, ctx.metadataFile, ctx.packageId, types.atomics)
await processNumber(db, ctx.metadataFile, ctx.packageId, types.subAtomics)
await processString(db, ctx.metadataFile, ctx.packageId, types.subAtomics)
await processEnums(db, ctx.metadataFile, ctx.packageId, types.enums)
await processBitmaps(db, ctx.metadataFile, ctx.packageId, types.bitmaps)
await processStruct(db, ctx.metadataFile, ctx.packageId, types.structs)
Expand Down
2 changes: 1 addition & 1 deletion test/zcl-loader-consecutive.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ test(
expect(x.length).toEqual(41)

x = await queryZcl.selectAllStrings(db, jsonPackageId)
expect(x.length).toEqual(5)
expect(x.length).toEqual(4)

x = await queryStruct.selectAllStructs(db, jsonPackageId)
expect(x.length).toEqual(54)
Expand Down

0 comments on commit 803483f

Please sign in to comment.