Changed callback random number printing to show a progress bar
This commit is contained in:
parent
7c042ef3ed
commit
bfeb204226
2 changed files with 15 additions and 6 deletions
|
|
@ -105,9 +105,16 @@ def stm32_into_download_mode(prepare="0"):
|
|||
|
||||
ser = None
|
||||
|
||||
def print_progress_bar (iteration, error_count, total):
|
||||
errors = "E:" + str(error_count)
|
||||
length = int(os.popen('stty size', 'r').read().split()[1]) - len(errors) - 11
|
||||
percent = ("{0:.1f}").format(100 * (iteration / float(total)))
|
||||
filled_length = int(length * iteration // total)
|
||||
bar = '█' * filled_length + '-' * (length - filled_length)
|
||||
print(f'\r |{bar}| {percent}% {errors}', end = "\r")
|
||||
|
||||
def callback(total_packets, success_count, error_count):
|
||||
print(total_packets, success_count, error_count)
|
||||
def callback(total_packets, success_count, error_count, total):
|
||||
print_progress_bar(total_packets, error_count, total)
|
||||
|
||||
|
||||
def send_file(file):
|
||||
|
|
@ -135,7 +142,7 @@ def send_file(file):
|
|||
|
||||
print("Sending", file)
|
||||
try:
|
||||
print("Send completed:", modem.send(file, callback=callback))
|
||||
print("\r\nSend completed:", modem.send(file, callback=callback))
|
||||
except Exception as e:
|
||||
print("Exception", e)
|
||||
SerialPortManager.switchToCmdMode()
|
||||
|
|
|
|||
|
|
@ -184,7 +184,7 @@ class YMODEM(object):
|
|||
getting status updates while a ymodem
|
||||
transfer is underway.
|
||||
Expected callback signature:
|
||||
def callback(total_packets, success_count, error_count)
|
||||
def callback(total_packets, success_count, error_count, total)
|
||||
:type callback: callable
|
||||
'''
|
||||
|
||||
|
|
@ -231,6 +231,7 @@ class YMODEM(object):
|
|||
error_count = 0
|
||||
success_count = 0
|
||||
total_packets = 0
|
||||
total = 0
|
||||
header_sent = False
|
||||
sequence = 0
|
||||
stream = None
|
||||
|
|
@ -253,6 +254,7 @@ class YMODEM(object):
|
|||
data = data.ljust(header_size, NUL)
|
||||
checksum = self._make_send_checksum(crc_mode, data)
|
||||
header_sent = True
|
||||
total = (stat.st_size / packet_size) + 1
|
||||
else:
|
||||
# normal data packet
|
||||
data = stream.read(packet_size)
|
||||
|
|
@ -282,7 +284,7 @@ class YMODEM(object):
|
|||
if char == ACK or char == ACK2 or char == NAK:
|
||||
success_count += 1
|
||||
if callable(callback):
|
||||
callback(total_packets, success_count, error_count)
|
||||
callback(total_packets, success_count, error_count, total)
|
||||
error_count = 0
|
||||
if char == NAK:
|
||||
rubbish = self.ser.read(1024)
|
||||
|
|
@ -302,7 +304,7 @@ class YMODEM(object):
|
|||
char, sequence)
|
||||
error_count += 1
|
||||
if callable(callback):
|
||||
callback(total_packets, success_count, error_count)
|
||||
callback(total_packets, success_count, error_count, total)
|
||||
if error_count > retry:
|
||||
# excessive amounts of retransmissions requested,
|
||||
# abort transfer
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue