Fix serial port redirection (index ≠ port num) (#16687)

This commit is contained in:
Robby Candra 2020-01-27 11:46:26 +07:00 committed by Scott Lahteine
parent 2325bede8a
commit a0a93e35ae
3 changed files with 10 additions and 11 deletions

View file

@ -29,7 +29,7 @@ static const char errormagic[] PROGMEM = "Error:";
static const char echomagic[] PROGMEM = "echo:"; static const char echomagic[] PROGMEM = "echo:";
#if NUM_SERIAL > 1 #if NUM_SERIAL > 1
int8_t serial_port_index = SERIAL_PORT; int8_t serial_port_index = 0;
#endif #endif
void serialprintPGM(PGM_P str) { void serialprintPGM(PGM_P str) {

View file

@ -191,7 +191,6 @@ bool GCodeQueue::process_injected_command() {
// Execute command if non-blank // Execute command if non-blank
if (i) { if (i) {
parser.parse(cmd); parser.parse(cmd);
PORT_REDIRECT(SERIAL_PORT);
gcode.process_parsed_command(); gcode.process_parsed_command();
} }
return true; return true;
@ -243,7 +242,7 @@ void GCodeQueue::ok_to_send() {
#if NUM_SERIAL > 1 #if NUM_SERIAL > 1
const int16_t pn = port[index_r]; const int16_t pn = port[index_r];
if (pn < 0) return; if (pn < 0) return;
PORT_REDIRECT(pn); PORT_REDIRECT(pn); // Reply to the serial port that sent the command
#endif #endif
if (!send_ok[index_r]) return; if (!send_ok[index_r]) return;
SERIAL_ECHOPGM(MSG_OK); SERIAL_ECHOPGM(MSG_OK);
@ -267,9 +266,9 @@ void GCodeQueue::ok_to_send() {
*/ */
void GCodeQueue::flush_and_request_resend() { void GCodeQueue::flush_and_request_resend() {
#if NUM_SERIAL > 1 #if NUM_SERIAL > 1
const int16_t p = port[index_r]; const int16_t pn = port[index_r];
if (p < 0) return; if (pn < 0) return;
PORT_REDIRECT(p); PORT_REDIRECT(pn); // Reply to the serial port that sent the command
#endif #endif
SERIAL_FLUSH(); SERIAL_FLUSH();
SERIAL_ECHOPGM(MSG_RESEND); SERIAL_ECHOPGM(MSG_RESEND);
@ -296,14 +295,14 @@ inline int read_serial(const uint8_t index) {
} }
} }
void GCodeQueue::gcode_line_error(PGM_P const err, const int8_t port) { void GCodeQueue::gcode_line_error(PGM_P const err, const int8_t pn) {
PORT_REDIRECT(port); PORT_REDIRECT(pn); // Reply to the serial port that sent the command
SERIAL_ERROR_START(); SERIAL_ERROR_START();
serialprintPGM(err); serialprintPGM(err);
SERIAL_ECHOLN(last_N); SERIAL_ECHOLN(last_N);
while (read_serial(port) != -1); // clear out the RX buffer while (read_serial(pn) != -1); // Clear out the RX buffer
flush_and_request_resend(); flush_and_request_resend();
serial_count[port] = 0; serial_count[pn] = 0;
} }
FORCE_INLINE bool is_M29(const char * const cmd) { // matches "M29" & "M29 ", but not "M290", etc FORCE_INLINE bool is_M29(const char * const cmd) { // matches "M29" & "M29 ", but not "M290", etc

View file

@ -150,7 +150,7 @@ private:
*/ */
static bool enqueue_one(const char* cmd); static bool enqueue_one(const char* cmd);
static void gcode_line_error(PGM_P const err, const int8_t port); static void gcode_line_error(PGM_P const err, const int8_t pn);
}; };