Merge pull request #2095 from thinkyhead/cherry_picking2

Add gcode_line_error to reduce code size
This commit is contained in:
Scott Lahteine 2015-05-16 21:09:15 -07:00
commit 64825a3d1e

View file

@ -723,6 +723,15 @@ void loop() {
lcd_update(); lcd_update();
} }
void gcode_line_error(const char *err, bool doFlush=true) {
SERIAL_ERROR_START;
serialprintPGM(err);
SERIAL_ERRORLN(gcode_LastN);
//Serial.println(gcode_N);
if (doFlush) FlushSerialRequestResend();
serial_count = 0;
}
/** /**
* Add to the circular command queue the next command from: * Add to the circular command queue the next command from:
* - The command-injection queue (queued_commands_P) * - The command-injection queue (queued_commands_P)
@ -768,12 +777,7 @@ void get_command() {
strchr_pointer = strchr(command, 'N'); strchr_pointer = strchr(command, 'N');
gcode_N = (strtol(strchr_pointer + 1, NULL, 10)); gcode_N = (strtol(strchr_pointer + 1, NULL, 10));
if (gcode_N != gcode_LastN + 1 && strstr_P(command, PSTR("M110")) == NULL) { if (gcode_N != gcode_LastN + 1 && strstr_P(command, PSTR("M110")) == NULL) {
SERIAL_ERROR_START; gcode_line_error(PSTR(MSG_ERR_LINE_NO));
SERIAL_ERRORPGM(MSG_ERR_LINE_NO);
SERIAL_ERRORLN(gcode_LastN);
//Serial.println(gcode_N);
FlushSerialRequestResend();
serial_count = 0;
return; return;
} }
@ -784,33 +788,22 @@ void get_command() {
strchr_pointer = strchr(command, '*'); strchr_pointer = strchr(command, '*');
if (strtol(strchr_pointer + 1, NULL, 10) != checksum) { if (strtol(strchr_pointer + 1, NULL, 10) != checksum) {
SERIAL_ERROR_START; gcode_line_error(PSTR(MSG_ERR_CHECKSUM_MISMATCH));
SERIAL_ERRORPGM(MSG_ERR_CHECKSUM_MISMATCH);
SERIAL_ERRORLN(gcode_LastN);
FlushSerialRequestResend();
serial_count = 0;
return; return;
} }
//if no errors, continue parsing // if no errors, continue parsing
} }
else { else {
SERIAL_ERROR_START; gcode_line_error(PSTR(MSG_ERR_NO_CHECKSUM));
SERIAL_ERRORPGM(MSG_ERR_NO_CHECKSUM);
SERIAL_ERRORLN(gcode_LastN);
FlushSerialRequestResend();
serial_count = 0;
return; return;
} }
gcode_LastN = gcode_N; gcode_LastN = gcode_N;
//if no errors, continue parsing // if no errors, continue parsing
} }
else { // if we don't receive 'N' but still see '*' else { // if we don't receive 'N' but still see '*'
if ((strchr(command, '*') != NULL)) { if ((strchr(command, '*') != NULL)) {
SERIAL_ERROR_START; gcode_line_error(PSTR(MSG_ERR_NO_LINENUMBER_WITH_CHECKSUM), false);
SERIAL_ERRORPGM(MSG_ERR_NO_LINENUMBER_WITH_CHECKSUM);
SERIAL_ERRORLN(gcode_LastN);
serial_count = 0;
return; return;
} }
} }