From 858cf26e5e548dbb4d25ff148c0d4b52a490e700 Mon Sep 17 00:00:00 2001 From: David Lechner Date: Thu, 21 May 2020 20:27:08 -0500 Subject: [PATCH] smoother firmware flash progress This waits for the OS to give a reply about the request being sent before updating progress. Before, we were just updating progress when requests were queued rather than actually sent. --- src/sagas/bootloader.ts | 42 +++++++++++++++++++++++++---------------- 1 file changed, 26 insertions(+), 16 deletions(-) diff --git a/src/sagas/bootloader.ts b/src/sagas/bootloader.ts index def68f12..3f0a637e 100644 --- a/src/sagas/bootloader.ts +++ b/src/sagas/bootloader.ts @@ -22,11 +22,14 @@ import { BootloaderConnectionDidErrorAction, BootloaderConnectionDidReceiveAction, BootloaderConnectionDidSendAction, + BootloaderDidRequestAction, + BootloaderDidRequestType, BootloaderEraseResponseAction, BootloaderErrorResponseAction, BootloaderFlashFirmwareAction, BootloaderInfoResponseAction, BootloaderInitResponseAction, + BootloaderProgramRequestAction, BootloaderProgramResponseAction, BootloaderRequestAction, BootloaderRequestActionType, @@ -314,25 +317,32 @@ function* flashFirmware(action: BootloaderFlashFirmwareAction): Generator { for (let offset = 0; offset < firmware.length; offset += MaxProgramFlashSize) { const payload = firmware.slice(offset, offset + MaxProgramFlashSize); - yield put(programRequest(info[0].startAddress + offset, payload.buffer)); + const req = (yield put( + programRequest(info[0].startAddress + offset, payload.buffer), + )) as BootloaderProgramRequestAction; + + // TODO: check for error + yield take( + (a: Action) => + a.type === BootloaderDidRequestType && + (a as BootloaderDidRequestAction).id === req.id, + ); - // TODO: wait for request to actually be sent before reporting progress yield put(progress(offset, firmware.length)); - // TODO: we can skip getting the checksum when canWriteWithoutResponse === false - // when the todo above is done. - - // request checksum every 8K to prevent buffer overrun on the hub - // because of sending too much data at once - if (++count % 585 === 0) { - yield put(checksumRequest()); - const checksum = (yield wait( - BootloaderResponseActionType.Checksum, - didConnect.canWriteWithoutResponse ? 5000 : 60000, - )) as WaitResponse; - if (!checksum[0]) { - // TODO: proper error handling - throw Error(`Failed to get checksum: ${checksum}`); + if (didConnect.canWriteWithoutResponse) { + // request checksum every 8K to prevent buffer overrun on the hub + // because of sending too much data at once + if (++count % 585 === 0) { + yield put(checksumRequest()); + const checksum = (yield wait( + BootloaderResponseActionType.Checksum, + 5000, + )) as WaitResponse; + if (!checksum[0]) { + // TODO: proper error handling + throw Error(`Failed to get checksum: ${checksum}`); + } } } }