Skip to content

Commit 24916b7

Browse files
committed
update firmware download
1 parent c494703 commit 24916b7

File tree

7 files changed

+80
-64
lines changed

7 files changed

+80
-64
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ dist
33
thonny_quecpython.egg-info
44
build/
55
__pycache__
6+
newFW

thonnycontrib/quecpython/fw/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def download(self):
3939
logger.info('fw_filepath: \"{}\".'.format(self.fw_filepath))
4040
if self.platform.upper() in ["ASR", "ASR1601", "ASR1606"]:
4141
return self.asrFwDownload()
42-
elif self.platform.lower() in ["unisoc", "unisoc8910", "unisoc8850"]:
42+
elif self.platform.upper() in ["UNISOC", "UNISOC8910", "UNISOC8850"]:
4343
return self.rdaFwDownload()
4444
elif self.platform.upper() == "RDA8908A":
4545
return self.nbFwDownload()
Binary file not shown.

thonnycontrib/quecpython/fw/newFW/platform_config.json

Lines changed: 0 additions & 3 deletions
This file was deleted.

thonnycontrib/quecpython/fw/proc.py

Lines changed: 52 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ def progress_rate(self):
109109
proc = Process(self.cmd, self.cwd)
110110
proc.run()
111111
with DownloadLogFile() as f:
112-
for line in self.proc.read_lines(timeout=60):
112+
for line in proc.read_lines(timeout=60):
113113
f.write(line)
114114
logger.info(line)
115115
rv = self.parse(line)
@@ -125,6 +125,8 @@ class _AsrExecutor(BaseExecutor):
125125
def __init__(self, cmd, cwd, **extra):
126126
self.json_string = ""
127127
self.flag = False
128+
self.progress = 0
129+
self.log_string = ""
128130
super().__init__(cmd, cwd, **extra)
129131

130132
def parse(self, line):
@@ -143,20 +145,29 @@ def parse(self, line):
143145
self.json_string = ""
144146
self.flag = False
145147
if rv and rv['status'] != 'OFFLINE':
146-
return rv['progress']
147-
148+
self.progress = rv['progress']
149+
return self.log_string, self.progress
150+
else:
151+
self.log_string = line
152+
return self.log_string, self.progress
148153

149154
class _200AExecutor(BaseExecutor):
150155

156+
def __init__(self, cmd, cwd, **extra):
157+
self.progress = 0
158+
super().__init__(cmd, cwd, **extra)
159+
151160
def parse(self, line):
152161
if "Successfully to prepare temp folder file for wtptp download" in line:
153162
return "RESET"
154-
155-
if "Download percentage" in line:
156-
return int(line.strip().split(' ')[-1])
157-
158-
if "flash percentage" in line:
159-
return int(line.strip().split(' ')[-1])
163+
elif "Download percentage" in line:
164+
self.progress = int(line.strip().split(' ')[-1])
165+
return line, self.progress
166+
elif "flash percentage" in line:
167+
self.progress = int(line.strip().split(' ')[-1])
168+
return line, self.progress
169+
else:
170+
return line, self.progress
160171

161172

162173
class _BG95Executor(BaseExecutor):
@@ -169,24 +180,30 @@ def parse(self, line):
169180

170181
if '[1]DL-' in line:
171182
self.progress += 2
172-
return self.progress
173-
174-
if '[1]Total upgrade time is' in line:
175-
return 100
176-
177-
if '[1]FW upgrade fail' in line:
183+
return line, self.progress
184+
elif '[1]FW upgrade success.' in line:
185+
return line, 100
186+
elif '[1]FW upgrade fail' in line:
178187
raise Exception('BG95 FW Download Failed.')
188+
else:
189+
return line, self.progress
179190

180191

181192
class _NBExecutor(BaseExecutor):
182193

194+
def __init__(self, cmd, cwd, **extra):
195+
self.progress = 0
196+
super().__init__(cmd, cwd, **extra)
197+
183198
def parse(self, line):
184199
if '[1]FW upgrade fail.' in line:
185200
raise Exception('NB FW Download Failed.')
186201

187202
if "[1]Upgrade:" in line:
188-
progress = int(line.replace("[1]Upgrade:", '').strip()[:-1])
189-
return progress
203+
self.progress = int(line.replace("[1]Upgrade:", '').strip()[:-1])
204+
return line, self.progress
205+
else:
206+
return line, self.progress
190207

191208

192209
class _UnisocExecutor(BaseExecutor):
@@ -199,10 +216,10 @@ def parse(self, line):
199216

200217
if "Downloading..." in line:
201218
self.progress += 1
202-
return self.progress * 10
219+
return line[:50], self.progress * 10
203220

204221
if "DownLoad Passed" in line:
205-
return 100
222+
return line[:50], 100
206223

207224
if "[ERROR] DownLoad Failed" in line:
208225
raise Exception('Unisoc FW Download Failed.')
@@ -214,15 +231,15 @@ def parse(self, line):
214231
try:
215232
data = json.loads(line)
216233
except Exception as e:
217-
return 1
234+
return line, 1
218235

