Skip to content

Commit

Permalink
Various changes for 3.01-RC11
Browse files Browse the repository at this point in the history
Tool change files are now run even if axes have not been homed
PanelDue replies are now sent immediately instead of being saved for
retrieval by M408
Added aux raw mode
On Duet 3, IO_0 is not configured in serial mode until M575 P1 is
executed
GCodeException class now stores a small string to allow more meaningful
error messages
  • Loading branch information
dc42 committed Apr 29, 2020
1 parent e96b00a commit 6f912e9
Show file tree
Hide file tree
Showing 12 changed files with 161 additions and 106 deletions.
11 changes: 9 additions & 2 deletions src/GCodes/GCodeBuffer/StringParser.cpp
Expand Up @@ -366,7 +366,10 @@ bool StringParser::CheckMetaCommand(const StringRef& reply) THROWS(GCodeExceptio
}
}

const bool b = ProcessConditionalGCode(reply, skippedBlockType, doingFile); // this may throw a ParseException
// Save and clear the command letter in case ProcessConditionalGCode throws an exception, so that the error message won't include the previous command
const char savedCommandLetter = commandLetter;
commandLetter = 'E'; // we use this to flag a meta command, see GCodeException::GetMessage
const bool b = ProcessConditionalGCode(reply, skippedBlockType, doingFile); // this may throw a GCodeException
if (b)
{
seenMetaCommand = true;
Expand All @@ -376,6 +379,10 @@ bool StringParser::CheckMetaCommand(const StringRef& reply) THROWS(GCodeExceptio
}
Init();
}
else
{
commandLetter = savedCommandLetter; // restore this so that we can handle Fanuc-style GCode
}

return b;
}
Expand All @@ -392,7 +399,7 @@ void StringParser::CheckForMixedSpacesAndTabs() noexcept

// Check for and process a conditional GCode language command returning true if we found one, false if it's a regular line of GCode that we need to process
// If we just finished skipping an if- or elif-block when the condition was false then 'skippedBlockType' is the type of that block, else it is BlockType::plain
bool StringParser::ProcessConditionalGCode(const StringRef& reply, BlockType skippedBlockType, bool doingFile)
bool StringParser::ProcessConditionalGCode(const StringRef& reply, BlockType skippedBlockType, bool doingFile) THROWS(GCodeException)
{
// First count the number of lowercase characters.
unsigned int i = 0;
Expand Down
36 changes: 33 additions & 3 deletions src/GCodes/GCodeException.cpp
Expand Up @@ -13,6 +13,7 @@
// Construct the error message. This will be prefixed with "Error: " when it is returned to the user.
void GCodeException::GetMessage(const StringRef &reply, const GCodeBuffer *gb) const noexcept
{
// Print the file location, if possible
const bool inFile = gb != nullptr && gb->IsDoingFile();
if (inFile)
{
Expand All @@ -27,11 +28,40 @@ void GCodeException::GetMessage(const StringRef &reply, const GCodeBuffer *gb) c
}
reply.cat(": ");
}
if (gb != nullptr && gb->HasCommandNumber())

// Print the command letter/number, if possible
if (gb != nullptr)
{
switch (gb->GetCommandLetter())
{
case 'E':
reply.cat("meta command: ");
break;

case 'G':
case 'M':
case 'T':
if (gb->HasCommandNumber())
{
reply.catf("%c%u: ", gb->GetCommandLetter(), gb->GetCommandNumber());
}
break;

case 'Q': // we use Q0 for comments
default:
break;
}
}

// Print the message and any parameter
if (haveStringParam)
{
reply.catf(message, stringParam.c_str());
}
else
{
reply.catf("%c%u: ", gb->GetCommandLetter(), gb->GetCommandNumber());
reply.catf(message, param.u);
}
reply.catf(message, param.u);
}

// End
18 changes: 8 additions & 10 deletions src/GCodes/GCodeException.h
Expand Up @@ -8,27 +8,24 @@
#ifndef SRC_GCODES_GCODEEXCEPTION_H_
#define SRC_GCODES_GCODEEXCEPTION_H_

#include <cstdint>

class StringRef;
class GCodeBuffer;
#include <RepRapFirmware.h>

