Skip to content

Commit a4e2781

Browse files
authored
Fix endianness issue when the hex value length is odd (#1579)
* Fix endianness issue when the hex value length is odd - See the unit test to understand the issue here where 1600 should not be 0x640 but 0x0640 for proper endian conversion - Added unit tests - Updating the matter build for ZAP and Matter repo integration testing - ZAPP-1610
1 parent 317a7db commit a4e2781

3 files changed

Lines changed: 31 additions & 2 deletions

File tree

.github/workflows/matter.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ jobs:
192192

193193
# CHIP container required because clang-format version needs to match
194194
container:
195-
image: connectedhomeip/chip-build:0.6.11
195+
image: ghcr.io/project-chip/chip-build:125
196196

197197
steps:
198198
- uses: actions/download-artifact@v4

src-electron/generator/helper-c.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,14 @@ function asHex(rawValue, padding, nullValue) {
6969
return `0x${value.slice(2).toUpperCase()}`
7070
} else {
7171
let val = parseInt(value)
72-
return `0x${val.toString(16).padStart(padding, '0').toUpperCase()}`
72+
let paddingLength = padding
73+
if (!paddingLength) {
74+
paddingLength =
75+
val.toString(16).length % 2 === 0
76+
? val.toString(16).length
77+
: val.toString(16).length + 1
78+
}
79+
return `0x${val.toString(16).padStart(paddingLength, '0').toUpperCase()}`
7380
}
7481
}
7582

test/helpers.test.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,28 @@ test(
478478
testUtil.timeout.short()
479479
)
480480

481+
test(
482+
'Generated Macro for 4 byte integer little endian',
483+
() => {
484+
let options = { hash: { endian: 'little' } }
485+
return zclHelper
486+
.as_generated_default_macro('1600', 4, options)
487+
.then((res) => expect(res).toBe('0x40, 0x06, 0x00, 0x00,'))
488+
},
489+
testUtil.timeout.short()
490+
)
491+
492+
test(
493+
'Generated Macro for 4 byte integer big endian',
494+
() => {
495+
let options = { hash: { endian: 'big' } }
496+
return zclHelper
497+
.as_generated_default_macro('1600', 4, options)
498+
.then((res) => expect(res).toBe('0x00, 0x00, 0x06, 0x40,'))
499+
},
500+
testUtil.timeout.short()
501+
)
502+
481503
test(
482504
'Generated Macro for string',
483505
() => {

0 commit comments

Comments
 (0)