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

GCodeMachineState.cpp « GCodes « src - github.com/Duet3D/RepRapFirmware.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 40f58c3524d15304fec52ff16147caba9f9952c9 (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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
/*
 * GCodeMachineState.cpp
 *
 *  Created on: 15 Nov 2016
 *      Author: David
 */

#include "GCodeMachineState.h"
#include "RepRap.h"

#include <limits>

GCodeMachineState *GCodeMachineState::freeList = nullptr;
unsigned int GCodeMachineState::numAllocated = 0;

#if HAS_LINUX_INTERFACE
static unsigned int LastFileId = 1;
#endif

// Create a default initialised GCodeMachineState
GCodeMachineState::GCodeMachineState()
	: previous(nullptr), feedRate(DefaultFeedRate * SecondsToMinutes), lockedResources(0), errorMessage(nullptr),
	  lineNumber(0), compatibility(Compatibility::reprapFirmware), drivesRelative(false), axesRelative(false), doingFileMacro(false), runningM501(false),
	  runningM502(false), volumetricExtrusion(false), g53Active(false), runningSystemMacro(false), usingInches(false),
	  waitingForAcknowledgement(false), messageAcknowledged(false), indentLevel(0), state(GCodeState::normal)
{
#if HAS_LINUX_INTERFACE
	fileId = 0;
	isFileFinished = fileError = false;
#endif
}

#if HAS_LINUX_INTERFACE

// Set the state to indicate a file is being processed
void GCodeMachineState::SetFileExecuting()
{
	fileId = LastFileId++;
	isFileFinished = fileError = false;
}

// Mark the currently executing file as finished
void GCodeMachineState::SetFileFinished(bool error)
{
	isFileFinished = true;
	fileError = error;
}

#endif

bool GCodeMachineState::DoingFile() const
{
#if HAS_LINUX_INTERFACE
	if (reprap.UsingLinuxInterface())
	{
		return fileId != 0;
	}
#endif
#if HAS_MASS_STORAGE
	return fileState.IsLive();
#else
	return false;
#endif
}

// Close the currently executing file
void GCodeMachineState::CloseFile()
{
#if HAS_LINUX_INTERFACE
	if (reprap.UsingLinuxInterface())
	{
		for (GCodeMachineState *ms = this; ms != nullptr; ms = ms->previous)
		{
			if (ms->fileId == fileId)
			{
				ms->isFileFinished = false;
				ms->fileId = 0;
			}
		}
	}
	else
#endif
	{
#if HAS_MASS_STORAGE
		fileState.Close();
#endif
	}
}

// Allocate a new GCodeMachineState
/*static*/ GCodeMachineState *GCodeMachineState::Allocate()
{
	GCodeMachineState *ms = freeList;
	if (ms != nullptr)
	{
		freeList = ms->previous;
		ms->lockedResources = 0;
		ms->errorMessage = nullptr;
		ms->state = GCodeState::normal;
	}
	else
	{
		ms = new GCodeMachineState();
		++numAllocated;
	}
	return ms;
}

/*static*/ void GCodeMachineState::Release(GCodeMachineState *ms)
{
#if HAS_LINUX_INTERFACE
	if (reprap.UsingLinuxInterface())
	{
		ms->fileId = 0;
		ms->isFileFinished = false;
	}
	else
#endif
	{
#if HAS_MASS_STORAGE
		ms->fileState.Close();
#endif
	}
	ms->previous = freeList;
	freeList = ms;
}

/*static*/ unsigned int GCodeMachineState::GetNumInUse()
{
	unsigned int inUse = numAllocated;
	for (GCodeMachineState *ms = freeList; ms != nullptr; ms = ms->previous)
	{
		--inUse;
	}
	return inUse;
}

GCodeMachineState::BlockState& GCodeMachineState::CurrentBlockState()
{
	return blockStates[min<size_t>(indentLevel, ARRAY_SIZE(blockStates) - 1)];
}

void GCodeMachineState::CreateBlock()
{
	++indentLevel;
	CurrentBlockState().SetPlainBlock();
}

void GCodeMachineState::EndBlock()
{
	if (indentLevel != 0)
	{
		--indentLevel;
	}
}

// End