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 May 31, 2024
2 parents 63ec08e + aee607b commit b055383
Show file tree
Hide file tree
Showing 24 changed files with 341 additions and 271 deletions.
4 changes: 4 additions & 0 deletions src/Config/Configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ constexpr unsigned int AUX2_BAUD_RATE = 115200; // Ditto - for second auxiliar
constexpr uint32_t SERIAL_MAIN_TIMEOUT = 2000; // timeout in ms for sending data to the main serial/USB port
constexpr uint32_t AuxTimeout = 2000; // timeout in ms for PanelDue replies

constexpr uint32_t UnsolicitedStatusReportInterval = 2000; // Interval between sending unsolicited status reports, in milliseconds

// Message boxes
constexpr unsigned int MaxMessageBoxes = 8; // the maximum number of message boxes that can be queued

Expand Down Expand Up @@ -171,10 +173,12 @@ constexpr size_t ShortGCodeLength = 64;
constexpr size_t OUTPUT_BUFFER_SIZE = 256; // How many bytes does each OutputBuffer hold?
constexpr size_t OUTPUT_BUFFER_COUNT = 40; // How many OutputBuffer instances do we have?
constexpr size_t RESERVED_OUTPUT_BUFFERS = 4; // Number of reserved output buffers after long responses, enough to hold a status response
constexpr size_t MinimumBuffersForObjectModel = 20; // Minimum number of free buffers we want before we start assembling a request for the object model
#elif SAM4E || SAM4S
constexpr size_t OUTPUT_BUFFER_SIZE = 256; // How many bytes does each OutputBuffer hold?
constexpr size_t OUTPUT_BUFFER_COUNT = 26; // How many OutputBuffer instances do we have?
constexpr size_t RESERVED_OUTPUT_BUFFERS = 4; // Number of reserved output buffers after long responses, enough to hold a status response
constexpr size_t MinimumBuffersForObjectModel = 20; // Minimum number of free buffers we want before we start assembling a request for the object model
#else
# error Unsupported processor
#endif
Expand Down
2 changes: 1 addition & 1 deletion src/Config/Pins_Duet3_MB6XD.h
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ constexpr PinDescription PinTable[] =
{ TcOutput::none, PwmOutput::none, AdcInput::none, PinCapability::rw, "io5.out,!io5.out.iso" }, // PD21 IO5_OUT (not PWM capable on TIOA11 because TIOB11 is used to generate step pulses)
{ TcOutput::none, PwmOutput::none, AdcInput::none, PinCapability::none, nullptr }, // PD22 step gate
{ TcOutput::none, PwmOutput::none, AdcInput::none, PinCapability::read, "out4.tach" }, // PD23 OUT4_TACH
{ TcOutput::none, PwmOutput::none, AdcInput::none, PinCapability::none, nullptr }, // PD24 SWD_EXT_RST
{ TcOutput::none, PwmOutput::none, AdcInput::none, PinCapability::write, "ate.rs422.txen" }, // PD24 was SWD_EXT_RST, now RS422 TX/~RX in board revision 1.02 and later
{ TcOutput::none, PwmOutput::none, AdcInput::none, PinCapability::read, "io0.in,serial0.rx" }, // PD25 IO0_IN Serial0 RX
{ TcOutput::none, PwmOutput::none, AdcInput::none, PinCapability::rw, "io0.out,serial0.tx" }, // PD26 IO0_OUT Serial0 TX
{ TcOutput::none, PwmOutput::none, AdcInput::none, PinCapability::rw, "io2.out,i2c0.dat" }, // PD27 IO2_OUT
Expand Down
17 changes: 13 additions & 4 deletions src/GCodes/GCodeBuffer/ExpressionParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,21 @@ namespace StackUsage
{
// The following values are the number of bytes of stack space needed by the corresponding functions and functions they call,
// not counting other called functions that call CheckStack. They are obtained from file ExpressionParser.su generated by the compiler.
constexpr uint32_t ParseInternal = 72;
constexpr uint32_t ParseIdentifierExpression = 296;
constexpr uint32_t GetObjectValueUsingTableNumber = 48;
constexpr uint32_t ReadArrayFromFile = 384;
#if SAME70
constexpr uint32_t ParseInternal = 80;
constexpr uint32_t ParseIdentifierExpression = 288;
constexpr uint32_t ParseGeneralArray = 360;
constexpr uint32_t ReadArrayFromFile = 384;
constexpr uint32_t ApplyObjectModelArrayIndex = 112;
constexpr uint32_t GetObjectValueUsingTableNumber = 48;
#else
constexpr uint32_t ParseInternal = 72;
constexpr uint32_t ParseIdentifierExpression = 288;
constexpr uint32_t ParseGeneralArray = 352;
constexpr uint32_t ReadArrayFromFile = 376;
constexpr uint32_t ApplyObjectModelArrayIndex = 120;
constexpr uint32_t GetObjectValueUsingTableNumber = 56;
#endif
}

