Skip to content

Commit

Permalink
- Add additional is_power_of_two helper for matter use case to determ…
Browse files Browse the repository at this point in the history
…ine odd sized data types (project-chip#1472)

- update the atomic table schema, retrieval and mapping
- Add unit tests with the example needed for Matter code
- update feature level pointer
- Updating the zap schema
- Adding support to determine if a data type is baseline type or not from the xml itself
- This is done by adding BASE_TYPE column to the atomic table and then mapping it appropriately to baseType for the zcl_atomics helper
- Adding base types for derived types in the atomic xml file
- This is done by adding baseType column to the atomic table and then mapping it appropriately to baseType for the zcl_atomics helper such that derived types can refer to base types
Cleanup
- Github: ZAP#1438
  • Loading branch information
brdandu authored Oct 29, 2024
1 parent ecf3659 commit baa3034
Show file tree
Hide file tree
Showing 15 changed files with 4,943 additions and 4,751 deletions.
2 changes: 1 addition & 1 deletion apack.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "Graphical configuration tool for application and libraries based on Zigbee Cluster Library.",
"path": [".", "node_modules/.bin/", "ZAP.app/Contents/MacOS"],
"requiredFeatureLevel": "apack.core:9",
"featureLevel": 104,
"featureLevel": 105,
"uc.triggerExtension": "zap",
"executable": {
"zap:win32.x86_64": {
Expand Down
13 changes: 13 additions & 0 deletions docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -11266,6 +11266,7 @@ This module contains the API for templating. For more detailed instructions, rea
* [~replace_string(mainString, replaceString, replaceWithString)](#module_Templating API_ toplevel utility helpers..replace_string) ⇒
* [~add_prefix_to_all_strings(str, prefixStr)](#module_Templating API_ toplevel utility helpers..add_prefix_to_all_strings) ⇒
* [~multiply()](#module_Templating API_ toplevel utility helpers..multiply) ⇒
* [~is_power_of_two(val)](#module_Templating API_ toplevel utility helpers..is_power_of_two) ⇒
* [~is_string_underscored(val)](#module_Templating API_ toplevel utility helpers..is_string_underscored) ⇒
* [~as_uppercase(val)](#module_Templating API_ toplevel utility helpers..as_uppercase) ⇒

Expand Down Expand Up @@ -11587,6 +11588,18 @@ Returns a concatenated string with spaces between each string
### Templating API: toplevel utility helpers~multiply() ⇒
**Kind**: inner method of [<code>Templating API: toplevel utility helpers</code>](#module_Templating API_ toplevel utility helpers)
**Returns**: A number which is result of multiplying all the arguments given
<a name="module_Templating API_ toplevel utility helpers..is_power_of_two"></a>

### Templating API: toplevel utility helpers~is\_power\_of\_two(val) ⇒
Returns a boolean based on whether a given value is a power or 2 or not.

**Kind**: inner method of [<code>Templating API: toplevel utility helpers</code>](#module_Templating API_ toplevel utility helpers)
**Returns**: boolean

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

<a name="module_Templating API_ toplevel utility helpers..is_string_underscored"></a>

### Templating API: toplevel utility helpers~is\_string\_underscored(val) ⇒
Expand Down
13 changes: 13 additions & 0 deletions docs/helpers.md
Original file line number Diff line number Diff line change
Expand Up @@ -2945,6 +2945,7 @@ This module contains the API for templating. For more detailed instructions, rea
* [~replace_string(mainString, replaceString, replaceWithString)](#module_Templating API_ toplevel utility helpers..replace_string) ⇒
* [~add_prefix_to_all_strings(str, prefixStr)](#module_Templating API_ toplevel utility helpers..add_prefix_to_all_strings) ⇒
* [~multiply()](#module_Templating API_ toplevel utility helpers..multiply) ⇒
* [~is_power_of_two(val)](#module_Templating API_ toplevel utility helpers..is_power_of_two) ⇒
* [~is_string_underscored(val)](#module_Templating API_ toplevel utility helpers..is_string_underscored) ⇒
* [~as_uppercase(val)](#module_Templating API_ toplevel utility helpers..as_uppercase) ⇒

Expand Down Expand Up @@ -3266,6 +3267,18 @@ Returns a concatenated string with spaces between each string
### Templating API: toplevel utility helpers~multiply() ⇒
**Kind**: inner method of [<code>Templating API: toplevel utility helpers</code>](#module_Templating API_ toplevel utility helpers)
**Returns**: A number which is result of multiplying all the arguments given
<a name="module_Templating API_ toplevel utility helpers..is_power_of_two"></a>

### Templating API: toplevel utility helpers~is\_power\_of\_two(val) ⇒
Returns a boolean based on whether a given value is a power or 2 or not.

**Kind**: inner method of [<code>Templating API: toplevel utility helpers</code>](#module_Templating API_ toplevel utility helpers)
**Returns**: boolean

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

<a name="module_Templating API_ toplevel utility helpers..is_string_underscored"></a>

### Templating API: toplevel utility helpers~is\_string\_underscored(val) ⇒
Expand Down
4,785 changes: 2,420 additions & 2,365 deletions docs/zap-schema.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 4 additions & 1 deletion src-electron/db/db-mapping.js
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,10 @@ exports.map = {
isString: dbApi.fromDbBool(x.IS_STRING),
isLong: dbApi.fromDbBool(x.IS_LONG),
isChar: dbApi.fromDbBool(x.IS_CHAR),
isSigned: dbApi.fromDbBool(x.IS_SIGNED)
isSigned: dbApi.fromDbBool(x.IS_SIGNED),
isComposite: dbApi.fromDbBool(x.IS_COMPOSITE),
isFloat: dbApi.fromDbBool(x.IS_FLOAT),
baseType: x.BASE_TYPE
}
},

Expand Down
5 changes: 4 additions & 1 deletion src-electron/db/query-atomic.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@ SELECT
IS_STRING,
IS_LONG,
IS_CHAR,
IS_SIGNED
IS_SIGNED,
IS_COMPOSITE,
IS_FLOAT,
BASE_TYPE
FROM ATOMIC
`

Expand Down
7 changes: 5 additions & 2 deletions src-electron/db/query-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -1090,7 +1090,7 @@ INSERT OR IGNORE INTO GLOBAL_ATTRIBUTE_BIT (
async function insertAtomics(db, packageId, data) {
return dbApi.dbMultiInsert(
db,
'INSERT INTO ATOMIC (PACKAGE_REF, NAME, DESCRIPTION, ATOMIC_IDENTIFIER, ATOMIC_SIZE, IS_DISCRETE, IS_SIGNED, IS_STRING, IS_LONG, IS_CHAR) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)',
'INSERT INTO ATOMIC (PACKAGE_REF, NAME, DESCRIPTION, ATOMIC_IDENTIFIER, ATOMIC_SIZE, IS_DISCRETE, IS_SIGNED, IS_STRING, IS_LONG, IS_CHAR, IS_COMPOSITE, IS_FLOAT, BASE_TYPE) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)',
data.map((at) => [
packageId,
at.name,
Expand All @@ -1101,7 +1101,10 @@ async function insertAtomics(db, packageId, data) {
at.isSigned,
at.isString,
at.isLong,
at.isChar
at.isChar,
at.isComposite,
at.isFloat,
at.baseType
])
)
}
Expand Down
3 changes: 3 additions & 0 deletions src-electron/db/zap-schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -600,6 +600,9 @@ CREATE TABLE IF NOT EXISTS "ATOMIC" (
"IS_LONG" integer default false,
"IS_CHAR" integer default false,
"IS_SIGNED" integer default false,
"IS_COMPOSITE" integer default false,
"IS_FLOAT" integer default false,
"BASE_TYPE" text,
foreign key (PACKAGE_REF) references PACKAGE(PACKAGE_ID) ON DELETE CASCADE ON UPDATE CASCADE
UNIQUE(PACKAGE_REF, NAME, ATOMIC_IDENTIFIER)
);
Expand Down
10 changes: 10 additions & 0 deletions src-electron/generator/helper-zap.js
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,15 @@ function multiply() {
return nums.reduce((prev, next) => prev * next, 1)
}

/**
* Returns a boolean based on whether a given value is a power or 2 or not.
* @param {*} val
* @returns boolean
*/
function is_power_of_two(val) {
return Number.isInteger(Math.log2(val))
}

/**
*
* @param {*} val
Expand Down Expand Up @@ -526,3 +535,4 @@ exports.add_prefix_to_all_strings = add_prefix_to_all_strings
exports.multiply = multiply
exports.is_string_underscored = is_string_underscored
exports.as_uppercase = as_uppercase
exports.is_power_of_two = is_power_of_two
4 changes: 2 additions & 2 deletions src-electron/importexport/import-json.js
Original file line number Diff line number Diff line change
Expand Up @@ -310,12 +310,12 @@ async function importSinglePackage(
if (packageMatch && packageNameMatch) {
p = packageNameMatch
env.logError(
`None of packages exist for ${pkg.path}, so using one which matches the file name: ${p.path} from ${pkgPaths}.`
`None of packages exist for ${pkg.path || pkg}, so using one which matches the file name: ${p.path} from ${pkgPaths}.`
)
} else {
// None exists, so use the first one from 'packages'.
env.logError(
`None of packages exist for ${pkg.path}, so using first one overall: ${p.path} from ${pkgPaths}.`
`None of packages exist for ${pkg.path || pkg}, so using first one overall: ${p.path} from ${pkgPaths}.`
)
}
return {
Expand Down
24 changes: 21 additions & 3 deletions src-electron/zcl/zcl-loader-silabs.js
Original file line number Diff line number Diff line change
Expand Up @@ -304,10 +304,28 @@ function prepareAtomic(a) {
size: a.$.size,
description: a.$.description,
isDiscrete: a.$.discrete == 'true',
isComposite: a.$.composite == 'true',
isSigned: a.$.signed == 'true',
isString: a.$.string == 'true',
isLong: a.$.long == 'true',
isChar: a.$.char == 'true'
isString:
a.$.string == 'true' ||
a.$.name.toLowerCase() == 'char_string' ||
a.$.name.toLowerCase() == 'long_char_string' ||
a.$.name.toLowerCase() == 'octet_string' ||
a.$.name.toLowerCase() == 'long_octet_string',
isLong:
a.$.long == 'true' ||
a.$.name.toLowerCase() == 'long_char_string' ||
a.$.name.toLowerCase() == 'long_octet_string',
isChar:
a.$.char == 'true' ||
a.$.name.toLowerCase() == 'char_string' ||
a.$.name.toLowerCase() == 'long_char_string',
isFloat:
a.$.float == 'true' ||
a.$.name.toLowerCase() === 'single' ||
a.$.name.toLowerCase() === 'double' ||
a.$.name.toLowerCase() === 'float',
baseType: a.$.baseType
}
}
/**
Expand Down
9 changes: 9 additions & 0 deletions test/gen-matter-1.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,15 @@ test(
expect(simpleTest).toContain(
'ExternalAddon : This is example of test external addon helper.'
)

// Testing base types based on xml defining them
expect(simpleTest).toContain('Base type for bitmap8 : int8u')
expect(simpleTest).toContain('Base type for bitmap32 : int32u')
expect(simpleTest).toContain('Base type for bitmap64 : int64u')
expect(simpleTest).toContain('Base type for enum8 : int8u')
expect(simpleTest).toContain('Base type for enum16 : int16u')
expect(simpleTest).toContain('Base type for ipv6adr : long_octet_string')

let deviceType = genResult.content['device-types.txt']
expect(deviceType).toContain(
'// device type: CHIP / 0x0105 => MA-colordimmerswitch // extension: '
Expand Down
7 changes: 7 additions & 0 deletions test/gen-template/matter/simple-test.zapt
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,10 @@ ExternalAddon : {{test_external_addon_all_commands_helper}}
ExternalAddon : {{test_external_addon_all_events_helper}}
ExternalAddon : {{test_external_addon_helper}}

// Extract all Base types:
{{#zcl_atomics}}
{{#if baseType}}
Base type for {{name}} : {{baseType}}
{{/if}}
{{/zcl_atomics}}

Loading

0 comments on commit baa3034

Please sign in to comment.