From 9d74c9800d3ce46b36541dc8af8cd066b2e32a8b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E7=AB=8B=E5=B8=AE?= <3294713004@qq.com> Date: Mon, 6 Jan 2025 11:51:43 +0800 Subject: [PATCH] =?UTF-8?q?Fix:=20=E4=BF=AE=E5=A4=8D=E4=B8=B2=E5=8F=A3?= =?UTF-8?q?=E6=8E=A5=E6=94=B6=E7=BC=96=E7=A0=81=E4=B8=AD=E6=96=87=E5=AD=97?= =?UTF-8?q?=E7=AC=A6=E4=B8=B2=E6=97=B6=E6=B2=A1=E6=9C=89=E6=89=A7=E8=A1=8C?= =?UTF-8?q?=E8=A7=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- common/modules/mixly-modules/common/serial.js | 27 ++++++++++++++++--- common/modules/mixly-modules/deps.json | 10 +++++++ 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/common/modules/mixly-modules/common/serial.js b/common/modules/mixly-modules/common/serial.js index 8d2f0278..bd3a86a8 100644 --- a/common/modules/mixly-modules/common/serial.js +++ b/common/modules/mixly-modules/common/serial.js @@ -100,6 +100,8 @@ class Serial { #rts_ = false; #isOpened_ = false; #port_ = ''; + #special_ = []; + #specialLength_ = 0; #events_ = new Events(['onOpen', 'onClose', 'onError', 'onBuffer', 'onString', 'onByte', 'onChar']); constructor(port) { this.#port_ = port; @@ -126,14 +128,33 @@ class Serial { **/ decodeByte(byte) { let output = ''; + if (byte !== 0x5F && this.#special_.length && !this.#specialLength_) { + const str = this.#special_.join(''); + try { + output += decodeURIComponent(str.replace(/_([0-9a-fA-F]{2})/gm, '%$1')); + } catch (_) { + output += str; + } + this.#special_ = []; + } if ((byte & 0x80) === 0x00) { // 1字节 this.#buffer_ = []; this.#bufferLength_ = 0; - if (byte !== 0x0A) { - output += String.fromCharCode(byte); + if (byte === 0x5F) { + // 如果当前字节是 "_" + this.#specialLength_ = 2; + this.#special_.push(String.fromCharCode(byte)); + } else if (byte !== 0x0A) { + // 如果当前字节是 "\n" + if (this.#specialLength_) { + this.#specialLength_--; + this.#special_.push(String.fromCharCode(byte)); + } else { + output += String.fromCharCode(byte); + } } - } else if ((byte & 0xc0) === 0x80) { + } else if ((byte & 0xC0) === 0x80) { /* * 2字节以上的中间字节,10xxxxxx * 如果没有起始头,则丢弃这个字节 diff --git a/common/modules/mixly-modules/deps.json b/common/modules/mixly-modules/deps.json index 56f06756..75d16e54 100644 --- a/common/modules/mixly-modules/deps.json +++ b/common/modules/mixly-modules/deps.json @@ -1538,6 +1538,7 @@ "path": "/web/burn-upload.js", "require": [ "path", + "BoardId", "FSWrapper", "DAPWrapper", "PartialFlashing", @@ -1611,6 +1612,15 @@ "Mixly.Web.FS" ] }, + { + "path": "/web/hid-transport.js", + "require": [ + "Mixly.Web" + ], + "provide": [ + "Mixly.Web.HIDTransport" + ] + }, { "path": "/web/hid.js", "require": [