/
GCodeException.cpp
67 lines (59 loc) · 1.26 KB
/
GCodeException.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/*
* ParseException.cpp
*
* Created on: 21 Dec 2019
* Author: David
*/
#include "GCodeException.h"
#include <General/StringRef.h>
#include <GCodes/GCodeBuffer/GCodeBuffer.h>
// 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)
{
reply.copy((gb->IsDoingFileMacro()) ? "in file macro": "in GCode file");
if (line >= 0)
{
reply.catf(" line %d", line);
if (column >= 0)
{
reply.catf(" column %d", column + 1);
}
}
reply.cat(": ");
}
// 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(message, param.u);
}
}
// End