class GCodeException
{
public:
GCodeException(int lin, int col, const char *msg) noexcept : line(lin), column(col), message(msg) { }
GCodeException(int lin, int col, const char *msg) noexcept : line(lin), column(col), message(msg), haveStringParam(false) { }

GCodeException(int lin, int col, const char *msg, const char *sparam) noexcept : line(lin), column(col), message(msg)
GCodeException(int lin, int col, const char *msg, const char *sparam) noexcept : line(lin), column(col), message(msg), haveStringParam(true)
{
param.s = sparam;
stringParam.copy(sparam);
}

GCodeException(int lin, int col, const char *msg, uint32_t uparam) noexcept : line(lin), column(col), message(msg)
GCodeException(int lin, int col, const char *msg, uint32_t uparam) noexcept : line(lin), column(col), message(msg), haveStringParam(false)
{
param.u = uparam;
}

GCodeException(int lin, int col, const char *msg, int32_t iparam) noexcept : line(lin), column(col), message(msg)
GCodeException(int lin, int col, const char *msg, int32_t iparam) noexcept : line(lin), column(col), message(msg), haveStringParam(false)
{
param.i = iparam;
}
Expand All @@ -43,8 +40,9 @@ class GCodeException
{
int32_t i;
uint32_t u;
const char *s;
} param;
bool haveStringParam;
String<StringLength20> stringParam;
};

