Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/3.5-dev' into v3.5-dev
Browse files Browse the repository at this point in the history
  • Loading branch information
gloomyandy committed Sep 18, 2024
2 parents 7f93748 + e7085e4 commit 92e8f74
Show file tree
Hide file tree
Showing 24 changed files with 186 additions and 113 deletions.
15 changes: 14 additions & 1 deletion src/GCodes/GCodeBuffer/BinaryParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

BinaryParser::BinaryParser(GCodeBuffer& gcodeBuffer) noexcept : gb(gcodeBuffer)
{
header = reinterpret_cast<const CodeHeader *>(gcodeBuffer.buffer);
header = reinterpret_cast<CodeHeader *>(gcodeBuffer.buffer);
}

void BinaryParser::Init() noexcept
Expand Down Expand Up @@ -600,6 +600,19 @@ FilePosition BinaryParser::GetFilePosition() const noexcept
return ((header->flags & CodeFlags::HasFilePosition) != 0) ? header->filePosition : noFilePosition;
}

void BinaryParser::SetFilePosition(FilePosition fpos) noexcept
{
if (fpos == noFilePosition)
{
header->flags = (CodeFlags)(header->flags & ~CodeFlags::HasFilePosition);
}
else
{
header->filePosition = fpos;
header->flags = (CodeFlags)(header->flags | CodeFlags::HasFilePosition);
}
}

const char* BinaryParser::DataStart() const noexcept
{
return gb.buffer;
Expand Down
3 changes: 2 additions & 1 deletion src/GCodes/GCodeBuffer/BinaryParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ class BinaryParser
void SetFinished() noexcept; // Set the G Code finished

FilePosition GetFilePosition() const noexcept; // Get the file position at the start of the current command
void SetFilePosition(FilePosition fpos) noexcept; // Overwrite the file position, e.g. when a macro finishes

const char* DataStart() const noexcept; // Get the start of the current command
size_t DataLength() const noexcept; // Get the length of the current command
Expand All @@ -78,7 +79,7 @@ class BinaryParser
void WriteParameters(const StringRef& s, bool quoteStrings) const noexcept;

size_t bufferLength;
const CodeHeader *header;
CodeHeader *header;

int reducedBytesRead;
ParameterLettersBitmap parametersPresent;
Expand Down
22 changes: 13 additions & 9 deletions src/GCodes/GCodeBuffer/GCodeBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ void GCodeBuffer::Reset() noexcept
isBinaryBuffer = false;
requestedMacroFile.Clear();
isWaitingForMacro = macroFileClosed = false;
macroJustStarted = macroJustFinished = macroFileError = macroFileEmpty = abortFile = abortAllFiles = sendToSbc = messagePromptPending = messageAcknowledged = false;
macroJustStarted = macroFileError = macroFileEmpty = abortFile = abortAllFiles = sendToSbc = messagePromptPending = messageAcknowledged = false;
machineState->lastCodeFromSbc = machineState->macroStartedByCode = false;
#endif
cancelWait = false;
Expand Down Expand Up @@ -298,7 +298,7 @@ void GCodeBuffer::PutBinary(const uint32_t *data, size_t len) noexcept
{
machineState->lastCodeFromSbc = true;
isBinaryBuffer = true;
macroJustStarted = macroJustFinished = false;
macroJustStarted = false;
binaryParser.Put(data, len);
}

Expand Down Expand Up @@ -1186,8 +1186,15 @@ void GCodeBuffer::MacroFileClosed() noexcept
{
machineState->CloseFile();
macroJustStarted = false;
macroJustFinished = macroFileClosed = true;
macroFileClosed = true;
#if HAS_SBC_INTERFACE
if (IsBinary())
{
// File position of the last code is no longer valid when we get here, reset it
binaryParser.SetFilePosition(IsFileChannel() && OriginalMachineState().DoingFile() ? printFilePositionAtMacroStart : noFilePosition);
}
reprap.GetSbcInterface().EventOccurred();
#endif
}

#endif
Expand Down Expand Up @@ -1250,12 +1257,9 @@ FilePosition GCodeBuffer::GetPrintingFilePosition(bool allowNoFilePos) const noe
}

