Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skip old line numbers on boot #1046

Open
wants to merge 1 commit into
base: dev2
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions src/Repetier/src/communication/gcode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,12 @@ void GCode::requestResend() {
Check if result is plausible. If it is, an ok is send and the command is stored in queue.
If not, a resend and ok is send.
*/

// Reject previous linenumbers through serial in case we startup very fast.
#ifndef REJECT_PREV_LINENUM_ON_BOOT
#define REJECT_PREV_LINENUM_ON_BOOT 0
#endif

void GCode::checkAndPushCommand() {
if (hasM()) {
if (M == 110) // Reset line number
Expand All @@ -273,7 +279,10 @@ void GCode::checkAndPushCommand() {
}
if (hasN()) {
if ((((GCodeSource::activeSource->lastLineNumber + 1) & 0xffff) != (actLineNumber & 0xffff))) {
if (static_cast<uint16_t>(GCodeSource::activeSource->lastLineNumber - actLineNumber) < 40) {
uint32_t dif = (actLineNumber > GCodeSource::activeSource->lastLineNumber)
? (actLineNumber - GCodeSource::activeSource->lastLineNumber)
: (GCodeSource::activeSource->lastLineNumber - actLineNumber);
if (dif < 40) {
// we have seen that line already. So we assume it is a repeated resend and we ignore it
commandsReceivingWritePosition = 0;
Com::printFLN(Com::tSkip, actLineNumber);
Expand All @@ -284,7 +293,16 @@ void GCode::checkAndPushCommand() {
Com::printF(Com::tExpectedLine, GCodeSource::activeSource->lastLineNumber + 1);
Com::printFLN(Com::tGot, actLineNumber);
}
requestResend(); // Line missing, force resend
#if REJECT_PREV_LINENUM_ON_BOOT
if (!GCodeSource::activeSource->lastLineNumber) {
HAL::serialFlush();
GCodeSource::activeSource->waitingForResend = sendAsBinary ? 30 : 14;
Com::println();
Com::printFLN(Com::tStart);
Com::printFLN(Com::tOk);
} else
#endif
requestResend(); // Line missing, force resend
} else {
--GCodeSource::activeSource->waitingForResend;
commandsReceivingWritePosition = 0;
Expand Down