2017-05-20 03:03:08 -05:00
|
|
|
/**
|
|
|
|
* Marlin 3D Printer Firmware
|
2020-02-03 08:00:57 -06:00
|
|
|
* Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
|
2017-05-20 03:03:08 -05:00
|
|
|
*
|
|
|
|
* Based on Sprinter and grbl.
|
2019-06-27 23:57:50 -05:00
|
|
|
* Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
|
2017-05-20 03:03:08 -05:00
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2020-07-22 22:20:14 -05:00
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2017-05-20 03:03:08 -05:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2017-09-06 06:28:31 -05:00
|
|
|
* parser.cpp - Parser for a GCode line, providing a parameter interface.
|
2017-05-20 03:03:08 -05:00
|
|
|
*/
|
|
|
|
|
2017-09-06 06:28:31 -05:00
|
|
|
#include "parser.h"
|
2017-05-20 03:03:08 -05:00
|
|
|
|
2020-01-02 19:01:38 -06:00
|
|
|
#include "../MarlinCore.h"
|
2017-09-06 06:28:31 -05:00
|
|
|
|
2017-05-20 03:03:08 -05:00
|
|
|
// Must be declared for allocation and to satisfy the linker
|
|
|
|
// Zero values need no initialization.
|
|
|
|
|
2017-09-16 11:41:12 -05:00
|
|
|
bool GCodeParser::volumetric_enabled;
|
|
|
|
|
2017-05-20 03:03:08 -05:00
|
|
|
#if ENABLED(INCH_MODE_SUPPORT)
|
|
|
|
float GCodeParser::linear_unit_factor, GCodeParser::volumetric_unit_factor;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if ENABLED(TEMPERATURE_UNITS_SUPPORT)
|
2019-06-11 07:27:39 -05:00
|
|
|
TempUnit GCodeParser::input_temp_units = TEMPUNIT_C;
|
2017-05-20 03:03:08 -05:00
|
|
|
#endif
|
|
|
|
|
|
|
|
char *GCodeParser::command_ptr,
|
|
|
|
*GCodeParser::string_arg,
|
|
|
|
*GCodeParser::value_ptr;
|
|
|
|
char GCodeParser::command_letter;
|
2020-11-14 18:09:17 -06:00
|
|
|
uint16_t GCodeParser::codenum;
|
2018-10-05 18:19:45 -05:00
|
|
|
|
2021-02-23 16:08:00 -06:00
|
|
|
#if USE_GCODE_SUBCODES
|
2017-07-06 14:06:39 -05:00
|
|
|
uint8_t GCodeParser::subcode;
|
2017-05-20 03:03:08 -05:00
|
|
|
#endif
|
2018-10-05 18:19:45 -05:00
|
|
|
|
|
|
|
#if ENABLED(GCODE_MOTION_MODES)
|
|
|
|
int16_t GCodeParser::motion_mode_codenum = -1;
|
2021-02-23 16:08:00 -06:00
|
|
|
#if USE_GCODE_SUBCODES
|
2018-10-05 18:19:45 -05:00
|
|
|
uint8_t GCodeParser::motion_mode_subcode;
|
2018-10-05 02:35:55 -05:00
|
|
|
#endif
|
|
|
|
#endif
|
2017-05-20 03:03:08 -05:00
|
|
|
|
|
|
|
#if ENABLED(FASTER_GCODE_PARSER)
|
|
|
|
// Optimized Parameters
|
2018-01-23 20:49:01 -06:00
|
|
|
uint32_t GCodeParser::codebits; // found bits
|
2017-05-20 03:03:08 -05:00
|
|
|
uint8_t GCodeParser::param[26]; // parameter offsets from command_ptr
|
|
|
|
#else
|
|
|
|
char *GCodeParser::command_args; // start of parameters
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Create a global instance of the GCode parser singleton
|
|
|
|
GCodeParser parser;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Clear all code-seen (and value pointers)
|
|
|
|
*
|
|
|
|
* Since each param is set/cleared on seen codes,
|
|
|
|
* this may be optimized by commenting out ZERO(param)
|
|
|
|
*/
|
|
|
|
void GCodeParser::reset() {
|
2019-05-09 11:45:55 -05:00
|
|
|
string_arg = nullptr; // No whole line argument
|
2017-05-20 03:03:08 -05:00
|
|
|
command_letter = '?'; // No command letter
|
|
|
|
codenum = 0; // No command code
|
2020-04-22 16:35:03 -05:00
|
|
|
TERN_(USE_GCODE_SUBCODES, subcode = 0); // No command sub-code
|
2017-05-20 03:03:08 -05:00
|
|
|
#if ENABLED(FASTER_GCODE_PARSER)
|
2018-01-23 20:49:01 -06:00
|
|
|
codebits = 0; // No codes yet
|
2017-05-20 03:03:08 -05:00
|
|
|
//ZERO(param); // No parameters (should be safe to comment out this line)
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2020-02-10 14:52:15 -06:00
|
|
|
#if ENABLED(GCODE_QUOTED_STRINGS)
|
|
|
|
|
|
|
|
// Pass the address after the first quote (if any)
|
|
|
|
char* GCodeParser::unescape_string(char* &src) {
|
|
|
|
if (*src == '"') ++src; // Skip the leading quote
|
|
|
|
char * const out = src; // Start of the string
|
|
|
|
char *dst = src; // Prepare to unescape and terminate
|
|
|
|
for (;;) {
|
|
|
|
char c = *src++; // Get the next char
|
|
|
|
switch (c) {
|
|
|
|
case '\\': c = *src++; break; // Get the escaped char
|
|
|
|
case '"' : c = '\0'; break; // Convert bare quote to nul
|
|
|
|
}
|
|
|
|
if (!(*dst++ = c)) break; // Copy and break on nul
|
|
|
|
}
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2021-04-16 01:59:28 -05:00
|
|
|
/**
|
|
|
|
* Populate the command line state (command_letter, codenum, subcode, and string_arg)
|
|
|
|
* by parsing a single line of GCode. 58 bytes of SRAM are used to speed up seen/value.
|
|
|
|
*/
|
2017-05-20 03:03:08 -05:00
|
|
|
void GCodeParser::parse(char *p) {
|
|
|
|
|
|
|
|
reset(); // No codes to report
|
|
|
|
|
2020-02-26 09:23:55 -06:00
|
|
|
auto uppercase = [](char c) {
|
2020-04-22 16:35:03 -05:00
|
|
|
if (TERN0(GCODE_CASE_INSENSITIVE, WITHIN(c, 'a', 'z')))
|
|
|
|
c += 'A' - 'a';
|
2020-02-26 09:23:55 -06:00
|
|
|
return c;
|
|
|
|
};
|
|
|
|
|
2017-05-20 03:03:08 -05:00
|
|
|
// Skip spaces
|
|
|
|
while (*p == ' ') ++p;
|
|
|
|
|
|
|
|
// Skip N[-0-9] if included in the command line
|
2020-02-26 09:23:55 -06:00
|
|
|
if (uppercase(*p) == 'N' && NUMERIC_SIGNED(p[1])) {
|
2020-04-22 16:35:03 -05:00
|
|
|
//TERN_(FASTER_GCODE_PARSER, set('N', p + 1)); // (optional) Set the 'N' parameter value
|
2017-05-20 03:03:08 -05:00
|
|
|
p += 2; // skip N[-0-9]
|
|
|
|
while (NUMERIC(*p)) ++p; // skip [0-9]*
|
|
|
|
while (*p == ' ') ++p; // skip [ ]*
|
|
|
|
}
|
|
|
|
|
|
|
|
// *p now points to the current command, which should be G, M, or T
|
|
|
|
command_ptr = p;
|
|
|
|
|
|
|
|
// Get the command letter, which must be G, M, or T
|
2020-02-26 09:23:55 -06:00
|
|
|
const char letter = uppercase(*p++);
|
2017-05-20 03:03:08 -05:00
|
|
|
|
|
|
|
// Nullify asterisk and trailing whitespace
|
|
|
|
char *starpos = strchr(p, '*');
|
|
|
|
if (starpos) {
|
|
|
|
--starpos; // *
|
|
|
|
while (*starpos == ' ') --starpos; // spaces...
|
|
|
|
starpos[1] = '\0';
|
|
|
|
}
|
|
|
|
|
2020-10-09 06:25:23 -05:00
|
|
|
#if ANY(MARLIN_DEV_MODE, SWITCHING_TOOLHEAD, MAGNETIC_SWITCHING_TOOLHEAD, ELECTROMAGNETIC_SWITCHING_TOOLHEAD)
|
|
|
|
#define SIGNED_CODENUM 1
|
2018-10-05 18:19:45 -05:00
|
|
|
#endif
|
|
|
|
|
2021-04-16 01:59:28 -05:00
|
|
|
/**
|
|
|
|
* Screen for good command letters. G, M, and T are always accepted.
|
|
|
|
* With Motion Modes enabled any axis letter can come first.
|
|
|
|
* With Realtime Reporting, commands S000, P000, and R000 are allowed.
|
|
|
|
*/
|
2018-10-05 18:19:45 -05:00
|
|
|
switch (letter) {
|
2020-10-09 06:25:23 -05:00
|
|
|
case 'G': case 'M': case 'T': TERN_(MARLIN_DEV_MODE, case 'D':)
|
2018-10-05 02:35:55 -05:00
|
|
|
// Skip spaces to get the numeric part
|
|
|
|
while (*p == ' ') p++;
|
|
|
|
|
2020-11-18 01:27:21 -06:00
|
|
|
#if HAS_PRUSA_MMU2
|
2019-01-31 19:10:52 -06:00
|
|
|
if (letter == 'T') {
|
|
|
|
// check for special MMU2 T?/Tx/Tc commands
|
|
|
|
if (*p == '?' || *p == 'x' || *p == 'c') {
|
2019-05-10 19:57:15 -05:00
|
|
|
command_letter = letter;
|
2019-01-31 19:10:52 -06:00
|
|
|
string_arg = p;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2019-05-10 19:57:15 -05:00
|
|
|
// Bail if there's no command code number
|
2020-10-09 06:25:23 -05:00
|
|
|
if (!TERN(SIGNED_CODENUM, NUMERIC_SIGNED(*p), NUMERIC(*p))) return;
|
2019-05-10 19:57:15 -05:00
|
|
|
|
|
|
|
// Save the command letter at this point
|
|
|
|
// A '?' signifies an unknown command
|
|
|
|
command_letter = letter;
|
2019-01-31 19:10:52 -06:00
|
|
|
|
2020-10-09 06:25:23 -05:00
|
|
|
{
|
|
|
|
#if ENABLED(SIGNED_CODENUM)
|
|
|
|
int sign = 1; // Allow for a negative code like D-1 or T-1
|
|
|
|
if (*p == '-') { sign = -1; ++p; }
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Get the code number - integer digits only
|
|
|
|
codenum = 0;
|
|
|
|
|
|
|
|
do { codenum = codenum * 10 + *p++ - '0'; } while (NUMERIC(*p));
|
|
|
|
|
|
|
|
// Apply the sign, if any
|
|
|
|
TERN_(SIGNED_CODENUM, codenum *= sign);
|
|
|
|
}
|
2018-10-05 02:35:55 -05:00
|
|
|
|
|
|
|
// Allow for decimal point in command
|
2021-02-23 16:08:00 -06:00
|
|
|
#if USE_GCODE_SUBCODES
|
2020-02-10 16:22:38 -06:00
|
|
|
if (*p == '.') {
|
|
|
|
p++;
|
|
|
|
while (NUMERIC(*p))
|
2020-10-09 06:25:23 -05:00
|
|
|
subcode = subcode * 10 + *p++ - '0';
|
2020-02-10 16:22:38 -06:00
|
|
|
}
|
2018-10-05 02:35:55 -05:00
|
|
|
#endif
|
|
|
|
|
|
|
|
// Skip all spaces to get to the first argument, or nul
|
|
|
|
while (*p == ' ') p++;
|
|
|
|
|
2018-10-05 18:19:45 -05:00
|
|
|
#if ENABLED(GCODE_MOTION_MODES)
|
2020-10-09 06:25:23 -05:00
|
|
|
if (letter == 'G'
|
|
|
|
&& (codenum <= TERN(ARC_SUPPORT, 3, 1) || codenum == 5 || TERN0(G38_PROBE_TARGET, codenum == 38))
|
2018-10-05 18:19:45 -05:00
|
|
|
) {
|
|
|
|
motion_mode_codenum = codenum;
|
2020-04-22 16:35:03 -05:00
|
|
|
TERN_(USE_GCODE_SUBCODES, motion_mode_subcode = subcode);
|
2018-10-05 02:35:55 -05:00
|
|
|
}
|
|
|
|
#endif
|
2018-10-05 18:19:45 -05:00
|
|
|
|
2018-10-05 02:35:55 -05:00
|
|
|
break;
|
2018-10-05 18:19:45 -05:00
|
|
|
|
|
|
|
#if ENABLED(GCODE_MOTION_MODES)
|
|
|
|
#if ENABLED(ARC_SUPPORT)
|
2021-04-17 03:54:43 -05:00
|
|
|
case 'I' ... 'J':
|
2018-10-05 18:19:45 -05:00
|
|
|
if (motion_mode_codenum != 2 && motion_mode_codenum != 3) return;
|
2018-10-05 02:35:55 -05:00
|
|
|
#endif
|
2021-04-17 03:54:43 -05:00
|
|
|
case 'Q':
|
2018-10-05 18:19:45 -05:00
|
|
|
if (motion_mode_codenum != 5) return;
|
2020-10-09 06:25:23 -05:00
|
|
|
case 'X' ... 'Z': case 'E' ... 'F':
|
2018-10-05 18:19:45 -05:00
|
|
|
if (motion_mode_codenum < 0) return;
|
|
|
|
command_letter = 'G';
|
|
|
|
codenum = motion_mode_codenum;
|
2020-04-22 16:35:03 -05:00
|
|
|
TERN_(USE_GCODE_SUBCODES, subcode = motion_mode_subcode);
|
2018-10-05 18:19:45 -05:00
|
|
|
p--; // Back up one character to use the current parameter
|
|
|
|
break;
|
2021-04-17 03:54:43 -05:00
|
|
|
#endif
|
2018-10-05 02:35:55 -05:00
|
|
|
|
2021-04-16 01:59:28 -05:00
|
|
|
#if ENABLED(REALTIME_REPORTING_COMMANDS)
|
2021-04-17 03:54:43 -05:00
|
|
|
case 'P': case 'R': {
|
|
|
|
if (letter == 'R') {
|
|
|
|
#if ENABLED(GCODE_MOTION_MODES)
|
|
|
|
if (ENABLED(ARC_SUPPORT) && !WITHIN(motion_mode_codenum, 2, 3)) return;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
else if (TERN0(GCODE_MOTION_MODES, motion_mode_codenum != 5)) return;
|
|
|
|
} // fall-thru
|
|
|
|
case 'S': {
|
2021-04-16 01:59:28 -05:00
|
|
|
codenum = 0; // The only valid codenum is 0
|
|
|
|
uint8_t digits = 0;
|
|
|
|
while (*p++ == '0') digits++; // Count up '0' characters
|
|
|
|
command_letter = (digits == 3) ? letter : '?'; // Three '0' digits is a good command
|
2021-04-17 03:54:43 -05:00
|
|
|
} return; // No parameters needed, so return now
|
2021-04-16 01:59:28 -05:00
|
|
|
#endif
|
|
|
|
|
2018-10-05 18:19:45 -05:00
|
|
|
default: return;
|
2018-10-05 02:35:55 -05:00
|
|
|
}
|
2017-05-20 03:03:08 -05:00
|
|
|
|
|
|
|
// The command parameters (if any) start here, for sure!
|
|
|
|
|
|
|
|
#if DISABLED(FASTER_GCODE_PARSER)
|
|
|
|
command_args = p; // Scan for parameters in seen()
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Only use string_arg for these M codes
|
2018-11-09 05:25:08 -06:00
|
|
|
if (letter == 'M') switch (codenum) {
|
|
|
|
#if ENABLED(GCODE_MACROS)
|
2019-10-01 19:59:48 -05:00
|
|
|
case 810 ... 819:
|
2018-11-09 05:25:08 -06:00
|
|
|
#endif
|
2019-08-13 23:38:45 -05:00
|
|
|
#if ENABLED(EXPECTED_PRINTER_CHECK)
|
|
|
|
case 16:
|
|
|
|
#endif
|
2020-10-09 06:25:23 -05:00
|
|
|
case 23: case 28: case 30: case 117 ... 118: case 928:
|
2020-02-10 14:52:15 -06:00
|
|
|
string_arg = unescape_string(p);
|
|
|
|
return;
|
2019-10-24 15:35:40 -05:00
|
|
|
default: break;
|
|
|
|
}
|
2020-02-10 14:52:15 -06:00
|
|
|
|
2017-05-20 03:03:08 -05:00
|
|
|
#if ENABLED(DEBUG_GCODE_PARSER)
|
|
|
|
const bool debug = codenum == 800;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Find all parameters, set flags and pointers for fast parsing
|
|
|
|
*
|
|
|
|
* Most codes ignore 'string_arg', but those that want a string will get the right pointer.
|
|
|
|
* The following loop assigns the first "parameter" having no numeric value to 'string_arg'.
|
|
|
|
* This allows M0/M1 with expire time to work: "M0 S5 You Win!"
|
2017-11-06 22:57:01 -06:00
|
|
|
* For 'M118' you must use 'E1' and 'A1' rather than just 'E' or 'A'
|
2017-05-20 03:03:08 -05:00
|
|
|
*/
|
2020-02-10 14:52:15 -06:00
|
|
|
#if ENABLED(GCODE_QUOTED_STRINGS)
|
|
|
|
bool quoted_string_arg = false;
|
|
|
|
#endif
|
2019-05-09 11:45:55 -05:00
|
|
|
string_arg = nullptr;
|
2020-02-26 09:23:55 -06:00
|
|
|
while (const char param = uppercase(*p++)) { // Get the next parameter. A NUL ends the loop
|
2017-05-20 03:03:08 -05:00
|
|
|
|
|
|
|
// Special handling for M32 [P] !/path/to/file.g#
|
|
|
|
// The path must be the last parameter
|
2020-11-14 18:09:17 -06:00
|
|
|
if (param == '!' && is_command('M', 32)) {
|
2017-05-20 03:03:08 -05:00
|
|
|
string_arg = p; // Name starts after '!'
|
|
|
|
char * const lb = strchr(p, '#'); // Already seen '#' as SD char (to pause buffering)
|
|
|
|
if (lb) *lb = '\0'; // Safe to mark the end of the filename
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-02-10 14:52:15 -06:00
|
|
|
#if ENABLED(GCODE_QUOTED_STRINGS)
|
|
|
|
if (!quoted_string_arg && param == '"') {
|
|
|
|
quoted_string_arg = true;
|
|
|
|
string_arg = unescape_string(p);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2017-05-20 03:03:08 -05:00
|
|
|
#if ENABLED(FASTER_GCODE_PARSER)
|
2020-02-26 09:23:55 -06:00
|
|
|
// Arguments MUST be uppercase for fast GCode parsing
|
|
|
|
#define PARAM_OK(P) WITHIN((P), 'A', 'Z')
|
2017-05-20 03:03:08 -05:00
|
|
|
#else
|
2020-02-26 09:23:55 -06:00
|
|
|
#define PARAM_OK(P) true
|
2017-05-20 03:03:08 -05:00
|
|
|
#endif
|
|
|
|
|
2020-02-26 09:23:55 -06:00
|
|
|
if (PARAM_OK(param)) {
|
2017-06-02 22:02:52 -05:00
|
|
|
|
2017-06-02 21:45:51 -05:00
|
|
|
while (*p == ' ') p++; // Skip spaces between parameters & values
|
2017-11-14 23:20:33 -06:00
|
|
|
|
2020-02-10 14:52:15 -06:00
|
|
|
#if ENABLED(GCODE_QUOTED_STRINGS)
|
|
|
|
const bool is_str = (*p == '"'), has_val = is_str || valid_float(p);
|
|
|
|
char * const valptr = has_val ? is_str ? unescape_string(p) : p : nullptr;
|
|
|
|
#else
|
|
|
|
const bool has_val = valid_float(p);
|
2020-03-02 13:17:52 -06:00
|
|
|
#if ENABLED(FASTER_GCODE_PARSER)
|
|
|
|
char * const valptr = has_val ? p : nullptr;
|
|
|
|
#endif
|
2020-02-10 14:52:15 -06:00
|
|
|
#endif
|
2017-05-20 03:03:08 -05:00
|
|
|
|
|
|
|
#if ENABLED(DEBUG_GCODE_PARSER)
|
|
|
|
if (debug) {
|
2021-04-07 15:43:07 -05:00
|
|
|
SERIAL_ECHOPAIR("Got param ", AS_CHAR(param), " at index ", p - command_ptr - 1);
|
2020-02-10 14:52:15 -06:00
|
|
|
if (has_val) SERIAL_ECHOPGM(" (has_val)");
|
2017-05-20 03:03:08 -05:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2020-02-10 14:52:15 -06:00
|
|
|
if (!has_val && !string_arg) { // No value? First time, keep as string_arg
|
2017-05-20 03:03:08 -05:00
|
|
|
string_arg = p - 1;
|
|
|
|
#if ENABLED(DEBUG_GCODE_PARSER)
|
|
|
|
if (debug) SERIAL_ECHOPAIR(" string_arg: ", hex_address((void*)string_arg)); // DEBUG
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2020-04-22 16:35:03 -05:00
|
|
|
if (TERN0(DEBUG_GCODE_PARSER, debug)) SERIAL_EOL();
|
2017-05-20 03:03:08 -05:00
|
|
|
|
2020-04-22 16:35:03 -05:00
|
|
|
TERN_(FASTER_GCODE_PARSER, set(param, valptr)); // Set parameter exists and pointer (nullptr for no value)
|
2017-05-20 03:03:08 -05:00
|
|
|
}
|
|
|
|
else if (!string_arg) { // Not A-Z? First time, keep as the string_arg
|
|
|
|
string_arg = p - 1;
|
|
|
|
#if ENABLED(DEBUG_GCODE_PARSER)
|
|
|
|
if (debug) SERIAL_ECHOPAIR(" string_arg: ", hex_address((void*)string_arg)); // DEBUG
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2017-11-14 23:20:33 -06:00
|
|
|
if (!WITHIN(*p, 'A', 'Z')) { // Another parameter right away?
|
|
|
|
while (*p && DECIMAL_SIGNED(*p)) p++; // Skip over the value section of a parameter
|
2017-06-02 21:45:51 -05:00
|
|
|
while (*p == ' ') p++; // Skip over all spaces
|
2017-06-02 19:22:40 -05:00
|
|
|
}
|
2017-05-20 03:03:08 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-04 16:36:41 -05:00
|
|
|
#if ENABLED(CNC_COORDINATE_SYSTEMS)
|
|
|
|
|
|
|
|
// Parse the next parameter as a new command
|
|
|
|
bool GCodeParser::chain() {
|
|
|
|
#if ENABLED(FASTER_GCODE_PARSER)
|
|
|
|
char *next_command = command_ptr;
|
|
|
|
if (next_command) {
|
|
|
|
while (*next_command && *next_command != ' ') ++next_command;
|
|
|
|
while (*next_command == ' ') ++next_command;
|
2019-05-09 11:45:55 -05:00
|
|
|
if (!*next_command) next_command = nullptr;
|
2017-11-04 16:36:41 -05:00
|
|
|
}
|
|
|
|
#else
|
|
|
|
const char *next_command = command_args;
|
|
|
|
#endif
|
|
|
|
if (next_command) parse(next_command);
|
|
|
|
return !!next_command;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // CNC_COORDINATE_SYSTEMS
|
|
|
|
|
2020-02-08 23:11:45 -06:00
|
|
|
void GCodeParser::unknown_command_warning() {
|
2020-02-26 03:02:03 -06:00
|
|
|
SERIAL_ECHO_MSG(STR_UNKNOWN_COMMAND, command_ptr, "\"");
|
2017-05-20 03:03:08 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#if ENABLED(DEBUG_GCODE_PARSER)
|
|
|
|
|
|
|
|
void GCodeParser::debug() {
|
2019-03-05 06:46:19 -06:00
|
|
|
SERIAL_ECHOPAIR("Command: ", command_ptr, " (", command_letter);
|
2017-05-20 03:03:08 -05:00
|
|
|
SERIAL_ECHO(codenum);
|
|
|
|
SERIAL_ECHOLNPGM(")");
|
|
|
|
#if ENABLED(FASTER_GCODE_PARSER)
|
2019-03-05 06:46:19 -06:00
|
|
|
SERIAL_ECHOPGM(" args: { ");
|
2020-01-08 18:31:57 -06:00
|
|
|
for (char c = 'A'; c <= 'Z'; ++c) if (seen(c)) SERIAL_CHAR(c, ' ');
|
2019-03-05 06:46:19 -06:00
|
|
|
SERIAL_CHAR('}');
|
2017-05-20 03:03:08 -05:00
|
|
|
#else
|
2019-03-05 06:46:19 -06:00
|
|
|
SERIAL_ECHOPAIR(" args: { ", command_args, " }");
|
2017-05-20 03:03:08 -05:00
|
|
|
#endif
|
2020-02-08 23:11:45 -06:00
|
|
|
if (string_arg) {
|
|
|
|
SERIAL_ECHOPAIR(" string: \"", string_arg);
|
|
|
|
SERIAL_CHAR('"');
|
|
|
|
}
|
2019-02-02 23:32:48 -06:00
|
|
|
SERIAL_ECHOLNPGM("\n");
|
2017-05-20 03:03:08 -05:00
|
|
|
for (char c = 'A'; c <= 'Z'; ++c) {
|
|
|
|
if (seen(c)) {
|
|
|
|
SERIAL_ECHOPAIR("Code '", c); SERIAL_ECHOPGM("':");
|
|
|
|
if (has_value()) {
|
2020-02-10 14:52:15 -06:00
|
|
|
SERIAL_ECHOLNPAIR(
|
2019-03-05 06:46:19 -06:00
|
|
|
"\n float: ", value_float(),
|
|
|
|
"\n long: ", value_long(),
|
|
|
|
"\n ulong: ", value_ulong(),
|
|
|
|
"\n millis: ", value_millis(),
|
|
|
|
"\n sec-ms: ", value_millis_from_seconds(),
|
|
|
|
"\n int: ", value_int(),
|
|
|
|
"\n ushort: ", value_ushort(),
|
2021-02-08 00:37:24 -06:00
|
|
|
"\n byte: ", value_byte(),
|
|
|
|
"\n bool: ", value_bool(),
|
2019-03-05 06:46:19 -06:00
|
|
|
"\n linear: ", value_linear_units(),
|
|
|
|
"\n celsius: ", value_celsius()
|
|
|
|
);
|
2017-05-20 03:03:08 -05:00
|
|
|
}
|
|
|
|
else
|
2020-02-10 14:52:15 -06:00
|
|
|
SERIAL_ECHOLNPGM(" (no value)");
|
2017-05-20 03:03:08 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // DEBUG_GCODE_PARSER
|