From: Robin Krens Date: Wed, 14 Feb 2024 09:51:50 +0000 (+0100) Subject: RAFlasher.py: add progress bar X-Git-Tag: v0.0.1~30 X-Git-Url: https://robinkrens.nl/gitweb/?a=commitdiff_plain;h=5ff2e757097051879793eef664c78d3078ffd51e;p=renesas-ra-flasher RAFlasher.py: add progress bar --- 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():