Skip to content

Commit

Permalink
- Adding base types for derived types in the atomic xml file
Browse files Browse the repository at this point in the history
- 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
- Github: ZAP#1438
  • Loading branch information
brdandu committed Oct 28, 2024
1 parent a407b2d commit 36889ff
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 42 deletions.
2 changes: 1 addition & 1 deletion src-electron/db/db-mapping.js
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ exports.map = {
isSigned: dbApi.fromDbBool(x.IS_SIGNED),
isComposite: dbApi.fromDbBool(x.IS_COMPOSITE),
isFloat: dbApi.fromDbBool(x.IS_FLOAT),
isBaseline: dbApi.fromDbBool(x.IS_BASELINE)
baseType: x.BASE_TYPE
}
},

Expand Down
2 changes: 1 addition & 1 deletion src-electron/db/query-atomic.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ SELECT
IS_SIGNED,
IS_COMPOSITE,
IS_FLOAT,
IS_BASELINE
BASE_TYPE
FROM ATOMIC
`

Expand Down
4 changes: 2 additions & 2 deletions src-electron/db/query-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -1005,7 +1005,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, IS_COMPOSITE, IS_FLOAT, IS_BASELINE) 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 @@ -1019,7 +1019,7 @@ async function insertAtomics(db, packageId, data) {
at.isChar,
at.isComposite,
at.isFloat,
at.isBaseline
at.baseType
])
)
}
Expand Down
2 changes: 1 addition & 1 deletion src-electron/db/zap-schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,7 @@ CREATE TABLE IF NOT EXISTS "ATOMIC" (
"IS_SIGNED" integer default false,
"IS_COMPOSITE" integer default false,
"IS_FLOAT" integer default false,
"IS_BASELINE" 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
2 changes: 1 addition & 1 deletion src-electron/zcl/zcl-loader-silabs.js
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ function prepareAtomic(a) {
a.$.name.toLowerCase() === 'single' ||
a.$.name.toLowerCase() === 'double' ||
a.$.name.toLowerCase() === 'float',
isBaseline: a.$.baseline == 'true'
baseType: a.$.baseType
}
}
/**
Expand Down
14 changes: 9 additions & 5 deletions test/gen-matter-1.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,11 +210,15 @@ test(
'return DecodeIntoEmberBuffer<double>(decoder, isNullable, out);'
)

// Testing baseline types based on xml defining them
expect(simpleTest).toContain('#DEFINE ZCL_BASELINE_INT32U_DATA_TYPE')
expect(simpleTest).toContain('#DEFINE ZCL_BASELINE_INT32S_DATA_TYPE')
expect(simpleTest).toContain('#DEFINE ZCL_BASELINE_CHAR_STRING_DATA_TYPE')
expect(simpleTest).toContain('#DEFINE ZCL_BASELINE_BOOLEAN_DATA_TYPE')
// Testing base types based on xml defining them
expect(simpleTest).toContain('Baseline type for bitmap8 : int8u')
expect(simpleTest).toContain('Baseline type for bitmap32 : int32u')
expect(simpleTest).toContain('Baseline type for bitmap64 : int64u')
expect(simpleTest).toContain('Baseline type for enum8 : int8u')
expect(simpleTest).toContain('Baseline type for enum16 : int16u')
expect(simpleTest).toContain(
'Baseline type for ipv6adr : long_octet_string'
)

let deviceType = genResult.content['device-types.txt']
expect(deviceType).toContain(
Expand Down
4 changes: 2 additions & 2 deletions test/gen-template/matter/simple-test.zapt
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ switch (AttributeBaseType(metadata->attributeType))

// Extract all baseline types:
{{#zcl_atomics}}
{{#if isBaseline}}
#DEFINE ZCL_BASELINE_{{as_delimited_macro name}}_DATA_TYPE
{{#if baseType}}
Baseline type for {{name}} : {{baseType}}
{{/if}}
{{/zcl_atomics}}

58 changes: 29 additions & 29 deletions zcl-builtin/matter/data-model/chip/chip-types.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,39 +18,39 @@ limitations under the License.
<atomic>
<type id="0x00" description="No data" name="no_data" size="0" />
<!-- Base Data Types -->
<type id="0x10" description="Boolean" name="boolean" size="1" discrete="true" baseline="true"/>
<type id="0x18" description="8-bit bitmap" name="bitmap8" size="1" discrete="true" />
<type id="0x10" description="Boolean" name="boolean" size="1" discrete="true"/>
<type id="0x18" description="8-bit bitmap" name="bitmap8" size="1" discrete="true" baseType="int8u"/>
<type id="0x19" description="16-bit bitmap" name="bitmap16" size="2" discrete="true" />
<type id="0x1A" description="24-bit bitmap" name="bitmap24" size="3" discrete="true" />
<type id="0x1B" description="32-bit bitmap" name="bitmap32" size="4" discrete="true" />
<type id="0x1F" description="64-bit bitmap" name="bitmap64" size="8" discrete="true" />
<type id="0x20" description="Unsigned 8-bit integer" name="int8u" size="1" analog="true" baseline="true"/>
<type id="0x21" description="Unsigned 16-bit integer" name="int16u" size="2" analog="true" baseline="true"/>
<type id="0x22" description="Unsigned 24-bit integer" name="int24u" size="3" analog="true" baseline="true"/>
<type id="0x23" description="Unsigned 32-bit integer" name="int32u" size="4" analog="true" baseline="true"/>
<type id="0x24" description="Unsigned 40-bit integer" name="int40u" size="5" analog="true" baseline="true"/>
<type id="0x25" description="Unsigned 48-bit integer" name="int48u" size="6" analog="true" baseline="true"/>
<type id="0x26" description="Unsigned 56-bit integer" name="int56u" size="7" analog="true" baseline="true"/>
<type id="0x27" description="Unsigned 64-bit integer" name="int64u" size="8" analog="true" baseline="true"/>
<type id="0x28" description="Signed 8-bit integer" name="int8s" size="1" analog="true" baseline="true"/>
<type id="0x29" description="Signed 16-bit integer" name="int16s" size="2" analog="true" baseline="true"/>
<type id="0x2A" description="Signed 24-bit integer" name="int24s" size="3" analog="true" baseline="true"/>
<type id="0x2B" description="Signed 32-bit integer" name="int32s" size="4" analog="true" baseline="true"/>
<type id="0x2C" description="Signed 40-bit integer" name="int40s" size="5" analog="true" baseline="true"/>
<type id="0x2D" description="Signed 48-bit integer" name="int48s" size="6" analog="true" baseline="true"/>
<type id="0x2E" description="Signed 56-bit integer" name="int56s" size="7" analog="true" baseline="true"/>
<type id="0x2F" description="Signed 64-bit integer" name="int64s" size="8" analog="true" baseline="true"/>
<type id="0x30" description="8-bit enumeration" name="enum8" size="1" discrete="true" />
<type id="0x31" description="16-bit enumeration" name="enum16" size="2" discrete="true" />
<type id="0x39" description="Single precision" name="single" size="4" analog="true" baseline="true"/>
<type id="0x3A" description="Double precision" name="double" size="8" analog="true" baseline="true"/>
<type id="0x41" description="Octet String" name="octet_string" composite="true" baseline="true"/>
<type id="0x43" description="Long Octet String" name="long_octet_string" composite="true" baseline="true"/>
<type id="0x1B" description="32-bit bitmap" name="bitmap32" size="4" discrete="true" baseType="int32u"/>
<type id="0x1F" description="64-bit bitmap" name="bitmap64" size="8" discrete="true" baseType="int64u"/>
<type id="0x20" description="Unsigned 8-bit integer" name="int8u" size="1" analog="true" />
<type id="0x21" description="Unsigned 16-bit integer" name="int16u" size="2" analog="true" />
<type id="0x22" description="Unsigned 24-bit integer" name="int24u" size="3" analog="true" />
<type id="0x23" description="Unsigned 32-bit integer" name="int32u" size="4" analog="true" />
<type id="0x24" description="Unsigned 40-bit integer" name="int40u" size="5" analog="true" />
<type id="0x25" description="Unsigned 48-bit integer" name="int48u" size="6" analog="true" />
<type id="0x26" description="Unsigned 56-bit integer" name="int56u" size="7" analog="true" />
<type id="0x27" description="Unsigned 64-bit integer" name="int64u" size="8" analog="true" />
<type id="0x28" description="Signed 8-bit integer" name="int8s" size="1" analog="true" />
<type id="0x29" description="Signed 16-bit integer" name="int16s" size="2" analog="true" />
<type id="0x2A" description="Signed 24-bit integer" name="int24s" size="3" analog="true" />
<type id="0x2B" description="Signed 32-bit integer" name="int32s" size="4" analog="true" />
<type id="0x2C" description="Signed 40-bit integer" name="int40s" size="5" analog="true" />
<type id="0x2D" description="Signed 48-bit integer" name="int48s" size="6" analog="true" />
<type id="0x2E" description="Signed 56-bit integer" name="int56s" size="7" analog="true" />
<type id="0x2F" description="Signed 64-bit integer" name="int64s" size="8" analog="true" />
<type id="0x30" description="8-bit enumeration" name="enum8" size="1" discrete="true" baseType="int8u"/>
<type id="0x31" description="16-bit enumeration" name="enum16" size="2" discrete="true" baseType="int16u"/>
<type id="0x39" description="Single precision" name="single" size="4" analog="true" />
<type id="0x3A" description="Double precision" name="double" size="8" analog="true" />
<type id="0x41" description="Octet String" name="octet_string" composite="true" />
<type id="0x43" description="Long Octet String" name="long_octet_string" composite="true" />
<type id="0x48" description="List" name="array" composite="true"/>
<type id="0x4C" description="Structure" name="struct" composite="true"/>
<!-- Derived Data Types -->
<type id="0x42" description="Character String" name="char_string" composite="true" baseline="true"/>
<type id="0x44" description="Long Character String" name="long_char_string" composite="true" baseline="true"/>
<type id="0x42" description="Character String" name="char_string" composite="true" />
<type id="0x44" description="Long Character String" name="long_char_string" composite="true" />
<type id="0xE0" description="Time of day" name="tod" size="4" analog="true" />
<type id="0xE1" description="Date" name="date" size="4" analog="true" />
<type id="0xE3" description="Epoch Microseconds" name="epoch_us" size="8" analog="true" />
Expand All @@ -77,7 +77,7 @@ limitations under the License.
<type id="0xF9" description="Fabric Index" name="fabric_idx" size="1" discrete="true" />
<type id="0xFA" description="IP Address" name="ipadr" composite="true"/>
<type id="0xFB" description="IPv4 Address" name="ipv4adr" size="4" composite="true"/>
<type id="0xFC" description="IPv6 Address" name="ipv6adr" size="16" composite="true"/>
<type id="0xFC" description="IPv6 Address" name="ipv6adr" size="16" composite="true" baseType="long_octet_string"/>
<type id="0xFD" description="IPv6 Prefix" name="ipv6pre" composite="true"/>
<type id="0xFE" description="Hardware Address" name="hwadr" composite="true"/>
<type id="0xFF" description="Unknown" name="unknown" size="0" />
Expand Down

0 comments on commit 36889ff

Please sign in to comment.