From 9105573ac97bbf94c10d564ad5131adb9cd02446 Mon Sep 17 00:00:00 2001 From: Yuri D'Elia Date: Wed, 14 Dec 2022 13:44:17 +0100 Subject: [PATCH] Handle/strip leading whitespace in gcode stream --- Firmware/cmdqueue.cpp | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/Firmware/cmdqueue.cpp b/Firmware/cmdqueue.cpp index 4c48c8b1d..768ce5e95 100755 --- a/Firmware/cmdqueue.cpp +++ b/Firmware/cmdqueue.cpp @@ -419,15 +419,21 @@ void get_command() return; } } - // if we don't receive 'N' but still see '*' - if (*(cmd_head != 'N') && (strchr(cmd_start, '*') != NULL)) + else { - SERIAL_ERROR_START; - SERIAL_ERRORRPGM(_n("No Line Number with checksum, Last Line: "));////MSG_ERR_NO_LINENUMBER_WITH_CHECKSUM - SERIAL_ERRORLN(gcode_LastN); - FlushSerialRequestResend(); - serial_count = 0; - return; + // move cmd_start past all spaces + while (*cmd_start == ' ') ++cmd_start; + + // if we didn't receive 'N' but still see '*' + if (strchr(cmd_start, '*') != NULL) + { + SERIAL_ERROR_START; + SERIAL_ERRORRPGM(_n("No Line Number with checksum, Last Line: "));////MSG_ERR_NO_LINENUMBER_WITH_CHECKSUM + SERIAL_ERRORLN(gcode_LastN); + FlushSerialRequestResend(); + serial_count = 0; + return; + } } // Handle KILL early, even when Stopped