Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implement progress_bar workaound #43

Merged
merged 1 commit into from
Feb 24, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
implement progress_bar workaound
Prevent progress bar overrun if flash_size is divisible by 254
  • Loading branch information
dmg210 authored Feb 24, 2024
commit d674fb3ad37347d5dcfb1274183834e6a52dc3fa
62 changes: 43 additions & 19 deletions flasher/memory.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,24 +101,48 @@ def write_memory(ecu, payload, flash_start, flash_size, progress_callback=False)
packets_to_write = int(flash_size/254)
packets_written = 0

while packets_to_write >= packets_written:
if (progress_callback):
progress_callback.title('Packet {}/{}'.format(packets_written, packets_to_write))

payload_packet_start = packets_written*254
payload_packet_end = payload_packet_start+254
payload_packet = payload[payload_packet_start:payload_packet_end]

while True:
try:
ecu.bus.execute(TransferData(list(payload_packet)))
break
except (GKBusTimeoutException):
print('Timed Out! Trying again...')
continue
packets_written += 1

if (progress_callback):
progress_callback(len(payload_packet))
#Workaround to prevent progress bar overrun if flash_size is divisible by 254
if (flash_size%254==0) :
while packets_to_write > packets_written:
if (progress_callback):
progress_callback.title('Packet {}/{}'.format(packets_written+1, packets_to_write))

payload_packet_start = packets_written*254
payload_packet_end = payload_packet_start+254
payload_packet = payload[payload_packet_start:payload_packet_end]

while True:
try:
ecu.bus.execute(TransferData(list(payload_packet)))
break
except (GKBusTimeoutException):
print('Timed Out! Trying again...')
continue

packets_written += 1

if (progress_callback):
progress_callback(len(payload_packet))
else:
while packets_to_write >= packets_written:
if (progress_callback):
progress_callback.title('Packet {}/{}'.format(packets_written, packets_to_write))

payload_packet_start = packets_written*254
payload_packet_end = payload_packet_start+254
payload_packet = payload[payload_packet_start:payload_packet_end]

while True:
try:
ecu.bus.execute(TransferData(list(payload_packet)))
break
except (GKBusTimeoutException):
print('Timed Out! Trying again...')
continue

packets_written += 1

if (progress_callback):
progress_callback(len(payload_packet))

ecu.bus.execute(RequestTransferExit())