From ffd2d3746f8f40ceb124b675fccf28b04131120e Mon Sep 17 00:00:00 2001 From: Ilya Zhuravlev Date: Wed, 2 Dec 2020 11:37:43 -0500 Subject: [PATCH] firmware_flasher: add more progress reporting and lock UI --- src/main/python/firmware_flasher.py | 98 +++++++++++++++++++++-------- src/main/python/main_window.py | 22 +++++-- 2 files changed, 88 insertions(+), 32 deletions(-) diff --git a/src/main/python/firmware_flasher.py b/src/main/python/firmware_flasher.py index d478370..9019a7d 100644 --- a/src/main/python/firmware_flasher.py +++ b/src/main/python/firmware_flasher.py @@ -31,45 +31,56 @@ def send_retries(dev, data, retries=20): CHUNK = 64 -def cmd_flash(device, firmware, log): +def cmd_flash(device, firmware, log_cb, progress_cb, complete_cb, error_cb): + while len(firmware) % CHUNK != 0: + firmware += b"\x00" + # Check bootloader is correct version device.send(b"VC\x00") data = device.recv(8) - log("* Bootloader version: {}".format(data[0])) + log_cb("* Bootloader version: {}".format(data[0])) if data[0] != 0: - log("Error: Unsupported bootloader version") - return + return error_cb("Error: Unsupported bootloader version") # TODO: Check vial ID against firmware package device.send(b"VC\x01") data = device.recv(8) - log("* Vial ID: {}".format(data.hex())) + log_cb("* Vial ID: {}".format(data.hex())) # Flash - firmware_size = len(firmware) - if firmware_size % CHUNK != 0: - firmware_size += CHUNK - firmware_size % CHUNK - log(device.send(b"VC\x02" + struct.pack("