diff --git a/HISTORY.rst b/HISTORY.rst index 9b6c8e0b..a905f858 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -24,6 +24,7 @@ test-driven methodologies, and modern toolchains for unrivaled success. * Addressed an issue where passing a relative path (``--project-dir``) to the `pio project init `__ command resulted in an error (`issue #4847 `_) * Resolved an issue related to the relative package path in the `pio pkg publish `__ command * Resolved an issue where the |LDF| selected an incorrect library version (`issue #4860 `_) +* Resolved an issue with the ``hexlify`` filter in the `device monitor `__ command, ensuring proper representation of characters with Unicode code points higher than 127 (`issue #4732 `_) 6.1.13 (2024-01-12) ~~~~~~~~~~~~~~~~~~~ diff --git a/docs b/docs index 09232d57..37c10d2f 160000 --- a/docs +++ b/docs @@ -1 +1 @@ -Subproject commit 09232d5768dcbbf87e3c8713575e200ae3ae6522 +Subproject commit 37c10d2f72c18d1b3f84db661e96fa7732d2c7ad diff --git a/platformio/device/monitor/command.py b/platformio/device/monitor/command.py index 87f64449..b3dc0a0e 100644 --- a/platformio/device/monitor/command.py +++ b/platformio/device/monitor/command.py @@ -58,7 +58,7 @@ from platformio.project.options import ProjectOptions "--encoding", help=( "Set the encoding for the serial port " - "(e.g. hexlify, Latin1, UTF-8) [default=%s]" + "(e.g. hexlify, Latin-1, UTF-8) [default=%s]" % ProjectOptions["env.monitor_encoding"].default ), ) diff --git a/platformio/device/monitor/filters/base.py b/platformio/device/monitor/filters/base.py index e773ed65..5a65f800 100644 --- a/platformio/device/monitor/filters/base.py +++ b/platformio/device/monitor/filters/base.py @@ -25,11 +25,12 @@ from platformio.project.config import ProjectConfig class DeviceMonitorFilterBase(miniterm.Transform): def __init__(self, options=None): """Called by PlatformIO to pass context""" - miniterm.Transform.__init__(self) + super().__init__() self.options = options or {} self.project_dir = self.options.get("project_dir") self.environment = self.options.get("environment") + self._running_terminal = None self.config = ProjectConfig.get_instance() if not self.environment: @@ -47,6 +48,12 @@ class DeviceMonitorFilterBase(miniterm.Transform): def NAME(self): raise NotImplementedError("Please declare NAME attribute for the filter class") + def set_running_terminal(self, terminal): + self._running_terminal = terminal + + def get_running_terminal(self): + return self._running_terminal + def register_filters(platform=None, options=None): # project filters diff --git a/platformio/device/monitor/filters/hexlify.py b/platformio/device/monitor/filters/hexlify.py index 28e83bfb..40fc203e 100644 --- a/platformio/device/monitor/filters/hexlify.py +++ b/platformio/device/monitor/filters/hexlify.py @@ -24,12 +24,18 @@ class Hexlify(DeviceMonitorFilterBase): super().__init__(*args, **kwargs) self._counter = 0 + def set_running_terminal(self, terminal): + # force to Latin-1, issue #4732 + if terminal.input_encoding == "UTF-8": + terminal.set_rx_encoding("Latin-1") + super().set_running_terminal(terminal) + def rx(self, text): result = "" - for b in serial.iterbytes(text): + for c in serial.iterbytes(text): if (self._counter % 16) == 0: result += "\n{:04X} | ".format(self._counter) - asciicode = ord(b) + asciicode = ord(c) if asciicode <= 255: result += "{:02X} ".format(asciicode) else: diff --git a/platformio/device/monitor/terminal.py b/platformio/device/monitor/terminal.py index 7b2a9b91..a3abf857 100644 --- a/platformio/device/monitor/terminal.py +++ b/platformio/device/monitor/terminal.py @@ -110,6 +110,12 @@ def new_terminal(options): term.raw = options["raw"] term.set_rx_encoding(options["encoding"]) term.set_tx_encoding(options["encoding"]) + for ts in (term.tx_transformations, term.rx_transformations): + for t in ts: + try: + t.set_running_terminal(term) + except AttributeError: + pass return term diff --git a/platformio/project/options.py b/platformio/project/options.py index 51611d24..3d9c8969 100644 --- a/platformio/project/options.py +++ b/platformio/project/options.py @@ -549,7 +549,7 @@ ProjectOptions = OrderedDict( ConfigEnvOption( group="monitor", name="monitor_encoding", - description="Custom encoding (e.g. hexlify, Latin1, UTF-8)", + description="Custom encoding (e.g. hexlify, Latin-1, UTF-8)", default="UTF-8", ), # Library