From 346c3ad2a05c98717ffd25e75bc761b7438dcac2 Mon Sep 17 00:00:00 2001 From: Arksine Date: Thu, 8 Oct 2020 14:24:47 -0400 Subject: [PATCH] PanelDue: Make checksums optional Some displays which emulate PD firmware do not use checksums. Signed-off-by: Eric Callahan --- moonraker/plugins/paneldue.py | 64 +++++++++++++++++++---------------- 1 file changed, 34 insertions(+), 30 deletions(-) diff --git a/moonraker/plugins/paneldue.py b/moonraker/plugins/paneldue.py index f8bd857..1d6befa 100644 --- a/moonraker/plugins/paneldue.py +++ b/moonraker/plugins/paneldue.py @@ -139,6 +139,7 @@ class PanelDue: self.last_gcode_response = None self.current_file = "" self.file_metadata = {} + self.enable_checksum = config.getboolean('enable_checksum', True) # Initialize tracked state. self.printer_state = { @@ -308,39 +309,42 @@ class PanelDue: await self.klippy_apis.emergency_stop() return - # Get line number - line_index = line.find(' ') - try: - line_no = int(line[1:line_index]) - except Exception: - line_index = -1 - line_no = None + if self.enable_checksum: + # Get line number + line_index = line.find(' ') + try: + line_no = int(line[1:line_index]) + except Exception: + line_index = -1 + line_no = None - # Verify checksum - cs_index = line.rfind('*') - try: - checksum = int(line[cs_index+1:]) - except Exception: - # Invalid checksum, do not process - msg = "!! Invalid Checksum" - if line_no is not None: - msg += f" Line Number: {line_no}" - logging.exception("PanelDue: " + msg) - raise PanelDueError(msg) + # Verify checksum + cs_index = line.rfind('*') + try: + checksum = int(line[cs_index+1:]) + except Exception: + # Invalid checksum, do not process + msg = "!! Invalid Checksum" + if line_no is not None: + msg += f" Line Number: {line_no}" + logging.exception("PanelDue: " + msg) + raise PanelDueError(msg) - # Checksum is calculated by XORing every byte in the line other - # than the checksum itself - calculated_cs = 0 - for c in line[:cs_index]: - calculated_cs ^= ord(c) - if calculated_cs & 0xFF != checksum: - msg = "!! Invalid Checksum" - if line_no is not None: - msg += f" Line Number: {line_no}" - logging.info("PanelDue: " + msg) - raise PanelDueError(msg) + # Checksum is calculated by XORing every byte in the line other + # than the checksum itself + calculated_cs = 0 + for c in line[:cs_index]: + calculated_cs ^= ord(c) + if calculated_cs & 0xFF != checksum: + msg = "!! Invalid Checksum" + if line_no is not None: + msg += f" Line Number: {line_no}" + logging.info("PanelDue: " + msg) + raise PanelDueError(msg) - await self._run_gcode(line[line_index+1:cs_index]) + await self._run_gcode(line[line_index+1:cs_index]) + else: + await self._run_gcode(line) async def _run_gcode(self, script): # Execute the gcode. Check for special RRF gcodes that