219236
if data['Status'] == 'Programming':
220-
return data['Progress']
237+
return line, data['Progress']
221238
else:
222239
if data['Status'] == 'Ready':
223-
return 5
240+
return line, 5
224241
elif data['Status'] == 'Finished' and data['Message'] == 'Success':
225-
return 100
242+
return line, 100
226243
else:
227244
raise Exception('360W Download Failed!')
228245

@@ -245,7 +262,7 @@ def progress_rate(self):
245262
f.write(line)
246263
logger.info(line)
247264
self.parse(line)
248-
yield self.progress
265+
yield line, self.progress
249266

250267
# pkg2img
251268
logger.info("---------- pkg2img ----------")
@@ -257,7 +274,7 @@ def progress_rate(self):
257274
f.write(line)
258275
logger.info(line)
259276
self.parse(line)
260-
yield self.progress
277+
yield line, self.progress
261278

262279
# 烧录固件
263280
logger.info("---------- Burn firmware ----------")
@@ -269,7 +286,7 @@ def progress_rate(self):
269286
f.write(line)
270287
logger.info(line)
271288
self.parse(line)
272-
yield self.progress
289+
yield line, self.progress
273290

274291
# 下载 ap_application.bin文件
275292
logger.info("---------- Download ap_application.bin flasherase ----------")
@@ -282,7 +299,7 @@ def progress_rate(self):
282299
f.write(line)
283300
logger.info(line)
284301
self.parse(line)
285-
yield self.progress
302+
yield line, self.progress
286303
logger.info("---------- Download ap_application.bin burnone ----------")
287304
cmd5 = self.cmd[:1] + ["--skipconnect", "1"] + self.cmd[1:] + ["burnone", "flexfile2"]
288305
logger.info('cmd5: {}'.format(cmd5))
@@ -292,7 +309,7 @@ def progress_rate(self):
292309
f.write(line)
293310
logger.info(line)
294311
self.parse(line)
295-
yield self.progress
312+
yield line, self.progress
296313

297314
# 下载 ap_updater.bin文件
298315
logger.info("---------- Download ap_updater.bin flasherase ----------")
@@ -305,7 +322,7 @@ def progress_rate(self):
305322
f.write(line)
306323
logger.info(line)
307324
self.parse(line)
308-
yield self.progress
325+
yield line, self.progress
309326
logger.info("---------- Download ap_updater.bin burnone ----------")
310327
cmd7 = self.cmd[:1] + ["--skipconnect", "1"] + self.cmd[1:] + ["burnone", "flexfile3"]
311328
logger.info('cmd7: {}'.format(cmd7))
@@ -315,7 +332,7 @@ def progress_rate(self):
315332
f.write(line)
316333
logger.info(line)
317334
self.parse(line)
318-
yield self.progress
335+
yield line, self.progress
319336

320337
# 下载 customer_fs.bin文件
321338
logger.info("---------- Download customer_fs.bin flasherase ----------")
@@ -328,7 +345,7 @@ def progress_rate(self):
328345
f.write(line)
329346
logger.info(line)
330347
self.parse(line)
331-
yield self.progress
348+
yield line, self.progress
332349
logger.info("---------- Download customer_fs.bin burnone ----------")
333350
cmd9 = self.cmd[:1] + ["--skipconnect", "1"] + self.cmd[1:] + ["burnone", "flexfile4"]
334351
logger.info('cmd9: {}'.format(cmd9))
@@ -338,7 +355,7 @@ def progress_rate(self):
338355
f.write(line)
339356
logger.info(line)
340357
self.parse(line)
341-
yield self.progress
358+
yield line, self.progress
342359

343360
if self.extra['File_Count'] == 4:
344361
# 下载 customer_backup_fs.bin 文件
@@ -352,7 +369,7 @@ def progress_rate(self):
352369
f.write(line)
353370
logger.info(line)
354371
self.parse(line)
355-
yield self.progress
372+
yield line, self.progress
356373
logger.info("---------- Download customer_backup_fs.bin burnone ----------")
357374
cmd11 = self.cmd[:1] + ["--skipconnect", "1"] + self.cmd[1:] + ["burnone", "flexfile5"]
358375
logger.info('cmd11: {}'.format(cmd11))
@@ -362,7 +379,7 @@ def progress_rate(self):
362379
f.write(line)
363380
logger.info(line)
364381
self.parse(line)
365-
yield self.progress
382+
yield line, self.progress
366383

367384
# 重启模块
368385
logger.info("---------- sysreset ----------")
@@ -374,7 +391,7 @@ def progress_rate(self):
374391
f.write(line)
375392
logger.info(line)
376393
self.parse(line)
377-
yield self.progress
394+
yield line, self.progress
378395
yield 100
379396

380397
def parse(self, line):