#if HAS_MASS_STORAGE || HAS_EMBEDDED_FILES || HAS_SBC_INTERFACE
const FilePosition pos = (IsDoingFileMacro()
# if HAS_SBC_INTERFACE
|| IsMacroFileClosed() || macroJustFinished // wait for the next code from the SBC to update the job file position
# endif
) ? printFilePositionAtMacroStart // the position before we started executing the macro
: GetJobFilePosition(); // the actual position, allowing for bytes cached but not yet processed
const FilePosition pos = IsDoingFileMacro()
? printFilePositionAtMacroStart // the position before we started executing the macro
: GetJobFilePosition(); // the actual position
return (pos != noFilePosition || allowNoFilePos) ? pos : 0;
#else
return allowNoFilePos ? noFilePosition : 0;
Expand Down
5 changes: 2 additions & 3 deletions src/GCodes/GCodeBuffer/GCodeBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -372,9 +372,8 @@ class GCodeBuffer INHERIT_OBJECT_MODEL
// Accessed only when the GB mutex is acquired
String<MaxFilenameLength> requestedMacroFile;
bool isBinaryBuffer;
uint16_t
uint8_t
macroJustStarted : 1, // Whether the GB has just started a macro file
macroJustFinished : 1, // Whether the GB has just finished a macro file
macroFileError : 1, // Whether the macro file could be opened or if an error occurred
macroFileEmpty : 1, // Whether the macro file is actually empty
abortFile : 1, // Whether to abort the last file on the stack
Expand All @@ -391,7 +390,7 @@ class GCodeBuffer INHERIT_OBJECT_MODEL
inline bool GCodeBuffer::IsDoingFileMacro() const noexcept
{
#if HAS_SBC_INTERFACE
return machineState->doingFileMacro || IsMacroRequestPending();
return machineState->doingFileMacro || IsMacroRequestPending() || macroFileClosed;
#else
return machineState->doingFileMacro;
#endif
Expand Down
2 changes: 1 addition & 1 deletion src/GCodes/GCodes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -993,7 +993,7 @@ bool GCodes::DoAsynchronousPause(GCodeBuffer& gb, PrintPausedReason reason, GCod
// TODO: when using RTOS there is a possible race condition in the following,
// because we might try to pause when a waiting move has just been added but before the gcode buffer has been re-initialised ready for the next command
ms.GetPauseRestorePoint().filePos = fgb.GetPrintingFilePosition(true);
while (fgb.IsDoingFileMacro()) // must call this after GetFilePosition because this changes IsDoingFileMacro
while (fgb.LatestMachineState().doingFileMacro) // must call this after GetFilePosition because this changes IsDoingFileMacro
{
ms.pausedInMacro = true;
fgb.PopState(false);
Expand Down
8 changes: 7 additions & 1 deletion src/GCodes/GCodes2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,13 @@ bool GCodes::HandleGcode(GCodeBuffer& gb, const StringRef& reply) THROWS(GCodeEx
}

GCodeResult result = GCodeResult::ok;
if (IsSimulating() && code > 4 && code != 10 && code != 11 && code != 20 && code != 21 && (code < 53 || code > 59) && (code < 90 || code > 94))
if (IsSimulating() && code > 4 // move & dwell
&& code != 10 && code != 11 // (un)retract
&& code != 17 && code != 18 && code != 19 // selected plane for arc moves
&& code != 68 && code != 69 // coordinate rotation
&& code != 20 && code != 21 // change units
&& (code < 53 || code > 59) // coordinate system
&& (code < 90 || code > 94)) // positioning & feedrate modes
{
HandleReply(gb, result, "");
return true; // we only simulate some gcodes
Expand Down
2 changes: 1 addition & 1 deletion src/GCodes/GCodes3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,7 @@ GCodeResult GCodes::DoDriveMapping(GCodeBuffer& gb, const StringRef& reply) THRO
const AxisWrapType wrapType = (newAxesType != AxisWrapType::undefined) ? newAxesType
: (c >= 'A' && c <= 'D') ? AxisWrapType::wrapAt360 // default A thru D to rotational but not continuous
: AxisWrapType::noWrap; // default other axes to linear
const bool isNistRotational = (seenS) ? newAxesAreNistRotational : (c >= 'A' && c <= 'D');
const bool isNistRotational = (seenS) ? newAxesAreNistRotational : wrapType != AxisWrapType::noWrap;
platform.SetAxisType(drive, wrapType, isNistRotational);
++numTotalAxes;
if (numTotalAxes + numExtruders > MaxAxesPlusExtruders)
Expand Down
13 changes: 10 additions & 3 deletions src/Networking/FtpResponder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,17 +55,24 @@ bool FtpResponder::Accept(Socket *s, NetworkProtocol protocol) noexcept
}

// This is called to force termination if we implement the specified protocol
void FtpResponder::Terminate(NetworkProtocol protocol, NetworkInterface *interface) noexcept
void FtpResponder::Terminate(NetworkProtocol protocol, const NetworkInterface *interface) noexcept
{
if (responderState != ResponderState::free && (protocol == FtpProtocol || protocol == AnyProtocol) && skt != nullptr && skt->GetInterface() == interface)
{
ConnectionLost();
// Don't call ConnectionLost here because that releases outbuf, which may be in use by the Network task, and this is called from the Main task
terminateResponder = true; // tell the responder to terminate
}
}

// Do some work, returning true if we did anything significant
bool FtpResponder::Spin() noexcept
{
if (terminateResponder)
{
ConnectionLost();
terminateResponder = false;
}

switch (responderState)
{
case ResponderState::free:
Expand Down Expand Up @@ -165,7 +172,7 @@ void FtpResponder::ConnectionLost() noexcept
void FtpResponder::SendData() noexcept
{
// Send our output buffer and output stack
for(;;)
while (!terminateResponder)
{
if (outBuf == nullptr)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Networking/FtpResponder.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class FtpResponder : public UploadingNetworkResponder

bool Spin() noexcept override; // do some work, returning true if we did anything significant
bool Accept(Socket *s, NetworkProtocol protocol) noexcept override; // ask the responder to accept this connection, returns true if it did
void Terminate(NetworkProtocol protocol, NetworkInterface *interface) noexcept override; // terminate the responder if it is serving the specified protocol on the specified interface
void Terminate(NetworkProtocol protocol, const NetworkInterface *interface) noexcept override; // terminate the responder if it is serving the specified protocol on the specified interface

void Diagnostics(MessageType mtype) const noexcept override;

Expand Down
11 changes: 9 additions & 2 deletions src/Networking/HttpResponder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@ bool HttpResponder::Accept(Socket *s, NetworkProtocol protocol) noexcept
// Do some work, returning true if we did anything significant
bool HttpResponder::Spin() noexcept
{
if (terminateResponder)
{
ConnectionLost();
terminateResponder = false;
}

switch (responderState)
{
case ResponderState::free:
Expand Down Expand Up @@ -1425,11 +1431,12 @@ void HttpResponder::DoUpload() noexcept
#endif

// This is called to force termination if we implement the specified protocol
void HttpResponder::Terminate(NetworkProtocol protocol, NetworkInterface *interface) noexcept
void HttpResponder::Terminate(NetworkProtocol protocol, const NetworkInterface *interface) noexcept
{
if (responderState != ResponderState::free && (protocol == HttpProtocol || protocol == AnyProtocol) && skt != nullptr && skt->GetInterface() == interface)
{
ConnectionLost();
// Don't call ConnectionLost here because that releases outbuf, which may be in use by the Network task, and this is called from the Main task
terminateResponder = true; // tell the responder to terminate
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/Networking/HttpResponder.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class HttpResponder : public UploadingNetworkResponder
HttpResponder(NetworkResponder *n) noexcept;
bool Spin() noexcept override; // do some work, returning true if we did anything significant
bool Accept(Socket *s, NetworkProtocol protocol) noexcept override; // ask the responder to accept this connection, returns true if it did
void Terminate(NetworkProtocol protocol, NetworkInterface *interface) noexcept override; // terminate the responder if it is serving the specified protocol on the specified interface
void Terminate(NetworkProtocol protocol, const NetworkInterface *interface) noexcept override; // terminate the responder if it is serving the specified protocol on the specified interface
void Diagnostics(MessageType mtype) const noexcept override;

static void InitStatic() noexcept;
Expand Down
Loading

0 comments on commit 92e8f74

Please sign in to comment.