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

GCodeException.cpp « GCodes « src - github.com/Duet3D/RepRapFirmware.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 9789ac524d8d02b4dc9c1af44f7db9e917653488 (plain)
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
68
69
70
71
72
73
74
75
/*
 * 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 *null 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 (message == nullptr)
	{
		reply.cat("<null error message>");					// should not happem
	}
	else if (strstr(message, "%s"))
	{
		reply.catf(message, stringParam.c_str());
	}
	else if (strstr(message, "%u"))
	{
		reply.catf(message, param.u);
	}
	else
	{
		reply.catf(message, param.i);
	}
}

// End