#endif /* SRC_GCODES_GCODEEXCEPTION_H_ */
10 changes: 5 additions & 5 deletions src/GCodes/GCodes.cpp
Expand Up @@ -518,10 +518,10 @@ void GCodes::StartNextGCode(GCodeBuffer& gb, const StringRef& reply) noexcept
if (gotCommand)
{
gb.DecodeCommand();
#ifdef SERIAL_AUX_DEVICE
if (&gb == auxGCode && !platform.HaveAux())
#if defined(SERIAL_AUX_DEVICE) && !defined(DUET3)
if (&gb == auxGCode && !platform.IsAuxEnabled())
{
platform.SetAuxDetected(false); // by default we assume no PanelDue is attached, so flag when we receive a command from it
platform.EnableAux(); // by default we assume no PanelDue is attached, so flag when we receive a command from it
}
#endif
}
Expand Down Expand Up @@ -3387,7 +3387,7 @@ void GCodes::HandleReplyPreserveResult(GCodeBuffer& gb, GCodeResult rslt, const
// Also check that this response was triggered by a gcode
if ( reply[0] == 0
&& ( (gb.MachineState().doingFileMacro && !gb.MachineState().waitingForAcknowledgement) // we must acknowledge M292
|| &gb == fileGCode || &gb == queuedGCode || &gb == triggerGCode || &gb == autoPauseGCode || &gb == auxGCode
|| &gb == fileGCode || &gb == queuedGCode || &gb == triggerGCode || &gb == autoPauseGCode || (&gb == auxGCode && !platform.IsAuxRaw())
)
)
{
Expand Down Expand Up @@ -3465,7 +3465,7 @@ void GCodes::HandleReply(GCodeBuffer& gb, OutputBuffer *reply) noexcept
#endif

// Second UART device, e.g. dc42's PanelDue. Do NOT use emulation for this one!
if (&gb == auxGCode)
if (&gb == auxGCode && !platform.IsAuxRaw())
{
platform.AppendAuxReply(reply, (*reply)[0] == '{');
return;
Expand Down
20 changes: 18 additions & 2 deletions src/GCodes/GCodes2.cpp
Expand Up @@ -3327,15 +3327,31 @@ bool GCodes::HandleMcode(GCodeBuffer& gb, const StringRef& reply) THROWS(GCodeEx
if (auxGCode != nullptr)
{
auxGCode->SetCommsProperties(val);
platform.SetAuxDetected((val & 2u) != 0);
const bool rawMode = (val & 2u) != 0;
platform.SetAuxRaw(rawMode);
if (rawMode && !platform.IsAuxEnabled()) // if enabling aux for the first time and in raw mode, set Marlin compatibility
{
auxGCode->MachineState().compatibility = Compatibility::Marlin;
}
}
break;
default:
break;
}
seen = true;
}
if (!seen)
if (seen)
{
if (chan == 1 && !platform.IsAuxEnabled())
{
platform.EnableAux();
}
else
{
platform.ResetChannel(chan);
}
}
else
{
const uint32_t cp = platform.GetCommsProperties(chan);
reply.printf("Channel %d: baud rate %" PRIu32 ", %s checksum", chan, platform.GetBaudRate(chan), (cp & 1) ? "requires" : "does not require");
Expand Down
15 changes: 6 additions & 9 deletions src/GCodes/GCodes4.cpp
Expand Up @@ -236,7 +236,7 @@ void GCodes::RunStateMachine(GCodeBuffer& gb, const StringRef& reply) noexcept
if ((toolChangeParam & TFreeBit) != 0)
{
const Tool * const oldTool = reprap.GetCurrentTool();
if (oldTool != nullptr && AllAxesAreHomed())
if (oldTool != nullptr) // 2020-04-29: run tfree file even if not all axes have been homed
{
String<StringLength20> scratchString;
scratchString.printf("tfree%d.g", oldTool->Number());
Expand All @@ -256,7 +256,7 @@ void GCodes::RunStateMachine(GCodeBuffer& gb, const StringRef& reply) noexcept
UpdateCurrentUserPosition(); // the tool offset may have changed, so get the current position
}
gb.AdvanceState();
if (reprap.GetTool(newToolNumber).IsNotNull() && AllAxesAreHomed() && (toolChangeParam & TPreBit) != 0)
if (reprap.GetTool(newToolNumber).IsNotNull() && (toolChangeParam & TPreBit) != 0) // 2020-04-29: run tpre file even if not all axes have been homed
{
String<StringLength20> scratchString;
scratchString.printf("tpre%d.g", newToolNumber);
Expand All @@ -278,14 +278,11 @@ void GCodes::RunStateMachine(GCodeBuffer& gb, const StringRef& reply) noexcept
gb.AdvanceState(); // skip moving tool to the new height if not a 3D printer
}

if (AllAxesAreHomed())
if (reprap.GetCurrentTool() != nullptr && (toolChangeParam & TPostBit) != 0) // 2020-04-29: run tpost file even if not all axes have been homed
{
if (reprap.GetCurrentTool() != nullptr && (toolChangeParam & TPostBit) != 0)
{
String<StringLength20> scratchString;
scratchString.printf("tpost%d.g", newToolNumber);
DoFileMacro(gb, scratchString.c_str(), false, 0);
}
String<StringLength20> scratchString;
scratchString.printf("tpost%d.g", newToolNumber);
DoFileMacro(gb, scratchString.c_str(), false, 0);
}
}
break;
Expand Down
7 changes: 6 additions & 1 deletion src/ObjectModel/ObjectModel.cpp
Expand Up @@ -277,6 +277,11 @@ GCodeException ObjectExplorationContext::ConstructParseException(const char *msg
return GCodeException(line, column, msg);
}

GCodeException ObjectExplorationContext::ConstructParseException(const char *msg, const char *sparam) const noexcept
{
return GCodeException(line, column, msg, sparam);
}

// Report this object
void ObjectModel::ReportAsJson(OutputBuffer* buf, ObjectExplorationContext& context, uint8_t tableNumber, const char* filter) const
{
Expand Down Expand Up @@ -735,7 +740,7 @@ ExpressionValue ObjectModel::GetObjectValue(ObjectExplorationContext& context, c
const ObjectModelTableEntry *const e = FindObjectModelTableEntry(tableNumber, idString);
if (e == nullptr)
{
throw context.ConstructParseException("unknown value"); // idString will have gone out of scope by the time the exception is caught
throw context.ConstructParseException("unknown value '%s'", idString);
}

idString = GetNextElement(idString);
Expand Down
1 change: 1 addition & 0 deletions src/ObjectModel/ObjectModel.h
Expand Up @@ -183,6 +183,7 @@ class ObjectExplorationContext
bool ShouldIncludeNulls() const noexcept { return includeNulls; }

GCodeException ConstructParseException(const char *msg) const noexcept;
GCodeException ConstructParseException(const char *msg, const char *sparam) const noexcept;

private:
static constexpr size_t MaxIndices = 4; // max depth of array nesting
Expand Down

0 comments on commit 6f912e9

Please sign in to comment.