Skip to content

Commit 6d1f6c9

Browse files
committed
test 360W fw download success
1 parent 1a447b9 commit 6d1f6c9

File tree

9 files changed

+278
-73
lines changed

9 files changed

+278
-73
lines changed

.gitignore

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

build.sh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
# enter `thonny-quecpython` dir then execute below shell command
2-
python setup.py sdist bdist_wheel
2+
python setup.py sdist bdist_wheel
3+
4+
# upload to pypi repository
5+
# twine upload [./dist/xxx.tar.gz | xxx.whl]

thonnycontrib/quecpython/api.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,14 @@ def __call__(self):
6262
class DownLoadFWApi(BaseApi):
6363
UPDATE_TOPIC = 'UPDATE_PROGRESS'
6464

65-
def __init__(self, firmware_file_path, com_info):
65+
def __init__(self, firmware_file_path, platform, com_info):
6666
self.firmware_file_path = firmware_file_path
67+
self.platform = platform
6768
self.com_info = com_info
6869

6970
def run(self):
70-
logger.info('enter download_firmware_api function. args: {}'.format((self.firmware_file_path, self.com_info)))
71-
fw_download_handler = FwDownloadHandler(self.firmware_file_path, self.com_info)
71+
logger.info('enter download_firmware_api function. args: {}'.format((self.firmware_file_path,)))
72+
fw_download_handler = FwDownloadHandler(self.firmware_file_path, self.platform, self.com_info)
7273
for data in fw_download_handler.download():
7374
self.emit(data)
7475

thonnycontrib/quecpython/fw/__init__.py

Lines changed: 103 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,13 @@
1313
# limitations under the License.
1414

1515
import glob
16-
import shutil
16+
import json
1717
import tempfile
1818
from threading import Lock
1919
from .proc import Process
2020
from .utils import *
2121
from logging import getLogger
22+
from ..locale import tr
2223

2324

2425
EXES_PATH = Path(__file__).with_name('exes')
@@ -137,59 +138,96 @@ def parse(self, line):
137138
raise Exception('Unisoc FW Download Failed.')
138139

139140

140-
def run_cmd(cmd, process_type, cwd):
141-
logger.info('enter run_cmd method, args: {}'.format((cmd, process_type, cwd,)))
141+
class LineParser360W(object):
142+
143+
def __init__(self):
144+
self.progress = 0
145+
146+
def parse(self, line):
147+
try:
148+
data = json.loads(line)
149+
except Exception as e:
150+
return 1
151+
152+
if data['Status'] == 'Programming':
153+
return data['Progress']
154+
else:
155+
if data['Status'] == 'Ready':
156+
return 5
157+
elif data['Status'] == 'Finished' and data['Message'] == 'Success':
158+
return 100
159+
else:
160+
raise Exception('360W Download Failed!')
161+
162+
163+
def run_cmd(cmd, platform, cwd):
164+
logger.info('enter run_cmd method, args: {}'.format((cmd, platform, cwd,)))
142165

143166
with DownloadLogFile() as f:
144167

145168
proc = Process(cmd, cwd)
146169
proc.run()
147170
running_timeout = 60
148171

149-
if process_type == "unisoc":
172+
if platform.upper() in ["ASR", "ASR1601", "ASR1606"]:
173+
parser = LineParserAsr()
174+
elif platform.upper() in ["UNISOC", "UNISOC8910", "UNISOC8850"]:
150175
parser = LineParserUnisoc()
151-
elif process_type == "NB":
176+
elif platform.upper() == "RDA8908A":
152177
parser = LineParserNB()
153-
elif process_type == "BG95":
154-
parser = LineParserBG95()
155-
elif process_type == '200A':
178+
elif platform.upper() == "ASR1803S":
156179
parser = LineParser200A()
180+
elif platform.upper() == "MDM9X05":
181+
parser = LineParserBG95()
182+
elif platform.upper() == "EIGEN":
183+
pass
184+
elif platform.upper() == "FCM360W":
185+
parser = LineParser360W()
157186
else:
158-
parser = LineParserAsr()
187+
pass
159188

160189
for line in proc.read_lines(timeout=running_timeout):
161190
f.write(line)
191+
logger.info(line)
162192
rv = parser.parse(line)
163193
if rv:
164194
yield rv
165195

166196

167197
class FwDownloadHandler(object):
168198

169-
def __init__(self, firmware_file_path, com_info):
199+
def __init__(self, firmware_file_path, platform, com_info):
170200
self.fw_filepath = Path(firmware_file_path)
171201
self.com_info = com_info
202+
self.platform = platform
172203

173204
def download(self):
174205
logger.info('enter FwDownloadHandler.download method.')
175206
if Path(self.fw_filepath).exists():
176-
logger.info('fw_filepath with suffix \"{}\".'.format(self.fw_filepath.suffix))
177-
if self.fw_filepath.suffix == ".pac":
207+
logger.info('fw_filepath: \"{}\".'.format(self.fw_filepath))
208+
if self.platform.upper() in ["ASR", "ASR1601", "ASR1606"]:
209+
return self.asrFwDownload()
210+
elif self.platform.lower() in ["unisoc", "unisoc8910", "unisoc8850"]:
178211
return self.rdaFwDownload()
179-
elif self.fw_filepath.suffix == ".lod":
212+
elif self.platform.upper() == "RDA8908A":
180213
return self.nbFwDownload()
181-
elif self.fw_filepath.suffix == ".blf":
182-
return self.blfFwDownload()
183-
elif self.fw_filepath.suffix == ".mbn":
214+
elif self.platform.upper() == "MDM9X05":
184215
return self.mbnFwDownload()
216+
elif self.platform.upper() == "ASR1803S":
217+
return self.blfFwDownload()
218+
elif self.platform.upper() == "FCM360W":
219+
return self.wifi360FwDownload()
220+
elif self.platform.upper() == "FC41D":
221+
return self.wifi41DFwDownload()
222+
elif self.platform.upper() == "EIGEN":
223+
return self.EigenFwDownload()
185224
else:
186-
return self.asrFwDownload()
225+
raise Exception(tr('firmware not supported'))
187226
else:
188-
raise Exception('固件文件不存在。')
227+
raise Exception(tr('fw filepath not exists'))
189228

