Skip to content

Commit 32f89d2

Browse files
committed
update the code
1 parent 099b7c5 commit 32f89d2

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

upload_python2.py

+7-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# -*- coding: utf-8 -*
2-
# python3
2+
# python2
33
import os
44
import time
55
import threading
@@ -191,7 +191,10 @@ def send_file(ser, input_file_path, target_file_path):
191191
input_file_fd = open(input_file_path, 'rb')
192192
input_file_data = input_file_fd.read()
193193
input_file_len = len(input_file_data)
194-
progress_bar.start(input_file_len)
194+
try:
195+
progress_bar.start(input_file_len)
196+
except:
197+
progress_bar.start()
195198
# Send file header
196199
# 1(file_type) + 4(file_size) + 4(file_check_sum) = 0x09
197200
cmd_len_str = int2byte(0x09 + len(target_file_path), 2, 'little')
@@ -220,7 +223,7 @@ def send_file(ser, input_file_path, target_file_path):
220223
retransmission_count = retransmission_count + 1
221224
print("resend the file header[" + str(retransmission_count) + "]")
222225
ser.write(binascii.a2b_hex(send_head_str))
223-
if retransmission_count >= 2:
226+
if retransmission_count >= 5:
224227
failed_to_exit = True
225228
update_completed = False
226229
print("Send header time out!")
@@ -261,7 +264,7 @@ def send_file(ser, input_file_path, target_file_path):
261264
retransmission_count = retransmission_count + 1
262265
print("resend the file block[" + str(retransmission_count) + "]")
263266
ser.write(send_block_bytes)
264-
if retransmission_count >= 2:
267+
if retransmission_count >= 3:
265268
failed_to_exit = True
266269
update_completed = False
267270
print("Send file block time out!")

upload_python3.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,10 @@ def send_file(ser, input_file_path, target_file_path):
154154
input_file_fd = open(input_file_path, 'rb')
155155
input_file_data = input_file_fd.read()
156156
input_file_len = len(input_file_data)
157-
progress_bar.start(input_file_len)
157+
try:
158+
progress_bar.start(100)
159+
except:
160+
progress_bar.start()
158161
# Send file header
159162
# 1(file_type) + 4(file_size) + 4(file_check_sum) = 0x09
160163
cmd_len_str = bytes_to_hex_str((0x09 + len(target_file_path)).to_bytes(2, byteorder = 'little'))
@@ -181,7 +184,7 @@ def send_file(ser, input_file_path, target_file_path):
181184
retransmission_count = retransmission_count + 1
182185
print("resend the file header[" + str(retransmission_count) + "]")
183186
ser.write(bytes.fromhex(send_head_str))
184-
if retransmission_count >= 2:
187+
if retransmission_count >= 5:
185188
failed_to_exit = True
186189
update_completed = False
187190
print("Send header time out!")
@@ -220,7 +223,7 @@ def send_file(ser, input_file_path, target_file_path):
220223
retransmission_count = retransmission_count + 1
221224
print("resend the file block[" + str(retransmission_count) + "]")
222225
ser.write(send_block_bytes)
223-
if retransmission_count >= 2:
226+
if retransmission_count >= 3:
224227
failed_to_exit = True
225228
update_completed = False
226229
print("Send file block time out!")

0 commit comments

Comments
 (0)