thonnycontrib/quecpython/fw/utils.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ def get_com_port(fw_file_path, platform):
165165
)
166166
return atPort
167167
elif platform.upper() in ["ASR", "ASR1601", "ASR1606"]:
168-
atPort = get_com_port(fw_config["firmware"]["vid_pid_work"], fw_config["firmware"]["Quectel_USB_AT_Port"])
168+
atPort = get_com_port_number(fw_config["firmware"]["vid_pid_work"], fw_config["firmware"]["Quectel_USB_AT_Port"])
169169
else:
170170
return "WIFI_DOWNLOAD"
171171

@@ -217,13 +217,13 @@ def get_fw_and_platform(fw_filepath):
217217
if not ifExist(newFW):
218218
return None
219219
except Exception as e:
220-
logger.error(e)
220+
print(e)
221221
return None
222222
else:
223223
if ifExist(newFWFolder + "\\system.img"):
224-
logger.info("asr fw")
224+
print("asr fw")
225225
platform = "ASR1601"
226-
newFW = fw_fileName
226+
newFW = fw_filepath
227227
else:
228228
return None
229229
else:

thonnycontrib/quecpython/view.py

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ def __init__(self, *args, **kwargs):
126126
self.log_stringvar = tk.StringVar()
127127
self.log_stringvar.set(tr('ready'))
128128
log_entry = tk.Label(fw_label_frame, textvariable=self.log_stringvar)
129-
log_entry.grid(row=3, column=1, sticky=tk.W, padx=(0, 5), pady=(5, 5))
129+
log_entry.grid(row=3, column=1, columnspan=11, sticky=tk.W, padx=(0, 5), pady=(5, 5))
130130
# <<<
131131

132132
# >>> 订阅
@@ -197,7 +197,7 @@ def get_validated_com_port(self, fw_file_path, platform):
197197

198198
rv = {'port': comport, 'baudrate': '115200'}
199199

200-
if comport in ("NB_DOWNLOAD", "ASR1803S_DOWNLOAD", "mbn_DOWNLOAD", "WIFI_DOWNLOAD"):
200+
if comport in ("NB_DOWNLOAD", "mbn_DOWNLOAD", "WIFI_DOWNLOAD"):
201201
if (self.serial is None) or (not self.serial.isOpen()):
202202
messagebox.showinfo(
203203
title=tr('Choose a COM Port'),
@@ -235,18 +235,6 @@ def on_fw_file_path_write(self, *args, **kwargs):
235235
else:
236236
self.set_com_widgets_state(tk.DISABLED)
237237

238-
def get_validated_fw_file_path(self):
239-
firmware_file_path = self.firmware_file_path_stringvar.get()
240-
logger.info('firmware_file_path: {}'.format(firmware_file_path))
241-
if not firmware_file_path:
242-
messagebox.showerror(
243-
title=tr('Error'),
244-
message=tr('no firmware file path selected!'),
245-
master=self
246-
)
247-
return
248-
return firmware_file_path
249-
250238
def download_widgets_ready(self):
251239
self.fw_file_choose_button.config(state=tk.DISABLED)
252240
self.fw_download_button.config(state=tk.DISABLED)
@@ -256,11 +244,25 @@ def download_widgets_ready(self):
256244
self.update()
257245

258246
def download_firmware_handler(self):
259-
firmware_file_path = self.get_validated_fw_file_path()
247+
firmware_file_path = self.firmware_file_path_stringvar.get()
248+
logger.info('firmware_file_path: {}'.format(firmware_file_path))
260249
if not firmware_file_path:
250+
messagebox.showerror(
251+
title=tr('Error'),
252+
message=tr('no firmware file path selected!'),
253+
master=self
254+
)
261255
return
262256

263-
fw_file_path, platform = get_fw_and_platform(firmware_file_path)
257+
rv = get_fw_and_platform(firmware_file_path)
258+
if rv is None:
259+
messagebox.showerror(
260+
title=tr('Error'),
261+
message=tr('unknow platform!'),
262+
master=self
263+
)
264+
return
265+
fw_file_path, platform = rv
264266
logger.info('fw file: {}'.format(fw_file_path))
265267
logger.info('platform: {}'.format(platform))
266268

@@ -286,10 +288,10 @@ def update_progress(self, payload):
286288
master=self
287289
)
288290
return
289-
self.progress_stringvar.set("{}%".format(payload.data))
290-
self.bar["value"] = payload.data
291-
self.log_stringvar.set(tr('downloading...'))
292-
self.update()
291+
self.progress_stringvar.set("{}%".format(payload.data[1]))
292+
self.bar["value"] = payload.data[1]
293+
self.log_stringvar.set('{:100s}'.format(payload.data[0].strip()))
294+
# self.update()
293295
elif payload.code == DownLoadFWApi.EXIT:
294296
if payload.exec:
295297
messagebox.showerror(
@@ -298,7 +300,6 @@ def update_progress(self, payload):
298300
master=self
299301
)
300302
else:
301-
self.log_stringvar.set(tr('download process exited.'))
302303
messagebox.showinfo(
303304
title=tr('Information'),
304305
message=tr('Download Firmware Progress Finished!'),

0 commit comments

Comments
 (0)