-
Notifications
You must be signed in to change notification settings - Fork 7
/
gcode.h
163 lines (129 loc) · 3.06 KB
/
gcode.h
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
158
159
160
161
162
163
// Header gaurd
#ifndef GCODE_H
#define GCODE_H
// Header files
#include <iostream>
#include <vector>
using namespace std;
// Gcode class
class Gcode {
// Public
public:
/*
Name: Constructor
Purpose: Initializes the variable
*/
Gcode();
/*
Name: Copy constructor
Purpose: Initializes the variable if copied
*/
Gcode(Gcode &value);
/*
Name: Parse line
Purpose: Extracts G-code from the parameter
*/
bool parseLine(const char *line);
bool parseLine(const string &line);
/*
Name: Parse binary
Purpose: Extracts G-code from the binary parameter
*/
bool parseBinary(const char *line);
/*
Name: Get original command
Purpose: Returns the orignal G-code command
*/
string getOriginalCommand() const;
/*
Name: Get binary
Purpose: Returns binary representation of the G-code
*/
vector<uint8_t> getBinary() const;
/*
Name: Get ascii
Purpose: Returns Ascii representation of the G-code
*/
string getAscii() const;
/*
Name: Get data type
Purpose: Returns the data type of the G-code
*/
uint32_t getDataType() const;
/*
Name: Has parameter
Purpose: Checks if the G-code has a specific parameter, but does not check if it has a value associated with it
*/
bool hasParameter(char parameter) const;
/*
Name: Remove parameter
Purpose: Removes a specified parameter from the G-cocdde
*/
void removeParameter(char parameter);
/*
Name: Has value
Purpose: Checks if the G-code has a value associated with a specific parameter, so it can't detect flags
*/
bool hasValue(char parameter) const;
/*
Name: Get value
Purpose: Retuns the value associated with a specific parameter
*/
string getValue(char parameter) const;
/*
Name: Set value
Purpose: Sets the value associated with a specific parameter
*/
void setValue(char parameter, const string &value);
/*
Name: Has string
Purpose: Returns if the G-code contained a string as a value for a parameter
*/
bool hasString() const;
/*
Name: Get string
Purpose: Returns the string value associated with a parameter
*/
string getString() const;
/*
Name: Set string
Purpose: Sets the string value associated with a parameter
*/
void setString(const string &value);
/*
Name: Clear
Purpose: Resets G-code to initial state
*/
void clear();
/*
Name: Is host command
Purpose: Returns if the G-code is a host command
*/
bool isHostCommand() const;
/*
Name: Is empty
Purpose: Returns if no G-code has attempted to be parsed yet
*/
bool isEmpty() const;
/*
Name: Assignment operator
Purpose: Allows using the assignment operator
*/
Gcode &operator=(const Gcode &value);
/*
Name: Output stream operator
Purpose: Allows using the output stream operator
*/
friend ostream &operator<<(ostream &output, const Gcode &value);
// Private
private:
// Original command
string originalCommand;
// Parameter values
vector<string> parameterValue;
// Data type
uint32_t dataType;
// Host command
string hostCommand;
};
#endif