Skip to content
Newer
Older
100644 399 lines (362 sloc) 12.6 KB
56c355c @triffid split gcode parse/process into separate files for readability
authored
1 #include "gcode_parse.h"
1e6c740 @triffid tons of changes, implementing 4D dda
authored
2
0dc7d77 @triffid Massive Doxygen documentation addition
authored
3 /** \file
4 \brief Parse received G-Codes
5 */
6
1e6c740 @triffid tons of changes, implementing 4D dda
authored
7 #include <string.h>
8
496d58f @triffid time to save again, preliminary PID/PWM support for extruder barrel h…
authored
9 #include "serial.h"
ef09d62 @triffid time to save again, tightened up gcode interpreter, added preliminary…
authored
10 #include "sermsg.h"
8cc6fa6 @triffid split up dda and its queue, moved clock tick functions from main loop…
authored
11 #include "dda_queue.h"
bce0890 @triffid time to save, added a tiny printf implementation which actually gives…
authored
12 #include "debug.h"
273d63f @triffid splitting heater stuff out into a separate file
authored
13 #include "heater.h"
209dfe6 @triffid prepare for protocol changes ie responses after ok instead of separat…
authored
14 #include "sersendf.h"
56c355c @triffid split gcode parse/process into separate files for readability
authored
15
16 #include "gcode_process.h"
2b8a5d3 @phord simulator: record g-codes in datalog
phord authored
17 #ifdef SIMULATOR
18 #include "simulator.h"
19 #endif
1e6c740 @triffid tons of changes, implementing 4D dda
authored
20
0dc7d77 @triffid Massive Doxygen documentation addition
authored
21 /// current or previous gcode word
22 /// for working out what to do with data just received
bce0890 @triffid time to save, added a tiny printf implementation which actually gives…
authored
23 uint8_t last_field = 0;
780ec03 @triffid time to save again, eliminated floats and dropped over 2k of codesize
authored
24
0dc7d77 @triffid Massive Doxygen documentation addition
authored
25 /// crude crc macro
abc0edc @Traumflug Add the option to not include the asterisk in checksum calculation.
Traumflug authored
26 #define crc(a, b) (a ^ b)
27
0dc7d77 @triffid Massive Doxygen documentation addition
authored
28 /// crude floating point data storage
c715044 @phord Zungmann's fixes to compile simulator on Mac OS X, part 2.
phord authored
29 decfloat BSS read_digit;
bce0890 @triffid time to save, added a tiny printf implementation which actually gives…
authored
30
0dc7d77 @triffid Massive Doxygen documentation addition
authored
31 /// this is where we store all the data for the current command before we work out what to do with it
c715044 @phord Zungmann's fixes to compile simulator on Mac OS X, part 2.
phord authored
32 GCODE_COMMAND BSS next_target;
1bde999 @triffid seems to be working nicely, although the speeds don't seem quite righ…
authored
33
1e6c740 @triffid tons of changes, implementing 4D dda
authored
34 /*
0dc623d @Traumflug gcode_parse.c: added comments, which show possible variable overflows.
Traumflug authored
35 decfloat_to_int() is the weakest subject to variable overflow. For evaluation, we assume a build room of +-1000 mm and STEPS_PER_MM_x between 1.000 and 4096. Accordingly for metric units:
36
37 df->mantissa: +-0..1048075 (20 bit - 500 for rounding)
34ab76f @Traumflug gcode_parse.c: review decfloat_to_int() again.
Traumflug authored
38 df->exponent: 0, 2, 3, 4 or 5 (10 bit)
39 multiplicand: 1000 (10 bit)
0dc623d @Traumflug gcode_parse.c: added comments, which show possible variable overflows.
Traumflug authored
40
41 imperial units:
42
43 df->mantissa: +-0..32267 (15 bit - 500 for rounding)
34ab76f @Traumflug gcode_parse.c: review decfloat_to_int() again.
Traumflug authored
44 df->exponent: 0, 2, 3, 4 or 5 (10 bit)
45 multiplicand: 25400 (15 bit)
0dc623d @Traumflug gcode_parse.c: added comments, which show possible variable overflows.
Traumflug authored
46 */
34ab76f @Traumflug gcode_parse.c: review decfloat_to_int() again.
Traumflug authored
47 // decfloat_to_int() can handle a bit more:
48 #define DECFLOAT_EXP_MAX 3 // more is pointless, as 1 um is our presision
49 // (2^^32 - 1) / multiplicand - powers[DECFLOAT_EXP_MAX] / 2 =
50 // 4294967295 / 1000 - 5000 =
51 #define DECFLOAT_MANT_MM_MAX 4289967 // = 4290 mm
52 // 4294967295 / 25400 - 5000 =
53 #define DECFLOAT_MANT_IN_MAX 164093 // = 164 inches = 4160 mm
0dc623d @Traumflug gcode_parse.c: added comments, which show possible variable overflows.
Traumflug authored
54
55 /*
1e6c740 @triffid tons of changes, implementing 4D dda
authored
56 utility functions
57 */
4febbea @sw fix decfloat_to_int, Less divisions in decfloat_to_int.
sw authored
58 extern const uint32_t powers[]; // defined in sermsg.c
1e6c740 @triffid tons of changes, implementing 4D dda
authored
59
0dc7d77 @triffid Massive Doxygen documentation addition
authored
60 /// convert a floating point input value into an integer with appropriate scaling.
61 /// \param *df pointer to floating point structure that holds fp value to convert
62 /// \param multiplicand multiply by this amount during conversion to integer
63 ///
5a9a134 @Traumflug gcode_parse.c: review decfloat_to_int() yet again.
Traumflug authored
64 /// Tested for up to 42'000 mm (accurate), 420'000 mm (precision 10 um) and
65 /// 4'200'000 mm (precision 100 um).
4c84b31 @Traumflug gcode_parse.c, decfloat_to_int(): use a smaller variable.
Traumflug authored
66 static int32_t decfloat_to_int(decfloat *df, uint16_t multiplicand) {
bdeb482 @Traumflug gcode_parse.c: replace some ints by uints to double the range.
Traumflug authored
67 uint32_t r = df->mantissa;
b6b2951 @triffid time to save, looks like the DDA is working! NOTE: endstops disabled …
authored
68 uint8_t e = df->exponent;
69
70 // e=1 means we've seen a decimal point but no digits after it, and e=2 means we've seen a decimal point with one digit so it's too high by one if not zero
71 if (e)
72 e--;
780ec03 @triffid time to save again, eliminated floats and dropped over 2k of codesize
authored
73
5a9a134 @Traumflug gcode_parse.c: review decfloat_to_int() yet again.
Traumflug authored
74 // This raises range for mm by factor 1000 and for inches by factor 100.
75 // It's a bit expensive, but we should have the time while parsing.
76 while (e && multiplicand % 10 == 0) {
77 multiplicand /= 10;
78 e--;
79 }
80
34ab76f @Traumflug gcode_parse.c: review decfloat_to_int() again.
Traumflug authored
81 r *= multiplicand;
6896aa5 @Traumflug gcode_parse.c: join the upper and the lower formula in decfloat_to_in…
Traumflug authored
82 if (e)
8cf8a8a @Traumflug gcode_parse.c: get rid of rounding[].
Traumflug authored
83 r = (r + powers[e] / 2) / powers[e];
780ec03 @triffid time to save again, eliminated floats and dropped over 2k of codesize
authored
84
bdeb482 @Traumflug gcode_parse.c: replace some ints by uints to double the range.
Traumflug authored
85 return df->sign ? -(int32_t)r : (int32_t)r;
1e6c740 @triffid tons of changes, implementing 4D dda
authored
86 }
87
eaf6c45 @Traumflug Introduce gcode_init() and honor E_ABSOLUTE as the default.
Traumflug authored
88 void gcode_init(void) {
89 // gcc guarantees us all variables are initialised to 0.
90
91 #ifndef E_ABSOLUTE
92 next_target.option_e_relative = 1;
93 #endif
94 }
95
0dc7d77 @triffid Massive Doxygen documentation addition
authored
96 /// Character Received - add it to our command
97 /// \param c the next character to process
56c355c @triffid split gcode parse/process into separate files for readability
authored
98 void gcode_parse_char(uint8_t c) {
931d81a @Traumflug gcode_parse.c: checksum the characters actually received.
Traumflug authored
99 uint8_t checksum_char = c;
100
1e6c740 @triffid tons of changes, implementing 4D dda
authored
101 // uppercase
102 if (c >= 'a' && c <= 'z')
103 c &= ~32;
2b8a5d3 @phord simulator: record g-codes in datalog
phord authored
104 #ifdef SIMULATOR
cfa4857 @phord simulator: cmdline switches for output options
phord authored
105 sim_gcode_ch(c);
2b8a5d3 @phord simulator: record g-codes in datalog
phord authored
106 #endif
4c47901 @triffid tons of commenting and tidying, fixes to heater PID loop
authored
107 // process previous field
b6b2951 @triffid time to save, looks like the DDA is working! NOTE: endstops disabled …
authored
108 if (last_field) {
4c47901 @triffid tons of commenting and tidying, fixes to heater PID loop
authored
109 // check if we're seeing a new field or end of line
c013a18 @Traumflug Every character, plus *, starts a new field. Previously,
Traumflug authored
110 // any character will start a new field, even invalid/unknown ones
111 if ((c >= 'A' && c <= 'Z') || c == '*' || (c == 10) || (c == 13)) {
1e6c740 @triffid tons of changes, implementing 4D dda
authored
112 switch (last_field) {
113 case 'G':
780ec03 @triffid time to save again, eliminated floats and dropped over 2k of codesize
authored
114 next_target.G = read_digit.mantissa;
85a9f63 @madscifi Pretest DEBUG_X constants for non-zero and && the test with all existing
madscifi authored
115 if (DEBUG_ECHO && (debug_flags & DEBUG_ECHO))
4c47901 @triffid tons of commenting and tidying, fixes to heater PID loop
authored
116 serwrite_uint8(next_target.G);
1e6c740 @triffid tons of changes, implementing 4D dda
authored
117 break;
118 case 'M':
780ec03 @triffid time to save again, eliminated floats and dropped over 2k of codesize
authored
119 next_target.M = read_digit.mantissa;
85a9f63 @madscifi Pretest DEBUG_X constants for non-zero and && the test with all existing
madscifi authored
120 if (DEBUG_ECHO && (debug_flags & DEBUG_ECHO))
4c47901 @triffid tons of commenting and tidying, fixes to heater PID loop
authored
121 serwrite_uint8(next_target.M);
1e6c740 @triffid tons of changes, implementing 4D dda
authored
122 break;
123 case 'X':
4c47901 @triffid tons of commenting and tidying, fixes to heater PID loop
authored
124 if (next_target.option_inches)
34ab76f @Traumflug gcode_parse.c: review decfloat_to_int() again.
Traumflug authored
125 next_target.target.X = decfloat_to_int(&read_digit, 25400);
4c47901 @triffid tons of commenting and tidying, fixes to heater PID loop
authored
126 else
34ab76f @Traumflug gcode_parse.c: review decfloat_to_int() again.
Traumflug authored
127 next_target.target.X = decfloat_to_int(&read_digit, 1000);
85a9f63 @madscifi Pretest DEBUG_X constants for non-zero and && the test with all existing
madscifi authored
128 if (DEBUG_ECHO && (debug_flags & DEBUG_ECHO))
4c47901 @triffid tons of commenting and tidying, fixes to heater PID loop
authored
129 serwrite_int32(next_target.target.X);
1e6c740 @triffid tons of changes, implementing 4D dda
authored
130 break;
131 case 'Y':
4c47901 @triffid tons of commenting and tidying, fixes to heater PID loop
authored
132 if (next_target.option_inches)
34ab76f @Traumflug gcode_parse.c: review decfloat_to_int() again.
Traumflug authored
133 next_target.target.Y = decfloat_to_int(&read_digit, 25400);
4c47901 @triffid tons of commenting and tidying, fixes to heater PID loop
authored
134 else
34ab76f @Traumflug gcode_parse.c: review decfloat_to_int() again.
Traumflug authored
135 next_target.target.Y = decfloat_to_int(&read_digit, 1000);
85a9f63 @madscifi Pretest DEBUG_X constants for non-zero and && the test with all existing
madscifi authored
136 if (DEBUG_ECHO && (debug_flags & DEBUG_ECHO))
4c47901 @triffid tons of commenting and tidying, fixes to heater PID loop
authored
137 serwrite_int32(next_target.target.Y);
1e6c740 @triffid tons of changes, implementing 4D dda
authored
138 break;
139 case 'Z':
4c47901 @triffid tons of commenting and tidying, fixes to heater PID loop
authored
140 if (next_target.option_inches)
34ab76f @Traumflug gcode_parse.c: review decfloat_to_int() again.
Traumflug authored
141 next_target.target.Z = decfloat_to_int(&read_digit, 25400);
4c47901 @triffid tons of commenting and tidying, fixes to heater PID loop
authored
142 else
34ab76f @Traumflug gcode_parse.c: review decfloat_to_int() again.
Traumflug authored
143 next_target.target.Z = decfloat_to_int(&read_digit, 1000);
85a9f63 @madscifi Pretest DEBUG_X constants for non-zero and && the test with all existing
madscifi authored
144 if (DEBUG_ECHO && (debug_flags & DEBUG_ECHO))
4c47901 @triffid tons of commenting and tidying, fixes to heater PID loop
authored
145 serwrite_int32(next_target.target.Z);
1e6c740 @triffid tons of changes, implementing 4D dda
authored
146 break;
147 case 'E':
4c47901 @triffid tons of commenting and tidying, fixes to heater PID loop
authored
148 if (next_target.option_inches)
34ab76f @Traumflug gcode_parse.c: review decfloat_to_int() again.
Traumflug authored
149 next_target.target.E = decfloat_to_int(&read_digit, 25400);
4c47901 @triffid tons of commenting and tidying, fixes to heater PID loop
authored
150 else
34ab76f @Traumflug gcode_parse.c: review decfloat_to_int() again.
Traumflug authored
151 next_target.target.E = decfloat_to_int(&read_digit, 1000);
85a9f63 @madscifi Pretest DEBUG_X constants for non-zero and && the test with all existing
madscifi authored
152 if (DEBUG_ECHO && (debug_flags & DEBUG_ECHO))
4c47901 @triffid tons of commenting and tidying, fixes to heater PID loop
authored
153 serwrite_uint32(next_target.target.E);
1e6c740 @triffid tons of changes, implementing 4D dda
authored
154 break;
155 case 'F':
4fc004c @triffid It's alive! (cue evil cackle). still has some bugs, eg small movement…
authored
156 // just use raw integer, we need move distance and n_steps to convert it to a useful value, so wait until we have those to convert it
4c47901 @triffid tons of commenting and tidying, fixes to heater PID loop
authored
157 if (next_target.option_inches)
34ab76f @Traumflug gcode_parse.c: review decfloat_to_int() again.
Traumflug authored
158 next_target.target.F = decfloat_to_int(&read_digit, 25400);
4c47901 @triffid tons of commenting and tidying, fixes to heater PID loop
authored
159 else
34ab76f @Traumflug gcode_parse.c: review decfloat_to_int() again.
Traumflug authored
160 next_target.target.F = decfloat_to_int(&read_digit, 1);
85a9f63 @madscifi Pretest DEBUG_X constants for non-zero and && the test with all existing
madscifi authored
161 if (DEBUG_ECHO && (debug_flags & DEBUG_ECHO))
4c47901 @triffid tons of commenting and tidying, fixes to heater PID loop
authored
162 serwrite_uint32(next_target.target.F);
1e6c740 @triffid tons of changes, implementing 4D dda
authored
163 break;
ef09d62 @triffid time to save again, tightened up gcode interpreter, added preliminary…
authored
164 case 'S':
f27e79a @triffid time to save again, added delay_ms, implemented cooling fan, tons of …
authored
165 // if this is temperature, multiply by 4 to convert to quarter-degree units
166 // cosmetically this should be done in the temperature section,
167 // but it takes less code, less memory and loses no precision if we do it here instead
3aa7fc8 @amsler M140: S value is a temperature
amsler authored
168 if ((next_target.M == 104) || (next_target.M == 109) || (next_target.M == 140))
34ab76f @Traumflug gcode_parse.c: review decfloat_to_int() again.
Traumflug authored
169 next_target.S = decfloat_to_int(&read_digit, 4);
4c47901 @triffid tons of commenting and tidying, fixes to heater PID loop
authored
170 // if this is heater PID stuff, multiply by PID_SCALE because we divide by PID_SCALE later on
171 else if ((next_target.M >= 130) && (next_target.M <= 132))
34ab76f @Traumflug gcode_parse.c: review decfloat_to_int() again.
Traumflug authored
172 next_target.S = decfloat_to_int(&read_digit, PID_SCALE);
f27e79a @triffid time to save again, added delay_ms, implemented cooling fan, tons of …
authored
173 else
34ab76f @Traumflug gcode_parse.c: review decfloat_to_int() again.
Traumflug authored
174 next_target.S = decfloat_to_int(&read_digit, 1);
85a9f63 @madscifi Pretest DEBUG_X constants for non-zero and && the test with all existing
madscifi authored
175 if (DEBUG_ECHO && (debug_flags & DEBUG_ECHO))
4c47901 @triffid tons of commenting and tidying, fixes to heater PID loop
authored
176 serwrite_uint16(next_target.S);
f27e79a @triffid time to save again, added delay_ms, implemented cooling fan, tons of …
authored
177 break;
178 case 'P':
34ab76f @Traumflug gcode_parse.c: review decfloat_to_int() again.
Traumflug authored
179 next_target.P = decfloat_to_int(&read_digit, 1);
85a9f63 @madscifi Pretest DEBUG_X constants for non-zero and && the test with all existing
madscifi authored
180 if (DEBUG_ECHO && (debug_flags & DEBUG_ECHO))
4c47901 @triffid tons of commenting and tidying, fixes to heater PID loop
authored
181 serwrite_uint16(next_target.P);
ef09d62 @triffid time to save again, tightened up gcode interpreter, added preliminary…
authored
182 break;
096d7df @triffid Merge release-candidate-triffid branch
authored
183 case 'T':
184 next_target.T = read_digit.mantissa;
85a9f63 @madscifi Pretest DEBUG_X constants for non-zero and && the test with all existing
madscifi authored
185 if (DEBUG_ECHO && (debug_flags & DEBUG_ECHO))
096d7df @triffid Merge release-candidate-triffid branch
authored
186 serwrite_uint8(next_target.T);
187 break;
ee4e71d @triffid preliminary support for line numbers and checksums, also some handy h…
authored
188 case 'N':
34ab76f @Traumflug gcode_parse.c: review decfloat_to_int() again.
Traumflug authored
189 next_target.N = decfloat_to_int(&read_digit, 1);
85a9f63 @madscifi Pretest DEBUG_X constants for non-zero and && the test with all existing
madscifi authored
190 if (DEBUG_ECHO && (debug_flags & DEBUG_ECHO))
2182d7b @triffid time to save, updated M253 read memory to accept a length, updated ut…
authored
191 serwrite_uint32(next_target.N);
ee4e71d @triffid preliminary support for line numbers and checksums, also some handy h…
authored
192 break;
193 case '*':
34ab76f @Traumflug gcode_parse.c: review decfloat_to_int() again.
Traumflug authored
194 next_target.checksum_read = decfloat_to_int(&read_digit, 1);
85a9f63 @madscifi Pretest DEBUG_X constants for non-zero and && the test with all existing
madscifi authored
195 if (DEBUG_ECHO && (debug_flags & DEBUG_ECHO))
2182d7b @triffid time to save, updated M253 read memory to accept a length, updated ut…
authored
196 serwrite_uint8(next_target.checksum_read);
ee4e71d @triffid preliminary support for line numbers and checksums, also some handy h…
authored
197 break;
1e6c740 @triffid tons of changes, implementing 4D dda
authored
198 }
4c47901 @triffid tons of commenting and tidying, fixes to heater PID loop
authored
199 // reset for next field
b6b2951 @triffid time to save, looks like the DDA is working! NOTE: endstops disabled …
authored
200 last_field = 0;
c013a18 @Traumflug Every character, plus *, starts a new field. Previously,
Traumflug authored
201 read_digit.sign = read_digit.mantissa = read_digit.exponent = 0;
1e6c740 @triffid tons of changes, implementing 4D dda
authored
202 }
b6b2951 @triffid time to save, looks like the DDA is working! NOTE: endstops disabled …
authored
203 }
204
4c47901 @triffid tons of commenting and tidying, fixes to heater PID loop
authored
205 // skip comments
7f57634 @Traumflug Allow comments in parentheses. Some GCode generators
Traumflug authored
206 if (next_target.seen_semi_comment == 0 && next_target.seen_parens_comment == 0) {
4c47901 @triffid tons of commenting and tidying, fixes to heater PID loop
authored
207 // new field?
c013a18 @Traumflug Every character, plus *, starts a new field. Previously,
Traumflug authored
208 if ((c >= 'A' && c <= 'Z') || c == '*') {
b6b2951 @triffid time to save, looks like the DDA is working! NOTE: endstops disabled …
authored
209 last_field = c;
85a9f63 @madscifi Pretest DEBUG_X constants for non-zero and && the test with all existing
madscifi authored
210 if (DEBUG_ECHO && (debug_flags & DEBUG_ECHO))
4c47901 @triffid tons of commenting and tidying, fixes to heater PID loop
authored
211 serial_writechar(c);
b6b2951 @triffid time to save, looks like the DDA is working! NOTE: endstops disabled …
authored
212 }
213
214 // process character
63d3f01 @Traumflug gcode_parse.c: process incoming digits earlier.
Traumflug authored
215 // Can't do ranges in switch..case, so process actual digits here.
216 // Do it early, as there are many more digits than characters expected.
217 if (c >= '0' && c <= '9') {
218 if (read_digit.exponent < DECFLOAT_EXP_MAX + 1 &&
219 ((next_target.option_inches == 0 &&
220 read_digit.mantissa < DECFLOAT_MANT_MM_MAX) ||
221 (next_target.option_inches &&
222 read_digit.mantissa < DECFLOAT_MANT_IN_MAX))) {
223 // this is simply mantissa = (mantissa * 10) + atoi(c) in different clothes
224 read_digit.mantissa = (read_digit.mantissa << 3) +
225 (read_digit.mantissa << 1) + (c - '0');
226 if (read_digit.exponent)
227 read_digit.exponent++;
228 }
229 }
230 else {
231 switch (c) {
232 // Each currently known command is either G or M, so preserve
233 // previous G/M unless a new one has appeared.
234 // FIXME: same for T command
235 case 'G':
236 next_target.seen_G = 1;
237 next_target.seen_M = 0;
238 next_target.M = 0;
239 break;
240 case 'M':
241 next_target.seen_M = 1;
242 next_target.seen_G = 0;
243 next_target.G = 0;
244 break;
245 case 'X':
246 next_target.seen_X = 1;
247 break;
248 case 'Y':
249 next_target.seen_Y = 1;
250 break;
251 case 'Z':
252 next_target.seen_Z = 1;
253 break;
254 case 'E':
255 next_target.seen_E = 1;
256 break;
257 case 'F':
258 next_target.seen_F = 1;
259 break;
260 case 'S':
261 next_target.seen_S = 1;
262 break;
263 case 'P':
264 next_target.seen_P = 1;
265 break;
266 case 'T':
267 next_target.seen_T = 1;
268 break;
269 case 'N':
270 next_target.seen_N = 1;
271 break;
272 case '*':
273 next_target.seen_checksum = 1;
274 break;
275
276 // comments
277 case ';':
278 next_target.seen_semi_comment = 1;
279 break;
280 case '(':
281 next_target.seen_parens_comment = 1;
282 break;
283
284 // now for some numeracy
285 case '-':
286 read_digit.sign = 1;
287 // force sign to be at start of number, so 1-2 = -2 instead of -12
288 read_digit.exponent = 0;
289 read_digit.mantissa = 0;
290 break;
291 case '.':
292 if (read_digit.exponent == 0)
293 read_digit.exponent = 1;
294 break;
295 #ifdef DEBUG
296 case ' ':
297 case '\t':
298 case 10:
299 case 13:
300 // ignore
301 break;
302 #endif
303
304 default:
305 #ifdef DEBUG
306 // invalid
307 serial_writechar('?');
308 serial_writechar(c);
309 serial_writechar('?');
310 #endif
311 break;
312 }
1e6c740 @triffid tons of changes, implementing 4D dda
authored
313 }
7f57634 @Traumflug Allow comments in parentheses. Some GCode generators
Traumflug authored
314 } else if ( next_target.seen_parens_comment == 1 && c == ')')
315 next_target.seen_parens_comment = 0; // recognize stuff after a (comment)
316
abc0edc @Traumflug Add the option to not include the asterisk in checksum calculation.
Traumflug authored
317 if (next_target.seen_checksum == 0)
931d81a @Traumflug gcode_parse.c: checksum the characters actually received.
Traumflug authored
318 next_target.checksum_calculated =
319 crc(next_target.checksum_calculated, checksum_char);
abc0edc @Traumflug Add the option to not include the asterisk in checksum calculation.
Traumflug authored
320
4c47901 @triffid tons of commenting and tidying, fixes to heater PID loop
authored
321 // end of line
fe9938b @triffid Accept CR as end of line, by popular request
authored
322 if ((c == 10) || (c == 13)) {
85a9f63 @madscifi Pretest DEBUG_X constants for non-zero and && the test with all existing
madscifi authored
323 if (DEBUG_ECHO && (debug_flags & DEBUG_ECHO))
f8eee36 @triffid Lots of minor tweaks during some test runs, most notable is that tail…
authored
324 serial_writechar(c);
aa590c4 @Traumflug Don't fail on unknown commands. For example, RepRap host sends T comm…
Traumflug authored
325
ec9e84a @Traumflug gcode_parse.c: assume G1 only for stuff which might actually move.
Traumflug authored
326 // Assume G1 for unspecified movements.
327 if ( ! next_target.seen_G &&
328 (next_target.seen_X || next_target.seen_Y || next_target.seen_Z ||
329 next_target.seen_E || next_target.seen_F)) {
330 next_target.seen_G = 1;
331 next_target.G = 1;
332 }
333
aa590c4 @Traumflug Don't fail on unknown commands. For example, RepRap host sends T comm…
Traumflug authored
334 if (
56c355c @triffid split gcode parse/process into separate files for readability
authored
335 #ifdef REQUIRE_LINENUMBER
5c0dde4 @Traumflug Changed M110 to match the description in the RepRap Wiki.
Traumflug authored
336 ((next_target.N >= next_target.N_expected) && (next_target.seen_N == 1)) ||
337 (next_target.seen_M && (next_target.M == 110))
56c355c @triffid split gcode parse/process into separate files for readability
authored
338 #else
aa590c4 @Traumflug Don't fail on unknown commands. For example, RepRap host sends T comm…
Traumflug authored
339 1
56c355c @triffid split gcode parse/process into separate files for readability
authored
340 #endif
aa590c4 @Traumflug Don't fail on unknown commands. For example, RepRap host sends T comm…
Traumflug authored
341 ) {
ee4e71d @triffid preliminary support for line numbers and checksums, also some handy h…
authored
342 if (
aa590c4 @Traumflug Don't fail on unknown commands. For example, RepRap host sends T comm…
Traumflug authored
343 #ifdef REQUIRE_CHECKSUM
344 ((next_target.checksum_calculated == next_target.checksum_read) && (next_target.seen_checksum == 1))
ff25c68 @Traumflug If line numbers aren't required, don't bother about their
Traumflug authored
345 #else
aa590c4 @Traumflug Don't fail on unknown commands. For example, RepRap host sends T comm…
Traumflug authored
346 ((next_target.checksum_calculated == next_target.checksum_read) || (next_target.seen_checksum == 0))
ff25c68 @Traumflug If line numbers aren't required, don't bother about their
Traumflug authored
347 #endif
2182d7b @triffid time to save, updated M253 read memory to accept a length, updated ut…
authored
348 ) {
aa590c4 @Traumflug Don't fail on unknown commands. For example, RepRap host sends T comm…
Traumflug authored
349 // process
209dfe6 @triffid prepare for protocol changes ie responses after ok instead of separat…
authored
350 serial_writestr_P(PSTR("ok "));
56c355c @triffid split gcode parse/process into separate files for readability
authored
351 process_gcode_command();
f8d8b2a @bjj gcode_parse.c: Send newline as char rather than PSTR
bjj authored
352 serial_writechar('\n');
aa590c4 @Traumflug Don't fail on unknown commands. For example, RepRap host sends T comm…
Traumflug authored
353
354 // expect next line number
355 if (next_target.seen_N == 1)
356 next_target.N_expected = next_target.N + 1;
ee4e71d @triffid preliminary support for line numbers and checksums, also some handy h…
authored
357 }
358 else {
72adba5 @triffid apparently repg expects N preceding line numbers in resend requests
authored
359 sersendf_P(PSTR("rs N%ld Expected checksum %d\n"), next_target.N_expected, next_target.checksum_calculated);
0dc7d77 @triffid Massive Doxygen documentation addition
authored
360 // request_resend();
ee4e71d @triffid preliminary support for line numbers and checksums, also some handy h…
authored
361 }
7326e17 @triffid misc tidying, added watchdog stuff, moved things around a bit
authored
362 }
aa590c4 @Traumflug Don't fail on unknown commands. For example, RepRap host sends T comm…
Traumflug authored
363 else {
72adba5 @triffid apparently repg expects N preceding line numbers in resend requests
authored
364 sersendf_P(PSTR("rs N%ld Expected line number %ld\n"), next_target.N_expected, next_target.N_expected);
0dc7d77 @triffid Massive Doxygen documentation addition
authored
365 // request_resend();
aa590c4 @Traumflug Don't fail on unknown commands. For example, RepRap host sends T comm…
Traumflug authored
366 }
ee4e71d @triffid preliminary support for line numbers and checksums, also some handy h…
authored
367
368 // reset variables
2004f04 @Traumflug An M-code stuck when receiving G commands and vice-versa.
Traumflug authored
369 next_target.seen_X = next_target.seen_Y = next_target.seen_Z = \
f5258ef @Traumflug Assume a G1 by default. This is expected by some GCode generators.
Traumflug authored
370 next_target.seen_E = next_target.seen_F = next_target.seen_S = \
096d7df @triffid Merge release-candidate-triffid branch
authored
371 next_target.seen_P = next_target.seen_T = next_target.seen_N = \
ec9e84a @Traumflug gcode_parse.c: assume G1 only for stuff which might actually move.
Traumflug authored
372 next_target.seen_G = next_target.seen_M = next_target.seen_checksum = \
373 next_target.seen_semi_comment = next_target.seen_parens_comment = \
374 next_target.checksum_read = next_target.checksum_calculated = 0;
03b52e0 @Traumflug gcode_parse.c: don't double-initialize last_field or read_digit.
Traumflug authored
375 // last_field and read_digit are reset above already
56c355c @triffid split gcode parse/process into separate files for readability
authored
376
9dda334 @Traumflug Revert the new relative handling for X, Y and Z.
Traumflug authored
377 if (next_target.option_all_relative) {
2871411 @Traumflug gcode.c: clarify relative coordinates handling. Saves another 82 bytes.
Traumflug authored
378 next_target.target.X = next_target.target.Y = next_target.target.Z = 0;
379 }
9dda334 @Traumflug Revert the new relative handling for X, Y and Z.
Traumflug authored
380 if (next_target.option_all_relative || next_target.option_e_relative) {
ae33cb7 @triffid start implementing absolute E support
authored
381 next_target.target.E = 0;
5f9ae5b @Traumflug Implement M82/M83 and handle relative movements entirely different.
Traumflug authored
382 }
1e6c740 @triffid tons of changes, implementing 4D dda
authored
383 }
384 }
385
096d7df @triffid Merge release-candidate-triffid branch
authored
386 /***************************************************************************\
ee4e71d @triffid preliminary support for line numbers and checksums, also some handy h…
authored
387 * *
0bd0848 @Traumflug Make resend requests RepRap host compatible, too.
Traumflug authored
388 * Request a resend of the current line - used from various places. *
389 * *
390 * Relies on the global variable next_target.N being valid. *
391 * *
096d7df @triffid Merge release-candidate-triffid branch
authored
392 \***************************************************************************/
0bd0848 @Traumflug Make resend requests RepRap host compatible, too.
Traumflug authored
393
81fd2c3 @Traumflug Fix a few warnings.
Traumflug authored
394 void request_resend(void) {
a565f31 @dpslwk Resend Request changed from "Resend:" to "rs "
dpslwk authored
395 serial_writestr_P(PSTR("rs "));
0bd0848 @Traumflug Make resend requests RepRap host compatible, too.
Traumflug authored
396 serwrite_uint8(next_target.N);
8468f22 @Traumflug Eliminate serial_writechar_P(). serial_writechar() perfoms better and
Traumflug authored
397 serial_writechar('\n');
0bd0848 @Traumflug Make resend requests RepRap host compatible, too.
Traumflug authored
398 }
Something went wrong with that request. Please try again.