Skip to content

Commit

Permalink
Fixed file aborts of the last file in SBC mode
Browse files Browse the repository at this point in the history
See DSF issue #205
  • Loading branch information
chrishamm committed Oct 18, 2024
1 parent f556068 commit f522904
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 11 deletions.
14 changes: 7 additions & 7 deletions src/GCodes/GCodeBuffer/GCodeBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1029,7 +1029,7 @@ bool GCodeBuffer::PopState(bool withinSameFile) noexcept

// Abort execution of any files or macros being executed
// We now avoid popping the state if we were not executing from a file, so that if DWC or PanelDue is used to jog the axes before they are homed, we don't report stack underflow.
void GCodeBuffer::AbortFile(bool abortAll, bool requestAbort) noexcept
void GCodeBuffer::AbortFile(bool abortAll) noexcept
{
if (machineState->DoingFile())
{
Expand All @@ -1050,12 +1050,12 @@ void GCodeBuffer::AbortFile(bool abortAll, bool requestAbort) noexcept
} while (PopState(false) && abortAll);

#if HAS_SBC_INTERFACE
abortFile = requestAbort;
abortAllFiles = requestAbort && abortAll;
}
else if (!requestAbort)
{
abortFile = abortAllFiles = false;
// Notify the SBC about the file(s) being closed
if (reprap.UsingSbcInterface())
{
abortFile = true;
abortAllFiles = abortAll;
}
#endif
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/GCodes/GCodeBuffer/GCodeBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,8 @@ class GCodeBuffer INHERIT_OBJECT_MODEL
bool PushState(bool withinSameFile) noexcept; // Push state returning true if successful (i.e. stack not overflowed)
bool PopState(bool withinSameFile) noexcept; // Pop state returning true if successful (i.e. no stack underrun)

void AbortFile(bool abortAll, bool requestAbort = true) noexcept;
void AbortFile(bool abortAll) noexcept;

bool IsDoingFile() const noexcept; // Return true if this source is executing a file
bool IsDoingLocalFile() const noexcept; // Return true if this source is executing a file from the local SD card
bool IsDoingFileMacro() const noexcept; // Return true if this source is executing a file macro
Expand Down
2 changes: 1 addition & 1 deletion src/GCodes/GCodes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3243,7 +3243,7 @@ bool GCodes::DoFileMacro(GCodeBuffer& gb, const char* fileName, bool reportMissi

if (!Push(gb, false))
{
gb.AbortFile(false, true);
gb.AbortFile(false);
return true;
}
gb.GetVariables().AssignFrom(initialVariables);
Expand Down
16 changes: 14 additions & 2 deletions src/SBC/SbcInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -684,7 +684,8 @@ void SbcInterface::ExchangeData() noexcept
if (locker.IsAcquired())
{
// Note that we do not call StopPrint here or set any other variables; DSF already does that
gb->AbortFile(true, false);
gb->AbortFile(true);
gb->FileAbortSent(); // don't notify the SBC
InvalidateBufferedCodes(channel);
}
else
Expand Down Expand Up @@ -1172,6 +1173,16 @@ void SbcInterface::ExchangeData() noexcept
}
}
#endif
// Send back a final code reply for codes that started the last macros, else the corresponding code will never finish
if (!gb->IsAbortAllRequested() && gb->GetState() == GCodeState::normal && (!gb->LatestMachineState().lastCodeFromSbc || gb->LatestMachineState().macroStartedByCode))
{
OutputBuffer *dummy = nullptr;
if (!transfer.WriteCodeReply(gb->GetResponseMessageType(), dummy))
{
// Cannot send an empty code reply now, do it later
HandleGCodeReply(gb->GetResponseMessageType(), dummy);
}
}
gb->FileAbortSent();
gb->Invalidate();
}
Expand Down Expand Up @@ -1323,7 +1334,8 @@ void SbcInterface::InvalidateResources() noexcept
{
gb->MacroRequestSent();
}
gb->AbortFile(true, false);
gb->AbortFile(true);
gb->FileAbortSent(); // don't notify the SBC
gb->MessageAcknowledged(true, 0, ExpressionValue());
}

Expand Down

0 comments on commit f522904

Please # to comment.