Browse Source

G-code line number for each serial port (for TFTs) (#18165)

vanilla_fb_2.0.x
Mark Scammacca 4 years ago
committed by GitHub
parent
commit
7119596170
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 5
      Marlin/src/gcode/host/M110.cpp
  2. 17
      Marlin/src/gcode/queue.cpp
  3. 13
      Marlin/src/gcode/queue.h

5
Marlin/src/gcode/host/M110.cpp

@ -27,5 +27,8 @@
* M110: Set Current Line Number
*/
void GcodeSuite::M110() {
if (parser.seenval('N')) queue.last_N = parser.value_long();
if (parser.seenval('N'))
queue.last_N[queue.command_port()] = parser.value_long();
}

17
Marlin/src/gcode/queue.cpp

@ -52,7 +52,7 @@ GCodeQueue queue;
* sending commands to Marlin, and lines will be checked for sequentiality.
* M110 N<int> sets the current line number.
*/
long gcode_N, GCodeQueue::last_N;
long GCodeQueue::last_N[NUM_SERIAL];
/**
* GCode Command Queue
@ -277,7 +277,7 @@ void GCodeQueue::enqueue_now_P(PGM_P const pgcode) {
*/
void GCodeQueue::ok_to_send() {
#if NUM_SERIAL > 1
const int16_t pn = port[index_r];
const int16_t pn = command_port();
if (pn < 0) return;
PORT_REDIRECT(pn); // Reply to the serial port that sent the command
#endif
@ -302,14 +302,15 @@ void GCodeQueue::ok_to_send() {
* indicate that a command needs to be re-sent.
*/
void GCodeQueue::flush_and_request_resend() {
const int16_t pn = command_port();
#if NUM_SERIAL > 1
const int16_t pn = port[index_r];
if (pn < 0) return;
PORT_REDIRECT(pn); // Reply to the serial port that sent the command
#endif
SERIAL_FLUSH();
SERIAL_ECHOPGM(STR_RESEND);
SERIAL_ECHOLN(last_N + 1);
SERIAL_ECHOLN(last_N[pn] + 1);
ok_to_send();
}
@ -336,7 +337,7 @@ void GCodeQueue::gcode_line_error(PGM_P const err, const int8_t pn) {
PORT_REDIRECT(pn); // Reply to the serial port that sent the command
SERIAL_ERROR_START();
serialprintPGM(err);
SERIAL_ECHOLN(last_N);
SERIAL_ECHOLN(last_N[pn]);
while (read_serial(pn) != -1); // Clear out the RX buffer
flush_and_request_resend();
serial_count[pn] = 0;
@ -475,9 +476,9 @@ void GCodeQueue::get_serial_commands() {
if (n2pos) npos = n2pos;
}
gcode_N = strtol(npos + 1, nullptr, 10);
const long gcode_N = strtol(npos + 1, nullptr, 10);
if (gcode_N != last_N + 1 && !M110)
if (gcode_N != last_N[i] + 1 && !M110)
return gcode_line_error(PSTR(STR_ERR_LINE_NO), i);
char *apos = strrchr(command, '*');
@ -490,7 +491,7 @@ void GCodeQueue::get_serial_commands() {
else
return gcode_line_error(PSTR(STR_ERR_NO_CHECKSUM), i);
last_N = gcode_N;
last_N[i] = gcode_N;
}
#if ENABLED(SDSUPPORT)
// Pronterface "M29" and "M29 " has no line number

13
Marlin/src/gcode/queue.h

@ -35,7 +35,8 @@ public:
* commands to Marlin, and lines will be checked for sequentiality.
* M110 N<int> sets the current line number.
*/
static long last_N;
static long last_N[NUM_SERIAL];
/**
* GCode Command Queue
@ -51,13 +52,21 @@ public:
static char command_buffer[BUFSIZE][MAX_CMD_SIZE];
/*
/**
* The port that the command was received on
*/
#if NUM_SERIAL > 1
static int16_t port[BUFSIZE];
#endif
static int16_t command_port() {
return (0
#if NUM_SERIAL > 1
+ port[index_r]
#endif
);
}
GCodeQueue();
/**

Loading…
Cancel
Save