This PR adds support for a progress callback that the user may use to log progress during the flashing process.
The following events have been added:
start-erase (Starts erase)
More easily testable for dfu than for control requests
For control requests via updateFirmware, the erase functionality depends on flags which are set inside the device-os. I am still adding in without checking for those flags
erased
Erase in progress and shows that bytes number of bytes are erased at that time
start-download
Started download process
downloaded
Download still in progress. Downloaded bytes number of bytes at that time
complete-download
Completed download without any errors
failed-download
Failed downloaded (Valid only for dfu. Unable to find this state in the updateFirmware function?)
For control requests, it appears that the error is caught by the caller
Usage
Checkout this branch
Point the usb module of your test script to the folder path of this branch
Description
This PR adds support for a progress callback that the user may use to log progress during the flashing process.
The following events have been added:
start-erase
(Starts erase)updateFirmware
, the erase functionality depends on flags which are set inside the device-os. I am still adding in without checking for those flagserased
bytes
number of bytes are erased at that timestart-download
downloaded
bytes
number of bytes at that timecomplete-download
failed-download
Usage
async function main() { const devices = await usb.getDevices(); if (devices.length === 0) { throw new Error('No devices found'); } const device = devices[0]; console.log('Device : ', device); await device.open(); await device.enterDfuMode();
const buf = await fs.readFile('/path/to/binaries/5.4.0/p2/p2-system-part1@5.4.0.bin'); const reader = new HalModuleParser(); const parsed = await reader.parseBuffer({ fileBuffer: buf }); const addr = parseInt(parsed.prefixInfo.moduleStartAddy, 16); await dev.writeOverDfu({ altSetting: 0, buffer: parsed.fileBuffer, addr: addr, options: {}, progress: this.progressCb });
const bufTinker = await fs.readFile('/path/to/binaries/5.4.0/p2/p2-tinker@5.4.0.bin'); const parsedTinker = await reader.parseBuffer({ fileBuffer: bufTinker }); const addrTinker = parseInt(parsedTinker.prefixInfo.moduleStartAddy, 16); await dev.writeOverDfu({ altSetting: 0, buffer: parsedTinker.fileBuffer, addr: addrTinker, options: {}, progress: this.progressCb });
await device.reset(); }
main().catch((error) => { console.error('Error:', error.message); });
progressCb({event: event, bytes: bytes}) { console.log('Event: ' + event + ' Bytes: ' + bytes); }
Event: start-erase Bytes: 1011712 // Started erasing System-part1 over DFU Event: erased Bytes: 4096 Event: erased Bytes: 4096 Event: erased Bytes: 4096 . . Event: erased Bytes: 4096 Event: erased Bytes: 4096 Event: start-download Bytes: 1009100 // Started downloading System-part1 over DFU Event: downloaded Bytes: 4096 Event: downloaded Bytes: 4096 . . Event: downloaded Bytes: 4096 Event: downloaded Bytes: 4096 Event: downloaded Bytes: 4096 Event: downloaded Bytes: 1484 Event: complete-download Bytes: 1009100 Event: start-erase Bytes: 49152 // Started erasing Tinker over DFU Event: erased Bytes: 4096 Event: erased Bytes: 4096 . . Event: erased Bytes: 4096 Event: erased Bytes: 4096 Event: start-download Bytes: 49152 // Started download Tinker over DFU Event: downloaded Bytes: 4096 Event: downloaded Bytes: 4096 . . Event: downloaded Bytes: 4096 Event: downloaded Bytes: 4096 Event: complete-download Bytes: 49152
Calling update firmware on tracker-bootloader@4.1.0.bin Event: start-erase Bytes: 46132 Event: erased Bytes: 46132 Event: start-download Bytes: 46132 Event: downloaded Bytes: 1024 Event: downloaded Bytes: 1024 . . Event: downloaded Bytes: 1024 Event: downloaded Bytes: 52 Event: complete-download Bytes: 46132
Calling update firmware on tracker-esp32-ncp@5.3.0.bin Event: start-erase Bytes: 864464 Event: erased Bytes: 864464 Event: start-download Bytes: 864464 Event: downloaded Bytes: 1024 Event: downloaded Bytes: 1024 . . Event: downloaded Bytes: 1024 Event: downloaded Bytes: 208 Event: complete-download Bytes: 864464 ! System firmware update successfully completed!
Process finished with exit code 0