|
@@ -89,7 +89,7 @@ char GCodeQueue::command_buffer[BUFSIZE][MAX_CMD_SIZE];
|
89
|
89
|
* The port that the command was received on
|
90
|
90
|
*/
|
91
|
91
|
#if HAS_MULTI_SERIAL
|
92
|
|
- int16_t GCodeQueue::port[BUFSIZE];
|
|
92
|
+ serial_index_t GCodeQueue::port[BUFSIZE];
|
93
|
93
|
#endif
|
94
|
94
|
|
95
|
95
|
/**
|
|
@@ -136,11 +136,11 @@ void GCodeQueue::clear() {
|
136
|
136
|
*/
|
137
|
137
|
void GCodeQueue::_commit_command(bool say_ok
|
138
|
138
|
#if HAS_MULTI_SERIAL
|
139
|
|
- , int16_t p/*=-1*/
|
|
139
|
+ , serial_index_t serial_ind/*=-1*/
|
140
|
140
|
#endif
|
141
|
141
|
) {
|
142
|
142
|
send_ok[index_w] = say_ok;
|
143
|
|
- TERN_(HAS_MULTI_SERIAL, port[index_w] = p);
|
|
143
|
+ TERN_(HAS_MULTI_SERIAL, port[index_w] = serial_ind);
|
144
|
144
|
TERN_(POWER_LOSS_RECOVERY, recovery.commit_sdpos(index_w));
|
145
|
145
|
if (++index_w >= BUFSIZE) index_w = 0;
|
146
|
146
|
length++;
|
|
@@ -153,14 +153,14 @@ void GCodeQueue::_commit_command(bool say_ok
|
153
|
153
|
*/
|
154
|
154
|
bool GCodeQueue::_enqueue(const char* cmd, bool say_ok/*=false*/
|
155
|
155
|
#if HAS_MULTI_SERIAL
|
156
|
|
- , int16_t pn/*=-1*/
|
|
156
|
+ , serial_index_t serial_ind/*=-1*/
|
157
|
157
|
#endif
|
158
|
158
|
) {
|
159
|
159
|
if (*cmd == ';' || length >= BUFSIZE) return false;
|
160
|
160
|
strcpy(command_buffer[index_w], cmd);
|
161
|
161
|
_commit_command(say_ok
|
162
|
162
|
#if HAS_MULTI_SERIAL
|
163
|
|
- , pn
|
|
163
|
+ , serial_ind
|
164
|
164
|
#endif
|
165
|
165
|
);
|
166
|
166
|
return true;
|
|
@@ -289,9 +289,9 @@ void GCodeQueue::enqueue_now_P(PGM_P const pgcode) {
|
289
|
289
|
*/
|
290
|
290
|
void GCodeQueue::ok_to_send() {
|
291
|
291
|
#if HAS_MULTI_SERIAL
|
292
|
|
- const int16_t pn = command_port();
|
293
|
|
- if (pn < 0) return;
|
294
|
|
- PORT_REDIRECT(pn); // Reply to the serial port that sent the command
|
|
292
|
+ const serial_index_t serial_ind = command_port();
|
|
293
|
+ if (serial_ind < 0) return; // Never mind. Command came from SD or Flash Drive
|
|
294
|
+ PORT_REDIRECT(serial_ind); // Reply to the serial port that sent the command
|
295
|
295
|
#endif
|
296
|
296
|
if (!send_ok[index_r]) return;
|
297
|
297
|
SERIAL_ECHOPGM(STR_OK);
|
|
@@ -314,14 +314,14 @@ void GCodeQueue::ok_to_send() {
|
314
|
314
|
* indicate that a command needs to be re-sent.
|
315
|
315
|
*/
|
316
|
316
|
void GCodeQueue::flush_and_request_resend() {
|
317
|
|
- const int16_t pn = command_port();
|
|
317
|
+ const serial_index_t serial_ind = command_port();
|
318
|
318
|
#if HAS_MULTI_SERIAL
|
319
|
|
- if (pn < 0) return;
|
320
|
|
- PORT_REDIRECT(pn); // Reply to the serial port that sent the command
|
|
319
|
+ if (serial_ind < 0) return; // Never mind. Command came from SD or Flash Drive
|
|
320
|
+ PORT_REDIRECT(serial_ind); // Reply to the serial port that sent the command
|
321
|
321
|
#endif
|
322
|
322
|
SERIAL_FLUSH();
|
323
|
323
|
SERIAL_ECHOPGM(STR_RESEND);
|
324
|
|
- SERIAL_ECHOLN(last_N[pn] + 1);
|
|
324
|
+ SERIAL_ECHOLN(last_N[serial_ind] + 1);
|
325
|
325
|
ok_to_send();
|
326
|
326
|
}
|
327
|
327
|
|
|
@@ -348,14 +348,14 @@ inline int read_serial(const uint8_t index) {
|
348
|
348
|
}
|
349
|
349
|
}
|
350
|
350
|
|
351
|
|
-void GCodeQueue::gcode_line_error(PGM_P const err, const int8_t pn) {
|
352
|
|
- PORT_REDIRECT(pn); // Reply to the serial port that sent the command
|
|
351
|
+void GCodeQueue::gcode_line_error(PGM_P const err, const serial_index_t serial_ind) {
|
|
352
|
+ PORT_REDIRECT(serial_ind); // Reply to the serial port that sent the command
|
353
|
353
|
SERIAL_ERROR_START();
|
354
|
354
|
serialprintPGM(err);
|
355
|
|
- SERIAL_ECHOLN(last_N[pn]);
|
356
|
|
- while (read_serial(pn) != -1); // Clear out the RX buffer
|
|
355
|
+ SERIAL_ECHOLN(last_N[serial_ind]);
|
|
356
|
+ while (read_serial(serial_ind) != -1); // Clear out the RX buffer
|
357
|
357
|
flush_and_request_resend();
|
358
|
|
- serial_count[pn] = 0;
|
|
358
|
+ serial_count[serial_ind] = 0;
|
359
|
359
|
}
|
360
|
360
|
|
361
|
361
|
FORCE_INLINE bool is_M29(const char * const cmd) { // matches "M29" & "M29 ", but not "M290", etc
|
|
@@ -473,13 +473,13 @@ void GCodeQueue::get_serial_commands() {
|
473
|
473
|
* Loop while serial characters are incoming and the queue is not full
|
474
|
474
|
*/
|
475
|
475
|
while (length < BUFSIZE && serial_data_available()) {
|
476
|
|
- LOOP_L_N(i, NUM_SERIAL) {
|
|
476
|
+ LOOP_L_N(p, NUM_SERIAL) {
|
477
|
477
|
|
478
|
|
- const int c = read_serial(i);
|
|
478
|
+ const int c = read_serial(p);
|
479
|
479
|
if (c < 0) continue;
|
480
|
480
|
|
481
|
481
|
#if ENABLED(MEATPACK)
|
482
|
|
- meatpack.handle_rx_char(uint8_t(c));
|
|
482
|
+ meatpack.handle_rx_char(uint8_t(c), p);
|
483
|
483
|
char c_res[2] = { 0, 0 };
|
484
|
484
|
const uint8_t char_count = meatpack.get_result_char(c_res);
|
485
|
485
|
#else
|
|
@@ -492,10 +492,10 @@ void GCodeQueue::get_serial_commands() {
|
492
|
492
|
if (ISEOL(serial_char)) {
|
493
|
493
|
|
494
|
494
|
// Reset our state, continue if the line was empty
|
495
|
|
- if (process_line_done(serial_input_state[i], serial_line_buffer[i], serial_count[i]))
|
|
495
|
+ if (process_line_done(serial_input_state[p], serial_line_buffer[p], serial_count[p]))
|
496
|
496
|
continue;
|
497
|
497
|
|
498
|
|
- char* command = serial_line_buffer[i];
|
|
498
|
+ char* command = serial_line_buffer[p];
|
499
|
499
|
|
500
|
500
|
while (*command == ' ') command++; // Skip leading spaces
|
501
|
501
|
char *npos = (*command == 'N') ? command : nullptr; // Require the N parameter to start the line
|
|
@@ -511,25 +511,25 @@ void GCodeQueue::get_serial_commands() {
|
511
|
511
|
|
512
|
512
|
const long gcode_N = strtol(npos + 1, nullptr, 10);
|
513
|
513
|
|
514
|
|
- if (gcode_N != last_N[i] + 1 && !M110)
|
515
|
|
- return gcode_line_error(PSTR(STR_ERR_LINE_NO), i);
|
|
514
|
+ if (gcode_N != last_N[p] + 1 && !M110)
|
|
515
|
+ return gcode_line_error(PSTR(STR_ERR_LINE_NO), p);
|
516
|
516
|
|
517
|
517
|
char *apos = strrchr(command, '*');
|
518
|
518
|
if (apos) {
|
519
|
519
|
uint8_t checksum = 0, count = uint8_t(apos - command);
|
520
|
520
|
while (count) checksum ^= command[--count];
|
521
|
521
|
if (strtol(apos + 1, nullptr, 10) != checksum)
|
522
|
|
- return gcode_line_error(PSTR(STR_ERR_CHECKSUM_MISMATCH), i);
|
|
522
|
+ return gcode_line_error(PSTR(STR_ERR_CHECKSUM_MISMATCH), p);
|
523
|
523
|
}
|
524
|
524
|
else
|
525
|
|
- return gcode_line_error(PSTR(STR_ERR_NO_CHECKSUM), i);
|
|
525
|
+ return gcode_line_error(PSTR(STR_ERR_NO_CHECKSUM), p);
|
526
|
526
|
|
527
|
|
- last_N[i] = gcode_N;
|
|
527
|
+ last_N[p] = gcode_N;
|
528
|
528
|
}
|
529
|
529
|
#if ENABLED(SDSUPPORT)
|
530
|
530
|
// Pronterface "M29" and "M29 " has no line number
|
531
|
531
|
else if (card.flag.saving && !is_M29(command))
|
532
|
|
- return gcode_line_error(PSTR(STR_ERR_NO_CHECKSUM), i);
|
|
532
|
+ return gcode_line_error(PSTR(STR_ERR_NO_CHECKSUM), p);
|
533
|
533
|
#endif
|
534
|
534
|
|
535
|
535
|
//
|
|
@@ -547,7 +547,7 @@ void GCodeQueue::get_serial_commands() {
|
547
|
547
|
#if ENABLED(BEZIER_CURVE_SUPPORT)
|
548
|
548
|
case 5:
|
549
|
549
|
#endif
|
550
|
|
- PORT_REDIRECT(i); // Reply to the serial port that sent the command
|
|
550
|
+ PORT_REDIRECT(p); // Reply to the serial port that sent the command
|
551
|
551
|
SERIAL_ECHOLNPGM(STR_ERR_STOPPED);
|
552
|
552
|
LCD_MESSAGEPGM(MSG_STOPPED);
|
553
|
553
|
break;
|
|
@@ -569,14 +569,14 @@ void GCodeQueue::get_serial_commands() {
|
569
|
569
|
#endif
|
570
|
570
|
|
571
|
571
|
// Add the command to the queue
|
572
|
|
- _enqueue(serial_line_buffer[i], true
|
|
572
|
+ _enqueue(serial_line_buffer[p], true
|
573
|
573
|
#if HAS_MULTI_SERIAL
|
574
|
|
- , i
|
|
574
|
+ , p
|
575
|
575
|
#endif
|
576
|
576
|
);
|
577
|
577
|
}
|
578
|
578
|
else
|
579
|
|
- process_stream_char(serial_char, serial_input_state[i], serial_line_buffer[i], serial_count[i]);
|
|
579
|
+ process_stream_char(serial_char, serial_input_state[p], serial_line_buffer[p], serial_count[p]);
|
580
|
580
|
|
581
|
581
|
} // char_count loop
|
582
|
582
|
|