From c6916e2a5b689784a4ded69040ec44f255eefbe3 Mon Sep 17 00:00:00 2001 From: Markus Hitter Date: Sun, 5 Jul 2015 20:04:42 +0200 Subject: [PATCH] G-code parser: an asterisk always ends all fields. This solves lines like these, with previous answer: M23 bla*3 ok E: Bad M-code 233 M23 123*92 ok E: Bad M-code 88 It should also solve lines with ;-comment _and_ a checksum. --- gcode_parse.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/gcode_parse.c b/gcode_parse.c index f31010c..81588cd 100644 --- a/gcode_parse.c +++ b/gcode_parse.c @@ -112,6 +112,12 @@ void gcode_parse_char(uint8_t c) { sim_gcode_ch(c); #endif + // An asterisk is a quasi-EOL and always ends all fields. + if (c == '*') { + next_target.seen_semi_comment = next_target.seen_parens_comment = + next_target.read_string = 0; + } + // Skip comments and strings. if (next_target.seen_semi_comment == 0 && next_target.seen_parens_comment == 0 && @@ -133,6 +139,7 @@ void gcode_parse_char(uint8_t c) { // SD card command with a filename. next_target.read_string = 1; // Reset by string handler or EOL. str_buf_ptr = 0; + last_field = 0; } #endif if (DEBUG_ECHO && (debug_flags & DEBUG_ECHO)) @@ -400,10 +407,11 @@ void gcode_parse_char(uint8_t c) { #ifdef SD // Handle string reading. After checking for EOL. if (next_target.read_string) { - if ((str_buf_ptr && c == ' ') || c == '*') { - next_target.read_string = 0; + if (c == ' ') { + if (str_buf_ptr) + next_target.read_string = 0; } - else if (c != ' ' && str_buf_ptr < STR_BUF_LEN) { + else if (str_buf_ptr < STR_BUF_LEN) { gcode_str_buf[str_buf_ptr] = c; str_buf_ptr++; gcode_str_buf[str_buf_ptr] = '\0';