From 5ff2e757097051879793eef664c78d3078ffd51e Mon Sep 17 00:00:00 2001 From: Robin Krens Date: Wed, 14 Feb 2024 10:51:50 +0100 Subject: [PATCH] RAFlasher.py: add progress bar --- src/RAFlasher.py | 30 +++++++++++++----------------- 1 file changed, 13 insertions(+), 17 deletions(-) diff --git a/src/RAFlasher.py b/src/RAFlasher.py index cf63a26..f6642eb 100644 --- a/src/RAFlasher.py +++ b/src/RAFlasher.py @@ -143,24 +143,20 @@ def write_img(dev, img, start_addr, end_addr, verify=False): unpack_pkt(ret) with open(img, 'rb') as f: - cnt = 0 - chunk = f.read(chunk_size) - while chunk: - if len(chunk) != chunk_size: - padding_length = chunk_size - len(chunk) - chunk += b'\0' * padding_length - cnt += 1 - packed = pack_pkt(WRI_CMD, chunk, ack=True) - print(f'Sending {len(chunk)} bytes: {cnt}') - dev.send_data(packed) - reply_len = 7 - reply = dev.recv_data(reply_len) - #reply = b'\x81\x00\x02\x00\x00\xFE\x03' # test reply - #if not reply == False: - #print(reply) - msg = unpack_pkt(reply) - #print(msg) + with tqdm(total=file_size, desc="Sending chunks") as pbar: chunk = f.read(chunk_size) + pbar.update(len(chunk)) + while chunk: + if len(chunk) != chunk_size: + padding_length = chunk_size - len(chunk) + chunk += b'\0' * padding_length + packed = pack_pkt(WRI_CMD, chunk, ack=True) + dev.send_data(packed) + reply_len = 7 + reply = dev.recv_data(reply_len) + msg = unpack_pkt(reply) + chunk = f.read(chunk_size) + pbar.update(len(chunk)) def main(): -- 2.7.4