M118 multiserial support (#15176)

This commit is contained in:
Lucio Tarantino 2019-09-08 07:57:59 +02:00 committed by Scott Lahteine
parent dbee0e9c54
commit 8ac52aedff

View File

@ -21,24 +21,55 @@
*/ */
#include "../gcode.h" #include "../gcode.h"
#include "../../core/serial.h"
/** /**
* M118: Display a message in the host console. * M118: Display a message in the host console.
* *
* A1 Prepend '// ' for an action command, as in OctoPrint * A1 Prepend '// ' for an action command, as in OctoPrint
* E1 Have the host 'echo:' the text * E1 Have the host 'echo:' the text
* Pn Redirect to another serial port
* 0 : Announce to all ports
* 1-9 : Serial ports 1 to 9
*/ */
void GcodeSuite::M118() { void GcodeSuite::M118() {
bool hasE = false, hasA = false; bool hasE = false, hasA = false;
#if NUM_SERIAL > 1
int8_t port = -1; // Assume no redirect
#endif
char *p = parser.string_arg; char *p = parser.string_arg;
for (uint8_t i = 2; i--;) for (uint8_t i = 3; i--;) {
if ((p[0] == 'A' || p[0] == 'E') && p[1] == '1') { // A1, E1, and Pn are always parsed out
if (p[0] == 'A') hasA = true; if (!( ((p[0] == 'A' || p[0] == 'E') && p[1] == '1') || (p[0] == 'P' && NUMERIC(p[1])) )) break;
if (p[0] == 'E') hasE = true; switch (p[0]) {
case 'A': hasA = true; break;
case 'E': hasE = true; break;
#if NUM_SERIAL > 1
case 'P': port = p[1] - '0'; break;
#endif
}
p += 2; p += 2;
while (*p == ' ') ++p; while (*p == ' ') ++p;
} }
#if NUM_SERIAL > 1
const int8_t old_serial = serial_port_index;
if (WITHIN(port, 0, NUM_SERIAL))
serial_port_index = (
port == 0 ? SERIAL_BOTH
: port == 1 ? SERIAL_PORT
#ifdef SERIAL_PORT_2
: port == 2 ? SERIAL_PORT_2
#endif
: SERIAL_PORT
);
#endif
if (hasE) SERIAL_ECHO_START(); if (hasE) SERIAL_ECHO_START();
if (hasA) SERIAL_ECHOPGM("// "); if (hasA) SERIAL_ECHOPGM("// ");
SERIAL_ECHOLN(p); SERIAL_ECHOLN(p);
#if NUM_SERIAL > 1
serial_port_index = old_serial;
#endif
} }