🐛 Fix G-code resend race condition

As pointed out in #24972 by @silycr, but simplified.
This commit is contained in:
Scott Lahteine 2022-11-27 23:23:00 -06:00
parent a8d7c8c89d
commit 791de40885

View file

@ -469,8 +469,11 @@ void GCodeQueue::get_serial_commands() {
const long gcode_N = strtol(npos + 1, nullptr, 10);
// The line number must be in the correct sequence.
if (gcode_N != serial.last_N + 1 && !M110) {
// In case of error on a serial port, don't prevent other serial port from making progress
// A request-for-resend line was already in transit so we got two - oops!
if (WITHIN(gcode_N, serial.last_N - 1, serial.last_N)) continue;
// A corrupted line or too high, indicating a lost line
gcode_line_error(F(STR_ERR_LINE_NO), p);
break;
}
@ -480,13 +483,11 @@ void GCodeQueue::get_serial_commands() {
uint8_t checksum = 0, count = uint8_t(apos - command);
while (count) checksum ^= command[--count];
if (strtol(apos + 1, nullptr, 10) != checksum) {
// In case of error on a serial port, don't prevent other serial port from making progress
gcode_line_error(F(STR_ERR_CHECKSUM_MISMATCH), p);
break;
}
}
else {
// In case of error on a serial port, don't prevent other serial port from making progress
gcode_line_error(F(STR_ERR_NO_CHECKSUM), p);
break;
}