From 996a239b111c4c08b77be2c0b181d1e16bbdb672 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E7=AB=8B=E5=B8=AE?= <3294713004@qq.com> Date: Sun, 18 Aug 2024 01:53:56 +0800 Subject: [PATCH] =?UTF-8?q?Fix:=20=E4=BF=AE=E5=A4=8Delectron=E7=8E=AF?= =?UTF-8?q?=E5=A2=83=E4=B8=8Bampy=E8=AF=BB=E5=8F=96=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E6=97=B6=E7=9A=84=E4=B8=AD=E6=96=87=E4=B9=B1=E7=A0=81=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- common/modules/mixly-modules/electron/ampy-fs.js | 3 ++- common/modules/mixly-modules/electron/ampy.js | 1 + tools/python/ampy/cli.py | 8 +++++--- tools/python/ampy/files.py | 3 +-- 4 files changed, 9 insertions(+), 6 deletions(-) diff --git a/common/modules/mixly-modules/electron/ampy-fs.js b/common/modules/mixly-modules/electron/ampy-fs.js index 39d4520c..2b55a0bf 100644 --- a/common/modules/mixly-modules/electron/ampy-fs.js +++ b/common/modules/mixly-modules/electron/ampy-fs.js @@ -23,6 +23,7 @@ class AmpyFS extends FS { #ampy_ = null; #port_ = ''; #baud_ = 115200; + #decoder_ = new TextDecoder('utf8'); constructor() { super(); @@ -58,7 +59,7 @@ class AmpyFS extends FS { try { const output = await this.#ampy_.get(this.#port_, this.#baud_, filePath); stdout = output.stdout; - stdout = stdout.replaceAll('\r\r', '\r'); + stdout = this.#decoder_.decode(this.#ampy_.unhexlify(stdout)); } catch (e) { error = e; Debug.error(error); diff --git a/common/modules/mixly-modules/electron/ampy.js b/common/modules/mixly-modules/electron/ampy.js index a05cd365..441c3b8b 100644 --- a/common/modules/mixly-modules/electron/ampy.js +++ b/common/modules/mixly-modules/electron/ampy.js @@ -41,6 +41,7 @@ class AmpyExt extends Ampy { ampy: this.AMPY_PATH }); } + #exec_ = util.promisify(child_process.exec); constructor() { diff --git a/tools/python/ampy/cli.py b/tools/python/ampy/cli.py index 1e7ee7dd..bb175240 100644 --- a/tools/python/ampy/cli.py +++ b/tools/python/ampy/cli.py @@ -25,7 +25,7 @@ import platform import posixpath import re import serial.serialutil - +import binascii import click import dotenv @@ -157,9 +157,11 @@ def get(remote_file, local_file): contents = board_files.get(remote_file) # Print the file out if no local file was provided, otherwise save it. if local_file is None: - print(contents.decode("utf-8")) + contents = str(contents)[2:-1] + print(contents, end='') else: - local_file.write(contents) + value = binascii.unhexlify(contents) + local_file.write(value.decode("utf-8")) @cli.command() diff --git a/tools/python/ampy/files.py b/tools/python/ampy/files.py index 32aea722..2fd7364d 100644 --- a/tools/python/ampy/files.py +++ b/tools/python/ampy/files.py @@ -21,7 +21,6 @@ # SOFTWARE. import ast import textwrap -import binascii import sys from pyboard import PyboardError @@ -84,7 +83,7 @@ class Files(object): except UnicodeDecodeError: raise ex self._pyboard.exit_raw_repl() - return binascii.unhexlify(out) + return out def ls(self, directory="/", long_format=True, recursive=False, exit_repl=True): """List the contents of the specified directory (or root if none is