Skip to content

Commit 4e7d682

Browse files
authored
- Minor cleanup on min/max values when they are not resolved correctly (#1618)
- Reverting the changes made to typecase the attribute values based on size and sign and sticking to uint16_t as before - Github: ZAP #1615
1 parent 93f5d14 commit 4e7d682

File tree

3 files changed

+35
-17
lines changed

3 files changed

+35
-17
lines changed

src-electron/generator/helper-endpointconfig.js

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -612,8 +612,28 @@ function endpoint_attribute_min_max_list(options) {
612612
let max = parseInt(mm.max)
613613

614614
if (isNaN(def)) def = 0
615-
if (isNaN(min)) min = 0
616-
if (isNaN(max)) max = '0x' + 'FF'.repeat(mm.typeSize)
615+
if (isNaN(min)) {
616+
if (mm.typeSize < 1)
617+
throw new Error(
618+
'Invalid type size for min value: ' + JSON.stringify(mm)
619+
)
620+
if (mm.isTypeSigned) {
621+
min = '0x80' + '00'.repeat(mm.typeSize - 1)
622+
} else {
623+
min = 0
624+
}
625+
}
626+
if (isNaN(max)) {
627+
if (mm.typeSize < 1)
628+
throw new Error(
629+
'Invalid type size for max value: ' + JSON.stringify(mm)
630+
)
631+
if (mm.isTypeSigned) {
632+
max = '0x7F' + 'FF'.repeat(mm.typeSize - 1)
633+
} else {
634+
max = '0x' + 'FF'.repeat(mm.typeSize)
635+
}
636+
}
617637

618638
let defS =
619639
(def >= 0 ? '' : '-') + '0x' + Math.abs(def).toString(16).toUpperCase()
@@ -628,19 +648,13 @@ function endpoint_attribute_min_max_list(options) {
628648
.forEach((tok) => {
629649
switch (tok) {
630650
case 'def':
631-
defMinMaxItems.push(
632-
`(${mm.isTypeSigned ? '' : 'u'}int${mm.typeSize * 8}_t)${defS}`
633-
)
651+
defMinMaxItems.push(`(uint16_t)${defS}`)
634652
break
635653
case 'min':
636-
defMinMaxItems.push(
637-
`(${mm.isTypeSigned ? '' : 'u'}int${mm.typeSize * 8}_t)${minS}`
638-
)
654+
defMinMaxItems.push(`(uint16_t)${minS}`)
639655
break
640656
case 'max':
641-
defMinMaxItems.push(
642-
`(${mm.isTypeSigned ? '' : 'u'}int${mm.typeSize * 8}_t)${maxS}`
643-
)
657+
defMinMaxItems.push(`(uint16_t)${maxS}`)
644658
break
645659
}
646660
})

test/custom-matter-xml.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,7 @@ test(
443443
' /* Endpoint: 1, Cluster: Sample Custom Cluster (server) */ \\'
444444
)
445445
expect(endpointConfig).toContain(
446-
'{ (uint8_t)0x0, (uint8_t)0x0, (uint8_t)0xFF }, /* Sample Mfg Specific Attribute 2 */ \\'
446+
'{ (uint16_t)0x0, (uint16_t)0x0, (uint16_t)0xFF }, /* Sample Mfg Specific Attribute 2 */ \\'
447447
)
448448

449449
let endpointOut = genResult.content['endpoints.out']
@@ -490,7 +490,7 @@ test(
490490
' /* Endpoint: 1, Cluster: Sample Custom Cluster (server) */ \\'
491491
)
492492
expect(endpointConfig).not.toContain(
493-
'{ (uint8_t)0x0, (uint8_t)0x0, (uint8_t)0xFF }, /* Sample Mfg Specific Attribute 2 */ \\'
493+
'{ (uint16_t)0x0, (uint16_t)0x0, (uint16_t)0xFF }, /* Sample Mfg Specific Attribute 2 */ \\'
494494
)
495495

496496
// create state from database and session to verify contents of .zap file

test/gen-matter-3-1.test.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,10 +126,12 @@ test(
126126
`{ 0x00000005, ZAP_TYPE(ENUM8), 1, ZAP_ATTRIBUTE_MASK(EXTERNAL_STORAGE) | ZAP_ATTRIBUTE_MASK(NULLABLE), ZAP_EMPTY_DEFAULT() }, /* LastNetworkingStatus */`
127127
)
128128
expect(ept).toContain(
129-
'{ (uint8_t)0xFF, (uint8_t)0x64, (uint8_t)0xFF }, /* BallastFactorAdjustment */'
129+
'{ (uint16_t)0xFF, (uint16_t)0x64, (uint16_t)0xFF }, /* BallastFactorAdjustment */'
130130
)
131131
expect(ept).toContain(`6, 'C', 'o', 'f', 'f', 'e', 'e', \\`)
132-
expect(ept).toContain('{ (int16_t)-0x64, (int16_t)-0x96, (int16_t)0xC8 }')
132+
expect(ept).toContain(
133+
'{ (uint16_t)-0x64, (uint16_t)-0x96, (uint16_t)0xC8 }'
134+
)
133135
expect(ept).toContain('#define GENERATED_MIN_MAX_DEFAULT_COUNT 51')
134136
expect(ept).toContain('#define GENERATED_ATTRIBUTE_COUNT 739')
135137
expect(ept).toContain(`/* EventList (index=8) */ \\
@@ -236,10 +238,12 @@ test(
236238
' { 0x00000000, ZAP_TYPE(TEMPERATURE), 2, ZAP_ATTRIBUTE_MASK(NULLABLE), ZAP_SIMPLE_DEFAULT(0x8000) },'
237239
)
238240
expect(ept).toContain(
239-
'{ (uint8_t)0xFF, (uint8_t)0x64, (uint8_t)0xFF }, /* BallastFactorAdjustment */'
241+
'{ (uint16_t)0xFF, (uint16_t)0x64, (uint16_t)0xFF }, /* BallastFactorAdjustment */'
240242
)
241243
expect(ept).toContain(`6, 'C', 'o', 'f', 'f', 'e', 'e', \\`)
242-
expect(ept).toContain('{ (int16_t)-0x64, (int16_t)-0x96, (int16_t)0xC8 }')
244+
expect(ept).toContain(
245+
'{ (uint16_t)-0x64, (uint16_t)-0x96, (uint16_t)0xC8 }'
246+
)
243247
expect(ept).toContain('#define GENERATED_MIN_MAX_DEFAULT_COUNT 51')
244248
expect(ept).toContain('#define GENERATED_ATTRIBUTE_COUNT 739')
245249
expect(ept).toContain(`/* EventList (index=8) */ \\

0 commit comments

Comments
 (0)