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-07-12 13:40:00 +0300
committerDavid Crocker <dcrocker@eschertech.com>2021-07-12 13:40:57 +0300
commit03bd591dac92c4fea398eaea128c0aa56e2e56ca (patch)
tree16a81fbccad2d92c2654f676fd5eee156613bc12 /src/GCodes/GCodeBuffer/StringParser.cpp
parent6288d72fb0242a44cf48cc4ca4f4c4af284e2f66 (diff)
Allow an expression to be used as a driver ID
Diffstat (limited to 'src/GCodes/GCodeBuffer/StringParser.cpp')
-rw-r--r--src/GCodes/GCodeBuffer/StringParser.cpp72
1 files changed, 50 insertions, 22 deletions
diff --git a/src/GCodes/GCodeBuffer/StringParser.cpp b/src/GCodes/GCodeBuffer/StringParser.cpp
index 4c89a853..691be0ac 100644
--- a/src/GCodes/GCodeBuffer/StringParser.cpp
+++ b/src/GCodes/GCodeBuffer/StringParser.cpp
@@ -1728,36 +1728,64 @@ int32_t StringParser::ReadIValue() THROWS(GCodeException)
DriverId StringParser::ReadDriverIdValue() THROWS(GCodeException)
{
DriverId result;
- const uint32_t v1 = ReadUIValue();
-#if SUPPORT_CAN_EXPANSION
- if (gb.buffer[readPointer] == '.')
- {
- ++readPointer;
- const uint32_t v2 = ReadUIValue();
- result.localDriver = v2;
- result.boardAddress = v1;
- }
- else
+ if (gb.buffer[readPointer] == '{')
{
- result.localDriver = v1;
- result.boardAddress = CanInterface::GetCanAddress();
- }
+ // Allow a floating point expression to be converted to a driver ID
+ // We assume that a driver ID only ever has a single fractional digit. This means that e.g. 3.10 will be treated the same as 3.1.
+ ExpressionParser parser(gb, gb.buffer + readPointer, gb.buffer + ARRAY_SIZE(gb.buffer), commandIndent + readPointer);
+ const float val = 10.0 * parser.ParseFloat();
+ readPointer = parser.GetEndptr() - gb.buffer;
+ const int32_t ival = lrintf(val);
+#if SUPPORT_CAN_EXPANSION
+ if (ival >= 0 && fabsf(val - (float)ival) <= 0.002)
+ {
+ result.boardAddress = ival/10;
+ result.localDriver = ival % 10;
+ }
#else
- // We now allow driver names of the form "0.x" on boards without CAN expansion
- if (gb.buffer[readPointer] == '.')
- {
- if (v1 != 0)
+ if (ival >= 0 && ival < 10 && fabsf(val - (float)ival) <= 0.002)
{
- throw ConstructParseException("Board address of driver must be 0");
+ result.localDriver = ival % 10;
+ }
+#endif
+ else
+ {
+ throw ConstructParseException("Invalid driver ID expression");
}
- ++readPointer;
- result.localDriver = ReadUIValue();
}
else
{
- result.localDriver = v1;
- }
+ const uint32_t v1 = ReadUIValue();
+#if SUPPORT_CAN_EXPANSION
+ if (gb.buffer[readPointer] == '.')
+ {
+ ++readPointer;
+ const uint32_t v2 = ReadUIValue();
+ result.localDriver = v2;
+ result.boardAddress = v1;
+ }
+ else
+ {
+ result.localDriver = v1;
+ result.boardAddress = CanInterface::GetCanAddress();
+ }
+#else
+ // We now allow driver names of the form "0.x" on boards without CAN expansion
+ if (gb.buffer[readPointer] == '.')
+ {
+ if (v1 != 0)
+ {
+ throw ConstructParseException("Board address of driver must be 0");
+ }
+ ++readPointer;
+ result.localDriver = ReadUIValue();
+ }
+ else
+ {
+ result.localDriver = v1;
+ }
#endif
+ }
return result;
}