Skip to content

Commit

Permalink
🐛 Fix G-code resend race condition
Browse files Browse the repository at this point in the history
As pointed out in #24972 by @silycr, but simplified.
  • Loading branch information
thinkyhead committed Nov 28, 2022
1 parent a8d7c8c commit 791de40
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions Marlin/src/gcode/queue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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;
}
Expand Down

0 comments on commit 791de40

Please sign in to comment.