Skip to content

Commit

Permalink
Restrict lowercase axis letters to a..f and speed up parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
dc42 committed Oct 11, 2022
1 parent 727efd3 commit a7e81b4
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 20 deletions.
60 changes: 41 additions & 19 deletions src/GCodes/GCodeBuffer/StringParser.cpp
Expand Up @@ -984,40 +984,56 @@ void StringParser::DecodeCommand() noexcept
void StringParser::FindParameters() noexcept
{
bool inQuotes = false;
bool escaped = false;
unsigned int localBraceCount = 0;
parametersPresent.Clear();
for (commandEnd = parameterStart; commandEnd < gcodeLineEnd; ++commandEnd)
{
const char c = gb.buffer[commandEnd];
if (c == '"')
if (c == '\'')
{
inQuotes = !inQuotes;
escaped = !inQuotes;
}
else if (!inQuotes)
else
{
if (c == '{')
if (c == '"')
{
++localBraceCount;
inQuotes = !inQuotes;
}
else if (localBraceCount != 0)
else if (!inQuotes)
{
if (c == '}')
if (c == '{')
{
--localBraceCount;
++localBraceCount;
}
}
else
{
const char c2 = toupper(c);
if ((c2 == 'G' || c2 == 'M') && gb.buffer[commandEnd - 1] != '\'')
else if (localBraceCount != 0)
{
break;
if (c == '}')
{
--localBraceCount;
}
}
if (c2 >= 'A' && c2 <= 'Z' && (c2 != 'E' || commandEnd == parameterStart || !isdigit(gb.buffer[commandEnd - 1])))
else
{
parametersPresent.SetBit(c2 - 'A');
const char c2 = toupper(c);
if (escaped)
{
if (c2 >= 'A' && c2 <= 'F' && (c2 != 'E' || commandEnd == parameterStart || !isdigit(gb.buffer[commandEnd - 1])))
{
parametersPresent.SetBit(c2 - ('A' - 26));
}
}
else if (c2 == 'G' || c2 == 'M')
{
break;
}
else if (c2 >= 'A' && c2 <= 'Z' && (c2 != 'E' || commandEnd == parameterStart || !isdigit(gb.buffer[commandEnd - 1])))
{
parametersPresent.SetBit(c2 - 'A');
}
}
}
escaped = false;
}
}
}
Expand Down Expand Up @@ -1109,16 +1125,22 @@ bool StringParser::IsLastCommand() const noexcept
return commandEnd >= gcodeLineEnd; // using >= here also covers the case where the buffer is empty and gcodeLineEnd has been set to zero
}

// Is 'c' in the G Code string?
// Is 'c' in the G Code string? 'c' must be in A..Z or a..f
// Leave the pointer one after it for a subsequent read.
bool StringParser::Seen(char c) noexcept
{
bool wantLowerCase = (c >= 'a');
const bool wantLowerCase = (c >= 'a');
unsigned int bit;
if (wantLowerCase)
{
bit = c - ('a' - 26);
c = toupper(c);
}
else if (!parametersPresent.IsBitSet(c - 'A'))
else
{
bit = c - 'A';
}
if (bit > 31 || !parametersPresent.IsBitSet(c - 'A'))
{
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion src/GCodes/GCodes.h
Expand Up @@ -287,7 +287,7 @@ class GCodes
void SetRemotePrinting(bool isPrinting) noexcept { isRemotePrinting = isPrinting; }
#endif

static constexpr const char *AllowedAxisLetters = "XYZUVWABCDabcdefghijkl";
static constexpr const char *AllowedAxisLetters = "XYZUVWABCDabcdef";

// Standard macro filenames
#define DEPLOYPROBE "deployprobe"
Expand Down

5 comments on commit a7e81b4

@morrisonj
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this temporary or is the plan to only support 16 axes? I have a fourth expansion board and was hoping to be able to use the steppers on it with the 3.5 update.

@dc42
Copy link
Collaborator Author

@dc42 dc42 commented on a7e81b4 Oct 28, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The current firmware limit is 15 axes on 6HC and 6XD. Lower on other boards.

@morrisonj
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your clarification. I'm using all 15 axes on my machines and looking to utilise 16-19 (I have two machines with Duet 3 boards and 4 expansion boards each). Is this in the pipeline for anytime soon?

@dc42
Copy link
Collaborator Author

@dc42 dc42 commented on a7e81b4 Oct 29, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please can you make a post on the Duet3D forum describing your use case.

@morrisonj
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.