tools/mpremote: Fix encoding error in PyboardCommand.
This is a fix for utf-8 decoding errors that are thrown when non-utf-8 content is received. For instance during a reboot of an ESP8266 module. The fix is to handle conversion errors by replacing illegal characters. Note that these illegal characters most often occur during an MCU reboot sequence when the MCU is using baudrates different from 115200. Signed-off-by: Jos Verlinde <Jos_Verlinde@hotmail.com>
This commit is contained in:
parent
8c47ff7153
commit
20e1ae0733
1 changed files with 2 additions and 2 deletions
|
|
@ -795,7 +795,7 @@ class PyboardCommand:
|
|||
if n == 0:
|
||||
return ""
|
||||
else:
|
||||
return str(self.fin.read(n), "utf8")
|
||||
return str(self.fin.read(n), "utf8", errors="backslashreplace")
|
||||
|
||||
def wr_s8(self, i):
|
||||
self.fout.write(struct.pack("<b", i))
|
||||
|
|
@ -925,7 +925,7 @@ class PyboardCommand:
|
|||
fd = self.rd_s8()
|
||||
buf = self.rd_bytes()
|
||||
if self.data_files[fd][1]:
|
||||
buf = str(buf, "utf8")
|
||||
buf = str(buf, "utf8", errors="backslashreplace")
|
||||
n = self.data_files[fd][0].write(buf)
|
||||
self.wr_s32(n)
|
||||
# self.log_cmd(f"write {fd} {len(buf)} -> {n}")
|
||||
|
|
|
|||
Loading…
Reference in a new issue