190229
def rdaFwDownload(self):
191230
logger.info('enter FwDownloadHandler.rdaFwDownload method.')
192-
193231
tmp_path = tempfile.mkdtemp()
194232
config_pac = myconf()
195233
config_pac.read(str(EXES_PATH / "rda/ResearchDownload.ini"))
@@ -292,32 +330,61 @@ def asrFwDownload(self):
292330
else:
293331
raise Exception('检查固件zip包是否未解压,请解压后重试')
294332

333+
def wifi360FwDownload(self):
334+
tmp_path = tempfile.mkdtemp()
335+
logger.info("tmp_path: {}".format(tmp_path))
336+
tempZip_filename = self.fw_filepath.with_suffix('.zip').name
337+
logger.info("临时文件名: " + tempZip_filename)
338+
shutil.copyfile(
339+
str(self.fw_filepath),
340+
str(Path(tmp_path) / tempZip_filename)
341+
)
342+
shutil.copyfile(
343+
str(EXES_PATH / "FCM360W/EswinFlashTool.exe"),
344+
str(Path(tmp_path) / "EswinFlashTool.exe")
345+
)
346+
347+
return self.fw_download(
348+
str(Path(tmp_path) / "EswinFlashTool.exe"),
349+
str(Path(tmp_path) / tempZip_filename)
350+
)
351+
352+
def wifi41DFwDownload(self):
353+
pass
354+
355+
def EigenFwDownload(self):
356+
pass
357+
295358
def fw_download(self, download_exe_path, fw_filepath):
296359
logger.info('enter FwDownloadHandler.fw_download method.')
297360

298-
if self.fw_filepath.suffix == ".pac":
361+
if self.platform.upper() in ["ASR", "ASR1601", "ASR1606"]:
362+
cmd = [
363+
download_exe_path, '-p', self.com_info['port'][3:],
364+
'-a', '-q', '-r', '-s', self.com_info['baudrate'], fw_filepath
365+
]
366+
logger.info('------------------adownload downloading factory package------------------')
367+
elif self.platform.upper() in ["UNISOC", "UNISOC8910", "UNISOC8850"]:
299368
cmd = [download_exe_path, '-pac', fw_filepath]
300369
logger.info('------------------unisoc downloading upgrade package------------------')
301-
downloadProcess = 'unisoc'
302-
elif self.fw_filepath.suffix == ".lod":
303-
cmd = [download_exe_path, self.com_info['port'][3:], self.com_info['baudrate'], fw_filepath]
370+
elif self.platform.upper() == "RDA8908A":
371+
cmd = [download_exe_path, self.com_info['port'][3:], '115200', fw_filepath]
304372
logger.info('------------------NB downloading upgrade package------------------')
305-
downloadProcess = 'NB'
306-
elif self.fw_filepath.suffix == ".blf":
373+
elif self.platform.upper() == "ASR1803S":
307374
cmd = [download_exe_path, '-f', fw_filepath]
308375
logger.info('------------------200A download downloading factory package(blf)------------------')
309-
downloadProcess = '200A'
310-
elif self.fw_filepath.suffix == ".mbn":
311-
cmd = [download_exe_path, self.com_info['port'][3:], self.com_info['baudrate'], fw_filepath]
376+
elif self.platform.upper() == "MDM9X05":
377+
cmd = [download_exe_path, self.com_info['port'][3:], '115200', fw_filepath]
312378
logger.info('------------------BG95 download downloading factory package(mbn)------------------')
313-
downloadProcess = 'BG95'
379+
elif self.platform.upper() == "EIGEN":
380+
pass
381+
elif self.platform.upper() == "FCM360W":
382+
cmd = [download_exe_path, '-p', self.com_info['port'][3:], '-b', "921600", '-file', fw_filepath]
383+
print('------------------ FCM360W downloading factory package: ------------------')
384+
elif self.platform.upper() == "FC41D":
385+
pass
314386
else:
315-
cmd = [
316-
download_exe_path, '-p', self.com_info['port'],
317-
'-a', '-q', '-r', '-s', self.com_info['baudrate'], fw_filepath
318-
]
319-
logger.info('------------------adownload downloading factory package------------------')
320-
downloadProcess = '"progress" :'
387+
pass
321388

322389
logger.info('run cmd: {}'.format(cmd))
323-
return run_cmd(cmd, downloadProcess, str(Path(download_exe_path).parent))
390+
return run_cmd(cmd, self.platform, str(Path(download_exe_path).parent))
Binary file not shown.
Binary file not shown.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"platform": "FCM360W"
3+
}

0 commit comments

Comments
 (0)