|
13 | 13 | # limitations under the License.
|
14 | 14 |
|
15 | 15 | import glob
|
16 |
| -import shutil |
| 16 | +import json |
17 | 17 | import tempfile
|
18 | 18 | from threading import Lock
|
19 | 19 | from .proc import Process
|
20 | 20 | from .utils import *
|
21 | 21 | from logging import getLogger
|
| 22 | +from ..locale import tr |
22 | 23 |
|
23 | 24 |
|
24 | 25 | EXES_PATH = Path(__file__).with_name('exes')
|
@@ -137,59 +138,96 @@ def parse(self, line):
|
137 | 138 | raise Exception('Unisoc FW Download Failed.')
|
138 | 139 |
|
139 | 140 |
|
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,))) |
142 | 165 |
|
143 | 166 | with DownloadLogFile() as f:
|
144 | 167 |
|
145 | 168 | proc = Process(cmd, cwd)
|
146 | 169 | proc.run()
|
147 | 170 | running_timeout = 60
|
148 | 171 |
|
149 |
| - if process_type == "unisoc": |
| 172 | + if platform.upper() in ["ASR", "ASR1601", "ASR1606"]: |
| 173 | + parser = LineParserAsr() |
| 174 | + elif platform.upper() in ["UNISOC", "UNISOC8910", "UNISOC8850"]: |
150 | 175 | parser = LineParserUnisoc()
|
151 |
| - elif process_type == "NB": |
| 176 | + elif platform.upper() == "RDA8908A": |
152 | 177 | parser = LineParserNB()
|
153 |
| - elif process_type == "BG95": |
154 |
| - parser = LineParserBG95() |
155 |
| - elif process_type == '200A': |
| 178 | + elif platform.upper() == "ASR1803S": |
156 | 179 | 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() |
157 | 186 | else:
|
158 |
| - parser = LineParserAsr() |
| 187 | + pass |
159 | 188 |
|
160 | 189 | for line in proc.read_lines(timeout=running_timeout):
|
161 | 190 | f.write(line)
|
| 191 | + logger.info(line) |
162 | 192 | rv = parser.parse(line)
|
163 | 193 | if rv:
|
164 | 194 | yield rv
|
165 | 195 |
|
166 | 196 |
|
167 | 197 | class FwDownloadHandler(object):
|
168 | 198 |
|
169 |
| - def __init__(self, firmware_file_path, com_info): |
| 199 | + def __init__(self, firmware_file_path, platform, com_info): |
170 | 200 | self.fw_filepath = Path(firmware_file_path)
|
171 | 201 | self.com_info = com_info
|
| 202 | + self.platform = platform |
172 | 203 |
|
173 | 204 | def download(self):
|
174 | 205 | logger.info('enter FwDownloadHandler.download method.')
|
175 | 206 | 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"]: |
178 | 211 | return self.rdaFwDownload()
|
179 |
| - elif self.fw_filepath.suffix == ".lod": |
| 212 | + elif self.platform.upper() == "RDA8908A": |
180 | 213 | 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": |
184 | 215 | 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() |
185 | 224 | else:
|
186 |
| - return self.asrFwDownload() |
| 225 | + raise Exception(tr('firmware not supported')) |
187 | 226 | else:
|
188 |
| - raise Exception('固件文件不存在。') |
| 227 | + raise Exception(tr('fw filepath not exists')) |
189 | 228 |
|
190 | 229 | def rdaFwDownload(self):
|
191 | 230 | logger.info('enter FwDownloadHandler.rdaFwDownload method.')
|
192 |
| - |
193 | 231 | tmp_path = tempfile.mkdtemp()
|
194 | 232 | config_pac = myconf()
|
195 | 233 | config_pac.read(str(EXES_PATH / "rda/ResearchDownload.ini"))
|
@@ -292,32 +330,61 @@ def asrFwDownload(self):
|
292 | 330 | else:
|
293 | 331 | raise Exception('检查固件zip包是否未解压,请解压后重试')
|
294 | 332 |
|
| 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 | + |
295 | 358 | def fw_download(self, download_exe_path, fw_filepath):
|
296 | 359 | logger.info('enter FwDownloadHandler.fw_download method.')
|
297 | 360 |
|
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"]: |
299 | 368 | cmd = [download_exe_path, '-pac', fw_filepath]
|
300 | 369 | 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] |
304 | 372 | logger.info('------------------NB downloading upgrade package------------------')
|
305 |
| - downloadProcess = 'NB' |
306 |
| - elif self.fw_filepath.suffix == ".blf": |
| 373 | + elif self.platform.upper() == "ASR1803S": |
307 | 374 | cmd = [download_exe_path, '-f', fw_filepath]
|
308 | 375 | 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] |
312 | 378 | 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 |
314 | 386 | 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 |
321 | 388 |
|
322 | 389 | 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)) |
0 commit comments