Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/Duet3D/RepRapFirmware.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Crocker <dcrocker@eschertech.com>2021-03-06 21:42:25 +0300
committerDavid Crocker <dcrocker@eschertech.com>2021-03-06 21:42:25 +0300
commit4cf8ed602d836ff2846786ed287f72ca5b4bb709 (patch)
tree20e135cae914ee2fcdd798033d6bb8b69ee961da /src/GCodes/GCodeBuffer/StringParser.cpp
parent0e34efd380543cbcf86ff077d3a820b7e9c15c9b (diff)
Started adding support for variables and parameters
Diffstat (limited to 'src/GCodes/GCodeBuffer/StringParser.cpp')
-rw-r--r--src/GCodes/GCodeBuffer/StringParser.cpp39
1 files changed, 34 insertions, 5 deletions
diff --git a/src/GCodes/GCodeBuffer/StringParser.cpp b/src/GCodes/GCodeBuffer/StringParser.cpp
index 2ebce1e2..85da823e 100644
--- a/src/GCodes/GCodeBuffer/StringParser.cpp
+++ b/src/GCodes/GCodeBuffer/StringParser.cpp
@@ -752,6 +752,7 @@ void StringParser::DecodeCommand() noexcept
// Find where the end of the command is. We assume that a G or M not inside quotes or { } and not preceded by ' is the start of a new command.
bool inQuotes = false;
unsigned int localBraceCount = 0;
+ parametersPresent.Clear();
for (commandEnd = parameterStart; commandEnd < gcodeLineEnd; ++commandEnd)
{
const char c = gb.buffer[commandEnd];
@@ -774,11 +775,15 @@ void StringParser::DecodeCommand() noexcept
}
else
{
- char c2;
- if (((c2 = toupper(c)) == 'G' || c2 == 'M') && gb.buffer[commandEnd - 1] != '\'')
+ const char c2 = toupper(c);
+ if ((c2 == 'G' || c2 == 'M') && gb.buffer[commandEnd - 1] != '\'')
{
break;
}
+ if (c2 >= 'A' && c2 <= 'Z' && (c2 != 'E' || commandEnd == parameterStart || !isdigit(gb.buffer[commandEnd - 1])))
+ {
+ parametersPresent.SetBit(c2 - 'A');
+ }
}
}
}
@@ -903,18 +908,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? 'c' must be uppercase.
+// Is 'c' in the G Code string?
// Leave the pointer one after it for a subsequent read.
bool StringParser::Seen(char c) noexcept
{
- bool inQuotes = false;
- bool escaped = false;
bool wantLowerCase = (c >= 'a');
if (wantLowerCase)
{
c = toupper(c);
}
+ else if (!parametersPresent.IsBitSet(c - 'A'))
+ {
+ return false;
+ }
+ bool inQuotes = false;
+ bool escaped = false;
unsigned int inBrackets = 0;
for (readPointer = parameterStart; (unsigned int)readPointer < commandEnd; ++readPointer)
{
@@ -1662,6 +1671,26 @@ void StringParser::SkipWhiteSpace() noexcept
}
}
+void StringParser::SetParameters(GCodeMachineState *mc, int codeRunning) noexcept
+{
+ parametersPresent.Iterate([this, mc, codeRunning](unsigned int bit, unsigned int count)
+ {
+ const char letter = 'A' + bit;
+ if ((letter != 'P' || codeRunning != 98) && Seen(letter))
+ {
+ ExpressionParser parser(gb, &gb.buffer[readPointer], &gb.buffer[commandEnd]);
+ try
+ {
+ ExpressionValue ev = parser.Parse();
+ char paramName[2] = { letter, 0 };
+ mc->variables.Insert(new Variable(paramName, ev, -1));
+ }
+ catch (const GCodeException&) { }
+ }
+ }
+ );
+}
+
GCodeException StringParser::ConstructParseException(const char *str) const noexcept
{
return GCodeException(gb.machineState->lineNumber, readPointer + commandIndent, str);