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

GCodeException.h « GCodes « src - github.com/Duet3D/RepRapFirmware.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 67f8f6ad42ca90a6263db0f85d8424556ada48d2 (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
/*
 * ParseException.h
 *
 *  Created on: 21 Dec 2019
 *      Author: David
 */

#ifndef SRC_GCODES_GCODEEXCEPTION_H_
#define SRC_GCODES_GCODEEXCEPTION_H_

#include <RepRapFirmware.h>

namespace StackUsage
{
	constexpr uint32_t Throw = 1050;					// how much stack we need to throw an exception
	constexpr uint32_t Margin = 300;					// the margin we allow for calls to non-recursive functions that can throw
}

class GCodeException
{
public:
	GCodeException(const char *msg) noexcept: line(-1), column(-1), message(msg), haveStringParam(false) { }

	GCodeException(int lin, int col, const char *msg) noexcept : line(lin), column(col), message(msg), haveStringParam(false)  { }

	GCodeException(int lin, int col, const char *msg, const char *sparam) noexcept : line(lin), column(col), message(msg), haveStringParam(true)
	{
		stringParam.copy(sparam);
	}

	GCodeException(int lin, int col, const char *msg, uint32_t uparam) noexcept : line(lin), column(col), message(msg), haveStringParam(false)
	{
		param.u = uparam;
	}

	GCodeException(int lin, int col, const char *msg, int32_t iparam) noexcept : line(lin), column(col), message(msg), haveStringParam(false)
	{
		param.i = iparam;
	}

	void GetMessage(const StringRef& reply, const GCodeBuffer *gb) const noexcept;

private:
	int line;
	int column;
	const char *message;
	union
	{
		int32_t i;
		uint32_t u;
	} param;
	bool haveStringParam;
	String<StringLength20> stringParam;
};

#endif /* SRC_GCODES_GCODEEXCEPTION_H_ */