PanelDue: Make checksums optional
Some displays which emulate PD firmware do not use checksums. Signed-off-by: Eric Callahan <arksine.code@gmail.com>
This commit is contained in:
parent
7a013a42f7
commit
346c3ad2a0
|
@ -139,6 +139,7 @@ class PanelDue:
|
||||||
self.last_gcode_response = None
|
self.last_gcode_response = None
|
||||||
self.current_file = ""
|
self.current_file = ""
|
||||||
self.file_metadata = {}
|
self.file_metadata = {}
|
||||||
|
self.enable_checksum = config.getboolean('enable_checksum', True)
|
||||||
|
|
||||||
# Initialize tracked state.
|
# Initialize tracked state.
|
||||||
self.printer_state = {
|
self.printer_state = {
|
||||||
|
@ -308,39 +309,42 @@ class PanelDue:
|
||||||
await self.klippy_apis.emergency_stop()
|
await self.klippy_apis.emergency_stop()
|
||||||
return
|
return
|
||||||
|
|
||||||
# Get line number
|
if self.enable_checksum:
|
||||||
line_index = line.find(' ')
|
# Get line number
|
||||||
try:
|
line_index = line.find(' ')
|
||||||
line_no = int(line[1:line_index])
|
try:
|
||||||
except Exception:
|
line_no = int(line[1:line_index])
|
||||||
line_index = -1
|
except Exception:
|
||||||
line_no = None
|
line_index = -1
|
||||||
|
line_no = None
|
||||||
|
|
||||||
# Verify checksum
|
# Verify checksum
|
||||||
cs_index = line.rfind('*')
|
cs_index = line.rfind('*')
|
||||||
try:
|
try:
|
||||||
checksum = int(line[cs_index+1:])
|
checksum = int(line[cs_index+1:])
|
||||||
except Exception:
|
except Exception:
|
||||||
# Invalid checksum, do not process
|
# Invalid checksum, do not process
|
||||||
msg = "!! Invalid Checksum"
|
msg = "!! Invalid Checksum"
|
||||||
if line_no is not None:
|
if line_no is not None:
|
||||||
msg += f" Line Number: {line_no}"
|
msg += f" Line Number: {line_no}"
|
||||||
logging.exception("PanelDue: " + msg)
|
logging.exception("PanelDue: " + msg)
|
||||||
raise PanelDueError(msg)
|
raise PanelDueError(msg)
|
||||||
|
|
||||||
# Checksum is calculated by XORing every byte in the line other
|
# Checksum is calculated by XORing every byte in the line other
|
||||||
# than the checksum itself
|
# than the checksum itself
|
||||||
calculated_cs = 0
|
calculated_cs = 0
|
||||||
for c in line[:cs_index]:
|
for c in line[:cs_index]:
|
||||||
calculated_cs ^= ord(c)
|
calculated_cs ^= ord(c)
|
||||||
if calculated_cs & 0xFF != checksum:
|
if calculated_cs & 0xFF != checksum:
|
||||||
msg = "!! Invalid Checksum"
|
msg = "!! Invalid Checksum"
|
||||||
if line_no is not None:
|
if line_no is not None:
|
||||||
msg += f" Line Number: {line_no}"
|
msg += f" Line Number: {line_no}"
|
||||||
logging.info("PanelDue: " + msg)
|
logging.info("PanelDue: " + msg)
|
||||||
raise PanelDueError(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):
|
async def _run_gcode(self, script):
|
||||||
# Execute the gcode. Check for special RRF gcodes that
|
# Execute the gcode. Check for special RRF gcodes that
|
||||||
|
|
Loading…
Reference in New Issue