Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Re-Organize Serial Port Output #16687

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Marlin/src/core/serial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ static const char errormagic[] PROGMEM = "Error:";
static const char echomagic[] PROGMEM = "echo:";

#if NUM_SERIAL > 1
int8_t serial_port_index = SERIAL_PORT;
int8_t serial_port_index = 0;
Copy link
Member

@thinkyhead thinkyhead Jan 27, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whatever value is set here will act as the default serial port for all output. 0 is SERIAL_PORT, 1 is SERIAL_PORT_2 and 0x7F will cause all general output to go to both serial ports. This is guaranteed because all changes to serial_port_index are temporary; it is always reset back to this initial value after the current g-code command completes.

#endif

void serialprintPGM(PGM_P str) {
Expand Down
17 changes: 8 additions & 9 deletions Marlin/src/gcode/queue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,6 @@ bool GCodeQueue::process_injected_command() {
// Execute command if non-blank
if (i) {
parser.parse(cmd);
PORT_REDIRECT(SERIAL_PORT);
thinkyhead marked this conversation as resolved.
Show resolved Hide resolved
gcode.process_parsed_command();
}
return true;
Expand Down Expand Up @@ -243,7 +242,7 @@ void GCodeQueue::ok_to_send() {
#if NUM_SERIAL > 1
const int16_t pn = port[index_r];
if (pn < 0) return;
PORT_REDIRECT(pn);
PORT_REDIRECT(pn); // Reply to the serial port that sent the command
#endif
if (!send_ok[index_r]) return;
SERIAL_ECHOPGM(MSG_OK);
Expand All @@ -267,9 +266,9 @@ void GCodeQueue::ok_to_send() {
*/
void GCodeQueue::flush_and_request_resend() {
#if NUM_SERIAL > 1
const int16_t p = port[index_r];
if (p < 0) return;
PORT_REDIRECT(p);
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(MSG_RESEND);
Expand All @@ -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) {
PORT_REDIRECT(port);
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);
while (read_serial(port) != -1); // clear out the RX buffer
while (read_serial(pn) != -1); // Clear out the RX buffer
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
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/gcode/queue.h
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ class GCodeQueue {
*/
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);

};

Expand Down