Browse Source

Merge pull request #8433 from thinkyhead/bf2_fix_parser_value

[2.0] Fix parser value handling
pull/1/head
Scott Lahteine 7 years ago
committed by GitHub
parent
commit
1c7b9f6d5d
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 22
      Marlin/src/gcode/parser.cpp

22
Marlin/src/gcode/parser.cpp

@ -170,7 +170,7 @@ void GCodeParser::parse(char *p) {
* For 'M118' you must use 'E1' and 'A1' rather than just 'E' or 'A' * For 'M118' you must use 'E1' and 'A1' rather than just 'E' or 'A'
*/ */
string_arg = NULL; string_arg = NULL;
while (char code = *p++) { // Get the next parameter. A NUL ends the loop while (const char code = *p++) { // Get the next parameter. A NUL ends the loop
// Special handling for M32 [P] !/path/to/file.g# // Special handling for M32 [P] !/path/to/file.g#
// The path must be the last parameter // The path must be the last parameter
@ -191,12 +191,20 @@ void GCodeParser::parse(char *p) {
if (PARAM_TEST) { if (PARAM_TEST) {
while (*p == ' ') p++; // Skip spaces between parameters & values while (*p == ' ') p++; // Skip spaces between parameters & values
const bool has_num = DECIMAL_SIGNED(*p); // The parameter has a number [-+0-9.]
const bool has_num = NUMERIC(p[0]) // [0-9]
|| (p[0] == '.' && NUMERIC(p[1])) // .[0-9]
|| (
(p[0] == '-' || p[0] == '+') && ( // [-+]
NUMERIC(p[1]) // [0-9]
|| (p[1] == '.' && NUMERIC(p[2])) // .[0-9]
)
);
#if ENABLED(DEBUG_GCODE_PARSER) #if ENABLED(DEBUG_GCODE_PARSER)
if (debug) { if (debug) {
SERIAL_ECHOPAIR("Got letter ", code); // DEBUG SERIAL_ECHOPAIR("Got letter ", code);
SERIAL_ECHOPAIR(" at index ", (int)(p - command_ptr - 1)); // DEBUG SERIAL_ECHOPAIR(" at index ", (int)(p - command_ptr - 1));
if (has_num) SERIAL_ECHOPGM(" (has_num)"); if (has_num) SERIAL_ECHOPGM(" (has_num)");
} }
#endif #endif
@ -213,11 +221,13 @@ void GCodeParser::parse(char *p) {
#endif #endif
#if ENABLED(FASTER_GCODE_PARSER) #if ENABLED(FASTER_GCODE_PARSER)
{
set(code, has_num ? p : NULL // Set parameter exists and pointer (NULL for no number) set(code, has_num ? p : NULL // Set parameter exists and pointer (NULL for no number)
#if ENABLED(DEBUG_GCODE_PARSER) #if ENABLED(DEBUG_GCODE_PARSER)
, debug , debug
#endif #endif
); );
}
#endif #endif
} }
else if (!string_arg) { // Not A-Z? First time, keep as the string_arg else if (!string_arg) { // Not A-Z? First time, keep as the string_arg
@ -227,8 +237,8 @@ void GCodeParser::parse(char *p) {
#endif #endif
} }
if (!WITHIN(*p, 'A', 'Z')) { if (!WITHIN(*p, 'A', 'Z')) { // Another parameter right away?
while (*p && NUMERIC(*p)) p++; // Skip over the value section of a parameter while (*p && DECIMAL_SIGNED(*p)) p++; // Skip over the value section of a parameter
while (*p == ' ') p++; // Skip over all spaces while (*p == ' ') p++; // Skip over all spaces
} }
} }

Loading…
Cancel
Save