Skip to content

Commit 2819a97

Browse files
committed
fix: fixing failed test - flash firmware hubname checksum calculation
1 parent 872ba15 commit 2819a97

File tree

1 file changed

+11
-15
lines changed

1 file changed

+11
-15
lines changed

src/firmware/sagas.ts

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -348,18 +348,26 @@ function* loadFirmware(
348348
const metadataV2 = metadata as FirmwareMetadataV200;
349349
const checksum_size = metadataV2['checksum-size'];
350350

351-
// TODO: v2.x supports setting checksum size, prior it was a fixed 4 bytes - check if it 4 or checksum_size
352351
const firmware = new Uint8Array(firmwareBase.length + 4);
353352
const firmwareView = new DataView(firmware.buffer);
353+
354+
firmware.set(firmwareBase);
355+
356+
// empty string means use default name (don't write over firmware)
357+
if (hubName) {
358+
firmware.set(
359+
encodeHubName(hubName, metadata),
360+
metadataV2['hub-name-offset'],
361+
);
362+
}
363+
354364
const checksum = (function () {
355365
switch (metadata['checksum-type']) {
356366
case 'sum':
357-
console.log('computing sum');
358367
return sumComplement32(
359368
firmwareIterator(firmwareView, metadataV2['checksum-size']),
360369
);
361370
case 'crc32':
362-
console.log('computing crc32');
363371
return crc32(
364372
firmwareIterator(firmwareView, metadataV2['checksum-size']),
365373
);
@@ -368,16 +376,6 @@ function* loadFirmware(
368376
}
369377
})();
370378

371-
firmware.set(firmwareBase);
372-
373-
// empty string means use default name (don't write over firmware)
374-
if (hubName) {
375-
firmware.set(
376-
encodeHubName(hubName, metadata),
377-
metadataV2['hub-name-offset'],
378-
);
379-
}
380-
381379
if (checksum === undefined) {
382380
// FIXME: we should return error/throw instead
383381
yield* put(
@@ -413,7 +411,6 @@ function* handleFlashFirmware(action: ReturnType<typeof flashFirmware>): Generat
413411
if (action.data !== null) {
414412
({ firmware, deviceId } = yield* loadFirmware(action.data, action.hubName));
415413
}
416-
console.log('>>> deviceId', deviceId, 'firmware', firmware, action.data);
417414

418415
yield* put(connect());
419416
const connectResult = yield* take([didConnect, didFailToConnect]);
@@ -601,7 +598,6 @@ function* handleFlashFirmware(action: ReturnType<typeof flashFirmware>): Generat
601598
}
602599

603600
if (flash.checksum !== runningChecksum) {
604-
console.error('>>>> checksum', flash.checksum, runningChecksum);
605601
// istanbul ignore next
606602
if (process.env.NODE_ENV !== 'test') {
607603
console.error(

0 commit comments

Comments
 (0)