From 3b3141218622405845e416455bf32f9c13b14f3b Mon Sep 17 00:00:00 2001 From: David Lechner Date: Thu, 21 Jan 2021 12:30:11 -0600 Subject: [PATCH] minor code improvements in flash-firmware --- src/sagas/flash-firmware.ts | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/sagas/flash-firmware.ts b/src/sagas/flash-firmware.ts index ac90b02e..787337e5 100644 --- a/src/sagas/flash-firmware.ts +++ b/src/sagas/flash-firmware.ts @@ -298,14 +298,10 @@ function* flashFirmware(action: FlashFirmwareFlashAction): Generator { throw Error(`Failed to init: ${init}`); } - let count = 0; - const maxDataSize = MaxProgramFlashSize.get(info[0].hubType); - if (maxDataSize === undefined) { - // istanbul ignore next: indicates programmer error if reached - throw Error('Missing hub type in MaxProgramFlashSize'); - } + // 14 is "safe" size for all hubs + const maxDataSize = MaxProgramFlashSize.get(info[0].hubType) || 14; - for (let offset = 0; ; ) { + for (let count = 1, offset = 0; ; count++) { const payload = firmware.slice(offset, offset + maxDataSize); const programAction = (yield put( programRequest( @@ -329,7 +325,7 @@ function* flashFirmware(action: FlashFirmwareFlashAction): Generator { // the hub because of sending too much data at once. The actual // number of packets that can be queued in the Bluetooth chip on // the hub is not known and could vary by device. - if (++count % 10 === 0) { + if (count % 10 === 0) { const checksumAction = (yield put( checksumRequest(nextMessageId()), )) as BootloaderChecksumRequestAction;