update code base to Marlin 2.0.9.2
This commit is contained in:
178
Marlin/src/gcode/parser.cpp
Executable file → Normal file
178
Marlin/src/gcode/parser.cpp
Executable file → Normal file
@@ -16,7 +16,7 @@
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
@@ -28,10 +28,6 @@
|
||||
|
||||
#include "../MarlinCore.h"
|
||||
|
||||
#if NUM_SERIAL > 1
|
||||
#include "queue.h"
|
||||
#endif
|
||||
|
||||
// Must be declared for allocation and to satisfy the linker
|
||||
// Zero values need no initialization.
|
||||
|
||||
@@ -49,15 +45,15 @@ char *GCodeParser::command_ptr,
|
||||
*GCodeParser::string_arg,
|
||||
*GCodeParser::value_ptr;
|
||||
char GCodeParser::command_letter;
|
||||
int GCodeParser::codenum;
|
||||
uint16_t GCodeParser::codenum;
|
||||
|
||||
#if ENABLED(USE_GCODE_SUBCODES)
|
||||
#if USE_GCODE_SUBCODES
|
||||
uint8_t GCodeParser::subcode;
|
||||
#endif
|
||||
|
||||
#if ENABLED(GCODE_MOTION_MODES)
|
||||
int16_t GCodeParser::motion_mode_codenum = -1;
|
||||
#if ENABLED(USE_GCODE_SUBCODES)
|
||||
#if USE_GCODE_SUBCODES
|
||||
uint8_t GCodeParser::motion_mode_subcode;
|
||||
#endif
|
||||
#endif
|
||||
@@ -83,9 +79,7 @@ void GCodeParser::reset() {
|
||||
string_arg = nullptr; // No whole line argument
|
||||
command_letter = '?'; // No command letter
|
||||
codenum = 0; // No command code
|
||||
#if ENABLED(USE_GCODE_SUBCODES)
|
||||
subcode = 0; // No command sub-code
|
||||
#endif
|
||||
TERN_(USE_GCODE_SUBCODES, subcode = 0); // No command sub-code
|
||||
#if ENABLED(FASTER_GCODE_PARSER)
|
||||
codebits = 0; // No codes yet
|
||||
//ZERO(param); // No parameters (should be safe to comment out this line)
|
||||
@@ -112,16 +106,17 @@ void GCodeParser::reset() {
|
||||
|
||||
#endif
|
||||
|
||||
// Populate all fields by parsing a single line of GCode
|
||||
// 58 bytes of SRAM are used to speed up seen/value
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
void GCodeParser::parse(char *p) {
|
||||
|
||||
reset(); // No codes to report
|
||||
|
||||
auto uppercase = [](char c) {
|
||||
#if ENABLED(GCODE_CASE_INSENSITIVE)
|
||||
if (WITHIN(c, 'a', 'z')) c += 'A' - 'a';
|
||||
#endif
|
||||
if (TERN0(GCODE_CASE_INSENSITIVE, WITHIN(c, 'a', 'z')))
|
||||
c += 'A' - 'a';
|
||||
return c;
|
||||
};
|
||||
|
||||
@@ -130,9 +125,7 @@ void GCodeParser::parse(char *p) {
|
||||
|
||||
// Skip N[-0-9] if included in the command line
|
||||
if (uppercase(*p) == 'N' && NUMERIC_SIGNED(p[1])) {
|
||||
#if ENABLED(FASTER_GCODE_PARSER)
|
||||
//set('N', p + 1); // (optional) Set the 'N' parameter value
|
||||
#endif
|
||||
//TERN_(FASTER_GCODE_PARSER, set('N', p + 1)); // (optional) Set the 'N' parameter value
|
||||
p += 2; // skip N[-0-9]
|
||||
while (NUMERIC(*p)) ++p; // skip [0-9]*
|
||||
while (*p == ' ') ++p; // skip [ ]*
|
||||
@@ -152,26 +145,39 @@ void GCodeParser::parse(char *p) {
|
||||
starpos[1] = '\0';
|
||||
}
|
||||
|
||||
#if ENABLED(GCODE_MOTION_MODES)
|
||||
#if ENABLED(ARC_SUPPORT)
|
||||
#define GTOP 3
|
||||
#else
|
||||
#define GTOP 1
|
||||
#endif
|
||||
#if ANY(MARLIN_DEV_MODE, SWITCHING_TOOLHEAD, MAGNETIC_SWITCHING_TOOLHEAD, ELECTROMAGNETIC_SWITCHING_TOOLHEAD)
|
||||
#define SIGNED_CODENUM 1
|
||||
#endif
|
||||
|
||||
// Bail if the letter is not G, M, or T
|
||||
// (or a valid parameter for the current motion mode)
|
||||
switch (letter) {
|
||||
/**
|
||||
* Screen for good command letters.
|
||||
* With Realtime Reporting, commands S000, P000, and R000 are allowed.
|
||||
*/
|
||||
#if ENABLED(REALTIME_REPORTING_COMMANDS)
|
||||
switch (letter) {
|
||||
case 'P': case 'R' ... 'S': {
|
||||
uint8_t digits = 0;
|
||||
char *a = p;
|
||||
while (*a++ == '0') digits++; // Count up '0' characters
|
||||
if (digits == 3) { // Three '0' digits is a good command
|
||||
codenum = 0;
|
||||
command_letter = letter;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
case 'G': case 'M': case 'T':
|
||||
#if ENABLED(CANCEL_OBJECTS)
|
||||
case 'O':
|
||||
#endif
|
||||
/**
|
||||
* Screen for good command letters. G, M, and T are always accepted.
|
||||
* With Motion Modes enabled any axis letter can come first.
|
||||
*/
|
||||
switch (letter) {
|
||||
case 'G': case 'M': case 'T': TERN_(MARLIN_DEV_MODE, case 'D':) {
|
||||
// Skip spaces to get the numeric part
|
||||
while (*p == ' ') p++;
|
||||
|
||||
#if ENABLED(PRUSA_MMU2)
|
||||
#if HAS_PRUSA_MMU2
|
||||
if (letter == 'T') {
|
||||
// check for special MMU2 T?/Tx/Tc commands
|
||||
if (*p == '?' || *p == 'x' || *p == 'c') {
|
||||
@@ -183,22 +189,31 @@ void GCodeParser::parse(char *p) {
|
||||
#endif
|
||||
|
||||
// Bail if there's no command code number
|
||||
if (!NUMERIC(*p)) return;
|
||||
if (!TERN(SIGNED_CODENUM, NUMERIC_SIGNED(*p), NUMERIC(*p))) return;
|
||||
|
||||
// Save the command letter at this point
|
||||
// A '?' signifies an unknown command
|
||||
command_letter = letter;
|
||||
|
||||
#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 *= 10, codenum += *p++ - '0'; } while (NUMERIC(*p));
|
||||
|
||||
do { codenum = codenum * 10 + *p++ - '0'; } while (NUMERIC(*p));
|
||||
|
||||
// Apply the sign, if any
|
||||
TERN_(SIGNED_CODENUM, codenum *= sign);
|
||||
|
||||
// Allow for decimal point in command
|
||||
#if ENABLED(USE_GCODE_SUBCODES)
|
||||
#if USE_GCODE_SUBCODES
|
||||
if (*p == '.') {
|
||||
p++;
|
||||
while (NUMERIC(*p))
|
||||
subcode *= 10, subcode += *p++ - '0';
|
||||
subcode = subcode * 10 + *p++ - '0';
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -206,57 +221,56 @@ void GCodeParser::parse(char *p) {
|
||||
while (*p == ' ') p++;
|
||||
|
||||
#if ENABLED(GCODE_MOTION_MODES)
|
||||
if (letter == 'G' && (codenum <= GTOP || codenum == 5
|
||||
#if ENABLED(G38_PROBE_TARGET)
|
||||
|| codenum == 38
|
||||
#endif
|
||||
)
|
||||
if (letter == 'G'
|
||||
&& (codenum <= TERN(ARC_SUPPORT, 3, 1) || TERN0(BEZIER_CURVE_SUPPORT, codenum == 5) || TERN0(G38_PROBE_TARGET, codenum == 38))
|
||||
) {
|
||||
motion_mode_codenum = codenum;
|
||||
#if ENABLED(USE_GCODE_SUBCODES)
|
||||
motion_mode_subcode = subcode;
|
||||
#endif
|
||||
TERN_(USE_GCODE_SUBCODES, motion_mode_subcode = subcode);
|
||||
}
|
||||
#endif
|
||||
|
||||
break;
|
||||
} break;
|
||||
|
||||
#if ENABLED(GCODE_MOTION_MODES)
|
||||
#if ENABLED(ARC_SUPPORT)
|
||||
case 'I': case 'J': case 'R':
|
||||
if (motion_mode_codenum != 2 && motion_mode_codenum != 3) return;
|
||||
|
||||
#if EITHER(BEZIER_CURVE_SUPPORT, ARC_SUPPORT)
|
||||
case 'I' ... 'J': case 'P':
|
||||
if (TERN1(BEZIER_CURVE_SUPPORT, motion_mode_codenum != 5)
|
||||
&& TERN1(ARC_P_CIRCLES, !WITHIN(motion_mode_codenum, 2, 3))
|
||||
) return;
|
||||
#endif
|
||||
case 'P': case 'Q':
|
||||
if (motion_mode_codenum != 5) return;
|
||||
case 'X': case 'Y': case 'Z': case 'E': case 'F':
|
||||
|
||||
#if ENABLED(BEZIER_CURVE_SUPPORT)
|
||||
case 'Q': if (motion_mode_codenum != 5) return;
|
||||
#endif
|
||||
|
||||
#if ENABLED(ARC_SUPPORT)
|
||||
case 'R': if (!WITHIN(motion_mode_codenum, 2, 3)) return;
|
||||
#endif
|
||||
|
||||
LOGICAL_AXIS_GANG(case 'E':, case 'X':, case 'Y':, case 'Z':, case AXIS4_NAME:, case AXIS5_NAME:, case AXIS6_NAME:)
|
||||
case 'F':
|
||||
if (motion_mode_codenum < 0) return;
|
||||
command_letter = 'G';
|
||||
codenum = motion_mode_codenum;
|
||||
#if ENABLED(USE_GCODE_SUBCODES)
|
||||
subcode = motion_mode_subcode;
|
||||
#endif
|
||||
TERN_(USE_GCODE_SUBCODES, subcode = motion_mode_subcode);
|
||||
p--; // Back up one character to use the current parameter
|
||||
break;
|
||||
#endif // GCODE_MOTION_MODES
|
||||
break;
|
||||
|
||||
#endif
|
||||
|
||||
default: return;
|
||||
}
|
||||
|
||||
// The command parameters (if any) start here, for sure!
|
||||
|
||||
#if DISABLED(FASTER_GCODE_PARSER)
|
||||
command_args = p; // Scan for parameters in seen()
|
||||
#endif
|
||||
IF_DISABLED(FASTER_GCODE_PARSER, command_args = p); // Scan for parameters in seen()
|
||||
|
||||
// Only use string_arg for these M codes
|
||||
if (letter == 'M') switch (codenum) {
|
||||
#if ENABLED(GCODE_MACROS)
|
||||
case 810 ... 819:
|
||||
#endif
|
||||
#if ENABLED(EXPECTED_PRINTER_CHECK)
|
||||
case 16:
|
||||
#endif
|
||||
case 23: case 28: case 30: case 117: case 118: case 928:
|
||||
TERN_(GCODE_MACROS, case 810 ... 819:)
|
||||
TERN_(EXPECTED_PRINTER_CHECK, case 16:)
|
||||
case 23: case 28: case 30: case 117 ... 118: case 928:
|
||||
string_arg = unescape_string(p);
|
||||
return;
|
||||
default: break;
|
||||
@@ -282,7 +296,7 @@ void GCodeParser::parse(char *p) {
|
||||
|
||||
// Special handling for M32 [P] !/path/to/file.g#
|
||||
// The path must be the last parameter
|
||||
if (param == '!' && letter == 'M' && codenum == 32) {
|
||||
if (param == '!' && is_command('M', 32)) {
|
||||
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
|
||||
@@ -319,7 +333,7 @@ void GCodeParser::parse(char *p) {
|
||||
|
||||
#if ENABLED(DEBUG_GCODE_PARSER)
|
||||
if (debug) {
|
||||
SERIAL_ECHOPAIR("Got param ", param, " at index ", (int)(p - command_ptr - 1));
|
||||
SERIAL_ECHOPGM("Got param ", AS_CHAR(param), " at index ", p - command_ptr - 1);
|
||||
if (has_val) SERIAL_ECHOPGM(" (has_val)");
|
||||
}
|
||||
#endif
|
||||
@@ -327,22 +341,18 @@ void GCodeParser::parse(char *p) {
|
||||
if (!has_val && !string_arg) { // No value? First time, keep as string_arg
|
||||
string_arg = p - 1;
|
||||
#if ENABLED(DEBUG_GCODE_PARSER)
|
||||
if (debug) SERIAL_ECHOPAIR(" string_arg: ", hex_address((void*)string_arg)); // DEBUG
|
||||
if (debug) SERIAL_ECHOPGM(" string_arg: ", hex_address((void*)string_arg)); // DEBUG
|
||||
#endif
|
||||
}
|
||||
|
||||
#if ENABLED(DEBUG_GCODE_PARSER)
|
||||
if (debug) SERIAL_EOL();
|
||||
#endif
|
||||
if (TERN0(DEBUG_GCODE_PARSER, debug)) SERIAL_EOL();
|
||||
|
||||
#if ENABLED(FASTER_GCODE_PARSER)
|
||||
set(param, valptr); // Set parameter exists and pointer (nullptr for no value)
|
||||
#endif
|
||||
TERN_(FASTER_GCODE_PARSER, set(param, valptr)); // Set parameter exists and pointer (nullptr for no value)
|
||||
}
|
||||
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
|
||||
if (debug) SERIAL_ECHOPGM(" string_arg: ", hex_address((void*)string_arg)); // DEBUG
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -380,7 +390,7 @@ void GCodeParser::unknown_command_warning() {
|
||||
#if ENABLED(DEBUG_GCODE_PARSER)
|
||||
|
||||
void GCodeParser::debug() {
|
||||
SERIAL_ECHOPAIR("Command: ", command_ptr, " (", command_letter);
|
||||
SERIAL_ECHOPGM("Command: ", command_ptr, " (", command_letter);
|
||||
SERIAL_ECHO(codenum);
|
||||
SERIAL_ECHOLNPGM(")");
|
||||
#if ENABLED(FASTER_GCODE_PARSER)
|
||||
@@ -388,18 +398,18 @@ void GCodeParser::unknown_command_warning() {
|
||||
for (char c = 'A'; c <= 'Z'; ++c) if (seen(c)) SERIAL_CHAR(c, ' ');
|
||||
SERIAL_CHAR('}');
|
||||
#else
|
||||
SERIAL_ECHOPAIR(" args: { ", command_args, " }");
|
||||
SERIAL_ECHOPGM(" args: { ", command_args, " }");
|
||||
#endif
|
||||
if (string_arg) {
|
||||
SERIAL_ECHOPAIR(" string: \"", string_arg);
|
||||
SERIAL_ECHOPGM(" string: \"", string_arg);
|
||||
SERIAL_CHAR('"');
|
||||
}
|
||||
SERIAL_ECHOLNPGM("\n");
|
||||
for (char c = 'A'; c <= 'Z'; ++c) {
|
||||
if (seen(c)) {
|
||||
SERIAL_ECHOPAIR("Code '", c); SERIAL_ECHOPGM("':");
|
||||
SERIAL_ECHOPGM("Code '", c); SERIAL_ECHOPGM("':");
|
||||
if (has_value()) {
|
||||
SERIAL_ECHOLNPAIR(
|
||||
SERIAL_ECHOLNPGM(
|
||||
"\n float: ", value_float(),
|
||||
"\n long: ", value_long(),
|
||||
"\n ulong: ", value_ulong(),
|
||||
@@ -407,8 +417,8 @@ void GCodeParser::unknown_command_warning() {
|
||||
"\n sec-ms: ", value_millis_from_seconds(),
|
||||
"\n int: ", value_int(),
|
||||
"\n ushort: ", value_ushort(),
|
||||
"\n byte: ", (int)value_byte(),
|
||||
"\n bool: ", (int)value_bool(),
|
||||
"\n byte: ", value_byte(),
|
||||
"\n bool: ", value_bool(),
|
||||
"\n linear: ", value_linear_units(),
|
||||
"\n celsius: ", value_celsius()
|
||||
);
|
||||
|
Reference in New Issue
Block a user