// Read a character from the text file.
Expand Down
6 changes: 3 additions & 3 deletions src/GCodes/GCodeBuffer/GCodeBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ GCodeBuffer::GCodeBuffer(GCodeChannel::RawType channel, GCodeInput *normalIn, Fi
binaryParser(*this),
#endif
stringParser(*this),
machineState(new GCodeMachineState()), whenReportDueTimerStarted(millis()),
machineState(new GCodeMachineState()), whenReportDueTimerStarted(millis()), lastStatusReportType(StatusReportType::none),
codeChannel(channel), lastResult(GCodeResult::ok),
timerRunning(false), motionCommanded(false)

Expand Down Expand Up @@ -190,13 +190,13 @@ bool GCodeBuffer::DoDwellTime(uint32_t dwellMillis) noexcept
return false;
}

// Delay executing this GCodeBuffer for the specified time. Return true when the timer has expired.
// Return true if we should send an unsolicited status report
bool GCodeBuffer::IsReportDue() noexcept
{
const uint32_t now = millis();

// Are we due?
if (now - whenReportDueTimerStarted >= reportDueInterval)
if (now - whenReportDueTimerStarted >= UnsolicitedStatusReportInterval)
{
ResetReportDueTimer();
return true;
Expand Down
38 changes: 25 additions & 13 deletions src/GCodes/GCodeBuffer/GCodeBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,15 @@ enum class GCodeBufferState : uint8_t
executing // we have a complete gcode and have started executing it
};

// Type of a status report
enum class StatusReportType : uint8_t
{
none = 0,
m105,
m408,
m409
};

// Class to hold an individual GCode and provide functions to allow it to be parsed
class GCodeBuffer INHERIT_OBJECT_MODEL
{
Expand Down Expand Up @@ -176,26 +185,29 @@ class GCodeBuffer INHERIT_OBJECT_MODEL
float InverseConvertSpeed(float speed) const noexcept;
const char *GetDistanceUnits() const noexcept;
unsigned int GetStackDepth() const noexcept;
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)
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;
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
FilePosition GetJobFilePosition() const noexcept; // Get the file position at the start of the current command
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
FilePosition GetJobFilePosition() const noexcept; // Get the file position at the start of the current command
FilePosition GetPrintingFilePosition(bool allowNoFilePos) const noexcept; // Get the file position in the printing file
void SavePrintingFilePosition() noexcept;

void WaitForAcknowledgement(uint32_t seq) noexcept; // Flag that we are waiting for acknowledgement
void ClosePrintFile() noexcept; // Close the print file
void WaitForAcknowledgement(uint32_t seq) noexcept; // Flag that we are waiting for acknowledgement
void ClosePrintFile() noexcept; // Close the print file

StatusReportType GetLastStatusReportType() const noexcept { return lastStatusReportType; }
void RespondedToStatusRequest(StatusReportType t) noexcept { lastStatusReportType = t; } // call this when a response to a status request is sent

#if HAS_SBC_INTERFACE
bool IsBinary() const noexcept { return isBinaryBuffer; } // Return true if the code is in binary format
bool IsBinary() const noexcept { return isBinaryBuffer; } // Return true if the code is in binary format

bool IsFileFinished() const noexcept; // Return true if this source has finished execution of a file
void SetFileFinished() noexcept; // Mark the current file as finished
void SetPrintFinished() noexcept; // Mark the current print file as finished
bool IsFileFinished() const noexcept; // Return true if this source has finished execution of a file
void SetFileFinished() noexcept; // Mark the current file as finished
void SetPrintFinished() noexcept; // Mark the current print file as finished

bool RequestMacroFile(const char *filename, bool fromCode) noexcept; // Request execution of a file macro
volatile bool IsWaitingForMacro() const noexcept { return isWaitingForMacro; } // Indicates if the GB is waiting for a macro to be opened
Expand Down Expand Up @@ -337,7 +349,7 @@ class GCodeBuffer INHERIT_OBJECT_MODEL

uint32_t whenTimerStarted; // When we started waiting
uint32_t whenReportDueTimerStarted; // When the report-due-timer has been started
static constexpr uint32_t reportDueInterval = 1000; // Interval in which we send in ms
StatusReportType lastStatusReportType; // the type of the last status report sent on this channel

const GCodeChannel codeChannel; // Channel number of this instance
GCodeBufferState bufferState; // Idle, executing or paused
Expand Down
7 changes: 7 additions & 0 deletions src/GCodes/GCodeException.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,19 @@

#include <General/StringRef.h>
#include <GCodes/GCodeBuffer/GCodeBuffer.h>
#include <Platform/RepRap.h>
#include <Platform/Tasks.h>

GCodeException::GCodeException(const GCodeBuffer *null gb, int col, const char *_ecv_array msg) noexcept : column(col), message(msg)
{
if (gb != nullptr)
{
#if HAS_SBC_INTERFACE
// Don't output the line number in case this exception is thrown from a SBC evaluation request, it's prepended by DSF
line = (!reprap.UsingSbcInterface() || RTOSIface::GetCurrentTask() == Tasks::GetMainTask()) ? gb->GetLineNumber() : -1;
#else
line = gb->GetLineNumber();
#endif
if (gb->IsDoingFileMacro())
{
source = GCodeExceptionSource::macro;
Expand Down
50 changes: 29 additions & 21 deletions src/GCodes/GCodes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,6 @@ void GCodes::Init() noexcept
limitAxes = noMovesBeforeHoming = true;
SetAllAxesNotHomed();

lastAuxStatusReportType = -1; // no status reports requested yet

laserMaxPower = DefaultMaxLaserPower;
laserPowerSticky = false;

Expand Down Expand Up @@ -4920,37 +4918,47 @@ void GCodes::GenerateTemperatureReport(const GCodeBuffer& gb, const StringRef& r
// 'reply' is a convenient buffer that is free for us to use.
void GCodes::CheckReportDue(GCodeBuffer& gb, const StringRef& reply) const noexcept
{
if (&gb == UsbGCode())
if ((&gb == UsbGCode() || &gb == AuxGCode() || &gb == Aux2GCode()) && gb.IsReportDue())
{
if (gb.LatestMachineState().compatibility == Compatibility::Marlin && gb.IsReportDue())
switch (gb.GetLastStatusReportType())
{
// In Marlin emulation mode we should return a standard temperature report every second
case StatusReportType::m105:
GenerateTemperatureReport(gb, reply);
if (reply.strlen() > 0)
{
reply.cat('\n');
platform.Message(UsbMessage, reply.c_str());
reply.Clear();
}
}
}
else if (&gb == AuxGCode())
{
if (lastAuxStatusReportType >= 0 && platform.IsAuxEnabled(0) && gb.IsReportDue())
{
// Send a standard status response for PanelDue
OutputBuffer * const statusBuf =
(lastAuxStatusReportType == ObjectModelAuxStatusReportType) // PanelDueFirmware v3.2 or later, using M409 to retrieve object model
? reprap.GetModelResponse(&gb, "", "d99fi")
: GenerateJsonStatusResponse(lastAuxStatusReportType, -1, ResponseSource::AUX); // older PanelDueFirmware using M408
if (statusBuf != nullptr)
break;

case StatusReportType::m408:
{
platform.AppendAuxReply(0, statusBuf, true);
if (reprap.Debug(Module::Gcodes))
OutputBuffer * statusBuf = GenerateJsonStatusResponse(0, -1, ResponseSource::AUX); // older PanelDueFirmware using M408
if (statusBuf != nullptr)
{
debugPrintf("%s: Sent unsolicited status report\n", gb.GetChannel().ToString());
platform.AppendAuxReply(0, statusBuf, true);
}
}
break;

case StatusReportType::m409:
{
OutputBuffer * statusBuf;
{
MutexLocker lock(reprap.GetObjectModelReportMutex());
if (OutputBuffer::GetFreeBuffers() < MinimumBuffersForObjectModel) { break; }
statusBuf = reprap.GetModelResponse(&gb, "", "d99fi");
}
if (statusBuf != nullptr)
{
platform.AppendAuxReply(0, statusBuf, true);
}
}
break;

default:
break;
}
}
}
Expand Down Expand Up @@ -5247,7 +5255,7 @@ void GCodes::AllocateAxes(const GCodeBuffer& gb, MovementState& ms, AxesBitmap a
if (reprap.GetDebugFlags(Module::Move).IsBitSet(MoveDebugFlags::AxisAllocation))
{
debugPrintf("Failed to allocate axes %07" PRIx32 " to MS %u letters %08"
#if defined(DUET3)
#if defined(DUET3) || STM32H7
PRIx64
#else
PRIx32
Expand Down
3 changes: 1 addition & 2 deletions src/GCodes/GCodes.h
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ class GCodes
#endif

static constexpr const char *AllowedAxisLetters =
#if defined(DUET3)
#if defined(DUET3) || STM32H7
"XYZUVWABCDabcdefghijklmnopqrstuvwxyz";
#else
"XYZUVWABCDabcdef";
Expand Down Expand Up @@ -790,7 +790,6 @@ class GCodes
bool isRemotePrinting;
#endif

int8_t lastAuxStatusReportType; // The type of the last status report requested by PanelDue
bool displayNoToolWarning; // True if we need to display a 'no tool selected' warning
bool m501SeenInConfigFile; // true if M501 was executed from config.g
bool daemonRunning;
Expand Down
Loading

0 comments on commit b055383

Please sign in to comment.