|
@@ -21,24 +21,55 @@
|
21
|
21
|
*/
|
22
|
22
|
|
23
|
23
|
#include "../gcode.h"
|
|
24
|
+#include "../../core/serial.h"
|
24
|
25
|
|
25
|
26
|
/**
|
26
|
27
|
* M118: Display a message in the host console.
|
27
|
28
|
*
|
28
|
29
|
* A1 Prepend '// ' for an action command, as in OctoPrint
|
29
|
30
|
* E1 Have the host 'echo:' the text
|
|
31
|
+ * Pn Redirect to another serial port
|
|
32
|
+ * 0 : Announce to all ports
|
|
33
|
+ * 1-9 : Serial ports 1 to 9
|
30
|
34
|
*/
|
31
|
35
|
void GcodeSuite::M118() {
|
32
|
36
|
bool hasE = false, hasA = false;
|
|
37
|
+ #if NUM_SERIAL > 1
|
|
38
|
+ int8_t port = -1; // Assume no redirect
|
|
39
|
+ #endif
|
33
|
40
|
char *p = parser.string_arg;
|
34
|
|
- for (uint8_t i = 2; i--;)
|
35
|
|
- if ((p[0] == 'A' || p[0] == 'E') && p[1] == '1') {
|
36
|
|
- if (p[0] == 'A') hasA = true;
|
37
|
|
- if (p[0] == 'E') hasE = true;
|
38
|
|
- p += 2;
|
39
|
|
- while (*p == ' ') ++p;
|
|
41
|
+ for (uint8_t i = 3; i--;) {
|
|
42
|
+ // A1, E1, and Pn are always parsed out
|
|
43
|
+ if (!( ((p[0] == 'A' || p[0] == 'E') && p[1] == '1') || (p[0] == 'P' && NUMERIC(p[1])) )) break;
|
|
44
|
+ switch (p[0]) {
|
|
45
|
+ case 'A': hasA = true; break;
|
|
46
|
+ case 'E': hasE = true; break;
|
|
47
|
+ #if NUM_SERIAL > 1
|
|
48
|
+ case 'P': port = p[1] - '0'; break;
|
|
49
|
+ #endif
|
40
|
50
|
}
|
|
51
|
+ p += 2;
|
|
52
|
+ while (*p == ' ') ++p;
|
|
53
|
+ }
|
|
54
|
+
|
|
55
|
+ #if NUM_SERIAL > 1
|
|
56
|
+ const int8_t old_serial = serial_port_index;
|
|
57
|
+ if (WITHIN(port, 0, NUM_SERIAL))
|
|
58
|
+ serial_port_index = (
|
|
59
|
+ port == 0 ? SERIAL_BOTH
|
|
60
|
+ : port == 1 ? SERIAL_PORT
|
|
61
|
+ #ifdef SERIAL_PORT_2
|
|
62
|
+ : port == 2 ? SERIAL_PORT_2
|
|
63
|
+ #endif
|
|
64
|
+ : SERIAL_PORT
|
|
65
|
+ );
|
|
66
|
+ #endif
|
|
67
|
+
|
41
|
68
|
if (hasE) SERIAL_ECHO_START();
|
42
|
69
|
if (hasA) SERIAL_ECHOPGM("// ");
|
43
|
70
|
SERIAL_ECHOLN(p);
|
|
71
|
+
|
|
72
|
+ #if NUM_SERIAL > 1
|
|
73
|
+ serial_port_index = old_serial;
|
|
74
|
+ #endif
|
44
|
75
|
}
|